>Case ignoring eq and cmp operators
>=head2 Problems with current ways to do it
>Perl currently knows basically two methods for checking of equality of
>strings case-insensitively:
> uc($a) eq uc($b)
> $a =~ /^$b$/i
>and for comparing them one:
> uc($a) cmp uc($b)
>The probably worst about these statements is that they look ugly.
To the contrary: in the case (ahem) of the application of lc() on
the comparison's operand, they look especially beautiful.
>Also,
>they further complicate statements and they are counter-intuitive for
>beginners - why should I change the case of variables if I only want
>to compare them?
Again, I reach the contrary conclusion: they say exactly what they
are doing, rendering them clear and obvious to all involved. By
your argument, one should not have to say
abs($a) == abs($b)
either, but should invent a sign-insensitive equality comparison
instead of knowing how to use the extant == operator and abs function.
That makes little sense, as I'm sure you'll agree. Similarly, so
too does the desire to have a new eq operator seem exceedingly
misplaced.
Power derives not from uncountably many special-purpose functions
and syntax, but rather from the ability to combine primitive features
*algorithmically* to arrive at the desired functionality. The
factorial powers of combinatorics put to shame a merely linear increase
in the number of available functions.
Of lesser but not inconsequential importance is that it is easier
on everyone if they don't have more distinct functions and syntax
to remember. Would it really be better to have a -==- operator
than for people to remember to use == with abs? Of course not.
A programmer learns to use the tools in hand to create new things.
> $a eq/i $b
> $a cmp/i $b
You want ugly, I'll give you ugly. That's ***UGLY***. It's a
syntactic anomaly that does not fall out of anything else in the
language. The analogy to m//i or s///g is a false one, as those
are not functions, and do not syntactically take argument in the
same way. Nothing else in Perl looks this way.
--tom