Skip to content

Instantly share code, notes, and snippets.

@Util
Created October 2, 2009 19:54
Show Gist options
  • Save Util/200051 to your computer and use it in GitHub Desktop.
Save Util/200051 to your computer and use it in GitHub Desktop.
package main; # Evil!
# Two notes:
# 1) The whole point of Y.pm is that you put your own bag-of-tricks into it.
# I have just supplied a starter kit here.
# 2) Never use this import technique for anything else; it is *deeply* evil.
# Assumes a global hash %h;
our %h;
# dha - Dump Hash in Alpha order
sub dha {
for my $k ( sort keys %h ) {
printf "%7d\t%s\n", $h{$k}, $k;
}
}
# dhn - Dump Hash in Numeric order
sub dhn {
for my $k ( sort { $h{$b} <=> $h{$a} } keys %h ) {
printf "%7d\t%s\n", $h{$k}, $k;
}
}
sub uniq {
my %seen;
return grep !$seen{$_}++, @_;
}
# dd - Data::Dumper
# Always uses qq mode. Auto-prints if called in void context.
sub dd {
require Data::Dumper;
$Data::Dumper::Useqq = 1;
return Data::Dumper::Dumper(@_) if defined wantarray;
print Data::Dumper::Dumper(@_);
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment