Re: Perl script does not work



"A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx> wrote:

While '>temp.txt' is quite safe, with "<$file", $file is interpolated.
That interpolation can have unintended effects.

My bad, I hadn't seen the OPs "<$file". I read it as: use

open my $fh, '<', $filename ...

I prefer:

open my $fh, $filename ...

Unless:

In the OP's case, there is no guarantee on what characters may appear in
the filename. In that particular case, perldoc -f open specifically
recommends the 3-argument form:

[...]

If the OP had limited the possible filenames to be processed by
filtering them in some way, I would not have made the recommendation.

Therefore, I find it better to stick with the three argument form unless
there is a specific reason to prefer the two argument form.

clear, thanks. Should have had a better peek at the OP's post, apologies.

--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
.



Relevant Pages

  • Re: Perl script does not work
    ... This is Pyth^W the New Perl. ... there is no guarantee on what characters may appear in ... the filename. ... recommends the 3-argument form: ...
    (comp.lang.perl.misc)
  • Re: Hello and a question
    ... They like you to bottom post of this list. ... hard work is done by split which will breaks the filename into two ... perldoc -f -X #' for info on file tests ...
    (perl.beginners)
  • RE: how the print the first 7 letter of file name
    ... Your solution will return only the first 7 characters of the filename. ... This happens to be "NewProcess". ... perldoc -q "What is the difference between a list and an array?" ... E-mail transmission cannot be guaranteed to be secure or error-free ...
    (perl.beginners)
  • Re: filehandles
    ... "readlineon closed filehandle FILENAME at ..." ... You _should_ have used the strict pragma which ... would have complained to you that $file and @protein aren't ... or "perldoc perldoc" if you wonder about that perldoc ...
    (comp.lang.perl.misc)
  • Re: Help with globbing
    ... >I've read what I could find on filename globbing and can't seem to get ... foreach $fileName ... You should read about dirhandles and regular expressions in the perl ... perldoc -f opendir ...
    (comp.lang.perl.misc)