kirk123 has asked for the wisdom of the Perl Monks concerning the following question:
I am getting different result from accessing an array as oppose to reading from a file.
Earlier I was executing a unix command and reading the result like this:
------system("lpstat -v -d -p -l -D >junk.txt"); open RI,"<junk.txt" || die "Can't open junk.txt for reading:$!\n"; my $data = do { local $/; <RI> }; # or however you load it. my( %device, %system ); for ( split /\n(?=\S)/, $data ) { if( /^device for (.*?):.*?\1$/ ) { $device{$1} = $1; } elsif ( /^system for (.*?): (\S+)/ ) { $system{$1} = $2; }
But now I want to avoid opening and reading from a file so I use an array instead:
my @output =`lpstat -o -v -d -p -l -D`;. my( %device, %system ); foreach my $line (@output) { chomp $line; for ( split /\n(?=\S)/, $line ) { if (/^system default/) { @test = split(/ /); chomp($test[3]); print "$test[3]|\n"; } if( /^device for (.*?):.*?\1$/ ) { $device{$1} = $1; } elsif ( /^system for (.*?): (\S+)/ ) { $system{$1} = $2; }
----
--
But by using an array I am getting a different answer than what I am getting by using a file.
How can I change my "array" code so that it works just like reading a file.
--thanks kirk123
20030218 Edit by Corion : Added formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How is outputting to an array different from outputting to a file
by mojotoad (Monsignor) on Feb 17, 2003 at 01:02 UTC | |
|
Re: How is outputting to an array different from outputting to a file
by blokhead (Monsignor) on Feb 17, 2003 at 01:04 UTC | |
|
Re: How is outputting to an array different from outputting to a file
by graff (Chancellor) on Feb 17, 2003 at 02:10 UTC | |
|
Re: How is outputting to an array different from outputting to a file
by dws (Chancellor) on Feb 17, 2003 at 01:32 UTC | |
|
Re: How is outputting to an array different from outputting to a file
by manux (Initiate) on Feb 18, 2003 at 14:08 UTC |