J
John M. Gamble
I was reviewing my code, and came across a bit that made me say, "wait,
that can't work." Followed immediately by "why does that work?"
Here is the code reduced to it's essence:
my $inputs = 8;
my @alphabase = ('a'..chr($inputs));
The *intent* was to create a simple translation array (more complex
arrays are possible in this application, which is why i was going
through the bother of an array with this one). Now, according to my
naive reading of this code, this shouldn't produce anything useful at all.
But if you add the line
print @alphabase, "\n";
you get "abcdefghijklmnopqrstuvwxyz", which accidentally saved me.
Thing is, i don't think i deserved to be saved. Not because i am not
worthy (heh), but because this could be an error waiting to happen.
What if i wanted the length of the translation array later on, and i
used C<scalar @alphabase> instead of $inputs? Complications ensue.
The "Give 'em up to Z" feature can be seen in the even simpler one-
liner:
perl -le "print 'h'..'a'"
which prints out h through z. It's too consistent not be deliberate,
but what on Earth was it supposed to solve that someone thought it
was DWIM? Should this feature persist?
Thanks,
that can't work." Followed immediately by "why does that work?"
Here is the code reduced to it's essence:
my $inputs = 8;
my @alphabase = ('a'..chr($inputs));
The *intent* was to create a simple translation array (more complex
arrays are possible in this application, which is why i was going
through the bother of an array with this one). Now, according to my
naive reading of this code, this shouldn't produce anything useful at all.
But if you add the line
print @alphabase, "\n";
you get "abcdefghijklmnopqrstuvwxyz", which accidentally saved me.
Thing is, i don't think i deserved to be saved. Not because i am not
worthy (heh), but because this could be an error waiting to happen.
What if i wanted the length of the translation array later on, and i
used C<scalar @alphabase> instead of $inputs? Complications ensue.
The "Give 'em up to Z" feature can be seen in the even simpler one-
liner:
perl -le "print 'h'..'a'"
which prints out h through z. It's too consistent not be deliberate,
but what on Earth was it supposed to solve that someone thought it
was DWIM? Should this feature persist?
Thanks,