TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Famous Perl One-Liners Explained, Part IV: String and Array Creation

18 pointsby phsrover 15 years ago

3 comments

jrockwayover 15 years ago
<i>You may use this array to convert a number (in variable $num) from decimal to hex using base conversion formula:</i><p>Or, you could save yourself the energy and just write "sprintf '%x', $whatever"...<p>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 ..."?<p>(If you want to play with Perl one line at a time, install Devel::REPL.)
评论 #1037460 未加载
blahedoover 15 years ago
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.
jgrahamcover 15 years ago
This is ugly to me<p><pre><code> $, = ","; print ("a".."z"); </code></pre> Why would you not use join()?<p><pre><code> print join(',',("a".."z"));</code></pre>
评论 #1037447 未加载