Perl tip of the day (was Re: Wellington Perlmongers)

Grant McLean Grantm at
Wed Sep 25 04:43:03 CDT 2002

Hi Piers

Just to let you know we're not all ignoring you.  I couldn't reply
straight away since I was writing Tcl code :-(

I'm all in favour of a bit more 'banter' on the list.  What would 
you like to talk about?

Perhaps since no one is asking questions, I could kick off with an
unsolicited answer...

Today's message is brought to you be the command line argument '-l'.

The problem: 
  I want to extract a list of subroutine names from a Perl .pm file.

The solution:

  perl -n -e '/^\s*sub\s+(\w+)/ && print "$1\n"' filenames

Unfortunately, although that works nicely on Unix, it doesn't work
on Windows.  At least not with the standard Windows command shell
which only recognises double quotes.  One alternative is to use 
the 'qq' double quoting operator:

  perl -n -e "/^\s*sub\s+(\w+)/ && print qq($1\n)" filenames

But my tip of the day is to dispense with the quotes and use the
'-l' option to append a linefeed onto every print:

  perl -nle "/^\s*sub\s+(\w+)/ && print $1" filenames

Which is less typing too.

Anyone else have a tip?


> -----Original Message-----
> From: Piers Harding [mailto:piers at]
> Subject: Re: Wellington Perlmongers
> Hi Guys - I listen into the list, and they seem to share
> lots of ideas, and regularily publish work/articles etc. to the list.
> Are people on this list interested in the same sort of thing, as it
> would be good to try and inject some life back into it?
> Also, as a kiwi overseas, it would be nice to have some 
> banter with the
> Perl community back home.
> Cheers.
> Piers Harding

More information about the Wellington-pm mailing list