TPJ One-Liner #28perl -0nal012e '@a{@F}++; print for sort keys %a' Extracts, sorts, and prints the words from a file. --Peter J. Kernan |
TPJ One-Liner #29This subroutine accepts a string and returns a true value if all of the parentheses, brackets, and braces in the string are balanced. sub is_balanced { my $it = $_[0]; $it =~ tr/()[]{}//cd; while ($it =~ s/\(\)|\[\]|\{\}//g) { 1 } return !length($it); } Sean M. Burke |
TPJ One-Liner #30"Regular expressions are to strings what math is to numbers." --Andrew Clinick, discussing what Microsoft thinks of Perl in http://www.microsoft.com/sitebuilder/magazine/clinick_perl.asp. Short answer: They like it. |
TPJ One Liner #31perl -e 'print "Internet Time @", int (((time + 3600) % 86400)/86.4), "\n";' Swatch's Internet Time, heralded as a revolutionary way of measuring time independent of geography. See http://www.swatch.com for details. --Anonymous |
TPJ One Liner #32A trick for indenting here strings: ($definition = <<'FINIS') =~ s/^\s+//gm; The five varieties of camelids are the familiar camel, his friends the llama and the alpaca, and the rather less well-known guanaco and vicuña. FINIS --The Perl Cookbook |
TPJ One Liner #33Efficiently finding the position of the first and last occurrences of a substring in a string: $first = index($string, $substring); $last = rindex($string, $substring); |
TPJ One Liner #34Some scalars that Perl defines for you: $^O contains the name of your operating system. |