CC Em has asked for the wisdom of the Perl Monks concerning the following question:

I have to following two statments:
new IO::File ("> $someFile"); IO::File -> new("> $someFile");
What is the difference between using one syntax over the other? Or is this merely a difference between Perl versions?

Updated: added code tags

Replies are listed 'Best First'.
Re: Calling Perl Modules
by dragonchild (Archbishop) on Apr 08, 2005 at 14:54 UTC
    The first is called the indirect syntax and the second is the direct syntax. The direct syntax is preferable over the indirect syntax, and should be used in all cases. The indirect syntax can cause very hard to find bugs in certain situations.

    In an unrelated note, you should open your files as so:

    my $fh = IO::File->new( '>', $someFile ) or die "Cannot open '$someFile': $!\n";

    That will protect against any craziness within the filename and will guarantee that the filename will work on all systems as the OS intends, including preserving whitespace and NULL characters, as appropriate.

      What then is the difference in interpretation using single quotes and double quotes?
      ('r', $someFile) #vs. ("< $someFile")

      Updated:added code tags

        Double quotes allows variable interpolation. Single quotes don't. See To Single Quote or to Double Quote for a longer discussion of people choosing one over the other, and see which reasons you like better. I posted my opinion there, too, which you can take or leave as you see fit ;-)

        It has nothing to do with single-quotes vs. double-quotes. It has to do with the difference between two-arg open() and 3-arg open().