Announcing perl1line.txt - A collection of handy Perl scripts
catonmat.net
catonmat.net
perl -MData::Dumper\ 999
Quickest way to get the version of a module you're running. perl -MData::Dumper -e 'print $Data::Dumper::VERSION."\n"' $ perl -MLWP::UserAgent\ 999
LWP::UserAgent version 999 required--this is only version 5.833. mike@server:~$ perl -MLWP::UserAgent -e 'print $LWP::UserAgent::VERSION."\n"'
5.835
mike@server:~$ $ perl -MLWP::UserAgent -le 'print $LWP::UserAgent::VERSION' $ M=LWP::UserAgent && perl -M$M -le "print \$$M::VERSION"
Even even shorter! $ M=LWP::UserAgent;perl -M$M -Esay\$$M::VERSION $ perl -MFile::Slurp\ 9999
<hangs forever> perl -MV=Data::Dumper
"Quicker", if you don't count install time. cpanm -n VThe equivalent in Ruby?
gem list $GEMNAME
It's shorter and more clear. Take that, Perl golfers!The only one off the top of my head would be ruby but I don't have that much ruby knowledge to judge.
This kind of thing however is perl's bread and butter.
So Perl's `print foreach @a` becomes Ruby's `a.each{|a| print a}`. Not so bad but it adds up.
print a.join
Perl: print foreach @a
Ruby wins! print @a;It isn't exactly the same--some examples are two or three lines and it's more about coolness than practicality--but it's in a similar spirit, and, more importantly, also interesting.
-- split at whitespace -- "hello world" -> ["hello","world"] words
unfoldr (\b -> fmap (const . (second $ drop 1) . break (==' ') $ b) . listToMaybe $ b)
takeWhile (not . null) . evalState (repeatM $ modify (drop 1) >> State (break (== ' '))) . (' ' :)
where repeatM = sequence . repeat
fix (\f l -> if null l then [] else let (s,e) = break (==' ') l in s:f (drop 1 e))
Not really in the same spirit at all. $ echo 'hello world' | ruby -e 'p STDIN.read.split' split.hs:
main = interact (show . words)
$ echo hello world | runhaskell split.hs