Cheat-Meta
view release on metacpan or search on metacpan
lib/Cheat/Sheet/Util.pod view on Meta::CPAN
=head2 List::Compare
use List::Compare; # Compare elements of two or more lists
# This object-oriented module is highly orthogonal,
# so that nearly any selection or choice may be combined with any other.
# Most methods are equally okay for ( just two ) or ( three or more ) lists;
# some will Carp if called inappropriately.
# === Options/Modes ===
# Regular: (default) Two lists, sorted results, many method calls ok
# Unsorted: Don't sort method results ( faster )
# Accelerated: Only one method call possible per $lc ( faster )
# Multiple: Three or more lists in constructor
# ! (specify $ix to refer to a given list; default 0; omit for only two lists)
# Seen-hash: Use hashrefs instead of arrayrefs:
# [ 11, 12, 14, 14, 14, 15 ] ~~ { 11 => 1, 12 => 1, 14 => 3, 15 => 1 }
#
# Construct a work-object
my $lc = List::Compare->new( \@a, \@b, @c ); # default
my $lc = List::Compare->new( '-u', \@a, \@b, @c ); # unsorted
my $lc = List::Compare->new( '-a', \@a, \@b, @c ); # accelerated
my $lc = List::Compare->new( '-u', '-a', \@a, \@b, @c ); #! -u before -a
# Wrap constructor arguments in a hashref
my $lc = List::Compare->new({
unsorted => 1,
accelerated => 1,
lists => [ \@a, \@b, @c ],
});
# Methods return lists of results
@gots = $lc->get_intersection; # found in each/both list(s)
@gots = $lc->get_union; # found in any/either list
@gots = $lc->get_bag; # ~get_union but also duplicates
@gots = $lc->get_unique($ix); # found only in list $ix
@gots = $lc->get_complement($ix); # not found in $ix, but elsewhere
@gots = $lc->get_symmetric_difference; # found in only one list
$gots = $lc->get_intersection_ref; # ~methods above but
$gots = $lc->get_union_ref; # returns \@gots
$gots = $lc->get_bag_ref; # "
$gots = $lc->get_unique_ref($ix); # "
$gots = $lc->get_complement_ref($ix); # "
$gots = $lc->get_symmetric_difference_ref; # "
# Methods return boolean truth # ( $ixL, $ixR ) default to ( 0, 1 )
$bool = $lc->is_LsubsetR( $ixL, $ixR ); # true if all L in R
$bool = $lc->is_RsubsetL( $ixL, $ixR ); # true if all R in L
$bool = $lc->is_LequivalentR( $ixL, $ixR ); # true if same items in L, R
$bool = $lc->is_LdisjointR( $ixL, $ixR ); # true if no items in common
# Methods return list of which lists ($ix) satisfying conditions
@ixs = $lc->is_member_which($string); # some item in $ix eq $string
@ixs = $lc->are_members_which(\@strings); # ~prev but eq any in @strings
# Dump
$lc->print_subset_chart; # pretty-print tables showing some
$lc->print_equivalence_chart; # relationships; row/col as $ix
# List::Compare
=head2 Hash::Util
use Hash::Util; # Hash locking, key locking, value locking
use Hash::Util qw(
lock_keys lock_keys_plus unlock_keys
lock_value unlock_value
lock_hash unlock_hash lock_hash_recurse unlock_hash_recurse
hash_locked hidden_keys legal_keys all_keys
);
# Restrict %hash to a set of keys; can delete but can't add other keys
\%hash = lock_keys ( %hash ); # current keys %hash
\%hash = lock_keys ( %hash, @keys ); # @keys; subset of keys @hash
\%hash = lock_keys_plus( %hash, @keys ); # superset
\%hash = unlock_keys ( %hash ); # remove restrictions
# Cannot alter value of $key but can delete the k/v pair
\%hash = lock_value ( %hash, $key );
\%hash = unlock_value ( %hash, $key );
# Lock the whole %hash; can't add, delete, or change value at all
\%hash = lock_hash ( %hash );
\%hash = unlock_hash ( %hash );
\%hash = lock_hash_recurse ( %hash ); # HoHoH... only
\%hash = unlock_hash_recurse ( %hash ); # ditto
# Other functions...
$bool = hash_unlocked ( %hash ); # true if %hash is unlocked
@keys = legal_keys ( %hash ); # list of keys allowed
@keys = hidden_keys ( %hash ); # see docs; experimental feature
\%hash = all_keys( %hash, @keys, @hidden ); # experimental feature
# Just like Daddy but take hashref arguments
\%hash = lock_ref_keys ( \%hash );
\%hash = lock_ref_keys ( \%hash, @keys );
\%hash = lock_ref_keys_plus ( \%hash, @keys );
\%hash = unlock_ref_keys ( \%hash );
\%hash = lock_ref_value ( \%hash, $key );
\%hash = unlock_ref_value ( \%hash, $key );
\%hash = lock_hashref ( \%hash );
\%hash = unlock_hashref ( \%hash );
\%hash = lock_hashref_recurse ( \%hash );
\%hash = unlock_hashref_recurse ( \%hash );
$bool = hash_ref_unlocked ( \%hash );
@keys = legal_ref_keys ( \%hash );
@keys = hidden_ref_keys ( \%hash );
## Hash::Util
=head1 SEE ALSO
=over
=item * L<Cheat::Meta>
=item * L<perlcheat>
=back
=head1 FUNCTIONS/METHODS
None. This module contains only POD. Don't try to load it.
=head1 INTERFACE
Open the cheat (the *.perl file) in your editor.
Copy out whatever you like.
If you look at the *.pod file, you'll see POD verbatim paragraphs.
Your choice.
You can also get the same content in your pager with:
perldoc Cheat::Sheet::Util
=head1 BUGS AND LIMITATIONS
No cheat sheet will teach you anything. It's only a reminder. You B<must>
consult each module's own full documentation I<at least> before using it.
I hope.
This module does not contain magic to squirt code into your module.
Copy and paste.
No boilerplate code will work right away. Edit it to your needs.
=head1 THANKS
=over
=item *
To about 8500 authors who have uploaded about 85,000 modules to the CPAN.
=back
=head1 AUTHOR
Xiong Changnian C<< <xiong@cpan.org> >>
=head1 LICENSE
Copyright (C) 2010 Xiong Changnian C<< <xiong@cpan.org> >>
This library and its contents are released under Artistic License 2.0:
( run in 1.361 second using v1.01-cache-2.11-cpan-39bf76dae61 )