Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

one-liner peeks at @INC

by mkmcconn (Chaplain)
on Feb 01, 2001 at 13:12 UTC ( #55676=snippet: print w/replies, xml ) Need Help??
Description:

This one trick pony is ridden to the end of the road, usefully even if not portably: from a bash prompt.
(Okay, some have too many ';' in there to be one-liners strictly speaking - but they all express a linear thought, briefly enough to be easily remembered). The idea here isn't "golf", but UYKAKYU (Use yields knowledge as knowledge yields use)

I've climbed the learning curve this past month, far enough that I deserve to be thwacked for bad practices if you notice any you want to point out.
mkmcconn

Print @INC
perl -we 'print "$_\n" for @INC;'
 
Print filenames in @INC to pipe
perl -we 'push @a, <$_/*> for @INC; print "$_\n" for @a;' | more
 
Search for "PerlMonks" in filenames of @INC excluding PWD
perl -we '/^\./ or push @a, glob "$_/*" for @INC; print "$_\n" for @a;' | grep "PerlMonks"
 
Grep for the lwp cookbook, perlishly
perl -we '/^\./ or push @a, <$_/*> for @INC; print "$_\n" for grep {/lwp.+(pod)/} @a;'
 
Page through all ".pm" files related to "(F|f)ile.." in @INC outside PWD, bash-fully
less $(perl -we '/^\./ or push @a, <$_/*> for @INC; print "$_\n" for grep{/\bFile.*\.pm/i} @a;')
 
Make a two-line (code-once-use-again) bash-ful aliased regexified search of leaves-only for "perl.."-stuff in @INC outside of $PWD
% function grep4inc { perl -we '/^\./ or push @a, <$_/*> for @INC; print "$_\n" for grep {/$ARGV[0]/i} @a;' $1;}
% grep4inc "\Wperl.[^\/]+$";
 
Modify all the above to use the -l switch (thanks chipmunk).
 
Or do any of the above eliminating the need of @a.
perl -wle 'for (@INC){ for (glob "$_/*"){ !/^\./ and print if /$ARGV[0]/;} }' "Stor"
 
for I in $(perl -wle'for (@INC){ for (glob "$_/*"){ next if /^\./; print if /$ARGV[0]/i;}}' "lwp") ; do perldoc $I; done
 
Replies are listed 'Best First'.
Re: one-liner peeks at @INC
by chipmunk (Parson) on Feb 01, 2001 at 20:32 UTC
    A nice way to get newlines automatically is to use the -l command-line option. This makes your one-liners even shorter:

    Print @INC     perl -wle 'print for @INC' Print filenames in @INC to pipe     perl -wle 'for (@INC) { print for <$_/*> }' | more ...and so on. -l is great for one-liners like these.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://55676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2023-06-05 00:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (22 votes). Check out past polls.

    Notices?