Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Perl Shell Scripting?!

by fraizerangus (Sexton)
on Sep 01, 2009 at 14:12 UTC ( [id://792660]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks just a quick question, I've written a perl script and want it to process several thousand data scripts on a database producing a long list of results which can be matched to the data files, I've been told that shell scripting is the way forward and that Perl has its own shell scripting process (I avoid using Bash that way!) can anyones tell me whats its called, how to go about it, or point me in the right direction?! many thanks in advance. much love Dan

Replies are listed 'Best First'.
Re: Perl Shell Scripting?!
by JavaFan (Canon) on Sep 01, 2009 at 14:24 UTC
    Do you have any idea what Perl is, and what the shell is? Perl doesn't have "its own shell scripting process" just like it doesn't have "its own Python scripting process" and Java doesn't have "its own Perl scripting process".

    There's the language Perl, compiled and run by perl. There's Python, compiled and run by python, jpython and a few more implementations. There are a dozen or more closely related shell dialects, each interpreted and run by a different binary (sh, bash, zsh, ksh, psh, ash, csh, tcsh, etc).

Re: Perl Shell Scripting?!
by ig (Vicar) on Sep 01, 2009 at 14:50 UTC

    Your description is too vague to be certain, but I guess that you should add a loop to iterate over your data files (I assume you mean data files when you say "data scripts") to the Perl script you have written, rather than writing a separate shell script.

    Can you turn your current script into a subroutine and call it once for each data file?

    Assuming your "data scripts" are files with extension '.dat' and you put your current script into a subroutine named process_data, maybe you could iterate over your data files with something like:

    foreach my $file (glob('*.dat')) { process_data($file); }
Re: Perl Shell Scripting?!
by cdarke (Prior) on Sep 01, 2009 at 15:17 UTC
    I've been told that shell scripting is the way forward and that Perl has its own shell scripting process

    Who gave you that piece of wisdom? Did he have pointy hair and is your boss?

    A shell has two main features: it can be used interactively and it can be used as a programming language. It is called a shell because its purpose was originally just to run external programs - nothing else. Any product that tries to perform two functions has to make compromises, so generally a shell will not compare well against a product which only does one of those tasks - like Perl.
    If you need that duality of interaction and programming in the same language then use a shell, otherwise use the language you are most comfortable with.
Re: Perl Shell Scripting?!
by kennethk (Abbot) on Sep 01, 2009 at 14:26 UTC
    It's unclear to me what precisely you mean by "shell scripting", so sorry if this is off point. If you mean sending an automated series of commands to the system shell, there a a few commands you can use, depending on what you want back. You probably want system, though depending on what precisely you are trying to do, you may want to use exec or backticks instead...
Re: Perl Shell Scripting?!
by Bloodnok (Vicar) on Sep 01, 2009 at 18:27 UTC
    A shell script in as much as a shell script is the combination of a text file containing a set of commands (each of which is individually runnable at the shell prompt) run by an instance of the shell interpreter.

    I've always considered a perl script to be a specialization of a shell script in as much as the perl script ...

    1. only contains perl commands and ...
    2. uses the perl interpreter to run the script.
    The normal way in which a script is made runnable in its' own right is to...
    • chmod(1) the script file to give it execute rights c/w ...
    • putting #! /usr/bin/sh (the shebang or hash-bang line) at the very top of the file
    So, in order to convert your script (after granting execute rights to the script (via chmod +x file), add the following at the very top of your script file:
    #! /usr/bin/env perl
    Does that help ??

    A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-23 21:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found