4 ms·
Famous Perl One-Liners Explained, Part IV: String and Array Creation
- blahedo 17y agoSome 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.
- jrockway 17y agoYou 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 17y agoYes, 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."
- jgrahamc 17y agoThis is ugly to me $, = ","; print ("a".."z"); Why would you not use join()? print join(',',("a".."z"));
- pkrumins 17y agoYes, you can do that. I just wanted to stick the special variable in there. I will update the article with this nicer solution.