Skip to content

Instantly share code, notes, and snippets.

@smpb
Created April 8, 2011 10:16
Show Gist options
  • Save smpb/909600 to your computer and use it in GitHub Desktop.
Save smpb/909600 to your computer and use it in GitHub Desktop.
generic Perl stuff
# print files in current dir, by date
my @files = sort { -M $a <=> -M $b } grep { ! -d } glob "./*";
print "files by modified date:\n";
print "\t$_\n" for @files;
# match valid number
($ARGV[0] =~ /^(\d+\.?\d*|\.\d+)$/) ? print "number\n" : print "not number\n";
# short way to slurp the contents of a file
open my $fh, '<', $ARGV[0];
my $slurp = do { local $/; <$fh> };
close $fh;
print $slurp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment