in reply to File open problem with "GLOB"

Instead of

my $output = new OUTFILE ('>C:\Program Files\cron\Cruise Ships\ship_da +ta.csv'); open (OUTFILE, '>C:\Program Files\cron\Cruise Ships\ship_data.csv'); # and later print (OUTFILE $input);
say
open my $output, '>', q{C:\Program Files\cron\Cruise Ships\ship_data.c +sv}; # and later print {$output} $input;

Replies are listed 'Best First'.
Re^2: File open problem with "GLOB"
by ikegami (Patriarch) on Mar 15, 2008 at 22:36 UTC
    No need for the curlies around $output in the print statement.

      They disambiguate the one use of the horrid indirect object syntax that you can't easily avoid in Perl 5. (I know about IO::Handle, but it's even further away from the principle of least surprise.)

        Yes, but there's no need to disambiguate with print when the handle is nothing more than a bareword or a simple scalar. For the very common use of print HANDLE LIST and print $fh LIST, there's no need for curlies. Given how much Perl programmers are familiar with the lack of curlies in those instances, the curlies do nothing to promote readability, maintainability or simplicity.

      theDamian, Perl Best Practices, Chapter 10: IO

      Printing to Filehandles

      Always put filehandles in braces within any print statement.

        Just because Damian Conway says it, that does not mean it's helpful or true. He has released a slew of really crap modules just for the book like Getopt::Euclid, Class::Std and IO::Prompt. The book recommends their use, even though they are buggy and unmaintained. By your "argumentation" we should be using them.

        If you want to argue for a guideline, and I believe Damian Conway says this in his book as well, you need to discuss the benefits over its drawbacks. Like blocks and using braces around filehandles with print does. Simply citing verse and chapter of a book that has many flaws does not help your argument.

      Dear brethren, I had the good fortune yesterday to spot an unanswered Seeker query to which I knew the answer. As I wrote my reply, I strove to be helpful, correct, but above all quick.

      There are details I might have done differently. The querent said

      '>C:\Program Files\cron\Cruise Ships\ship_data.csv'
      and when I converted to three-arg open I could have left the filename at
      'C:\Program Files\cron\Cruise Ships\ship_data.csv'
      or converted to
      'C:/Program Files/cron/Cruise Ships/ship_data.csv'
      because (as all Windows Perl programmers should be told) forward slashes work just fine for telling Windows where to go, and can never be mistakenly parsed as escapes, and I'd rather not spend any time at all thinking about when a backslash is an escape and when it isn't.

      I could also have changed $output to $output_fh and $input to $input_data, but chose instead to retain the querent's own variable names.

      Others would certainly have made different choices. I'm still surprised that the particular nit that was picked was the pair of braces around the filehandle in

      print {$output} $input;