On Jan 29, 2008 10:28 AM, Horvath, Peter <[EMAIL PROTECTED]> wrote:
> You are correct. It is a command that I put to an array. I try to work
> with the while loop. Thank you for the guidance.
snip

I assume by "a command that I put to an array" you mean you are doing
something like

my @lines = `somecommand`;

To get a file handle for this do

open my $fh, "-|", "somecommand"
    or die "could not get a file handle for the command somecommand: $!";

After that point you can use the code I sent you (if you replace DATA
with $fh).  You may also find it useful to access your records as a
hash like this

#!/sur/bin/perl

use strict;
use warnings;

open my $fh, "-|", "somecommand"
    or die "could not get a file handle for the command somecommand: $!";

{
       local $/ = ("=" x 80) . "\n"; #set the record separtor
       while (my $rec = <$fh>) {
               chomp($rec); #remove record separator
               next unless length($rec); #skip empty records
               my %record = map { /(.*?):\s+(.*)/ } split /\n/, $rec;
               print "$record{'media ID'} is in pool $record{'volume pool'}\n"
       }
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to