[9439] in Perl-Users-Digest
Perl-Users Digest, Issue: 3034 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 1 00:07:24 1998
Date: Tue, 30 Jun 98 21: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, 30 Jun 1998 Volume: 8 Number: 3034
Today's topics:
Re: A funny problem with "use integer" <ljz@asfast.com>
Re: Cookies with Perl and IIS 4.0 (Jeremy D. Zawodny)
Re: Couple of quick ?'s from perl newbie (Jon Orwant)
Re: error using time on NT (Bob Trieger)
Re: File Upload - Need Help... <webmaster@triologic.com>
Re: Flames.... (Firebeard)
Re: Gurus or perl hackers a quick question!! (Ronald J Kimball)
Re: How do you do system administration with perl? (Martien Verbruggen)
Re: How to in perl <zenin@bawdycaste.org>
Re: Is perl5-porters closed to subscription? (Jeremy D. Zawodny)
Re: Looking for Perl seminars or classes (Tad McClellan)
Re: Looking for Perl seminars or classes (Thomas Munn)
Re: Matching over multiple lines (regexp problem) (Ronald J Kimball)
need a script (Raven)
Re: need a script (Jeremy D. Zawodny)
Re: Passing arguments to perl CGI (Martien Verbruggen)
Pg.pm rasyidi@my-dejanews.com
Re: Pg.pm <dgris@rand.dimensional.com>
Re: rename() not working ...any ideas? info@insyte.com
Re: rename() not working ...any ideas? (Ronald J Kimball)
Rexx perl translator <jlspea01@homer.louisville.edu>
Re: Scoping of test in if and while (Larry Rosler)
Re: Scoping of test in if and while (David A. Black)
Re: Scoping of test in if and while (Michael Rubenstein)
Re: What a Crappy World (Ronald J Kimball)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Jun 1998 21:50:45 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: A funny problem with "use integer"
Message-Id: <lthg12z6dm.fsf@asfast.com>
lr@hpl.hp.com (Larry Rosler) writes:
> In article <6nbvfr$mnt$1@news.cs.tu-berlin.de> on 1 Jul 1998 00:22:19
> GMT, Martin Schwartz <schwartz@cs.tu-berlin.de> says...
> > Josh Kortbein <kortbein@iastate.edu> wrote:
> >
> > >> Vivek> [kci]% cat |perl
> >
> > >> As I've said before, it's a good thing I don't give out Useless Use
> > >> of Cat Awards anywhere other than comp.unix.{shell,questions}.
> >
> > > Excuse this one, but what's so useless about the above usage?
> >
> > Try both:
> >
> > kir> cat | perl
> > print "Cats!\n";
> > ^D
> >
> > kir> perl
> > print "Dogs!\n";
> > ^D
>
> file cats contains: print "Cats!\n";
> file dogs contains: print "Dogs!\n";
>
> Try both:
>
> kir> cat cats dogs | perl
>
> kir> perl cats dogs
>
> Not so useless, eh?
Very true. But "Useless Uses of cat" do not include cases where `cat'
takes more than a single filename on the command line. The name `cat'
is short for `catenate' (or perhaps `concatenate'), and this
concatenation usage is precisely something that `cat' is quite useful
for.
In case there are those out there who aren't familiar with this
"Useless Use of cat" concept, some of the traditional cases of this
are exemplified as follows:
(1) program | cat >file
Alternative: program >file
(2) program | cat | other-program
Alternative: program | other-program
(3) cat file | program
Alternative: program <file
(4) cat | program
Alternative: program
(5) cat file | typical-filter-program (see below)
Alternative: typical-filter-program file
(6) ... etc. ...
By "typical-filter-program", I'm referring to one of a number of
programs which either take their input from the effective
concatenation of the contents of the files named on their command
lines, or else if there are no such filename arguments, from stdin. A
far-from-exhaustive list of such programs (in addition to `cat'
itself, of course) is:
awk, sed, grep, eqn, nroff, cut, od ...
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: 30 Jun 1998 22:47:41 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Cookies with Perl and IIS 4.0
Message-Id: <m3iuli478y.fsf@peach.z.org>
bigbeta69@my-dejanews.com writes:
> # Print out the HTML Content-Type header.
> print "Content-type: text/html\n";
> # Set a new cookie.
> &SetCookies('user','1'); #This is from a library from Matt's Script Archive
> # End the headers sent to browser.
> print "\n";
> I know i'm missing somehting very simple.. Any help is appreciated..
Maybe the fact that you're printing a Content-type header before your
cookies? Beats me. Try CGI.pm and your problems will vanish. Really.
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: 01 Jul 1998 03:43:05 GMT
From: orwant@bad-taste.media.mit.edu (Jon Orwant)
To: cberry@cinenet.net (Craig Berry)
Subject: Re: Couple of quick ?'s from perl newbie
Message-Id: <ORWANT.98Jun30234305@bad-taste.media.mit.edu>
cberry@cinenet.net (Craig Berry) writes:
cia1@ix.netcom.com wrote:
[snip]
: print DB "$FORM{'name'}|$FORM{'email'}|$FORM{'phone'}|$FORM{'room'}|
: $FORM{'month'}|$FORM{'day'}|$FORM{'year'}|$FORM{'from'}|$FORM{'ampm'}|
: $FORM{'to'}|$FORM{'ampm2'}\n";
[snip]
It's often easier to write multi-hash-field concatenations such as yours
like this:
my @outfields = qw( name email phone room month day year
from ampm to ampm2 );
print DB join('|', @FORM{@outfields}), "\n";
Both easier to type and a *whole* lot easier to maintain.
Even easier: Just set $, to "|".
-Jon
------------------------------------
Jon Orwant http://tpj.com
Editor & Publisher, The Perl Journal
--
------------------------------
Date: Wed, 01 Jul 1998 02:06:31 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: error using time on NT
Message-Id: <6nc5n3$kua$1@strato.ultra.net>
[ posted and mailed ]
"Michael Equi" <mequi@newtonline.com> wrote:
-> I am trying to do something very simple, but am getting an error.
-> I want to get the current time. I have tried:
->
-> $string =time;
->
-> I also tried:
->
-> use Time::localtime;
->
-> printf "Year is %d\n", localtime->year() + 1900;
->
-> as a test but I always get the response:
->
-> "The system cannot accept the time entered.
-> Enter the new time:"
->
-> Any ideas?
The documentation is your friend.
perldoc -f localtime
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
and let the jerk that answers know that his
toll free number was sent as spam. "
------------------------------
Date: Wed, 01 Jul 1998 02:25:01 GMT
From: Nick Forte <webmaster@triologic.com>
To: Russ Allbery <rra@stanford.edu>
Subject: Re: File Upload - Need Help...
Message-Id: <35999C33.C0286BEF@triologic.com>
Russ,
Thanks. I'm kinda new to PERL, so bare with me. What's the difference if I
have a PERL file create and write to a file on the server (which I can do) or
if I have upload it from a user's PC? Both ways are entrusting the PERL
script to handle it.
Nick Forte
Russ Allbery wrote:
> Nick Forte <webmaster@triologic.com> writes:
>
> > I have this script running on an ISP's box and it basically does this:
>
> > * Take an image file(jpg only) from the user's PC and write to the
> > server in a certain directory.
>
> Hope you're using CGI.pm to do the file upload, as pretty much any other
> tool is unlikely to get it right.
>
> > My problem is that it writes 0 bytes, because the owner defaults to
> > 'nobody', which doesn't have permission to write to the server. How do I
> > get around this?
>
> Um, change the permissions?
>
> > Is there a special module just for this?
>
> No?
>
> Honestly, the problem that you're having is that the web server can't
> write to directories. This is intentional. If the web server could write
> to directories, the web server would be a big potential security hole. If
> you grant the web server permissions to write to directories, including by
> file upload, you're creating a security hole, and the server is going to
> make it hard for you to do that.
>
> You have a few options:
>
> * Create a directory that's world-writeable or writeable by the web
> server user (who, if you do this, should be a user *other* than nobody
> so that you don't break the Unix semantics for nobody). This is
> functionally equivalent to setting up an anonymous upload directory
> via ftp and should be handled with the same caution, including
> carefully watching what shows up there. In particular, you should not
> write to a "live" directory; you should pick things up from the
> directory and move them (possibly from cron).
>
> * Use one of the many toolsets available for CGI scripts to let them run
> as users and run the upload script as a user that has permissions to
> write to the directory you want to write to. THIS SHOULD BE DONE WITH
> EXTREME CAUTION -- see the warnings on the toolsets that let you do
> this.
>
> BTW, your question really doesn't have anything to do with Perl; in the
> future, please send questions like this to a CGI programming group
> instead.
>
> --
> #!/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: 30 Jun 1998 19:38:50 -0500
From: stend+c.l.perl.misc@sten.tivoli.com (Firebeard)
Subject: Re: Flames....
Message-Id: <vplnqequat.fsf@dogbert.support.tivoli.com>
>>>>> birgitt writes:
b> The pain is on the side of those who are paying for services to
b> people who reveal here how funny it is when they try to get rid of
b> a customer's project in charging extreme prices and then
b> nevertheless get it, happily abusing the customer's non-programming
b> status. In no other profession would you find that kind of
b> behaviour.
Auto mechanics. Several organizations and publications (AAA,
Popular Mechanics, Consumer Reports, etc) periodically report on the
number of auto shops which will happily abuse the customer's
non-mechanical (and, often, non-male) status. Of course, they don't
do it to get rid of the customer, but to rip the customer off, so I
guess that's better.
--
#include <disclaimer.h> /* Sten Drescher */
Unsolicited bulk email will be stored and handled for a US$500/KB fee.
"ThisemailhasbeenbroughttoyoubyJOLTCola,favoredbyssysadmins,netadminsand
programmerseverywhere.JOLTCola--forallthesugarandtwicethecaffeine(R)."-
bofh@visi.com
------------------------------
Date: Tue, 30 Jun 1998 23:29:45 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Gurus or perl hackers a quick question!!
Message-Id: <1dbgjr1.16stacv1uaufniN@bay2-513.quincy.ziplink.net>
Charlie Stross <charlie@antipope.org> wrote:
> my (@bits) = split(/\s+?-\s+?/, $_);
The first ? is useless, the second ? is incorrect.
Consider:
DB<1> $_ = 'foo - bar';
DB<2> x split /\s+?-\s+?/
0 'foo'
1 ' bar'
DB<3> x split /\s+-\s+/
0 'foo'
1 'bar'
Whether you use non-greedy matching or not, the regex will still match
the *leftmost* substring. In 'foo - bar', both regexes start at
the space after foo and match up to the -. (And the non-greedy one is a
little less efficient.)
non-greedy matching is useful only when the quantified subexpression and
the subsequent subexpression can match an identical substring. For
example, in /.*?[xyz]/, both .*? and [xyz] can match the substring 'x'.
After the dash, the non-greedy version matches one space and quits,
while the greedy version matches all the spaces.
non-greedy matching is never useful at the end of a regex.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 1 Jul 1998 02:34:13 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: How do you do system administration with perl?
Message-Id: <6nc775$ac7$2@comdyn.comdyn.com.au>
In article <359982cb.610639@news.direct.ca>,
charlesh@direct.ca writes:
> Advanced perl users,
> I'd like to read some real examples as mentioned in subject.
You write scripts that do what you want to do. I can't be more
specific, because you fail to mention the platform and tasks.
Please, don't post your platform and tasks without checking the
following:
> Anyone can point some places or books for me?
http://www.perl.com is always a good starting point for this.
http://www.perl.com/CPAN/modules might have some modules to assist
you.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | This matter is best disposed of from a
Commercial Dynamics Pty. Ltd. | great height, over water.
NSW, Australia |
------------------------------
Date: 1 Jul 98 02:26:04 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: How to in perl
Message-Id: <899260723.211116@thrush.omix.com>
ac123@simpatico.ca wrote:
: I am new to perl and would like to do the following sed command but
: all in perl:
:
: sed 1,6d filename
Here's one way
perl -ne 'print if $. > 6' filename
You could also check out the s2p (sed to perl) translator, although
it does tend to spit out massive amounts of code for otherwise
simple things. -Just the script "1,6d" for instance creates a
31 line perl script!
: The reason why I want to do this in perl is because I am on a win32
: platform running Perl and don't have access to sed.
Well, gnu tools are available for Win32, sed included.
: Many people have
: said that if I had perl I didn't need sed for win32.
Many people are correct. :-)
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: 30 Jun 1998 22:44:41 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Is perl5-porters closed to subscription?
Message-Id: <m3lnqe47dy.fsf@peach.z.org>
Quentin Fennessy <quentin@shaddam.amd.com> writes:
> Is perl5-porters closed to subscription?
I don't think so.
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: Tue, 30 Jun 1998 21:33:19 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Looking for Perl seminars or classes
Message-Id: <f57cn6.nci.ln@localhost>
Winter War Gaming Convention (xx598@prairienet.org) wrote:
: My company has some funds in the training budget this year, and I'm
: looking for a good company that offers perl classes for our new guys.
I think you may find a lead or two if you do a word search for
'training' in the documentation that is included with the perl
distribution.
: Please reply to me in e-mail.
Why? Do you want to keep it a secret or something?
Maybe someone else on the newsgroup would like to see the answer too.
This is not a personal service help desk.
Ask it here, get the answer here.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 01 Jul 1998 03:26:14 GMT
From: munn@bigfoot.com (Thomas Munn)
Subject: Re: Looking for Perl seminars or classes
Message-Id: <6ncagb$a5l$1@News.Alliance.Net>
Have you considered Randall Schwartz's class? He offers 5 day lectures both onsite and in Portland Oregon.
Thomas
------------------------------
Date: Tue, 30 Jun 1998 23:29:49 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Matching over multiple lines (regexp problem)
Message-Id: <1dbgkym.iourun14fgou8N@bay2-513.quincy.ziplink.net>
F.Quednau <quednauf@nortel.co.uk> wrote:
> open FILE, "< /u/quednauf/temp/knowledge.net" or die "*sigh*: $!";
> $/ = undef;
undef $/; or local $/; might be preferred.
> SLURP: while (<FILE>) {
Why do you undef $/, and then iterate over <FILE>? You do realize that
undef-ing $/ means you read an entire file at once, don't you?
> if (/Subject: (.*?)\n/) {
Useless use of non-greedy matching (. won't match newline). Also rather
inefficient.
Don't forget to anchor the regex to the beginning of a line.
if (/^Subject:\s+(.*)$/m) {
(The $ doesn't really make a difference.)
The same applies to your other regexes to match the headers.
> if (/X-Mozilla-Status: 8001\n(.*?)\nFrom -/s) {
I'm not sure why this doesn't match. Are you sure there is no white
space after '8001' in the file?
Don't forget to anchor the regex to the beginning of a line.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 01 Jul 1998 05:20:07 GMT
From: raven1@hotmail.com (Raven)
Subject: need a script
Message-Id: <3599c6c3.9386015@news.mindspring.com>
anyone have a script that records how many times a file has been
downloaded, and then puts on a webpage that number?
------------------------------
Date: 30 Jun 1998 22:52:24 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: need a script
Message-Id: <m3g1gm4713.fsf@peach.z.org>
raven1@hotmail.com (Raven) writes:
> anyone have a script that records how many times a file has been
> downloaded, and then puts on a webpage that number?
Yes.
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: 1 Jul 1998 02:31:43 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Passing arguments to perl CGI
Message-Id: <6nc72f$ac7$1@comdyn.comdyn.com.au>
In article <6nbpti$mvj$1@news.rt66.com>,
mikep@rt66.com (mikep) writes:
> I'm using a perl script as a CGI script. I'd like to pass arguments to
> it. What is the appropriate syntax to interact with the HTTP server
> (e.g. is there one general way in which parameters are passed to a CGI
> script?)? Once I pass the arguments, how do they appear to the script
> itself (e.g. in the $ARGV built-in variable?)?
You're really asking two things:
1) How does CGI work?
You should ask this on a CGI specific newsgroup, and/or read some
documentation on the CGI protocol. Go to www.cgi-resources.com and
look at some of the stuff there. CGI has nothing to do with perl
2) How do I do CGI stuff in perl?
Use a module. CGI.pm comes to mind. It should be included in every
recent perl distribution.
Don't try to do everything yourself. You're bound to make mistakes.
CGI.pm is a thoroughly debugged environment to do CGI stuff.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd. | excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Wed, 01 Jul 1998 01:28:12 GMT
From: rasyidi@my-dejanews.com
Subject: Pg.pm
Message-Id: <6nc3bb$n4a$1@nnrp1.dejanews.com>
Where can I get the full documentation, reference, example script and
tutorial for Pg.pm(Perl for PostgreSQL)?
Thanks
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Wed, 01 Jul 1998 02:53:02 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Pg.pm
Message-Id: <6nc7oh$evb$1@rand.dimensional.com>
In article <6nc3bb$n4a$1@nnrp1.dejanews.com>
rasyidi@my-dejanews.com wrote:
>Where can I get the full documentation, reference, example script and
>tutorial for Pg.pm(Perl for PostgreSQL)?
>
Look in the eg/ directory of your Pg distribution. It has examples
of both the oldstyle and newstyle interfaces.
Daniel
--
Daniel Grisinger dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
Dave Clark
------------------------------
Date: Wed, 01 Jul 1998 02:36:00 GMT
From: info@insyte.com
Subject: Re: rename() not working ...any ideas?
Message-Id: <6nc7ah$v0l$1@nnrp1.dejanews.com>
If you are using Build 316 of the ActiveState port of PERL this is a known bug
see their web site.
John Steele
In article <Pine.GSO.3.96.980630135856.15737Q-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>
> On 30 Jun 1998, Glenn Holden - Internet Support wrote:
>
> > rename("$dirpath/$oldfile", "$dirpath/$newfile");
>
> > No error messages are generated. The file is simply NOT renamed.
>
> If you want error messages, write code that makes error messages! Perl
> doesn't read your mind unless you use the DWIM module. :-)
>
> rename("$dirpath/$oldfile", "$dirpath/$newfile")
> or die "Couldn't rename '$dirpath/$oldfile' to '$dirpath/$newfile': $!";
>
> Hope this helps!
>
> --
> Tom Phoenix Perl Training and Hacking Esperanto
> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
>
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Tue, 30 Jun 1998 23:29:53 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: rename() not working ...any ideas?
Message-Id: <1dbglsi.ah1we4os3kdN@bay2-513.quincy.ziplink.net>
Tom Phoenix <rootbeer@teleport.com> wrote:
> Perl doesn't read your mind unless you use the DWIM module. :-)
I tried to use the DWIM module, and got this output:
Can't locate DWIM.pm in @INC at readmind line 1.
BEGIN failed--compilation aborted at readmind line 1.
Is there a way to make Perl read my mind without using modules?
;-)
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 30 Jun 1998 22:27:45 -0400
From: Joe Spears <jlspea01@homer.louisville.edu>
Subject: Rexx perl translator
Message-Id: <35999EA1.AB3B891A@homer.louisville.edu>
> I am working on a program to translate rexx code written using xedit on
> a vm mainframe system into EXECUTABLE code written in perl for a unix
> system, using perl 5.0.
>
> My question is, has anyone any knowledge of similar projects, or maybe
> someone who has already done something similar to this, maybe even using
> a different version of rexx or perl.. (notes would be helpful)
>
> If anyone is interested in collaborating on this project is welcome to
> join... I have some of the parsing already done and some system flow
> stuff... of course there are always bugs...
>
> Thank you,
> Joe
------------------------------
Date: Tue, 30 Jun 1998 18:16:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Scoping of test in if and while
Message-Id: <MPG.10032dca6409177a9896df@nntp.hpl.hp.com>
In article <359b8516.77856441@nntp.ix.netcom.com> on Wed, 01 Jul 1998
00:45:33 GMT, Michael Rubenstein <miker3@ix.netcom.com> says...
...
> Apparently the test expression of an if is considered to be outside
> the scope of the controlled block and the test expression of a while
> is considered to be inside.
>
> I cannot find any documentation on this feature (bug?).
For information about Perl's special variables, did you look in perlvar
(`perldoc perlvar`)?
$& The string matched by the last succe4ssful pattern match (not
counting any matches hidden within a BLOCK or eval() enclosed
by the current BLOCK).
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 30 Jun 1998 22:05:27 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: Scoping of test in if and while
Message-Id: <6nc5h7$fpe$1@earth.superlink.net>
Hello -
lr@hpl.hp.com (Larry Rosler) writes:
>In article <359b8516.77856441@nntp.ix.netcom.com> on Wed, 01 Jul 1998
>00:45:33 GMT, Michael Rubenstein <miker3@ix.netcom.com> says...
>...
>> Apparently the test expression of an if is considered to be outside
>> the scope of the controlled block and the test expression of a while
>> is considered to be inside.
>>
>> I cannot find any documentation on this feature (bug?).
>For information about Perl's special variables, did you look in perlvar
>(`perldoc perlvar`)?
>$& The string matched by the last succe4ssful pattern match (not
> counting any matches hidden within a BLOCK or eval() enclosed
> by the current BLOCK).
But Michael understood that. He wasn't puzzled by the fact that $&
didn't retain a value from inside a block. He was puzzled by the fact
that the definition of "inside a block" (i.e., whether or not we are)
seems to be different as between the test expressions of if and while.
(Indeed, he was using the fact that $& doesn't reflect block-enclosed
matches to make his point.)
I don't understand it (the if vs. while behavior) either, but for
what it's worth, here's another little testbed for it - this time
using local and my variables to report on scope (which they do
differently from each other).
#!/usr/local/bin/perl
#
# (-w is a slight distraction here)
print "Using local variables:\n";
$x = "x initialized in outer scope"; # global incarnation
if (local $x = "x initialized in if test") {
print "Inside if block: $x\n"
}
print "Out of if block: $x\n";
while (local $x = "x initialized in while test") {
print "Inside while block: $x\n";
last;
}
print "Out of while block: $x\n";
print "\nUsing my variables:\n";
my $y = "y initialized in outer scope";
if (my $y = "y initialized in if test") {
print "Inside if block: $y\n"
}
print "Out of if block: $y\n";
while (my $y = "y initialized in while test") {
print "Inside while block: $y\n";
last;
}
print "Out of while block: $y\n";
__END__
[output]
Using local variables:
Inside if block: x initialized in if test
Out of if block: x initialized in if test
Inside while block: x initialized in while test
Out of while block: x initialized in if test
Using my variables:
Inside if block: y initialized in if test
Out of if block: y initialized in outer scope
Inside while block: y initialized in while test
Out of while block: y initialized in outer scope
David Black
dblack@saturn.superlink.net
------------------------------
Date: Wed, 01 Jul 1998 02:33:41 GMT
From: miker3@ix.netcom.com (Michael Rubenstein)
Subject: Re: Scoping of test in if and while
Message-Id: <35a29e33.84285786@nntp.ix.netcom.com>
On Tue, 30 Jun 1998 18:16:33 -0700, lr@hpl.hp.com (Larry Rosler)
wrote:
>In article <359b8516.77856441@nntp.ix.netcom.com> on Wed, 01 Jul 1998
>00:45:33 GMT, Michael Rubenstein <miker3@ix.netcom.com> says...
>...
>> Apparently the test expression of an if is considered to be outside
>> the scope of the controlled block and the test expression of a while
>> is considered to be inside.
>>
>> I cannot find any documentation on this feature (bug?).
>
>For information about Perl's special variables, did you look in perlvar
>(`perldoc perlvar`)?
>
>$& The string matched by the last succe4ssful pattern match (not
> counting any matches hidden within a BLOCK or eval() enclosed
> by the current BLOCK).
Of course I did. That quote has nothing to do with my question.
Why is the test expression in the while considered to be within the
block controlled by the while and the test expression in the if not
considered to be within the block controlled by the if?
If the quote you cite explains that, I'm afraid it escapes me.
--
Michael M Rubenstein
------------------------------
Date: Tue, 30 Jun 1998 23:29:59 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: What a Crappy World
Message-Id: <1dbgmda.17u89vs18g26emN@bay2-513.quincy.ziplink.net>
John Stanley <stanley@skyking.OCE.ORST.EDU> wrote:
> How suave. The analogy I used isn't an identity. That's why it's called
> an analogy.
Tomorrow, we'll learn about something called "a sense of humor". :-)
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
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 3034
**************************************