Added WebGUI::Utility::scalarEquals for strict equality checks of scalars
This commit is contained in:
parent
afb94a6bbd
commit
d26ce5b447
2 changed files with 63 additions and 2 deletions
|
|
@ -23,7 +23,7 @@ use Net::Subnets;
|
|||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(&isBetween &makeTabSafe &makeArrayTabSafe &randomizeHash &commify &randomizeArray &isInSubnet
|
||||
&formatBytes &sortHashDescending &sortHash &isIn &makeCommaSafe &makeArrayCommaSafe &randint &round
|
||||
&formatBytes &sortHashDescending &sortHash &isIn &makeCommaSafe &makeArrayCommaSafe &randint &round &scalarEquals
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -376,6 +376,32 @@ sub round {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 scalarEquals ( $a, $b, .. )
|
||||
|
||||
Checks an arbitrary number of scalars for strict equality.
|
||||
|
||||
Lets perl do all the work for us, via clever use of hash keys.
|
||||
|
||||
Credit goes to davido on perlmonks: http://www.perlmonks.org/?node_id=525349
|
||||
|
||||
Be aware that this may actually be more strict than you want. See Utility.t
|
||||
for the full list of scalars that are considered equal and not equal.
|
||||
|
||||
=cut
|
||||
|
||||
sub scalarEquals {
|
||||
# False when < 2 defined args
|
||||
return 0 if ( grep { defined($_) } @_ ) < 2;
|
||||
|
||||
# Use args as hash keys, all equal if we end up with only 1 key
|
||||
no warnings qw/uninitialized/;
|
||||
my %gadget;
|
||||
@gadget{@_} = ();
|
||||
return scalar keys %gadget == 1 ? 1 : 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 sortHash ( hash )
|
||||
|
||||
Sorts a hash by its values. Returns a Tie::IxHash. You must assign this to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue