Click here to get back home

FAQ 3.23 Can I write useful Perl programs on the command line?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
FAQ 3.23 Can I write useful Perl programs on the command line? PerlFAQ Server 05-03-2008
Posted by PerlFAQ Server on May 3, 2008, 3:03 pm
Please log in for more thread options
This is an excerpt from the latest version perlfaq3.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

3.23: Can I write useful Perl programs on the command line?

Yes. Read perlrun for more information. Some examples follow. (These
assume standard Unix shell quoting rules.)

# sum first and last fields
perl -lane 'print $F[0] + $F[-1]' *

# identify text files
perl -le 'for(@ARGV) {print if -f && -T _}' *

# remove (most) comments from C program
perl -0777 -pe 's{}gs' foo.c

# make file a month younger than today, defeating reaper daemons
perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' *

# find first unused uid
perl -le '$i++ while getpwuid($i); print $i'

# display reasonable manpath
echo $PATH | perl -nl -072 -e '
s![^/+]*$!man!&&-d&&!$s++&&push@m,$_;END'

OK, the last one was actually an Obfuscated Perl Contest entry. :-)



--------------------------------------------------------------------

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.

Posted by Ben Bullock on May 3, 2008, 7:55 pm
Please log in for more thread options
On Sat, 03 May 2008 12:03:02 -0700, PerlFAQ Server wrote:

> 3.23: Can I write useful Perl programs on the command line?

Has anybody ever, even once, asked this question, or even something
similar to it? I just can't imagine anybody asking that kind of question.

Posted by John W. Krahn on May 3, 2008, 8:28 pm
Please log in for more thread options
Ben Bullock wrote:
> On Sat, 03 May 2008 12:03:02 -0700, PerlFAQ Server wrote:
>
>> 3.23: Can I write useful Perl programs on the command line?
>
> Has anybody ever, even once, asked this question, or even something
> similar to it? I just can't imagine anybody asking that kind of question.

Yes, but usually in comp.unix.shell or a group with *unix* in it.


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Similar ThreadsPosted
FAQ: Can I write useful Perl programs on the command line? October 12, 2004, 5:10 am
FAQ 3.25 Can I write useful Perl programs on the command line? January 22, 2005, 12:03 am
FAQ 3.24 Can I write useful Perl programs on the command line? April 11, 2005, 5:03 pm
FAQ 3.24 Can I write useful Perl programs on the command line? June 27, 2005, 5:03 pm
FAQ 3.24 Can I write useful Perl programs on the command line? November 2, 2005, 11:03 am
FAQ 3.24 Can I write useful Perl programs on the command line? April 11, 2006, 9:03 am
FAQ 3.24 Can I write useful Perl programs on the command line? May 26, 2006, 3:03 pm
FAQ 3.24 Can I write useful Perl programs on the command line? July 25, 2006, 3:03 pm
FAQ 3.23 Can I write useful Perl programs on the command line? October 6, 2006, 9:03 pm
FAQ 3.23 Can I write useful Perl programs on the command line? December 21, 2006, 9:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap