Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: reading array elements

by Erez (Priest)
on Nov 26, 2008 at 10:07 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://726057]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found