I have slowly been finding using perl at the cli more and more useful,
but I'm confused as to how to do certain tasks.

Although the following pipeline is hugely ugly and I know that it can be
shortened extremely, from time-to-time I just like to play around with
all manner of manipulation. So, Perl one-liners are welcome after I get
pointers on what I'm doing wrong with perl here ;)

% egrep -r "sub \w+ {" * \
  | grep -v svn \
  | awk '{FS=":"} {print $1, " ", $2}' \
  | awk '{FS=" "} {print $1, " ", $3}'

What that does, is it searches through a project directory looking for
all subs in all files (eliminating those I don't want).  Its output (on
a fbsd machine) is this:

lib/ISP/Vars.pm   _defined_plan
lib/ISP/Vars.pm   _defined_credit_card
lib/ISP/Vars.pm   _defined_payment_method
lib/ISP/Transac.pm   purchase
lib/ISP/Transac.pm   payment
lib/ISP/Transac.pm   renew
lib/ISP/Transac.pm   credit_card_payment
lib/ISP/Transac.pm   calculate_invoice_amount

I now want to further process that, so that I can get each sub from a
specific file, and print only the sub name. Essentially, I want this:

perl -e '$s="lib/ISP/User.pm this_sub"; $s =~ s/.*\s+//; print $s."\n"'

...by appending the following lines to the above pipeline, and throwing
it at perl with the -p arg:

% egrep -r "sub \w+ {" * \
  | grep -v svn \
  | awk '{FS=":"} {print $1, " ", $2}' \
  | awk '{FS=" "} {print $1, " ", $3}' \
  | egrep "^lib/ISP/User.pm$" \
  | perl -p -e 's/.*\s+//'

But alas, I get nothing, so I tried this as my last line, thinking that
the input would be put in $_:

perl -e '$_ =~ s/.*\s+//; print $_'

Then, as a last resort:

perl -e '$_[0] =~ s/.*\s+//; print $_[0]'

Can someone point out where I'm going wrong?

Steve

ps. any eta on perlmonks?






-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to