in reply to On being 'critical'
There's another reason for using the three-arg open. Consider the following statement:
open(my $handle, $filename) or die "Unable to open $filename: $!";This may look OK but it really isn't, especially if $filename is part of the user input. Consider what happens if $filename is "|rm -rf *". This actually does execute rm -rf *, try it out (well, use echo or something a little safer instead). The three-arg open doesn't suffer from this problem:
open(my $handle, '<', $filename) or die "Unable to open $filename: $!"If $filename eq "|rm -rf *" it'll try to open a file named "|rm -rf *" (which will probably fail) and won't clobber your directory.
Your code doesn't suffer so much from this problem, because you explicitly tell open how you want the file opened. In any case the three-arg open is vastly preferable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: On being 'critical'
by bart (Canon) on Dec 14, 2006 at 21:04 UTC | |
by BrowserUk (Patriarch) on Dec 14, 2006 at 23:16 UTC | |
by ikegami (Patriarch) on Dec 15, 2006 at 00:26 UTC | |
by BrowserUk (Patriarch) on Dec 15, 2006 at 01:21 UTC | |
by pjf (Curate) on Dec 17, 2006 at 06:55 UTC | |
by Sartak (Hermit) on Dec 15, 2006 at 07:22 UTC | |
| |
by bart (Canon) on Dec 15, 2006 at 18:51 UTC | |
by diotalevi (Canon) on Dec 15, 2006 at 19:30 UTC |