Hi,

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


In reply to How is outputting to an array different from outputting to a file by kirk123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.