Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Using open in for loop

by grep (Monsignor)
on Jun 14, 2007 at 14:06 UTC ( #621238=note: print w/ replies, xml ) Need Help??


in reply to Using open in for loop

That is not perl code. It won't even compile.

I assume you mean something more like this:

use strict; use warnings; my @array = qw/ foo bar baz blah /; for(my $i = 0; $i < @array; $i++) { print "$i $array[$i]\n"; }
Which is fine but this is better:
use strict; use warnings; my @array = qw/ foo bar baz blah /; foreach my $filename (@array) { print "$filename\n"; }

Please notice I added use strict; and use warnings these are a MUST when you are learning perl.

Also notice I did not use the actual open - I simplified to find the real root of the problem

grep
1)Gain XP 2)??? 3)Profit


Comment on Re: Using open in for loop
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2015-07-29 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls