in reply to Re: Which way is recommended ?
in thread Which way is recommended ?

Thanks for the reply
So, for one-off codes/small codes it doesn't make sense right? Any form could be used.

Replies are listed 'Best First'.
Re^3: Which way is recommended ?
by gwadej (Chaplain) on Nov 21, 2008 at 19:06 UTC

    I would suggest that using the lexical variable for the filehandle is a good idea even in small one-off scripts. A very wise person once told me

    There is nothing more permanent than temporary code.

    Quite often quick-and-dirty scripts grow and become critical. Also, using the lexical filehandles is a good habit to cultivate.

    On the other hand, I often prefer to use $_ rather than an explicit variable in small loops. For me that's more of a style issue than anything else.

    G. Wade
Re^3: Which way is recommended ?
by jeffa (Bishop) on Nov 21, 2008 at 18:52 UTC

    Exactly. If you are feeling (over)confident you can just code this:

    open (FILE, $filename) or die $!; print while <FILE>;

    Or on the command line:

    perl -pe '$_' file.txt

    UPDATE: thanks for the correction, quester

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Pardon me, but even one liners need to enable warnings...
      $ perl -wpe '$_' file.txt Useless use of a variable in void context at -e line 1. ...
      It should actually just be
      $ perl -wpe '' file.txt