Shlomi Fish wrote:
Hi all,
Hello,
after being tired of telling Perl newcomers about the same problems with their
code times and times again, I've decided to create this page detailing "Perl
Elements to avoid":
http://perl-begin.org/tutorials/bad-elements/
<QUOTE>
the ultimately wrong, insecure and/or outdated styles are:
# Bareword filehandle (type glob), two arguments open (insecure) and no
# error handling
open INPUT, "<$filename";
</QUOTE>
You say "outdated styles" implying more than one example but you don't
show the other style i.e.:
use vars qw/ $INPUT /;
our $INPUT = $filename;
open INPUT;
You say "wrong" and "insecure" which is incorrect if the file name is
prefixed and postfixed correctly, as described in the documentation.
$filename = "./$filename\0";
<QUOTE>
Make sure you never use bareword here documents <<EOF which are valid
syntax, but people are never sure whether they are <<"EOF" or <<`EOF`.
</QUOTE>
I am a "people" and I am very sure that <<EOF is exactly the same as
<<"EOF". And EOF is usually short for End-Of-File so why use it for a
string delimiter?
<QUOTE>
Slurping a file (i.e: Reading it all into memory)
</QUOTE>
You are missing some other examples:
read $fh, my $contents, -s $fh;
sysread $fh, my $contents, -s $fh;
<QUOTE>
sub my_func
{
my ($prefix, $array_ref) = @_;
foreach my $item (@{$array_ref})
{
print $prefix, ": ", $item, "\n";
}
return;
}
</QUOTE>
Why use a loop to print a list?
sub my_func
{
my ($prefix, $array_ref) = @_;
print $prefix, join( ": ", @$array_ref ), "\n";
return;
}
<QUOTE>
An arbitrary C-style loop can be replaced with a while loop with a
continue block.
</QUOTE>
For example?
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/