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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |