[18022] in Perl-Users-Digest
Perl-Users Digest, Issue: 182 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 31 09:20:03 2001
Date: Wed, 31 Jan 2001 06:10:20 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980950219-v10-i182@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 31 Jan 2001 Volume: 10 Number: 182
Today's topics:
Newbie Problem with setting environment variables and h scottpa@my-deja.com
Re: Newbie Problem with setting environment variables a <Peter.Dintelmann@dresdner-bank.com>
perl script to control ppp connection <gdaniell@wt.com.au>
Re: perl script to control ppp connection (Abigail)
Re: qr and backreferences (Rafael Garcia-Suarez)
Re: qr and backreferences (Abigail)
Re: qr and backreferences (Gwyn Judd)
Re: qr and backreferences (Rafael Garcia-Suarez)
Re: qr and backreferences (Abigail)
Re: Question on appending to file <Jerome.Abela@free.fr>
secure server ibjdt@my-deja.com
Securely tarring a directory on the web server (EED)
Sorting in NT like in Unix donz30@my-deja.com
Re: Sorting in NT like in Unix (Bernard El-Hagin)
Re: Sorting in NT like in Unix donz30@my-deja.com
Re: Sorting in NT like in Unix <pilsl_@goldfisch.at>
Re: Sorting in NT like in Unix <wyzelli@yahoo.com>
Re: Sorting in NT like in Unix <gdaniell@wt.com.au>
Re: Sorting in NT like in Unix donz30@my-deja.com
Re: Sorting in NT like in Unix (Garry Williams)
Re: to shift, or not to shift <bart.lateur@skynet.be>
Re: to shift, or not to shift <h.camp@scm.de>
traping die <ducateg@info.bt.co.uk>
Re: Unresponsive file handles.. <uri@sysarch.com>
Re: Windows NT Version <sturdevr@yahoo.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 31 Jan 2001 10:59:50 GMT
From: scottpa@my-deja.com
Subject: Newbie Problem with setting environment variables and hashes
Message-Id: <958r74$1l8$1@nnrp1.deja.com>
Hi,
Hope you can help. I am trying to set a new environment variable on
Win95 before calling a program. I found an example on the ng and tried
it but I am getting an error message and I am not sure what it means.
Can you tell me what I am doing wrong.
Thanks,
Alan
CODE:
%ENV{SSDIR} = "SET SSDIR=\\\\GCHE1\\DEVLPMNT\\SourceSafe
Databases\\Renaissance Apps";
D:\MyDocuments\perl>perl x
Can't use subscript on hash deref at x line 1, near "{SSDIR}"
(Did you mean $ or @ instead of %?)
Execution of x aborted due to compilation errors.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 31 Jan 2001 14:34:46 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: Newbie Problem with setting environment variables and hashes
Message-Id: <9594c8$am05@intranews.bank.dresdner.net>
Hi,
> CODE:
> %ENV{SSDIR} = "SET SSDIR=\\\\GCHE1\\DEVLPMNT\\SourceSafe
> Databases\\Renaissance Apps";
I expected to see something like
$ENV{SSDIR} = "\\\\GCHE1\\DEVLPMNT\\SourceSafeDatabases\\Renaissance
Apps";
> D:\MyDocuments\perl>perl x
> Can't use subscript on hash deref at x line 1, near "{SSDIR}"
> (Did you mean $ or @ instead of %?)
and did you follow this hint?
Regards,
Peter Dintelmann
------------------------------
Date: Wed, 31 Jan 2001 20:50:32 +0800
From: Graham Daniell <gdaniell@wt.com.au>
Subject: perl script to control ppp connection
Message-Id: <3A780A18.F84C76C@wt.com.au>
I am learning to use Perl on a RH 6.2 PC, which I use to share out my
internet connection to my wife's and kid's PC's.
I presently use 'ifup ppp0' in a batch file to allow them to start the
internet up. However if they dont check before running it, it
terminates the open connection and dials again - costing me another
phone call.
I want to write a script to test and report if the internet is connected
_before_ running 'ifup ppp0'.
Can I use perl to do this? If anyone can tell me how to call shell
commands from Perl it would be a big start.
Thanks,
Graham Daniell
gdaniell@wt.com.au
------------------------------
Date: 31 Jan 2001 13:50:50 GMT
From: abigail@foad.org (Abigail)
Subject: Re: perl script to control ppp connection
Message-Id: <slrn97g61q.cnd.abigail@tsathoggua.rlyeh.net>
Graham Daniell (gdaniell@wt.com.au) wrote on MMDCCX September MCMXCIII in
<URL:news:3A780A18.F84C76C@wt.com.au>:
!! I am learning to use Perl on a RH 6.2 PC, which I use to share out my
!! internet connection to my wife's and kid's PC's.
!!
!! I presently use 'ifup ppp0' in a batch file to allow them to start the
!! internet up. However if they dont check before running it, it
!! terminates the open connection and dials again - costing me another
!! phone call.
!!
!! I want to write a script to test and report if the internet is connected
!! _before_ running 'ifup ppp0'.
!!
!! Can I use perl to do this?
Well, yeah. The question hardly has to do with perl. Check out the
other programs in the if* family.
!! If anyone can tell me how to call shell
!! commands from Perl it would be a big start.
man perlipc
Abigail
--
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();
------------------------------
Date: Wed, 31 Jan 2001 08:05:30 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: qr and backreferences
Message-Id: <slrn97fhrh.69o.rgarciasuarez@rafael.kazibao.net>
Joseph Gottman wrote in comp.lang.perl.misc:
>
> I just realized that there is a problem with the interaction between the
> qr() operator and backreferences. Consider the following code
>
> my $repeat = qr((.)\1); #Look for repeated characters.
>
> If this pattern is later interpolated into a longer regular expression that
> also contains capturing parens, then the \1 refers to the first pair of
> capturing parentheses in the larger regular expression. Thus
>
> print ('abb' =~ /(.)$repeat/) ? 'true' : 'false'; #Prints false.
> print ('aba' =~ /(.)$repeat/) ? 'true' : 'false'; #Prints true.
>
> Is there any way to define $repeat so that it finds repeated characters even
> when interpolated into a longer regular expression?
I don't know. But you can use (?:...) to avoid making backreferences :
(see perlre)
print (('abb' =~ /(?:.)$repeat/) ? 'true' : 'false');
print (('aba' =~ /(?:.)$repeat/) ? 'true' : 'false');
-> prints 'true' and 'false'
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 31 Jan 2001 09:06:10 GMT
From: abigail@foad.org (Abigail)
Subject: Re: qr and backreferences
Message-Id: <slrn97flc2.c6t.abigail@tsathoggua.rlyeh.net>
Rafael Garcia-Suarez (rgarciasuarez@free.fr) wrote on MMDCCX September
MCMXCIII in <URL:news:slrn97fhrh.69o.rgarciasuarez@rafael.kazibao.net>:
?? Joseph Gottman wrote in comp.lang.perl.misc:
?? >
?? > I just realized that there is a problem with the interaction between the
?? > qr() operator and backreferences. Consider the following code
?? >
?? > my $repeat = qr((.)\1); #Look for repeated characters.
?? >
?? > If this pattern is later interpolated into a longer regular expression that
?? > also contains capturing parens, then the \1 refers to the first pair of
?? > capturing parentheses in the larger regular expression. Thus
?? >
?? > print ('abb' =~ /(.)$repeat/) ? 'true' : 'false'; #Prints false.
?? > print ('aba' =~ /(.)$repeat/) ? 'true' : 'false'; #Prints true.
?? >
?? > Is there any way to define $repeat so that it finds repeated characters even
?? > when interpolated into a longer regular expression?
??
?? I don't know. But you can use (?:...) to avoid making backreferences :
?? (see perlre)
??
?? print (('abb' =~ /(?:.)$repeat/) ? 'true' : 'false');
?? print (('aba' =~ /(?:.)$repeat/) ? 'true' : 'false');
??
?? -> prints 'true' and 'false'
That's not fixing the problem, it just avoids it in a specific case.
It won't work for instance for:
/$repeat$repeat/;
which matches 'aaba' and not aabb.
I strongly suggest that the original poster uses perlbug to report this.
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
------------------------------
Date: Wed, 31 Jan 2001 09:17:18 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: qr and backreferences
Message-Id: <slrn97fm0t.747.tjla@thislove.dyndns.org>
I was shocked! How could Abigail <abigail@foad.org>
say such a terrible thing:
>That's not fixing the problem, it just avoids it in a specific case.
>It won't work for instance for:
>
> /$repeat$repeat/;
>
>which matches 'aaba' and not aabb.
>
>I strongly suggest that the original poster uses perlbug to report this.
I disagree. I think the current behaviour is correct (but then I'm
weird). Someone suggested a solution that does the correct thing using
the postponed regular subexpression thing in 5.6 which I like better.
Maybe the problem is that the backreferences count up from the start of
the pattern match but that sometimes you might like a way to count
backwards and say "give me the n'th previous matched backref"?
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Man's unique agony as a species consists in his perpetual conflict between
the desire to stand out and the need to blend in.
-- Sydney J. Harris
------------------------------
Date: Wed, 31 Jan 2001 12:44:41 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: qr and backreferences
Message-Id: <slrn97g26v.6uu.rgarciasuarez@rafael.kazibao.net>
Gwyn Judd wrote in comp.lang.perl.misc:
> I was shocked! How could Abigail <abigail@foad.org>
> say such a terrible thing:
> >That's not fixing the problem, it just avoids it in a specific case.
> >It won't work for instance for:
> >
> > /$repeat$repeat/;
> >
> >which matches 'aaba' and not aabb.
> >
> >I strongly suggest that the original poster uses perlbug to report this.
>
> I disagree. I think the current behaviour is correct (but then I'm
> weird). Someone suggested a solution that does the correct thing using
> the postponed regular subexpression thing in 5.6 which I like better.
> Maybe the problem is that the backreferences count up from the start of
> the pattern match but that sometimes you might like a way to count
> backwards and say "give me the n'th previous matched backref"?
Thinking about this, I believe Abigail is right.
Quoting perlop :
qr/STRING/imosx
This operators quotes--and compiles--its STRING as
a regular expression.
If the result of qr// is compiled separately, then \1 should refer to a
backreference _inside_ the qr// pattern.
If not, why the following line produces an error ?
$ perl -e 'qr/\1/'
/\1/: reference to nonexistent group at -e line 1.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
perl -sleprint -- -_='Just another Perl hacker,'
------------------------------
Date: 31 Jan 2001 13:43:34 GMT
From: abigail@foad.org (Abigail)
Subject: Re: qr and backreferences
Message-Id: <slrn97g5k6.cnd.abigail@tsathoggua.rlyeh.net>
Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote on MMDCCX September MCMXCIII
in <URL:news:slrn97fm0t.747.tjla@thislove.dyndns.org>:
%% I was shocked! How could Abigail <abigail@foad.org>
%% say such a terrible thing:
%% >That's not fixing the problem, it just avoids it in a specific case.
%% >It won't work for instance for:
%% >
%% > /$repeat$repeat/;
%% >
%% >which matches 'aaba' and not aabb.
%% >
%% >I strongly suggest that the original poster uses perlbug to report this.
%%
%% I disagree. I think the current behaviour is correct (but then I'm
%% weird). Someone suggested a solution that does the correct thing using
%% the postponed regular subexpression thing in 5.6 which I like better.
%% Maybe the problem is that the backreferences count up from the start of
%% the pattern match but that sometimes you might like a way to count
%% backwards and say "give me the n'th previous matched backref"?
You mean, as in $qr = /(.)\2/;?
Well, may I suggest in that case you use perlbug, as that doesn't compile?
Abigail
--
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'
------------------------------
Date: Wed, 31 Jan 2001 10:44:37 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: Question on appending to file
Message-Id: <3A77EB92.2A0E00C0@free.fr>
dtbaker_dejanews@my-deja.com wrote :
> In article <956n4u$608$1@nnrp1.deja.com>,
> igotlooks.com <rbfitzpa@my-deja.com> wrote:
> > for(<*>) {
> > open(FILE,"<$_");
> > <FILE>;
> > if(!defined(<FILE>)) {
> > close(FILE);
> > open(FILE, ">>$_");
> > print FILE "";
> --------------
> with this one you might get in memory trouble if any of the files are
> VERY big, or you have LOTS of files in the directory. If neither is
> expected to be huge, then slurping should be fine. You might want to use
> a tight loop that just increments a counter and zips thru the file a
> line at a time rather than slurping in the entire contents. If the
> counter is one, then add you bogus line.
Double read the source. It does not slurp the files, it only reads the
first 2 lines.
> But I agree that the program READING the file should be fixed rather
> than this workaround if possible.
I think everyone agrees on this one...
Jerome.
------------------------------
Date: Wed, 31 Jan 2001 11:52:43 GMT
From: ibjdt@my-deja.com
Subject: secure server
Message-Id: <958uaa$418$1@nnrp1.deja.com>
i have a perl script which i run from a secure server. this script
needs to access a flatfile database (plain .txt file) which resides on
the non-secure server. i only need to read the file and post
information from it, but i have been unable to make this happen. is
this legal??
i have tried using the direct path, the url, you name it i feel i have
tried it. any other suggestions would be greatly appreciated.
also, i can't simply move the txt file to the secure server because it
is needed on the non-secure server by other scripts. this would create
the same problem in the other direction.
thanks
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 31 Jan 2001 14:23:58 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
To: eedrfl@eed.ericsson.se
Subject: Securely tarring a directory on the web server
Message-Id: <3A7811EE.A4BFA5D9@eed.ericsson.se>
Hi,
I am using File::Temp module to generate a temporary
directory on my web server:
use File::Temp qw (tempdir);
$TEMPDIR = '/www/doc/services/eed-x-sl/tmp';
...
$temp = tempdir (DIR => $TEMPDIR);
($short = $temp) =~ s/^$TEMPDIR\///o;
Then it is filled with some files by an external command
(clearmake of ClearCase)[1]. After that I would like to
offer a possibilty to download all the files as compressed
tarball, so I do:
system ("tar cfh - -C $TEMPDIR $short | gzip -c > $TEMPDIR/$short.tar.gz") and die $!
I am however concerned about the tmpfile attack (sp?) - if
someone would create a soft link from some system file to
the (to be created) tarball $TEMPDIR/$short.tar.gz - after
I create the temporary dir but before I call the tar command.
Are my concerns reasonable and how would you handle it?
Thanks
Alex
[1]: The clearmake creates some files with well-known
names, so this probably could be abused as well?
------------------------------
Date: Wed, 31 Jan 2001 09:11:48 GMT
From: donz30@my-deja.com
Subject: Sorting in NT like in Unix
Message-Id: <958ksh$t5q$1@nnrp1.deja.com>
Could somebody help me?
I need to find a way to sort in NT like in Unix environment.
The command line that i need to let work in NT is:
sort -k 4
In Unix, it works perfectly... but in NT no...do you know if there is
something similar?
Many Thanks
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 31 Jan 2001 09:52:24 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Sorting in NT like in Unix
Message-Id: <slrn97fo2o.2q0.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 31 Jan 2001 09:11:48 GMT, donz30@my-deja.com
<donz30@my-deja.com> wrote:
>Could somebody help me?
>I need to find a way to sort in NT like in Unix environment.
>
>The command line that i need to let work in NT is:
>sort -k 4
>
>In Unix, it works perfectly... but in NT no...do you know if there is
>something similar?
What the friggin' hell does this have to do with Perl???
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Wed, 31 Jan 2001 11:41:48 GMT
From: donz30@my-deja.com
Subject: Re: Sorting in NT like in Unix
Message-Id: <958tlr$3jt$1@nnrp1.deja.com>
You are right...just because i need to include it in a Perl script,
could you help me in finding a way?
Tks
In article <slrn97fo2o.2q0.bernard.el-hagin@gdndev25.lido-tech>,
bernard.el-hagin@lido-tech.net wrote:
> On Wed, 31 Jan 2001 09:11:48 GMT, donz30@my-deja.com
> <donz30@my-deja.com> wrote:
> >Could somebody help me?
> >I need to find a way to sort in NT like in Unix environment.
> >
> >The command line that i need to let work in NT is:
> >sort -k 4
> >
> >In Unix, it works perfectly... but in NT no...do you know if there is
> >something similar?
>
> What the friggin' hell does this have to do with Perl???
>
> Cheers,
> Bernard
> --
> #requires 5.6.0
> perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @
= [$ ?] }'
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 31 Jan 2001 12:56:51 +0100
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: Sorting in NT like in Unix
Message-Id: <MPG.14e21bf310250a2f9896f3@news.inode.at>
In article <958tlr$3jt$1@nnrp1.deja.com>, donz30@my-deja.com says...
> You are right...just because i need to include it in a Perl script,
> could you help me in finding a way?
you could write a perl-script that does what you want ?
peter
--
pilsl@
goldfisch.at
------------------------------
Date: Wed, 31 Jan 2001 22:02:58 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Sorting in NT like in Unix
Message-Id: <_BTd6.5$HS5.1579@vic.nntp.telstra.net>
<donz30@my-deja.com> wrote in message news:958tlr$3jt$1@nnrp1.deja.com...
> You are right...just because i need to include it in a Perl script,
> could you help me in finding a way?
> Tks
Use Perl's built in sort function?
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Wed, 31 Jan 2001 20:44:11 +0800
From: Graham Daniell <gdaniell@wt.com.au>
To: donz30@my-deja.com
Subject: Re: Sorting in NT like in Unix
Message-Id: <3A78089B.8803D323@wt.com.au>
Yes - you can download Perl for NT and install it, then use it as you
would on Unix
Graham Daniell
------------------------
peter pilsl wrote:
> In article <958tlr$3jt$1@nnrp1.deja.com>, donz30@my-deja.com says...
> > You are right...just because i need to include it in a Perl script,
> > could you help me in finding a way?
>
> you could write a perl-script that does what you want ?
>
> peter
>
> --
> pilsl@
> goldfisch.at
--
Graham Daniell
Perth, Western Australia
gdaniell@wt.com.au
------------------------------
Date: Wed, 31 Jan 2001 12:52:07 GMT
From: donz30@my-deja.com
Subject: Re: Sorting in NT like in Unix
Message-Id: <9591pl$6k4$1@nnrp1.deja.com>
Unfortunately i'm not a develloper, i'm just trying to modify an
existent script.
In article <MPG.14e21bf310250a2f9896f3@news.inode.at>,
peter pilsl <pilsl_@goldfisch.at> wrote:
> In article <958tlr$3jt$1@nnrp1.deja.com>, donz30@my-deja.com says...
> > You are right...just because i need to include it in a Perl script,
> > could you help me in finding a way?
>
> you could write a perl-script that does what you want ?
>
> peter
>
> --
> pilsl@
> goldfisch.at
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 31 Jan 2001 13:18:24 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Sorting in NT like in Unix
Message-Id: <AgUd6.9$Sn3.1609@eagle.america.net>
On Wed, 31 Jan 2001 09:11:48 GMT, donz30@my-deja.com <donz30@my-deja.com> wrote:
>Could somebody help me?
>I need to find a way to sort in NT like in Unix environment.
>
>The command line that i need to let work in NT is:
>sort -k 4
>
>In Unix, it works perfectly... but in NT no...do you know if there is
>something similar?
I would read the manual for the NT operating system. (You probably
will find that the command specifies its options in a different way
than the command with the same name in Unix.)
I would not ask this question here.
--
Garry Williams
------------------------------
Date: Wed, 31 Jan 2001 11:12:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: to shift, or not to shift
Message-Id: <5isf7t0rmoleo6gh2fj286idjehuvd0fh1@4ax.com>
Russ Jones wrote:
>In Christiansen & Torkington's Perl Cookbook, (in the parse_csv()
>segment on page 31), they show two ways to get a scalar into a
>subroutine. In the first one, they use
>
> my $text = shift;
>
>which seems pretty straight-forward to me. But in the second example,
>they don't use "shift" at all, instead they just reference $_[0]
>which also is relatively straight-forward. So can anyone tell me, is
>this just an example of "there's more than one way to do it" or is
>there some advantage to one way over the other?
In general, it's basically just TMTOWTDI, with as a basic rule:
my $one = shift;
vs.
my($foo, $bar) = @_;
but do feel free to break this rule. In other words: don't take it so
seriously.
Also note that direct usage of $_[0] (which is a bit unhandy only if you
want to access it more than just a few times) allows you to modify the
original parameter.
sub test {
chop $_[0];
}
$x = 'abc';
test($x);
print "\$x is '$x'\n";
-->
$x is 'ab'
--
Bart.
------------------------------
Date: Wed, 31 Jan 2001 12:57:22 +0100
From: H. Camphausen <h.camp@scm.de>
Subject: Re: to shift, or not to shift
Message-Id: <958ubc$934$2@surz18.uni-marburg.de>
[F'up zu Russ Jones's Posting vom Tue, 30 Jan 2001 16:23:25 -0600]
> ...two ways to get a scalar into a
> subroutine. In the first one, they use
>
> my $text = shift;
>
> which seems pretty straight-forward to me. But in the second example,
> ...they just reference $_[0]
> which also is relatively straight-forward. So can anyone tell me, is
> this just an example of "there's more than one way to do it" or is
> there some advantage to one way over the other?
This is not a question of style.
If you shift() (or assign $_[n]) to your variable, you get a /copy/ of
The Value. Further processing of your var will just affect this var.
It is thus up to you to decide what to return().
If you do something with $_[n], you work on the /passed data/, i.e. you
modify the respective /caller's data/ passed to your sub{}.
This may or may be not desirable.
hth + mfg, Hartmut
--
CREAGEN Computerkram Fon: 06422/850527
Hartmut Camphausen Fax: 06422/850528
Am kleinen Born 1 E-Mail: h.camp@creagen.de
35287 Amöneburg WWW: http://www.creagen.de
------------------------------
Date: Wed, 31 Jan 2001 10:12:51 -0000
From: "Géry" <ducateg@info.bt.co.uk>
Subject: traping die
Message-Id: <958okc$9j2$1@pheidippides.axion.bt.co.uk>
I have a module that is meant to trap die, it looks like this:
#!c:\perl\bin\perl
package Index::Error;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(display_error);
use CGI ( -unique_header );
use CGI::Carp qw(fatalsToBrowser);
use strict;
BEGIN
{
sub carp_error
{
my $error_message = shift;
my $q = new CGI;
my $discard_this = $q -> ("text/html");
display_error($q, $error_message);
}
CGI::Carp::set_message(\&carp_error);
}
sub display_error
{
my ($q, $error_message)=@_;
print $q->header("text/html"),
print $q->p("Error msg $error_message"),
print $q->end_html;
exit;
}
1;
I got that code of the CGI programming with Perl book.
I have another module that opens some files, thus the picture:
CGI perl script ---------> module to open file ----------> module to trap
die.
The CGI perl script calls a module that should open some files, read data
and return its business to the CGI bit. In case a die is call, I want to
trap it and display a house message.
This code sits in the "module to open file":
I have tried
open (INV, "< $inverted_file") or die "Cannot open the inverted file:
$!";
which return a blank page
and
open (INV, "< $inverted_file") or display_error($q, "Cannot open the
inverted file");
which has a very odd behaviour. It seems to compile upside down, thus, the
html header is only cast to the browser last, which is a behaviour that does
not seem to suit the browsers...
Any help, shared experience more than welcome
--
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Géry Ducatel
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
------------------------------
Date: Wed, 31 Jan 2001 08:11:34 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Unresponsive file handles..
Message-Id: <x7ofworvij.fsf@home.sysarch.com>
>>>>> "J/NE" == Jargon / Network Engineer <webmaster@jargonnetengineer.cjb.net> writes:
J/NE> Okay, now I feel like a complete idiot. Never mind this thread - I went
J/NE> back and put some files into place and the error went away.. One of the
J/NE> first things every hacker should learn - make sure all the files are
J/NE> there. Wow. I'm so stupid!
no, the first thing you should learn in perl is to test the result of
your open calls. if you had, you wouldn't have had your supposed bug and
made yourself look so foolish in public.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Wed, 31 Jan 2001 07:49:08 -0500
From: "BobS" <sturdevr@yahoo.com>
Subject: Re: Windows NT Version
Message-Id: <9591h2$n8t$1@bob.news.rcn.net>
"BobS" <sturdevr@yahoo.com> wrote in message
news:9571gr$oq3$1@bob.news.rcn.net...
> Hi,
> Does anyone know of a Perl way to identify NT Server vs NT Workstation?
> Environment variables only identify Windows_NT in both platforms. I've
come
> up with a kludge using winmsd.exe but it's bad ;-( Thanks.
> Bob
>
>
Thanks Chris and HC for the input. I've studied the doc for
Win32::TieRegistry...another Perl challenge. I figured the registry was the
way to identify the OS version but couldn't put the pieces together. I'm
pretty new to Perl but will give it a try.
Bob
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V10 Issue 182
**************************************