Hi all,
in reflection about Gabor’s talk yesterday, I’ve been spending some time
refactoring the code of the Config::IniFiles CPAN module, of which I am a
co-maintainer, and which I adopted because I’ve made use of it for one project.
While doing that I’ve ran into this gem:
sub GetFileName
{
my $self = shift;
my $filename;
if (exists $self->{cf}) {
$filename = $self->{cf};
} else {
undef $filename;
}
return $filename;
}
It's indicative of a lot of ignorance of how Perl 5 works.
This ended up being shortened into:
sub GetFileName
{
my $self = shift;
return $self->{cf};
}
Who said Golf is incompatible with refactoring? ;-)
(of course if we take golfing this method to extreme it would be
something like "sub GetFileName{$_[0]{cf}}").
Anyway, later I've ran into this loop:
# process continuation lines, if any
while($self->{allowcontinue} && $val =~ s/\\$//) {
$line = $self->_read_next_line($fh);
$val .= $line;
}
Now, $self->{allowcontinue} is not modified within _read_next_line() (or
anywhere else except for initialisation) so in case it is true, it is
evaluated every time the condition is processed (not to mention, it gave me a
"WTF?" moment).
I wonder which surprises await for me next in the code.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/
God gave us two eyes and ten fingers so we will type five times as much as we
read.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl