Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

RE:(3) All array elements the same? (Code explained)

by Russ (Deacon)
on Aug 01, 2000 at 20:34 UTC ( [id://25494]=note: print w/replies, xml ) Need Help??


in reply to RE: Re: All array elements the same?
in thread All array elements the same?

He's putting all the elements of the array into a hash, using a hash slice @check{@arr} = @arr x 1;

Then, if there is only one key, all the values must have been identical.

@check{@arr} is the "keys" part of the slice, and @arr x 1 just gives us the correct number of "values."

Voila! A list of the unique elements of @arr (in keys %check). If there is only one unique element, then they are all the same. Two problems solved for the price (two lines, in this case) of one. :-)

Russ
Brainbench 'Most Valuable Professional' for Perl

Replies are listed 'Best First'.
RE: RE:(3) All array elements the same? (Code explained)
by jjhorner (Hermit) on Aug 01, 2000 at 20:38 UTC

    I see now. Apparently I don't have enough caffeine.

    It was the @hash{@array} thing that threw me. Don't see that often and have never used it.

    J. J. Horner
    Linux, Perl, Apache, Stronghold, Unix
    jhorner@knoxlug.org http://www.knoxlug.org/
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://25494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-29 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found