Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: reading array elements

by Erez (Curate)
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.


Comment on Re: reading array elements
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-10-23 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (129 votes), past polls