

Announcing perl1line.txt - A collection of handy Perl scripts - pkrumins
http://www.catonmat.net/blog/announcing-perl1line-txt/

======
symkat
It's missing one of my favorites:

    
    
        perl -MData::Dumper\ 999
    

Quickest way to get the version of a module you're running.

~~~
mike-cardwell
Interesting. I would have done it this way previously:

    
    
      perl -MData::Dumper -e 'print $Data::Dumper::VERSION."\n"'

~~~
pkrumins
Works for any module:

    
    
        $ perl -MLWP::UserAgent\ 999             
        LWP::UserAgent version 999 required--this is only version 5.833.

~~~
mike-cardwell

      mike@server:~$ perl -MLWP::UserAgent -e 'print $LWP::UserAgent::VERSION."\n"'
      5.835
      mike@server:~$

~~~
d5ve
Even shorter, as -l appends \n to all prints:

    
    
        $ perl -MLWP::UserAgent -le 'print $LWP::UserAgent::VERSION'

~~~
pkrumins
Even shorter!

    
    
        $ M=LWP::UserAgent && perl -M$M -le "print \$$M::VERSION"
    

Even even shorter!

    
    
        $ M=LWP::UserAgent;perl -M$M -Esay\$$M::VERSION

~~~
sliverstorm
This reminds me of that joke in which jokes have been reduced to numbers. It's
nearly as obscure, too.

~~~
pkrumins
Did Gödel come up with that joke?

------
pkrumins
Direct download link: <http://www.catonmat.net/download/perl1line.txt>

------
brador
Making this for all the different languages would be awesome. I'm thinking
PHP, jquery etc. one liners.

~~~
wx77
Do any other languages really lend themselves to the one line command tools
like perl does?

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.

~~~
mapgrep
Compared to Ruby, one liners are more efficient in Perl because the normally
infuriating cryptic variables and defaults save space. For example in Perl you
can run a foreach without naming the current iteration value and it defaults
to $_. $_ in turn is the default target for many commands, like print.

So Perl's `print foreach @a` becomes Ruby's `a.each{|a| print a}`. Not so bad
but it adds up.

~~~
stouset
Ruby:

    
    
       print a.join
    

Perl:

    
    
       print foreach @a
    

Ruby wins!

~~~
chromatic
I think you mean:

    
    
        print @a;

