Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: reading array elements

by Erez (Priest)
on Nov 26, 2008 at 10:07 UTC ( #726057=note: print w/replies, xml ) Need Help??

in reply to reading array elements

I'd like to know why lines 9 & 10 in my script have to have $_ instead of $in

Because you wrote it that way?

The idiom while (<FH>) implicitely assign each line read to $_. In essence, what you were probably aiming for is

foreach my $in (<$datfh>)
then use $in instead of $_ in your script. You also don't need next or last, unless you want to force flow control to act differently than it usually does, which brings me to:

Instead of traversing left to right until end of line, then processing the next line until the end of the file; the script processes the ith element of each line only, bypassing the other elements of each line.

No, it does exactly that, only you request it to pick only the 11th element (my $i = 11; then print $fields[$i]). If you want to print all the splitted parts of the line, just say print join "\n", @fields;

"A core tenant of the greater Perl philosophy is to trust that the developer knows enough to solve the problem" - Jay Shirley, A case for Catalyst.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://726057]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2018-06-21 13:04 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.