Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Difference between a perl script & shell script

by JohnMG (Beadle)
on Dec 19, 2005 at 15:34 UTC ( [id://517759]=note: print w/replies, xml ) Need Help??


in reply to Difference between a perl script & shell script

The stuff you type into the terminal window is getting interpreted by the shell interactively (as you type it, after you hit the enter key). You may not've ever tried it, but you can do loops in terminal window. Try:
$ for i in `ls` > do > echo "found this: $i" > done
(You don't type the '>' characters -- they'll show up automatically.)

So, one difference is, a shell script could be typed in one line at a time in a terminal window, and it would work. Python has this same sort of interactive "shell". Perl's interpreter isn't really interactive like that (though it does offer the -e option for making "one-liners").

Replies are listed 'Best First'.
Re^2: Difference between a perl script & shell script
by Perl Mouse (Chaplain) on Dec 19, 2005 at 16:30 UTC
    I usually type my loops on a single line:
    for i in `ls`; do echo "found this: $i"; done
    Perl --((8:>*
Re^2: Difference between a perl script & shell script
by Hue-Bond (Priest) on Dec 19, 2005 at 15:49 UTC
    Perl's interpreter isn't really interactive like that
    $ perl print "Look ma, I'm interactive!\n"; __END__ Look ma, I'm interactive! $ _

    --
    David Serrano

      That's not interactive, that's taking the source code via STDIN. There's a difference, namely in that interactive means you run one command, get the return value. Run another, get another return value. This is commonly known as REPL, or a Read Eval Print Loop. You can make one in Perl:

      perl -le '@ret = eval and print "Returned [@ret]" while <STDIN>'

      But it's not quite as fully featured as most interactive shells.

        Have you tried perl -demo ???

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of

      Interesting. Didn't know you could do that. Thanks.

      A quick comparison of Perl, Python, and shell interactive modes:

      • Perl -- You type in the whole script, line by line, and you get the output only after all lines have been entered and after you've typed __END__ as the last line. A syntax error will dump you back to the command line.
      • shell -- you always get the output (if there is any) right after each line/command. View $? to see the return value of the last command that was run.
      • Python -- You get the output of statements as you run them, just like the shell. Also, it automatically prints out the value of the expression evaluated on the line you just typed.

      IMO, the Python shell is pretty darn interactive. The Perl shell might be nice for one-liners that take up more than one line ;), but it doesn't seem all that interactive to me.

        The python interactive environment is definitely nice.

        Term::ShellKit provides something along the same lines. I generally make do with perl -de1.

Log In?
Username:
Password:

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

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

    No recent polls found