Re: groups of values from an array



On Jan 29, 2008 10:28 AM, Horvath, Peter <phorvath@xxxxxxxxxxxx> 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"
}
}
.



Relevant Pages

  • Re: How to list the statement of all var ?
    ... > of an object when the question was about `var' statements? ... And as soon as i will test it for this particular host ... to use an Object object instead of an Array object. ...
    (comp.lang.javascript)
  • Re: Great SWT Program
    ... These lines are the output of a directory-listing command and are ... With typical Windows tools, one can select a block of ... the editor you don't even have the benefit of whatever autocomplete ...
    (comp.lang.java.programmer)
  • Re: Warning on assigning a function-returning-a-pointer-to-arrays
    ... reminder that it's a pointer and not merely a locally declared array ... That would indicate a bug in the compiler, ... int main{ ...
    (comp.lang.c)
  • Re: Name change
    ... nearly impossible to uninstall, so I'm a bit wary about giving it a go. ... hard to scrape off the walls if the uninstall or make uninstall command ... when it shuts down - startup's quick (RAM check aside), ...
    (uk.people.support.depression)
  • Re: (some) Old Templars do not die/Long and Speculative
    ... but the leadership was composed entirely of (French) knights.... ... But not inventors. ... in command of the strategy in Outremer. ...
    (soc.history.medieval)