B
Brian McCauley
sam said:Is the following "legal" and "sensible?"
while(<LOGFILE>) {
undef($splinter);
@record = split;
$archivesection = $record[6];
($interestingpart, $junk) = split(/\?/,$archivesection,2);
$userid = $searchpattern{$interestingpart} && $splinter =
$_, last if(defined($searchpattern{$interestingpart}))
if (defined($splinter) &&
(&daily || &weekly || &monthly || &yearly)) {
&add_splinter_to_pile;
}
}
While it is legal to fail to declare all your variables as lexically
scoped in the smallest applicable scope it is cetainly not sensible to
do so without a positive reason.
While it is legal to use the Perl4 subroutine calling convention is not
sensible to do so without a positive reason.
While it is legal to use shared variables to pass information between a
subroutine and its caller is not sensible to do so without a positive
reason.
It is legal to save the result of a short expression into a variable
whose name is longer than the expression and then only use that variable
once ($archivesection,@record). It is, of course, not sensible.
It is legal to store data you don't want into a variable you never use
again ($junk). It is, of course, not sensible. (Just don't save it).
It is legal to use && and , to combine multiple expressions into one so
that they can be goverened by a single 'if' statement qualifier. It
can sometimes even be sensible to do so where it aid readability.
It is not legal to attempt to assign to the result of an && opreator. To
get "Can't modify logical and (&&) in scalar assignment".
I shall assume '&&' should read 'and' or ','.
However once it gets above a very small number of characters it would be
more sensible just to use a proper 'if' statement.
It is legal to have a variable with a name (%searchpattern) that doesn't
contain patterns. It is not sensible.
While it is legal to put unreachable code in your programs it is rarely
sensible. I'm 98% sure that condition defined($splinter) can never be
true. If you eschewed the obfuscatation this would be more obvious.