Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: scanning hash

by davido (Archbishop)
on Aug 01, 2004 at 09:47 UTC ( #379044=note: print w/ replies, xml ) Need Help??

in reply to scanning hash

I just wanted to add that ysth's solution can also be adapted in such a way that it can be applied to arrays.

Determine if all elements in @array are equal.

use strict; use warnings; my @goodarray = ( 1, 1, 1, 1, 1 ); my @badarray = ( 1, 2, 3, 4, 5 ); foreach my $aref ( \@goodarray, \@badarray ) { print SameVals($aref) ? "Good!\n" : "Bad!\n"; } sub SameVals { keys %{ { map { $_ => undef } @{ +shift } } } <= 1; }



Comment on Re: scanning hash
Download Code
Replies are listed 'Best First'.
Re^2: scanning hash
by Aristotle (Chancellor) on Aug 01, 2004 at 14:42 UTC
    This too suffers the same problem as Re: scanning hash: it treats undefs and empty strings as the same.

    Makeshifts last the longest.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2015-12-02 07:38 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (36 votes), past polls