in reply to Using open in for loop

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: Using open in for loop
by grep (Monsignor) on Jun 14, 2007 at 15:16 UTC
    The answers you are looking for are in my previous post

    • Add use strict; and use warnings; - Make your code work with them.
    • Simplify and print out
      print "$array[$i]\n"; #open(FILE,"$array[$i]") or die "Could not open file :$!"; # do something #close(FILE);

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

Re^2: Using open in for loop
by blazar (Canon) on Jun 15, 2007 at 11:02 UTC
    open(FILE,"$_") or die " Could not open file :$! " ;

    In addition to everything else that has been said, the oft and rightly so repeated mantra is:

    • use lexical filehandles;
    • use the three args form of open;
    • (include relevant info in the error message.)

    To which I add: "$_" is called "useless use of quotes." Thus:

    open my $file, '<', $_ or die "Could not open `$_': $!\n";