Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Line Commands In Perl

by tux242 (Acolyte)
on Nov 19, 2003 at 22:21 UTC ( [id://308426]=perlquestion: print w/replies, xml ) Need Help??

tux242 has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone have any suggestions about how to best do commands inside a perl script, trying to keep it simple here, I have some copying commands to the . directory that I need to do on a repeat basis. Thanks.

Replies are listed 'Best First'.
Re: Line Commands In Perl
by AcidHawk (Vicar) on Nov 20, 2003 at 01:55 UTC

    If you are looking at copying files to the . dir, have a look at File::Copy.

    use File::Copy; copy("file1","file2");
    If you are trying to run system commands try ``, or system().
    `cp file1 file2`;
    OR
    system(cp file1 file2);

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
Re: Line Commands In Perl
by Abigail-II (Bishop) on Nov 19, 2003 at 22:25 UTC
    What do you mean by "commands"? External programs? External programs are often called by using 'system' or 'qx', and sometimes by using 'open'.

    Abigail

Re: Line Commands In Perl
by duff (Parson) on Nov 19, 2003 at 22:27 UTC

    "Best do commands"??? Best is what does the job correctly. It sounds like you just want to use system() though. Or, if you want to avoid spawning processes for some reason, you could use File::Copy

Re: Line Commands In Perl
by ysth (Canon) on Nov 19, 2003 at 23:41 UTC
    I think Larry Wall created this as sort of a joke, but you can do:
    use Shell; &cp qw( tmp/* . ); &cat qw( tmp/* ); &rm qw( -rf tmp );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-24 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found