
Famous Perl One-Liners Explained, Part IV: String and Array Creation - phsr
http://www.catonmat.net/blog/perl-one-liners-explained-part-four/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+catonmat+%28good+coders+code%2C+great+reuse%29
======
jrockway
_You may use this array to convert a number (in variable $num) from decimal to
hex using base conversion formula:_

Or, you could save yourself the energy and just write "sprintf '%x',
$whatever"...

I'm also unsure of the value of treating everything as a one-liner. If your
one-liner is "change foo to bar in all files in the directory", that's useful.
If it's "find the length of an array", that's not so useful in the one-liner
context. So why wrap every example with "perl -le ..."?

(If you want to play with Perl one line at a time, install Devel::REPL.)

~~~
pkrumins
Yes, that's the easiest way to convert. I was illustrating a use of a hex
lookup table there.

I wrapped most of them in "perl -le ..." so that you can quickly just
copy/paste to try them out. I had forgotten about Devel::REPL.

I sometimes blended together perl recipes and perl one-liners, that's why I
included that print "length of an array."

------
blahedo
Some of these are "obvious" to the Perl veteran but more because they're
idiomatic than that they look like anything you'd see in another language, so
this is great for relative Perl newbies. But even for the experience Perl
hacker, there's a few clever items in there that make it worth a quick glance.

------
jgrahamc
This is ugly to me

    
    
      $, = ",";
      print ("a".."z");
    

Why would you not use join()?

    
    
      print join(',',("a".."z"));

~~~
pkrumins
Yes, you can do that. I just wanted to stick the special variable in there.

I will update the article with this nicer solution.

