| Stupid Perl Tricks |
|
|
|
| Written by Mr-Oss | |
| Sunday, 18 January 2009 | |
|
STUPID PERL TRICKSA collection of useful and useless perl command line techniques. perl -e 'print "STUPID PERL TRICKS TO USE ON THE COMMAND LINE"'
Printing out your perl module include path root@slacker:~# perl -e 'print join ("\n", @INC)' /usr/lib/perl5/5.8.8/i486-linux-thread-multi Checking for specific perl modules existence ( does not exist on the system ) root@slacker:~# perl -e 'use MIME::Lite' Can't locate MIME/Lite.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/i486-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/i486-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl .) at -e line 1. BEGIN failed--compilation aborted at -e line 1. Install a perl module root@slacker:~# perl -MCPAN -e 'install MIME::Lite' ........lots and lots of truncated text and questions to answer yes to Installing /usr/lib/perl5/site_perl/5.8.8/MIME/Lite.pm Re-Check for a perl modules existence ( does exist on the system ) root@slacker:~# perl -e 'use MIME::Lite' Print if pattern matches current file line root@slacker:~# perl -nle 'print if /root/' /etc/passwd root:x:0:0::/root:/bin/bash Print match when piped from command root@slacker:~# ps -ef | perl -nle 'print if /bash/' root 3907 3906 0 07:45 pts/1 00:00:00 -bash Conditional printing from regex match cat /etc/passwd | perl -nle '(=~/root/)?print "MATCHED FOR $_\n":print "NO MATCH\n"' MATCHED FOR root:x:0:0::/root:/bin/bash root@slacker:~# perl -MCPAN -le 'print $INC{"Config.pm"}' /usr/lib/perl5/5.8.8/i486-linux-thread-multi/Config.pm Edit a files contents directly with search and replace root@slacker:~# more example.txt Check your current operating system root@slacker:~# perl -e 'print $^O,"\n"' linux That's all for now folks
Check back for future updates!
|
| Next > |
|---|
| |