perlquestion
princepawn
<I>Note that the first word in the title is <B>apparent</b>, meaning that the rest of the title is thing as they appear to me, not necessarily the way they are.</I>
<P>
Ok, let's do this storybook style. I'm sitting in my office and my boss says "how do you find out the <B>length</B> of an array in Perl?" So I tell him
<code>
1+$#array
#or
scalar @array
</code>
<P>
A week later I'm reading comp.lang.perl.misc and Uri Guttman says to someone asking a similar question about strings: <I>To take the <B>length</B> of a string, you use length. Larry did a good job of naming the Perl functions.</I>
<P>
So then I, the nobody, have the nerve to email Uri Guttman, one of the Perl 5 Porters and lead author on one of the best Perl papers ever (on sorting) and tell him he isn't right about Larry naming the functions... Larry didn't do so great a job... why? Take a look:
<P>
<table align=center>
<tr>
<td>
Desired operation
</td>
<td>
Perl datatype
</td>
<td>
Perl function
</td>
</tr>
<tr>
<td>length</td><td>string</td><td>length</td>
</tr>
<tr>
<td>length</td><td>array</td><td>scalar</td>
</tr>
<<tr><td>length</td><td>list</td><td>?</td></tr>
<tr><td>length</td><td>hash</td><td>scalar keys </td></tr>
</table>
<P>
In other words, the desired operation is the same in each case, but the way it is done in Perl is not... while one may say: "RTFM", one thing that reduces the learning curve for a language is for it to be intuitive. That's why I'm in awe when I hear people (even Damian Conway) say: "my brain thinks like Perl"... I have to stop,drop my jaw and say: "why in the world would you want different names for the exact same conceptual operation and what is it about your brain that seeks diversity in the function names for the exact same thing?
<h1> Example 2</h1>
<h2>Operation: Taking a "slice" of something in Perl</h2>
<table>
<tr>
<td>A string</td>
<td>substr $STRING, $OFFSET, $LENGTH</td>
</tr>
<tr>
<td>An array</td>
<td><code>@array[$OFFSET..$LENGTH+OFFSET]</code></td>
<tr>
</table>
<P>
Again while a logical person would say "how do I take subseries of something, regardless of whether it is a string or an array", we have the questionable brilliance involved in creating two radically different syntactic mechanisms for doing so.
<P>
And again, one must think seriously about offering a CAT scan to anyone who proclaims that such unwarranted non-homogeneity is "how their brain thinks".
<h1>Conclusion</h1>
Perl makes simple things simple, and hard things possible, but also makes consistent operations possible through highly inconsistent means.
<P>
And of course we cant forget the recent interview on Perl.COM with Ilya Zakharavich handled by [BigJoe] about how FILEhandle information is inconsistently handled by Perl.
<P>