Re: USe Shell comands in perl
by cdarke (Prior) on Jul 17, 2007 at 09:23 UTC
|
While there are some occasions that using shell commands from Perl are justified, there are many more when they are not. Decide: use the shell OR use Perl. Mixing them is to encourage inefficiency.
This is a rough conversion table from UNIX commands to Perl.
Please note that there are not always direct single equivalents, and that there are certainly many more that I can't think of (but many others will).
| UNIX | Perl | Origin |
| . | do | built-in |
| awk | perl ;-) (often 'split') | built-in |
| basename | File::Basename::basename | Base module |
| cat | while(<>){print} | built-in |
| | ExtUtils::Command::cat | Base module |
| cd | chdir | built-in |
| chmod | chmod | built-in |
| chown | chown | built-in |
| cp | File::Copy | Base module |
| | ExtUtils::Command::cp | Base module |
| date | localtime | built-in |
| POSIX::strftime | Base module |
| declare | see typedef |
| df | Filesys::Df | CPAN |
| diff | File::Compare | Base module |
| dirname | File::Basename::dirname | Base modules |
| echo | print | built-in |
| egrep | while(<>){print if /re/} | built-in |
| eval | eval | built-in |
| exec | exec | built-in |
| | pipe (co-processes) | built-in |
| | open (file descriptors) | built-in |
| export | Assign to %ENV | Hash variable |
| | Env::C | CPAN |
| find | File::Find | Base module |
| ftp | Net::Ftp | Base module |
| function | sub | built-in |
| grep | see egrep |
| integer | int | built-in |
| kill | kill | built-in |
| ln -s | link | built-in |
| ls | glob | built-in |
| | opendir/readdir/closedir | built-in |
| | stat/lstat | built-in |
| mkdir | mkdir | built-in |
| mkpath | ExtUtils::Command::mkpath | Base module |
| mv | rename | built-in |
| | ExtUtils::Command::mv | Base module |
| od | ord | built-in |
| | printf | built-in |
| print | print | built-in |
| printf | printf | built-in |
| rand | rand | built-in |
| rm | unlink | built-in |
| | ExtUtils::Command::rm | Base module |
| rm –f | ExtUtils::Command::rm_rf | Base module |
| sed | s/// (usually) | built-in |
| select | Shell::POSIX::select | CPAN |
| sleep | sleep | built-in |
| | alarm | built-in |
| sort | sort | built-in |
| source | do | built-in |
| tail | File::Tail | CPAN |
| times | times | built-in |
| touch | open()/close() | built-in |
| | ExtUtils::Command::touch | Base module |
| trap | %SIG | Hash |
| | sigtrap | pragma |
| typeset | my | built-in |
| typeset –i | int | built-in |
| typeset –l | lc | built-in |
| typeset –u | uc | built-in |
| typeset -Z | sprintf | built-in |
| [reply] |
|
|
cdarke++, excellent article! Really this reply of mine may have been a /msg, but I wanted others to read it, and see if they share my feeling: have you considered (possibly expanding on the subject and) making it into a meditation? So one could refer to it for the future...
| [reply] |
|
|
Thanks blazar. Added to meditations as you suggested 627015. I suggest that monks wishing to add more to the list do so in the meditation.
| [reply] |
|
|
I agree with blazar... excellent.
What about adding?
telnet Net::Telnet CPAN
regexes
| [reply] [d/l] |
|
|
I think you need an "Origin" column for the UNIX side as well, since you seem to have thrown in external utilities, shell built-ins, and C library functions without distinction. (This is mainly meant as feedback for your other post.)
| [reply] |
|
|
I can see why you say that, it is this phrase "UNIX command" that is so commonly used but is really too general. Strictly I guess it should only contain names from the POSIX/SUS standard section "Shell&Utilities", but that would miss many out. I will try and apply a new column when I can.
| [reply] |
Re: USe Shell comands in perl
by Zaxo (Archbishop) on Jul 17, 2007 at 04:35 UTC
|
You can use qx (ie. `backticks`), system, open, or exec, depending on what you want to accomplish. Those links will get you started, and we'll be glad to help if you ask a more specific question.
| [reply] |
Re: USe Shell comands in perl
by GrandFather (Saint) on Jul 17, 2007 at 04:35 UTC
|
| [reply] |
Re: USe Shell comands in perl
by jesuashok (Curate) on Jul 17, 2007 at 06:02 UTC
|
| [reply] |