tobold.org

correct • elegant • free

△ comp.unix.shell △

◅ Shell Programming - Address Book

Help appreciared on the , init S command ▻

Perl and shell question....

In article <8cjneq$gqf$1@nnrp1.deja.com>,  <little_jenny@my-deja.com> wrote:
>I have a perl question.  I don't know if this is the right group,
>though....

comp.lang.perl.misc would be more appropriate, but some of us here
grok Perl, too...

>command_here | perl_script_here.pl NAME=$NAME SURNAME=$SURNAME NUM=$NUM

>This part of the perl script that I don't understand.  It's in the
>beginning of the Perl script though.....
>
>eval '$'.$1.'$2 ;' while  $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift ;

What part don't you understand?  The regular expression matches
arguments of the form `FOO=BAR', so the (inside-out) while loop runs
over each argument that fits this pattern.  The `eval' evaluates each of
these assignment arguments so that the variable is available to Perl.

So after all this, the Perl variables $NAME, $SURNAME, and $NUM will
have the same values as the same-named variables did in the shell
script.

This is actually all fairly pointless.  If the shell variables are
exported, they're *already* available to Perl, as $ENV{NAME}, etc.
Also, handing user-derived data (the Perl script's command-line
arguments) directly to `eval' makes me extremely nervous.  If a bad guy
could persuade NAME to have a value like `Smith; system "rm -rf /"',
you've got a serious problem...

Export those variables, and use %ENV instead.

Tim.
--
Tim Goodwin   | "If you don't know what closures are, you probably don't
Leicester, UK | want to know what closures are." -- Larry Wall

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.unix.shell
Subject: Re: Perl and shell question....
Date: 7 Apr 2000 13:04:18 +0100
Message-ID: <8ckiso$9oa$1@ltpcg.star.le.ac.uk>
References: <8cjneq$gqf$1@nnrp1.deja.com>

△ comp.unix.shell △

◅ Shell Programming - Address Book

Help appreciared on the , init S command ▻