Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

-e Option & Multi-Line Programs

20 views
Skip to first unread message

Tom Christiansen

unread,
Jul 24, 1991, 10:40:42 PM7/24/91
to
From the keyboard of stei...@hpl-opus.hpl.hp.com (Guenter Steinbach):
:This is no help to the basenote poster but rather a plea to the Father
:of Perl:
:
:Please give us multi-line perl scripts, like we have them in awk!

I suspect that the original poster's problems were due to the difficulties
in quoting in the shell, not in perl. You can use as many -e's as you
want, and they can be as long as you want. But if you use quotes in your
perl program that match the quotes in the enclosing shell script, then
you're running the risk of running into trouble with the shell, not with
perl. It's really much easier for programs of any non-trivial length to
be placed in their own file.

--tom
--
"Since when did you hear people talk about writing LISP or BASIC *scripts*?
JCL and shell make command *scripts*; perl and LISP make *programs*." --me

Tom Christiansen tch...@convex.com convex!tchrist

Guenter Steinbach

unread,
Jul 24, 1991, 7:34:05 PM7/24/91
to
This is no help to the basenote poster but rather a plea to the Father
of Perl:

Please give us multi-line perl scripts, like we have them in awk!

Sure you can do everything in perl, but then you have to learn how to do
everything in perl. I am a hardware person (IC designer), and I only
write scripts when I need a new little tool. I'd love to convert my
shell/awk scripts to perl, if I could just translate the awk parts and
still have a working tool. And maybe I'd even go back later and hack
the surrounding ksh stuff some more. But I don't get paid for learning
all the intricacies of a baroquely complex language like perl.
(Although I hope to absorb them over the years.)

Anybody want to chime in or flame me?

Guenter Steinbach gunter_s...@hplabs.hp.com

Mike Greiner

unread,
Jul 24, 1991, 11:24:30 AM7/24/91
to
I'm a fairly new Perl user, and I've been experimenting with different ways
to include Perl in my unix toolbox. I've written standalone Perl programs,
Perl programs that invoke shell commands, and shell scripts that include
Perl programs. My question arises from the last case -- shell scripts that
include Perl programs.

In my shell script, I invoke a small perl program via the perl -e ' prog_
goes_here ' syntax. In one script, this worked fine, even for perl progs
of about 20 lines or so. In another script with a larger program (~100
lines), however, I kept getting an error message like unmatched "'. In
the end, I was able to convert the whole thing to a perl program, but I
never discovered why one script worked and the other didn't.

On page 349 of Programming perl, it says that the -e option

"May be used to enter one line of script. Multiple -e commands
may be given to build up a multi-line script. If -e is given,
Perl will not look for a script filename in the argument list."

So, have I just been getting lucky that multi-line perl programs have been
working in some of my shell scripts? (I'm not sure how to invoke with
multiple -e commands, so I don't think I've been doing it!)

Theories/tips appreciated!

--Mike

Stephane Payrard

unread,
Jul 25, 1991, 9:57:03 AM7/25/91
to

What is fantastic with perl is that you can choose your quotation
character so you don't have to wonder what is interpreted by who.
So you don't end up with shitload of bacslashes.

in perl:
q|whatever| is equivalent to 'whatever'
qq|whatever| is equivalent to "whatever"


perl -e 'print q|hello |.qq|'"$USER"'\n|'


Note that the breaking by the shell of the line to a command and its
argument is done after the various interpolation. So here, assuming
that $USER has value 'stef', the result is

perl -e 'print q|hello |.qq|'"$USER"'\n|'

and executed by perl prints:

stef

--
Stephane Payrard -- stephane...@eng.sun.com -- (415) 336 3726
SMI 2550 Garcia Avenue M/S 10-09 Mountain View CA 94043

Larry Wall

unread,
Jul 31, 1991, 1:45:23 PM7/31/91
to
In article <7240...@hpl-opus.hpl.hp.com> stei...@hpl-opus.hpl.hp.com (Guenter Steinbach) writes:
: This is no help to the basenote poster but rather a plea to the Father

: of Perl:
:
: Please give us multi-line perl scripts, like we have them in awk!

I can't, because I already did. I just typed the following to sh.
Note that each -e just appends a newline.

$ perl -l12e 'print __LINE__;
> print __LINE__;
> print __LINE__;
> print __LINE__;' -e 'print __LINE__;' -e 'print __LINE__'
1
2
3
4
5
6
$

In general, if you think something isn't in Perl, try it out, because it
usually is. :-)

: Sure you can do everything in perl, but then you have to learn how to do


: everything in perl. I am a hardware person (IC designer), and I only
: write scripts when I need a new little tool. I'd love to convert my
: shell/awk scripts to perl, if I could just translate the awk parts and
: still have a working tool. And maybe I'd even go back later and hack
: the surrounding ksh stuff some more. But I don't get paid for learning
: all the intricacies of a baroquely complex language like perl.
: (Although I hope to absorb them over the years.)

Fortunately, most of the baroque complexity of Perl is the spirit (ghost?
ghoul?) of Unix shining through, so a lot of that effort will apply elsewhere.

: Anybody want to chime in or flame me?

It's usually both or neither.

Larry

0 new messages