in reply to Re: problem using seek on some systems
in thread problem using seek on some systems

thank you very much sir. what's the benefit of using lexical variables and 3-arg opens over the old way of doing things?
  • Comment on Re^2: problem using seek on some systems

Replies are listed 'Best First'.
Re^3: problem using seek on some systems
by ikegami (Patriarch) on Dec 06, 2006 at 22:59 UTC

    Lexical variables have a tighter scope than package variables. There are numerous advantages to limiting the scope of a variable. Predominantly, your handle will be closed if even if you don't execute the block to its end.

    Reasons not to use a lexical variable for a file handle: Supporting Perl versions older than 5.6.0.

    The 3-arg open can open files 2-arg open can't open. The 3-arg open is not subject to the injection bugs and attacks to which 2-arg open is vulnerable.

    Reasons not to 3-arg open. Wanting to open STDIN/STDOUT using '-'. Wanting to work file descriptors. Wanting to open a pipe.