[Israel.pm] Is there an operator like IN in perl

Berler Chanan bc.other at gmail.com
Thu Mar 5 07:10:01 PST 2009


Since I got some background as DBA also, some operators would have make it
easy for me working with Perl.
Tell you what, I would have prefer a set of operators dedicated for arrays
Like "in"  find the value in the array
     "max" find the max value
     "min" find the min value
     "avg" find the avg value (assume numeric)
     "first" find the first elemnt
     "last" / "top" find the last element
     "find" find the location of the element in the array

These are useful operators, which as I believe should be part of the Perl
standard,
Without using any external modules.

As for if numeric or character, I would suggest adding a default: numeric,
option for strings compare.
PS: why not adding also:

@array + elemnt -> adds the element
@array - elemnt -> removes first element
@array + @array -> return one array with both elements
@array - @array -> return subtract of arrays (all elements which are found
on both arrays)
@array ~ @array -> xor of arrays (elements found on the first array and are
not found on the second one).
@array++        -> increase by 1 for all elements found (postfix)
++ at array        -> increase by 1 for all elements found (prefix)
@array--        -> decrease by 1 for all elements found (postfix)
-- at array        -> decrease by 1 for all elements found (prefix)

The list can go on....but all these are not implemented as far as I know as
operators
Please correct me if I am missing anything, would help me a lot

PS: using modules, well I can but why shouldn't these be standard ?
Thanks
Chanan


-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
Of Offer Kaye
Sent: Thursday, March 05, 2009 4:48 PM
To: Perl in Israel
Subject: Re: [Israel.pm] Is there an operator like IN in perl

On Wed, Mar 4, 2009 at 4:21 PM, Berler Chanan wrote:
> 2) Using hash is great but I looked for more suite and elegant solution

You could simply wrap the hash solution in an appropriately names sub,
giving you the elegant solution for example:

{{{
if ( is_in_array(item => 'George' , aref => \@Beatles) )
}}}

You could even put "sub is_in_array" in a separate .pm file and "use"
it so that the user need never be exposed to the "ugly" code which
implements the pretty and elegant interface :)

Cheers,
-- 
Offer Kaye
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list