[9489] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3082 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 7 14:07:24 1998

Date: Tue, 7 Jul 98 11:00:27 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 7 Jul 1998     Volume: 8 Number: 3082

Today's topics:
    Re: 'NEXT' and 'LAST' in do-until <merlyn@stonehenge.com>
    Re: -- Picking up Extra .. Abigail, A Question for you. (Abigail)
    Re: -w on production code (was Re: better way of gettin (Larry Rosler)
    Re: -w on production code (was Re: better way of gettin (Stefan Berglund)
    Re: -w on production code (was Re: better way of gettin (Abigail)
    Re: -w on production code (was Re: better way of gettin <rra@stanford.edu>
    Re: -w on production code (was Re: better way of gettin <rra@stanford.edu>
    Re: -w on production code (Scott Erickson)
    Re: -w on production code (Mike Stok)
        2 dimensional array - Help needed (Huang)
    Re: 2 dimensional array - Help needed (brian d foy)
    Re: Abigail - Another Question for you. (Abigail)
        Accessing shell variables in a perl script <xmarkjones@mindless.com>
    Re: Accessing shell variables in a perl script (Sean McAfee)
    Re: autovivification and tie questions (Tye McQueen)
    Re: backticks <acornet@emory.edu>
    Re: backticks (brian d foy)
    Re: beginners csh problem. (brian d foy)
    Re: can glob do pattern matching like */*.c (Tye McQueen)
    Re: Command line argument (brian d foy)
    Re: delete key from array <simonf@conduit.co.uk>
    Re: Finding a string between to known tags? (Andre L.)
    Re: How do you delete arbitrary elements of an array in (brian d foy)
    Re: how long does it take to execute some code? (Michael J Gebis)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 07 Jul 1998 16:15:30 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: 'NEXT' and 'LAST' in do-until
Message-Id: <8cu34tk57y.fsf@gadget.cscaper.com>

>>>>> "Tom" == Tom Christiansen <tchrist@mox.perl.com> writes:

Tom>  [courtesy cc of this posting sent to cited author via email]
Tom> In comp.lang.perl.misc, 
Tom>     Randal Schwartz <merlyn@stonehenge.com> writes:
Tom> :This is one of the reasons that the Llama doesn't teach the do-while
Tom> :loop: 

Tom> Ahem: see p 62 in that new-spangled blue version, which you aren't 
Tom> quite so familiar with as you are with the pink version. :-)

Ahh, yes.  And if I had had my full say (which I didn't, as you
recall), it wouldn't have been in there.  So I suppose I'm blanking it
out to suppress the painful memories of that process.

:-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $22,319.19 collected, $186,159.85 spent; just 55 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: 7 Jul 1998 16:58:13 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: -- Picking up Extra .. Abigail, A Question for you.
Message-Id: <6ntk35$7v5$2@client3.news.psi.net>

Webcruiser (dfsdf@ziplink.net) wrote on MDCCLXX September MCMXCIII in
<URL: news:35A0E02C.796@ziplink.net>:
++ Abigail, what do you mean you wouldn't re-open the file?

That I would open the file for read/write, read the data, seek,
write new data, truncate then close.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


------------------------------

Date: Tue, 7 Jul 1998 09:07:46 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <MPG.100be7b259d58fa198971f@nntp.hpl.hp.com>

In article <6ntfa9$c7l$1@news1.sol.no> on 7 Jul 1998 15:36:41 GMT, Tina 
Marie Holmboe <tina@scandinaviaonline.se> says...
 ...
>     A script is written, with -w, and works nicely with Perl 5.xxx.
>     The script is put into production. with -w, and all is well.
>     Perl 5.xxx is updated to 5.xxx++
>     The script starts filling the errorslogs with warnings; warnings which are
>      quite correct, but which makes *other* peoples lives harder.

The only people who should have access to the error logs are those who 
know how to deal with them.  Then the owner of the program can fix the 
warnings (or the bugs they may reveal :-).

>   In other words, and again, leave off -w in *production* code. IMnsHO.

Don't...

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 7 Jul 1998 16:52:27 GMT
From: emwsbl@emw.ericsson.se (Stefan Berglund)
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <6ntjob$inr$1@news.mo.emw.ericsson.se>

Tina Marie Holmboe (tina@scandinaviaonline.se) wrote:
:   I thought I'd add a comment... personally I would *strangle* anyone
:   who left -w in production code; and be tempted to be rather mean to them
:   even with development ditto.

I would teach my coworker/boss an inpleasant lesson if they would even
imply that they where this stupid.

The reason to have -w is to be able to see the warnings, not looking
don't mean that they will go away it will just mean that they will
bite you without you knowing where it came from.  Warnings should be
_very rare_ in production code don't leave them in out of ignorance.

:   This, my attitude, has a reason. My current workplace has alot of people
:   developing alot of programs meant for running by HTTP servers. It is known
:   as "CGI-programming"... :)

Ooops... ;-)
The quality demands on CGI programs is much greater than on "ordinary"
scripts.  With this attitude you make serious security tradeoffs that
will open up your site.
You should not only use -w but use strict and -T as well.

Yes, it will mean that you have to be more careful when writing your
scripts.
Yes, it will mean that you have to know what your doing, which you
obviously don't, read perlsec, but you should probably start all over
again with perlrun...
Yes, it will take a little bit longer to write the scripts but the
extra time is well invested and it won't take _that_ much longer (if
your using incremental development... :-)

:   Most of the scripts written are not heavily debugged to rid themselves
:   of warnings. Like so many others I tend to tail -f the error logs when
:   I testrun CGI-script.

Exactly my point. :-)

You really don't call getting rid of warnings "debugging" getting rid
of all warnings is part of the development process. The reason that a
compiler/interpreter gives out warnings is to alert you that something
is wrong and the reason to get rid of it is so that they won't bite
you later.  In my world a warning is equivalent to a possible bug and
leaving them in production code is just not proffessional. 
CGI on the other hand is a much more serious matter leaving warnings
there is really more like suicide...
And you should probably do some serious debugging to ensure that your
programs really do what you intended/think they do.

:   And when people then use -w the net result is a furiously scrolling
:   screen, with absolutely *no* way of seeing any of the more serious
:   errors that might occur.

Then they should:
1. Learn to program perl, if you know what your doing then a
   "furiously scrolling screen" of errors and warnings just wont happen.
   Btw ever heard of more/less ;-) ?
2. Change career.

:   My .5c: think twice before leaving -w on production code. It might not
:   always be productive...

On the contrary in your application you should _always_ leave -w -T
and use strict in, they will provide you with warnings that will
signal a error that _must_ be fixed. They will also provide a basic
security to protect your site.

: -- 
:   Tina Marie Holmboe                
:   Systems Programmer    (Geeks'R'Us)         [tina@tech.scandinaviaonline.se]

No your not.

:   WebMaster                                  [webmaster@scandinaviaonline.se]

<sigh>

:   Scandinavia Online AB Development Dept.    (+46) 08 587 81000 (switchboard)
:                                              (+46) 08 587 81189 (direct)

Is this the quality you get when signing up for scandinavia online?

--
Stefan Berglund
UNIX and realtime software developer

Stefan.Berglund@emw.ericsson.se
f94stbe@dd.chalmers.se



------------------------------

Date: 7 Jul 1998 16:57:16 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <6ntk1c$7v5$1@client3.news.psi.net>

Tina Marie Holmboe (tina@scandinaviaonline.se) wrote on MDCCLXXI
September MCMXCIII in <URL: news:6ntfa9$c7l$1@news1.sol.no>:
++ In article <6nte3m$6gl$2@client3.news.psi.net>,
++ 	abigail@fnx.com (Abigail) writes:
++ 
++ 
++ > ++   My .5c: think twice before leaving -w on production code. It might not
++ > ++   always be productive...
++ > 
++ > 
++ > You shouldn't label alpha code as production code.
++ 
++   And exactly where did I write 'alpha' in the above ? I talked about
++   *production* code. I *meant* production code. Do me the courtesy of not
++   suggesting meaning that is not there.

You wrote:
++   And when people then use -w the net result is a furiously scrolling
++   screen, with absolutely *no* way of seeing any of the more serious
++   errors that might occur.

Anything that contains "serious errors" is alpha code in my book.

++     A script is written, with -w, and works nicely with Perl 5.xxx.
++     The script is put into production. with -w, and all is well.
++     Perl 5.xxx is updated to 5.xxx++
++     The script starts filling the errorslogs with warnings; warnings which ar
++      quite correct, but which makes *other* peoples lives harder.
++ 
++ 
++   In other words, and again, leave off -w in *production* code. IMnsHO.


Just for those once in more than a year events of upgrading Perl?
Don't you want to know what might be broken now, or will be broken
in the next release? Ever considered *testing* your scripts before
installing a new version of Perl?

If there's one reason to keep -w, it's for catching new problems when
Perl is upgraded.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


------------------------------

Date: 07 Jul 1998 10:17:44 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <m367h9r35z.fsf@windlord.Stanford.EDU>

Abigail <abigail@fnx.com> writes:

> Just for those once in more than a year events of upgrading Perl?  Don't
> you want to know what might be broken now, or will be broken in the next
> release? Ever considered *testing* your scripts before installing a new
> version of Perl?

> If there's one reason to keep -w, it's for catching new problems when
> Perl is upgraded.

We have hundreds of deployed scripts, sometimes in odd crannies of places.
It sometimes simply isn't feasible to delay a sitewide Perl upgrade,
particularly one that contains *security fixes* just to make sure that
we've tested every single piece of code.  And warnings suddenly showing up
*are* perceived as fatal errors by people who then procede to do dumb
things on that basis.

People should run their scripts frequently under -w.  People should test
all of their deployed scripts under -w before upgrading Perl.  But I've
learned from experience that the attitude that One Must Run Everything
Everywhere Under -w Always is flat-out wrong.  For one thing, the only
reason why the Perl core development team *can* move forward on things is
that hundreds of thousands of people aren't going to have their scripts
broken by a new warning.

If -w were mandatory, the development of Perl would be greatly slowed.
I'm serious.  Abigail should have seen this phenomenon; it's a common
theme on perl5-porters.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


------------------------------

Date: 07 Jul 1998 10:13:20 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <m390m5r3db.fsf@windlord.Stanford.EDU>

Stefan Berglund <emwsbl@emw.ericsson.se> writes:

> The reason to have -w is to be able to see the warnings, not looking
> don't mean that they will go away it will just mean that they will bite
> you without you knowing where it came from.  Warnings should be _very
> rare_ in production code don't leave them in out of ignorance.

This is a fallacy.  If you upgrade your production Perl, you'll quite
likely get warnings from deprecated functions and the like; these warnings
are ignorable for that version of code.  You should catch them in your own
check of your production code against the new version of Perl.

I challenge you to find any production Perl code that suddenly failed
because it had duplicate my declarations.

> Ooops... ;-)
> The quality demands on CGI programs is much greater than on "ordinary"
> scripts.  With this attitude you make serious security tradeoffs that
> will open up your site.

>From -w?  You've *got* to be kidding.

> You should not only use -w but use strict and -T as well.

use strict and -T, yes.  Not -w.

> Yes, it will take a little bit longer to write the scripts but the extra
> time is well invested and it won't take _that_ much longer (if your
> using incremental development... :-)

You *write* the script under -w.  You *test* the script under -w.  No one
is arguing anything different.  You then take -w off in production code,
because otherwise you're likely to get spurious warnings.

> You really don't call getting rid of warnings "debugging" getting rid
> of all warnings is part of the development process.

And for code that isn't still in development...?

> The reason that a compiler/interpreter gives out warnings is to alert
> you that something is wrong

Heh.  That's arguable.  It means that the compiler/interpreter *thinks*
there's something wrong.  I don't run all of my one-line scripts under -w
either.

> In my world a warning is equivalent to a possible bug and leaving them
> in production code is just not proffessional.

Sometimes a warning is a bug.  Sometimes it's a precaution.  Sometimes,
like with duplicate my declarations, it's lint.

> On the contrary in your application you should _always_ leave -w -T
> and use strict in, they will provide you with warnings that will
> signal a error that _must_ be fixed.

Bull.

> They will also provide a basic security to protect your site.

-w most certainly does not.

>> Systems Programmer    (Geeks'R'Us)

> No your not.

You're hardly one to talk about professionalism, if you think stooping to
personal insults in a comp.* group is going to win you anything at all.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


------------------------------

Date: Tue, 07 Jul 1998 16:11:23 GMT
From: Scott.L.Erickson@HealthPartners.com (Scott Erickson)
Subject: Re: -w on production code
Message-Id: <35a24712.522455541@news.mr.net>

Previously, tina@scandinaviaonline.se (Tina Marie Holmboe) wrote:

>  I thought I'd add a comment... personally I would *strangle* anyone
>  who left -w in production code; and be tempted to be rather mean to them
>  even with development ditto.

>  Most of the scripts written are not heavily debugged to rid themselves
>  of warnings.

>  And when people then use -w the net result is a furiously scrolling
>  screen, with absolutely *no* way of seeing any of the more serious
>  errors that might occur.

I agree that removing the -w switch is one way to eliminate some of
the error messages that are filling up your error logs. However, I
believe a better action to take is to fix the code that is causing the
error messages.

Where I am working, we are taking such an approach, fix the errors and
leave in the -w switch for production code. However, we have lots of
code that must be fixed. *sigh*

Scott.


------------------------------

Date: 7 Jul 1998 16:51:19 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: -w on production code
Message-Id: <6ntjm7$f59@news-central.tiac.net>

In article <35a24712.522455541@news.mr.net>,
Scott Erickson <Scott.L.Erickson@HealthPartners.com> wrote:

>I agree that removing the -w switch is one way to eliminate some of
>the error messages that are filling up your error logs. However, I
>believe a better action to take is to fix the code that is causing the
>error messages.
>
>Where I am working, we are taking such an approach, fix the errors and
>leave in the -w switch for production code. However, we have lots of
>code that must be fixed. *sigh*

How can I tell what new -w errors are likely to be put into future
versions of perl.  I think that -w is an amazingly useful development
aid.  

I try and make code -w and use strict clean in development and then take
-w off code in production.  One of the tests to try *before* upgrading
perl is to see if your code is still -w clean. 

-w does uncover potential danger spots, but how to satisfy everyone in all
eventualities seems a difficult problem...

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


------------------------------

Date: Tue, 07 Jul 1998 16:08:59 GMT
From: wong2020@tm.net.my (Huang)
Subject: 2 dimensional array - Help needed
Message-Id: <35a24750.15648766@news.tm.net.my>

Hi all:

   I have an input file with the following format 
1 2 3
4 5 6
7 8 9 

   I wish to input it into an array. 
The results I wish to accomplish is 
@x[1,1]=1
@x[1,2]=2
@x[3,1]=7

   I am not sure how Perl do it. I need help on this.
Huang
Thanks in advance. 


------------------------------

Date: Tue, 07 Jul 1998 13:10:43 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: 2 dimensional array - Help needed
Message-Id: <comdog-ya02408000R0707981310430001@news.panix.com>
Keywords: from just another new york perl hacker

In article <35a24750.15648766@news.tm.net.my>, wong2020@tm.net.my (Huang) posted:

>   I have an input file with the following format 
>1 2 3
>4 5 6
>7 8 9 

>   I wish to input it into an array. 
>The results I wish to accomplish is 
>@x[1,1]=1

those aren't the results that you want.  those are array slices -
somthing completely different (but it's not time for that yet).

how about multi-dimensional arrays, as discussed in the perldsc
man page?

   $matrix[$m][$n] = $value; #and so on.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


------------------------------

Date: 7 Jul 1998 17:06:50 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Abigail - Another Question for you.
Message-Id: <6ntkja$7v5$3@client3.news.psi.net>

Webcruiser (dfsdf@ziplink.net) wrote on MDCCLXX September MCMXCIII in
<URL: news:35A0E5EA.5C21@ziplink.net>:
++ I installed your suggested changes, but I still get a leading white
++ space. Here is the code I am using for the various routines. Also, I
++ have a question related to some of your comments. First, the code:
++ 
++ Subroutine to add a new merchant to my system:
++ sub addmerchant{
++ 	$aidfile = "$filedirectory$AID.dta";
++ 	open(FILE,">$aidfile")|| die "can't open file";
++ 	@status="New";               # All new merchants get this default
++ status
++ 	$STATUS=@status[0];          # $STATUS is the variable used in the html
++ form.
++ 	print FILE (@status);
++ 	close FILE;
++ }

What's the point of this? Have you any idea what
        @status="New";
does?

And 
        $STATUS=@status[0];
does something else than you think it does.

++ 
++ Subroutine to get the status of a merchant:
++ sub getstatus {
++ 	$aidfile = "$filedirectory$AID.dta";
++ 	open(FILE,"<$aidfile");
++ 	@STATUS=<FILE>;
++ 	foreach (@STATUS) {s/^ //;}   # Your suggested change.
++ 	$numlines=@STATUS;            # my old routine to look for a leading
++ space.
++ 	for ($x=1; $x<$numlines; $x++){
++ 		if (substr($STATUS[$x],0,1) eq " "){
++ 		$STATUS[$x]=substr($STATUS[$x],1);
++ 		}
++ 	}
++ 	close FILE;
++ }

Note that you read in the data into @STATUS, but you print out @status.
There is of course no need for your for() after my foreach ().

++ Subroutine to send the updateed changes as made from the html form at
++ http://webcruiser.com/manager/mmadmin.htm
++ 
++ sub updatestatus {
++ 	$aidfile = "$filedirectory$AID.dta";
++ 	open(FILE,">$aidfile");
++ 	print FILE (@STATUS);
++ 	close FILE;
++ }
++ 
++ ----------------------------
++ Now, my question. What did you mean with these comments?
++ 
++ # the return value of open.

That's only half of the comment. The entire comment reads:

        "Always, always, *always* test the return value of open."

++ #  @STATUS  eq join $,, @STATUS
++ # "@STATUS" eq join $", @STATUS
++ # $, eq "", $" eq " "
++ # That's where the spaces are coming
++ # from.

Exactly what I say. If you do 'print @STATUS;', you get the same as
you would have done 'print join $,, @STATUS;', and if you do
'print "@STATUS";', you get the same as 'print join $", @STATUS;'.

Please refer to 'perlvar' for detailed explaination of $" and $,.



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


------------------------------

Date: Tue, 07 Jul 1998 11:03:27 -0500
From: Mark Evan Jones <xmarkjones@mindless.com>
Subject: Accessing shell variables in a perl script
Message-Id: <35A246CF.B7426CBF@mindless.com>

We've got a handy little %ENV for accessing environment settings.  But
is there
any way to access the shell's own variables?  I've tried thigs like:

$temp = `echo $user`;
print ":$temp:\n";

which only print "::".  using $temp = `echo \$user`; prints ":$user:"
which makes
me believe there's a strange exchange going on between what string
escapes are
evealuated in perl and in the shell.  Doing

$var = '$user';
$temp = `echo $var`;

(thinking perl might be expanding the variable $user) also didn't work. 
Using the above
idea,

$var = '\nwhee\n'
$temp = `echo $var`;

prints "nwheen" while $temp = `echo \nwhee\n`; gives an error as the \n
becomes a newline
and ends the echo, when the shell then tries to run the command "whee."

I'm running out of ideas.  Anyone done this/know how to?

Mark Jones
(remove the x to reply by email)


------------------------------

Date: Tue, 07 Jul 1998 16:13:49 GMT
From: mcafee@breakout.rs.itd.umich.edu (Sean McAfee)
Subject: Re: Accessing shell variables in a perl script
Message-Id: <1Pro1.2758$24.15968582@news.itd.umich.edu>

In article <35A246CF.B7426CBF@mindless.com>,
Mark Evan Jones  <xmarkjones@mindless.com> wrote:
>We've got a handy little %ENV for accessing environment settings.  But
>is there
>any way to access the shell's own variables?

No.  Variables which are not exported are simply not available to child
processes of the shell (eg, Perl).  You can either a) export the
appropriate variables prior to running Perl, or b) pass the (expanded)
variables as arguments to Perl.  If you don't know ahead of time which
shell variables you need, and can't use either of the above methods (for
whatever reason), it's probably time to rethink your approach.

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


------------------------------

Date: 7 Jul 1998 11:53:34 -0500
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: autovivification and tie questions
Message-Id: <6ntjqe$eqn@fohnix.metronet.com>

gorilla@elaine.drink.com (Alan Barclay) writes:
) 
) Is this a typo, or will there be a 5.004_05 before 5.005?

5.004_05 is in beta.  5.005 is not in beta that I know of (but I
don't follow that too closely).
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


------------------------------

Date: Tue, 07 Jul 1998 11:56:59 -0400
From: Ben Cornett <acornet@emory.edu>
Subject: Re: backticks
Message-Id: <35A2454B.167E@emory.edu>

Klaus Peper wrote:
> 
> The following code is doing wrong at our website:
> 
> $files=`ls`;
> print "$files\n";
> 
> There is no print in this case, the webmaster told me that the
> list goes to the monitor.
> 
> I have implemented the Simple Search by Matt as a cgi script at
> my home page. The script uses similar backticks:
> $ls = `ls $file`;
> to scan directories.
> $ls was always empty.
> 
> I decided to provide the search script with an input file
> with all searchable files are indexed.
> This approach works fine.
> 
> However, I still wonder why the backticks do not work?
> 
> Klaus Peper
> http://www.med-rz.uni-sb.de/med_fak/physiol2/camellia/home.htm


I see nothing wrong with the above code.  In your script, is '$file'
still in scope when you call 'print'?
  
Ben


------------------------------

Date: Tue, 07 Jul 1998 13:03:23 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: backticks
Message-Id: <comdog-ya02408000R0707981303230001@news.panix.com>
Keywords: from just another new york perl hacker

In article <35A246D0.5AF1ECE9@med-ph.uni-sb.de>, Klaus Peper <peper@med-ph.uni-sb.de> posted:

>The following code is doing wrong at our website:
>
>$files=`ls`;
>print "$files\n";
>
>There is no print in this case, the webmaster told me that the
>list goes to the monitor.

does the output really go to the "monitor" (console?) or is he
just trying to hide his inability to answer the question?

the most glaring problem is that you did not specify which
ls you wanted to run.  CGI scripts typically have a different
environment or value for PATH, so the shell interaction is
a bit different.  you might not have any PATH at all, and if
you do, you should inspect it carefully to remove Bad Things.
see the beginning of 

you might try specifying the absolute path

   $files = `/bin/ls`;

or tweaking the PATH

   $ENV{'PATH'} = "/bin:/usr/bin";

if these don't work, there might be other problems, but let's
wait to see what happens before we speculate ;)

>I have implemented the Simple Search by Matt as a cgi script at
>my home page. The script uses similar backticks:
>$ls = `ls $file`;
>to scan directories.
>$ls was always empty.

looking at Matt's code is bad because it neglects Perl's built-in
features for tasks, ignores CGI programming conventions, and has 
lots security risks.

in this case, use of opendir() and friends would have probably
been easier - especially since you can get the filenames as a list
rather than having to parse the ls output or use another process.

>However, I still wonder why the backticks do not work?

the backticks work, and like any other programming task, the
computer does only what we tell it without trying to interpret what
we wanted to do. ;)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


------------------------------

Date: Tue, 07 Jul 1998 12:32:57 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: beginners csh problem.
Message-Id: <comdog-ya02408000R0707981232570001@news.panix.com>
Keywords: from just another new york perl hacker

In article <Pine.OSF.3.96.980707155133.3019C-100000@groay.cryst.bbk.ac.uk>, Neil Ranson <ubcg16u@mail.cryst.bbk.ac.uk> posted:

>I've just started learning perl and converting some csh scripts along the
>way, but I've run into a problem. How do I execute a program from perl
>which takes input from STDIN rather than as args?

i like IPC::Open3, but you might like one of the other techniques
found in the perlipc man page.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


------------------------------

Date: 7 Jul 1998 12:05:08 -0500
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: can glob do pattern matching like */*.c
Message-Id: <6ntkg4$iau@fohnix.metronet.com>

"Dave Smart" <re36648@deere.NOSPAM.com> writes:
) can glob do pattern matching like that shown below?
) 
) @files = glob("*.c");    # This works
) @files = glob("*/*.c");    # This does not work to iterate all next level
) sub-dirs.
) 
) I'm thinking the answer is no, but perhaps it's possible, but not with
) v5.004_02 on NT.

perlglob.exe under Win32 doesn't do this (I think it uses
OS routines to expand wildcards and these are really minimal).

perlglob.bat does this just fine (the name may be different or
it may not be included depending on the distribution you got but
it should match *glob*.bat -- it isn't included in the latest
ActiveState bundling of 5.004_69, silly people).

So just rename perlglob.exe do dosglob.exe and make sure that
*glob*.bat is named perlglob.bat (and is in your PATH) and
glob("*/*.c") will start working.

You can also do something like

    set PERL5OPTS=-MFile::DosGlob=glob

which prevents glob() from having to run an external program.
I haven't tested that line so there could be a mistake or two
in it.

I need to fix my module to make sure you can do

    set PERL5OPTS=-MFile::KGlob=glob

on Win32 and handle spaces in files and \ as directory separator.

Please don't switch to using <*/*.c> in place of glob("*/*.c").
<> for file globs needs to be phased out, IMHO.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


------------------------------

Date: Tue, 07 Jul 1998 12:31:40 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Command line argument
Message-Id: <comdog-ya02408000R0707981231400001@news.panix.com>
Keywords: from just another new york perl hacker

In article <35A23C69.63DE@aspentech.com>, Ian Boys <boys@aspentech.com> posted:

>Calle Dybedahl wrote:
>> 
>> Naama Kraus <naamah@haifa.vnet.ibm.com> writes:
>> 
>> > Now, when running:
>> > > my_prog abc*
>> > I receive the error:
>> > my_prog: No match

>> This is a Unix-shell question, not a Perl question. Get a beginner's
>> guide to Unix.

>Naama: The command shell tries to expand abc* with matching file names
>before calling the perl script.  When it can't find any matching files
>it gives the error you see.  It is misleading because 
>
>my_prog: No match
>
>makes you think the error comes from my_prog, instead of the shell. But
>your program has not even thought about beginning to run when this
>message gets printed.

>Can any Unix gurus tell my why this isn't a bug, or at least a
>mis-feature?  If the error comes from (say) sh, then why isn't the
>message
>
>sh: No match

well, you have to start talking about shell implementations since
not all of them do this.  (and, all of a sudden, this becomes a
discussion for some other forum.)

for example, with my stock Solaris shells:

(csh)
% ./test z*
No match

(sh and ksh do the same (they report no error) )
$ ./test z*
Hello World!

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


------------------------------

Date: Tue, 7 Jul 1998 11:30:00 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: delete key from array
Message-Id: <35a1f7e4.0@nnrp1.news.uk.psi.net>

Hi,

If you just want to lose the first value ( which is $array[0] BTW and not
$array[1] ) then you could just do a shift() if you want to selectively
delete elements from an array then look at the splice() function in the
perlfunc manpage.

Simon

dwiesel@my-dejanews.com wrote in message
<6nsqfq$bhf$1@nnrp1.dejanews.com>...
>Hi.
>
>I don't seem to find the (probably) simple answer...
>
>I have an array and want to delete a key from it
>
>@array = ("hallo", "hallo2");
>
>how do I delete $array[1] so that the arrays new look is ("hallo2") ???
>
>// Daniel
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




------------------------------

Date: Tue, 07 Jul 1998 13:35:10 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Finding a string between to known tags?
Message-Id: <alecler-0707981335100001@dialup-782.hip.cam.org>

In article <35A22CFF.C1E7105B@mesmtp.ericsson.se>, Marcus Spangenberg
<era.eraspma@mesmtp.ericsson.se> wrote:

> How do I find a string from a file that is located between a known
> start-tag and a known end-tag?
> 
> /Marcus


You can use the scalar range operator (..) .

A demo:


#!/usr/local/bin/perl -w

while (<DATA>) {
   $s .= $_ if /^START_TAG$/../^END_TAG$/;
}

$s =~ s/(?:START|END)_TAG\n//g; # to remove the tags
print $s;

__DATA__
This is the
first paragraph.
START_TAG
This is the text
we want.
END_TAG
This is a third
paragraph.


HTH,
A.L.


------------------------------

Date: Tue, 07 Jul 1998 12:16:34 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <comdog-ya02408000R0707981216340001@news.panix.com>
Keywords: from just another new york perl hacker

In article <35A23A2E.1DF445F@nortel.co.uk>, "F.Quednau" <quednauf@nortel.co.uk> posted:

>David A. Black wrote:

>> Looks pretty sorted to me.
>
>Yes, indeed. I said that above because of the following:
>
>sub sorthing {
>   my @arr = @_; 
>   for (sort @_) { print $_;}
>   for (sort @arr) { print $_;}
>}
>
>
>&sorthing(5,4,6);
>
>Gives: 546456


hmmm....

   #!/usr/bin/perl
   
   print "MacPerl version $]\n";
   
   &sorthing(5,4,6);
   
   sub sorthing {
      my @arr = @_; 
      for (sort @_) { print }
      print "\n";
      for (sort @arr) { print }
   }
   
   __END__

   MacPerl version 5.004
   456
   456

looks like it works to me.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


------------------------------

Date: 7 Jul 1998 16:19:48 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: how long does it take to execute some code?
Message-Id: <6nthr4$qc9@mozo.cc.purdue.edu>

dwiesel@my-dejanews.com writes:

}How do I find out how long time it takes to execute some code?

In addition to the Benchmark module others have already mentioned, you
may want to take a look at the Prof module, which lets you profile
your code.  It's fun, too.
 
-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 3082
**************************************

home help back first fref pref prev next nref lref last post