[9294] in Perl-Users-Digest
Perl-Users Digest, Issue: 2889 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 17 06:07:16 1998
Date: Wed, 17 Jun 98 03: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 Wed, 17 Jun 1998 Volume: 8 Number: 2889
Today's topics:
Re: $a: numeric or NOT ? (Abigail)
`fork' in Perl debugger under emacs (Mark-Jason Dominus)
AIX Question jcamp@plexi.com
BOOK: Perl from the Ground Up <cornelius21@yahoo.com>
Re: Electronic Fax? (Colin Macleod)
Re: Input type="file" <spisser@bigfoot.com>
Re: Missing module - IO::File (M.J.T. Guy)
Re: More efficient search - binary search?? (Mark-Jason Dominus)
Perl & Database jcamp@plexi.com
Perl & GDBM jcamp@plexi.com
Re: PERL/CRON problem (Martien Verbruggen)
Re: Placing variables in system calls (M.J.T. Guy)
Re: print <<END (with variables) <msazonov@usa.net>
Re: print <<END (with variables) <ebohlman@netcom.com>
Re: Puzzle challenge (clarified) (Ronald J Kimball)
Re: Puzzle challenge (clarified) (Ilya Zakharevich)
Re: Q: grep/map and regex recompilation (Mark-Jason Dominus)
Re: Q: grep/map and regex recompilation (Mark-Jason Dominus)
Re: Q: grep/map and regex recompilation (Ilya Zakharevich)
Re: Reading in multiple lines from file--elegant soluti (Matt Knecht)
Re: Reading in multiple lines from file--elegant soluti (Larry Rosler)
Re: REVIEW: Perl CGI Programming - No Experience Requir (Ronald J Kimball)
Re: REVIEW: Perl CGI Programming - No Experience Requir (Rahul Dhesi)
Re: REVIEW: Perl CGI Programming - No Experience Requir (Rahul Dhesi)
Re: strange error message .. "value of <handle> ..." (Ronald J Kimball)
Re: Undefined subroutine CGI::pram (Martien Verbruggen)
win32 <nospam_billteam@creaweb.fr>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Jun 1998 06:49:32 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: $a: numeric or NOT ?
Message-Id: <6m7ots$ppv$1@client3.news.psi.net>
Ronald J Kimball (rjk@coos.dartmouth.edu) wrote on MDCCLI September
MCMXCIII in <URL: news:1daqr6b.nz8r3xglbmtuN@bay1-114.quincy.ziplink.net>:
++ Keith Thompson <kst@king.cts.com> wrote:
++
++ > I couldn't find any mention of this issue in the Perl documentation;
++ > perhaps it should be mentioned in perltrap.
++
++ It's in Programming Perl, but not the standard documentation. :-(
Well, it's there, but Tom's method of using 'grep' fails this time.
Unless you know what the grep for :)
>From perldata.pod:
=head2 Scalar value constructors
Numeric literals are specified in any of the customary floating point or
integer formats:
12345
12345.67
.23E-10
0xffff # hex
0377 # octal
4_294_967_296 # underline for legibility
Underscores are called "underline" here....
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: 17 Jun 1998 03:31:49 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: `fork' in Perl debugger under emacs
Message-Id: <6m7rd5$m7k$1@monet.op.net>
Today I noticed that if you're running the Perl debugger in an xterm,
and your program does `fork', the debugger forks itself instead, with
the child running in a new xterm window, so that you can debug the two
processes independently. That's very nice.
I never noticed it before because I always debug under emacs, and that
feature doesn't work under emacs.
It seems (form looking at perl5db.pl) that if I can define a
subroutine called DB::get_fork_TTY, which will allocate a new emacs
buffer and set the variable $DB::fork_TTY to the device name of the
TTY associated with the buffer, then I'll get the nice fork behavior
under emacs also. Unfortunately, I'm an emacs ignoramus.
Has anyone else ever done this? Is there an emacs expert who can
offer hints?
------------------------------
Date: Wed, 17 Jun 1998 07:06:54 GMT
From: jcamp@plexi.com
Subject: AIX Question
Message-Id: <6m7pue$941$1@nnrp1.dejanews.com>
Ok, I'm developing on a Rehat linux machine, and GDBM works fine. But the
production is on an IBM AIX machine. When a GDBM database gets 5 or 6 20k
records, it returns the following error:
[14/Jun/1998:14:50:27] failure: for host nywa140950.btco.com trying to POST
/cgi-bin/euro/faq/admin.cgi, cgi-parse-ou
tput reports: the CGI program /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi did
not produce a valid header (name without
value: got line "lseek error at /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi
line 363.")
But this works fine on Redhat linux. Below is the script, if anyone can help
me out then it would be very appreciated, any suggestions you can make are
grateful, we're completely stumped.
#!/usr/bin/perl
use POSIX;
use GDBM_File;
tie (%test,GDBM_File,"test", O_RDWR | O_CREAT, 0666);
open(TEST_FILE,"test.txt"); # Gets 20k file and stufs into variable $temp
while(<TEST_FILE>) {
$temp = $temp . $_;
}
close TEST_FILE;
$x = 1;
while($x < 30) { # Stuffs the 20k var into dbase 30 times
$test{$x} = "$temp"; # Store in database
$x = $x + 1;
}
untie %test;
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 17 Jun 1998 05:45:58 -0400
From: "Cornelius" <cornelius21@yahoo.com>
Subject: BOOK: Perl from the Ground Up
Message-Id: <6m82p1$lea$1@news.monmouth.com>
Osborne has just published a new Perl book, Perl from the Ground
Up, by Michael McMillan. You can view more information, the
complete Table of Contents, and an excerpt at:
http://www.smartbooks.com/b9806/bw806perlftgu.htm
Hope this is helpful.
Cornelius
------------------------------
Date: 17 Jun 1998 09:07:59 GMT
From: cmacleod@mcs.dundee.ac.uk (Colin Macleod)
Subject: Re: Electronic Fax?
Message-Id: <6m811f$bc4$1@dux.dundee.ac.uk>
Ong Joo Chin (jcong@ipacs.com) wrote:
: Is it possible to write a PERL script (or any CGI script) that send data
: from the internet to a fax machine? If possible, what is the best
: language to use (C, PERL, shell script)? Is there any reference or codes
: that you can recommend?
A couple of years ago I hacked up something rough to accept
input through a web form and send it as a fax.
It uses perl, CGI.pm, hylafax, etc.
You will need to be on a Unix machine, or make a lot of changes.
It's at: ftp://ftp.mcs.dundee.ac.uk/pub/cmacleod/web-fax.0.1.tar
--
<<<<<<<<<<<^^^^^^^>>>>>>>>vvvvvvv<<<<<<<<<<<^^^^^^^>>>>>>>>vvvvvvv
Colin Macleod, software engineer, Intrasoft SA, Athens, Greece
email (remove added spaces to use) : macleod @ intrasoft . gr
<<<<<<<<<<<^^^^^^^>>>>>>>>vvvvvvv<<<<<<<<<<<^^^^^^^>>>>>>>>vvvvvvv
------------------------------
Date: Wed, 17 Jun 1998 10:40:19 +0100
From: Reinhard Spisser <spisser@bigfoot.com>
Subject: Re: Input type="file"
Message-Id: <35878F03.28E6@bigfoot.com>
>
> In article <6m4pkk$3i5$1@news01.deltanet.com>,
> "Andrew Arrow" <andrew@deltanet.com> wrote:
> >
> > Hi all,
> >
> > Can anyone tell me where to find information on the:
> >
> > <input type="file" name="whatever">
> >
> > It makes a nice text field with a "browse" button next to it, but how do I
> > go about reading the file the user selects?
> >
> > Say the user selects "c:\textfile.txt" How do I read that file off the
> > user's hard drive from my web application?
> >
> > Please respond to andrew@deltanet.com
> >
> > Thanks!
With CGI.pm it's easy:
add enctype="multipart/form-data" to the <form> field in the HTML
page
add the following lines to your perl script:
use CGI;
$query = new CGI;
my $whatever=param('whatever');
my $tmpfilename=$cgiquery->tmpFileName($imgpath);
CGI.pm automatically uploads the file and stores the contents in
a temporary file ($tmpfilename).
Reinhard
--
Reinhard Spisser
spisser@bigfoot.com
------------------------------
Date: 17 Jun 1998 07:41:03 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Missing module - IO::File
Message-Id: <6m7ruf$hl6$1@pegasus.csx.cam.ac.uk>
Mark Thompson <mark-lists@webstylists.com> wrote:
>Hi,
>
>I just installed a module called Image::Size and it has a dependency on
>another module called IO::File. From everything that I read, IO::File is
>something that should already be in a standard install of Perl 5.004 but
>we're running Perl 5.003 (and I don't know if it was standard then too).
>
>My problem is that I can't find IO::File on our system anywhere (I checked
>for it in the normal Perl Library place as well as used the locate command we
>have on our system.
>
>According to Image::Size, it says that if it's not on the system that we need
>to find it and install it. Does anyone know of a place where I can find it
>by itself without reinstalling Perl 5.004?
Like all other Perl modules, it can be found on CPAN:
http://www.perl.com/CPAN/
Mike Guy
------------------------------
Date: 17 Jun 1998 03:16:51 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: More efficient search - binary search??
Message-Id: <6m7qh3$m69$1@monet.op.net>
In article <IJIh1.28$qF2.150812@news3.voicenet.com>,
Matt Knecht <hex@voicenet.com> wrote:
>True enough, but sometimes there exists the need to search an array. I
>imagine that's at least part of the reason grep exists.
grep usually makes more sense when you are expecting multiple matches.
Typically:
@useful_items = grep {is_useful $_} @items;
Using grep to detect the presence of an item in a list is usually wasteful.
------------------------------
Date: Wed, 17 Jun 1998 07:06:44 GMT
From: jcamp@plexi.com
Subject: Perl & Database
Message-Id: <6m7pu4$940$1@nnrp1.dejanews.com>
Ok, I'm developing on a Rehat linux machine, and GDBM works fine. But the
production is on an IBM AIX machine. When a GDBM database gets 5 or 6 20k
records, it returns the following error:
[14/Jun/1998:14:50:27] failure: for host nywa140950.btco.com trying to POST
/cgi-bin/euro/faq/admin.cgi, cgi-parse-ou
tput reports: the CGI program /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi did
not produce a valid header (name without
value: got line "lseek error at /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi
line 363.")
But this works fine on Redhat linux. Below is the script, if anyone can help
me out then it would be very appreciated, any suggestions you can make are
grateful, we're completely stumped.
#!/usr/bin/perl
use POSIX;
use GDBM_File;
tie (%test,GDBM_File,"test", O_RDWR | O_CREAT, 0666);
open(TEST_FILE,"test.txt"); # Gets 20k file and stufs into variable $temp
while(<TEST_FILE>) {
$temp = $temp . $_;
}
close TEST_FILE;
$x = 1;
while($x < 30) { # Stuffs the 20k var into dbase 30 times
$test{$x} = "$temp"; # Store in database
$x = $x + 1;
}
untie %test;
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 17 Jun 1998 07:06:25 GMT
From: jcamp@plexi.com
Subject: Perl & GDBM
Message-Id: <6m7ptg$93q$1@nnrp1.dejanews.com>
Ok, I'm developing on a Rehat linux machine, and GDBM works fine. But the
production is on an IBM AIX machine. When a GDBM database gets 5 or 6 20k
records, it returns the following error:
[14/Jun/1998:14:50:27] failure: for host nywa140950.btco.com trying to POST
/cgi-bin/euro/faq/admin.cgi, cgi-parse-ou
tput reports: the CGI program /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi did
not produce a valid header (name without
value: got line "lseek error at /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi
line 363.")
But this works fine on Redhat linux. Below is the script, if anyone can help
me out then it would be very appreciated, any suggestions you can make are
grateful, we're completely stumped.
#!/usr/bin/perl
use POSIX;
use GDBM_File;
tie (%test,GDBM_File,"test", O_RDWR | O_CREAT, 0666);
open(TEST_FILE,"test.txt"); # Gets 20k file and stufs into variable $temp
while(<TEST_FILE>) {
$temp = $temp . $_;
}
close TEST_FILE;
$x = 1;
while($x < 30) { # Stuffs the 20k var into dbase 30 times
$test{$x} = "$temp"; # Store in database
$x = $x + 1;
}
untie %test;
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 17 Jun 1998 05:11:55 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: PERL/CRON problem
Message-Id: <6m7j6r$d4n$1@comdyn.comdyn.com.au>
It's Perl when you talk about the language, perl when you talk about
the program.
In article <6m6q19$rn5$1@vixen.cso.uiuc.edu>,
mesnier@lyle.cs.uiuc.edu (Mike Mesnier) writes:
> Any idea why:
>
> open(handle, "date |");
> works just fine from the shell:
> but when run from cron fails:
When you run something from cron, you have a different environment.
Specifically, the path will be different. Use full path names for this
sort of stuff.
What does this have to do with perl?
Ok, let's make it more perl relevant.
- You should always check the return value of an open statement, and
in the case of a pipe you should check some extra things.
# perldoc -f open
# perldoc perlfaq8
/Why doesn't open() return an error when a pipe open fails?
- Why are you calling date in this way? Is this the standard
/usr/bin/date that returns a formatted date? You might be better off
with backticks (perldoc perlop), or using the perl builtin localtime
(perldoc -f localtime) if you need a date and/or time. You could
also have a look at the various date modules available for date
manipulation and formatting.
There.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about it's friends.
NSW, Australia |
------------------------------
Date: 17 Jun 1998 07:35:24 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Placing variables in system calls
Message-Id: <6m7rjs$hj3$1@pegasus.csx.cam.ac.uk>
Wesley Posvar <wesley.posvar@worldnet.att.net> wrote:
>I am new to Perl, and was wondering, if there is way to place variables
>into system calls with qx. Everything I've tried doesn't work the way I
>intended.
Not knowing your intentions, it's difficult to say. Variable
interpolation in qx{} works for everyone else. It's described in
"perldoc perlop" under the heading "Quote and Quote-like Operators".
If you can't get it to work, you'll need to post (a) what you tried
(b) what output you expected (c) what output you obtained.
Mike Guy
------------------------------
Date: Wed, 17 Jun 1998 10:34:38 +0400
From: "Michael Sazonov" <msazonov@usa.net>
Subject: Re: print <<END (with variables)
Message-Id: <6m7o17$m6s@xpress.inforis.nnov.su>
Alex Barilo wrote:
> Follow up question: is there a way to do like this:
>print <<"EOT"
> &my_func
>EOT
And another follow up question: is there a way to do like
this:
print <<"EOT"
&perl_func
EOT
For example, "${&localtime}[5]" call (I want get current
year) gets error "Undefined subroutine &main::localtime"
--
Mike
------------------------------
Date: Wed, 17 Jun 1998 07:02:57 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: print <<END (with variables)
Message-Id: <ebohlmanEuoowy.HI8@netcom.com>
Michael Sazonov <msazonov@usa.net> wrote:
: And another follow up question: is there a way to do like
: this:
: print <<"EOT"
: &perl_func
: EOT
: For example, "${&localtime}[5]" call (I want get current
: year) gets error "Undefined subroutine &main::localtime"
print <<"EOT";
The year is ${[localtime()]}[5].
EOT
The square brackets force list context on localtime() and create an
anonymous array.
------------------------------
Date: Wed, 17 Jun 1998 02:02:53 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Puzzle challenge (clarified)
Message-Id: <1daqt5p.1lds28x1mcdy4nN@bay1-114.quincy.ziplink.net>
Daniel Grisinger <dgris@perrin.dimensional.com> wrote:
> Okay. Ten messengers delivered the following ten messages.
> All components of the original message were delivered at least
> once.
>
> This differs from Tim's original challenge in the following ways-
> 1. No messenger delivered the original message
> 2. Some messengers scrambled the order of the message, others forgot
> parts of it. None did both, all did one.
^^^^^^^^^^^^^^^^^^^^^^^^^^^
That makes it rather easy.
Find two messages with words in a different order. The longer one must
contain all the words and be in the wrong order. All messages which
contain the same number of words are also in the wrong order. All
messages which contain fewer words are in the correct order.
This was your original message:
phantasmagoria puerperal intinction bourse efferent heath milliner
sexagenarian dehydrogenate luddite
--
_ / ' _ / - 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: 17 Jun 1998 08:57:29 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Puzzle challenge (clarified)
Message-Id: <6m80dp$3uq$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Tim Bunce) (Tim Bunce
<Tim.Bunce@ig.co.uk>],
who wrote in article <EuHuH2.28D@ig.co.uk>:
> [Here's a (hopefully) clarified restatement of the puzzle]
> They _occasionally_ get the order wrong.
I do not think one can get to anything close to a solution unless you
describe *how* wrong is the order how often. Is two-transpositions
rarer that one, etc.
Ilya
------------------------------
Date: 17 Jun 1998 03:24:24 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Q: grep/map and regex recompilation
Message-Id: <6m7qv8$m6v$1@monet.op.net>
In article <x7yauwejd2.fsf@sysarch.com>, Uri Guttman <uri@sysarch.com> wrote:
>
>when you use a regex in the expression of a map or grep, does the regex
>get recompiled for each internal iteration? or does it keep the complete
>expression and compiled regex and just apply it to each $_ in the loop?
>
>i know about /o but a friend's
It's the same as any other regex.
If it doesn't contain any variables, it is compiled once at the time
the rest of the program is compiled, and needn't be recompiled,
because it never changes.
If it contains variables, and doesn't have /o, then it's recompiled
every time it's used, which means it is recompiled for every iteration
of the map or grep.
If it contains variable, but does have /o, then it's compiled once,
the first time it is used, and never recompiled thereafter.
------------------------------
Date: 17 Jun 1998 03:46:50 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Q: grep/map and regex recompilation
Message-Id: <6m7s9a$m8e$1@monet.op.net>
In article <6m7qv8$m6v$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>If it contains variables, and doesn't have /o, then it's recompiled
>every time it's used, which means it is recompiled for every iteration
>of the map or grep.
Guy Decoux pointed out that this is not exactly correct. It seems
there's something going on that I didn't know about, perhaps that the
recompilation is omitted if the variables appear not to have changed.
However, this:
>It's the same as any other regex.
is correct.
------------------------------
Date: 17 Jun 1998 08:54:14 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Q: grep/map and regex recompilation
Message-Id: <6m807m$3o2$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Uri Guttman
<uri@sysarch.com>],
who wrote in article <x7yauwejd2.fsf@sysarch.com>:
>
> when you use a regex in the expression of a map or grep, does the regex
> get recompiled for each internal iteration? or does it keep the complete
> expression and compiled regex and just apply it to each $_ in the loop?
To add to what the others said:
a) Yes, it is the same as any other RE;
If RE contains variables:
b) Thus the value will be checked whether it changed, and if not,
the already compiled form will be used;
c) Starting from just-released 5.004_67, if it is /$regexp/, the
comparison in b) is skipped if $regexp was not modified.
Ilya
------------------------------
Date: Wed, 17 Jun 1998 06:22:42 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: Reading in multiple lines from file--elegant solution?
Message-Id: <SgJh1.29$qF2.171393@news3.voicenet.com>
Larry Rosler <lr@hpl.hp.com> wrote:
>> >This 'print' will never be executed. Preferable would be:
>> > print("File didn't terminate with '//'!\n"), last if eof(FH);
>> I do need ask ask why it's better to use a comma instead of 'and' there.
>> What's the difference?
>
>I'm glad you asked. (More accurately, took the bait. :-)
Heh. Glad to be of service.
>The comma designates sequence. The second expression is evaluated after
>the first.
>
>The 'and' designates consequence. The second expression is evaluated
>only if the first operation succeeds (returns TRUE). As 'print' will
>return TRUE "all the time" (barring mishaps such as writing to a full
>file system), the test is specious.
Excellent advice. Although, testing it out almost confused me more!
The first line of code I tried was this:
print "One\n", print "Two\n", print "Three\n";
Which caught me completly off guard when it produced:
Three
Two
1One
1
Until I realized the first print was taking the other two as arguments
in it's list and printing their return codes (Each of the other print
statements having the 'side effect' of printing their own arguments).
This took me a bit to figure out, and quite nicely diagrams the order in
which the functions are actually called (As you'd expect them to be).
'Fixing' the line with parentheses makes it behave as I expected.
--
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"
------------------------------
Date: Wed, 17 Jun 1998 02:33:40 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Reading in multiple lines from file--elegant solution?
Message-Id: <MPG.ff12d44df888a709896bc@nntp.hpl.hp.com>
In article <SgJh1.29$qF2.171393@news3.voicenet.com>, hex@voicenet.com
says...
> Larry Rosler <lr@hpl.hp.com> wrote:
...
> LR>The comma designates sequence. The second expression is evaluated after
> LR>the first.
...
> Excellent advice. Although, testing it out almost confused me more!
> The first line of code I tried was this:
>
> print "One\n", print "Two\n", print "Three\n";
>
> Which caught me completly off guard when it produced:
> Three
> Two
> 1One
> 1
>
> Until I realized the first print was taking the other two as arguments
> in it's list and printing their return codes (Each of the other print
> statements having the 'side effect' of printing their own arguments).
> This took me a bit to figure out, and quite nicely diagrams the order in
> which the functions are actually called (As you'd expect them to be).
> 'Fixing' the line with parentheses makes it behave as I expected.
Actually, I was surprised too, and didn't understand this result without
more analysis. Here's why:
The comma operator in scalar context is easy to understand. It causes
each of its operands to be evaluated left-to-right for their side
effects, then retains the value of the rightmost operand expression.
List context is harder to explain. In C, each of the operands is
evaluated in unspecified order, their values are put on a stack in the
left-to-right order, then a function is called with the argument list
from the stack. In Perl, the operands are evaluated left-to-right, a
list is created, and one of many operations can then be done using the
list operand (assignment, function call, ...).
Yet your results show that the third 'print' expression was evaluated
first! Why? Let's experiment some more:
#!/usr/local/bin/perl -w
use strict;
my ($x, $y, $z, $a, $b, $c) = (0, 0);
print $a = $x, $b = ++$x, $c = ++$x, "\n";
print $z = $y, $z = ++$y, $z = ++$y, "\n";
__END__
012
222
The first print verifies left-to-right evaluation. The second print
indicates further that it is not the values that form the list, but
references to the values.
So here's what actually happens in Matt's test:
The first print causes evaluation of its list operand. The first value
in the list is a reference to "One\n". Evaluating its second operand
causes the second print to evaluate *its* list operand. The first value
in the list is a reference to "Two\n". Evaluating *its* second operand
causes the third print to evaluate *its* list operand, then print it
("Three\n"), then return *its* value (1) as the second list value for the
second print. The second print now prints its list operand ("Two\n1"),
and returns *its* value (1) as the second list value for the first print.
The first print now prints its list operand ("One\n1").
Wow! My old C brain is trained never to rely on the order of side
effects in evaluating the arguments to a function. My new Perl brain
knows that the elements of a list are evaluated strictly left-to-right,
but as we have seen the side effects may *appear* to be evaluated right-
to-left. Yet "all is right as right can be" (The Mikado).
My simply baited hook has turned into a full-scale seminar. "I'm tired
and I wanna go to bed." (Show Me the Way to Go Home)
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: Wed, 17 Jun 1998 02:02:55 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: REVIEW: Perl CGI Programming - No Experience Required
Message-Id: <1daqusm.1h15wzae5fru0N@bay1-114.quincy.ziplink.net>
Nathan Franzen <franzen@pmel.noaa.gov> wrote:
> Is it even possible to look at a list without altering it?
Not according to the uncertainty principle.
;-)
--
_ / ' _ / - 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: 17 Jun 1998 09:36:57 GMT
From: c.c.eiftj@54.usenet.us.com (Rahul Dhesi)
Subject: Re: REVIEW: Perl CGI Programming - No Experience Required
Message-Id: <6m82np$4up$1@samba.rahul.net>
In <pudge-1606980854110001@dynamic404.ply.adelphia.net> pudge@pobox.com
(Chris Nandor) writes:
># >Here we put a subscript on the contents of `perl -v`, split that line into
># >a list, and subscript that list, and neither is an array.
>#
># By my definition it is.
>Your logic escapes me. If ('a' .. 'z') is an array, then why is $a
>different in this two situations?
> $a = ('a' .. 'z'); print $a;
> @a = ('a' .. 'z'); $a = @a; print $a;
The code is different, and the perl interpreter reacts differently to
it.
>Because a list and an array are not interchangable. If they were, then $a
>would be the same in both lines, right? Of course right.
If you don't start with a definition of what is a list and what is an
array, how can you decide which is which? First give me a definition.
Then I can look at your code and try to classify it.
>You have been given a completely unambiguous definition. You just don't
>understand it. An array has an AV allocated, and a list is just some
>values on a stack somewhere. Think of it like this: an array is accessed
>through symbols like $ and @, and a list is not. A list cannot be changed
>or altered in any way, an array can be. These are all unambiguous.
1. A definition in terms of the symbol AV is useless unless you first
define that symbol. What's your definition of AV?
2. How do I know what is stored in an AV and what is not? Do I have
to compile perl in debugging mode and make it dump the gnerated code
in order to define arrays versus lists? If not, how else do we
decide what is stored in an AV and what is not?
3. If the list/array distinction depends on the internal workings of
the perl interpreter, then the distinction could become invalid if
the perl interpreter is revised to behave differently without changing
the language. You can't usefully define a programming langauge by
depending on the internal data structures of the language compiler.
So far the only simple definition distinguishing between arrays and
lists, that does not depend on arbitrary code examples, and does not
depending on knowing the internals of the perl interpreter, is my own:
If we use subscript notation on something at least once, it's
an array, otherwise it's not.
If anybody has a better definition I would like to see it. I didn't
find one in 'Programming Perl'. You came sort of close above, when you
said "an array is accessed through symbols like $ and @, and a list is
not," but your language is too fuzzy. For example, which symbols are
defined to be "like" $ and @? Is everything accessed with $ or @ an
array? if not, we don't have a useful definition.
>Now you have gotten lots of examples of how they behave differently,
>including mine above. You can push/pop/shift/unshift/slice an array, not a
>list. You can make a reference to an array, but not to a list. You can
>tie an array, and you cannot tie a list.
You can't define things by simply providing code examples, because
nobody can tell (just by looking at the code) what something is supposed
to be called.
>And, of course, they behave differently in different contexts. In
>particular, in scalar context (above) and in 1multidimensional array
>emulation context:
> $; = '|';
> $a{'a', 'b'} = 'z'; # $a{'a|b'} == 'z'
> @a = ('a', 'b');
> $a{@a} = 'y'; # $a{2} == 'y'
Again, by looking at the code alone, it's impossible to say what is an
array and what is a list. You must refer to some other definition
outside the code. What definition are you using?
--
Rahul Dhesi <dhesi@spams.r.us.com>
------------------------------
Date: 17 Jun 1998 09:42:50 GMT
From: c.c.eiftj@54.usenet.us.com (Rahul Dhesi)
Subject: Re: REVIEW: Perl CGI Programming - No Experience Required
Message-Id: <6m832q$57l$1@samba.rahul.net>
In <6m5q3c$60m$1@csnews.cs.colorado.edu> Tom Christiansen
<tchrist@mox.perl.com> writes:
>:By my definition it is.
>Since we're speaking in the context of Perl, *your* definition
>of an array is immaterial: only Perl's definition counts. If
>there's no AV, there's no array. It's quite that simple.
Unfortunately you haven't told us how to decide, by examning perl code,
whether or not there is an AV. Neither does 'Programming Perl', so far
as I can tell. So, even if your definition is correct from the
perspective of somebody familiar with perl internals, it's not useful to
the typical programmer.
In the absence of any other useful definition, what choice do I have but
to create my own? I find it logical and intuitive:
If we use subscript notation on it at least once, it's an array;
otherwise it's not.
--
Rahul Dhesi <dhesi@spams.r.us.com>
------------------------------
Date: Wed, 17 Jun 1998 02:02:58 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: strange error message .. "value of <handle> ..."
Message-Id: <1daqvea.yf0fcy1nh80e7N@bay1-114.quincy.ziplink.net>
[posted and mailed]
Byron Jones <byronj@nd.edu.au> wrote:
> http://www.nd.edu.au/perl/print.pl
Looks like your original problem was answered. Here a few other things
to think about.
while (substr ($baseurl, -1, 1) ne "/") {
chop ($baseurl);
}
There are much better ways to get the path.
($baseurl = $_) =~ s|[^/]+$||g;
use Basename;
$baseurl = dirname($_);
open INDEX, "$urlfile" || bail ("Couldn't open \"$urlfile\" : $!");
That line does not do what you intend. Read up on operator precedence,
then put parens around the arguments to open, or replace || with or.
s/header.html/print_header.html/gi;
Backslash literal periods in regular expressions:
s/header\.html/print_header.html/gi;
s/href=\"\//tempref=\"\//gi;
To avoid leaning toothpick syndrome, use a different regex delimiter:
s|href="/|tempref="/|gi;
sub bail {
print "<body bgcolor=#ffffff><h4>Fatal Error</h4>@_";
exit;
}
Aren't you missing something?
</body></html>
--
_ / ' _ / - 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: 17 Jun 1998 05:16:45 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Undefined subroutine CGI::pram
Message-Id: <6m7jft$d4n$2@comdyn.comdyn.com.au>
In article <EunvuK.Bv2@boss.cs.ohiou.edu>,
"Dave" <hannum@oak.cat.ohiou.edu> writes:
> I'm using the following format to define the parsed variables:
> $variable = $form->pram('variable');
Ugh. What is this supposed to do? spawn a child and transport it?
Why is the error message so hard to understand?
Why don't you read the documentation that comes with CGI.pm? If you
did, you would know that the method is called param, not pram. The
error message also was a big giveaway that you might be mistyping
something.
# perldoc CGI
Please, read
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | In the fight between you and the world,
Commercial Dynamics Pty. Ltd. | back the world - Franz Kafka
NSW, Australia |
------------------------------
Date: Tue, 16 Jun 1998 19:50:02 +0200
From: "F Chauvreau" <nospam_billteam@creaweb.fr>
Subject: win32
Message-Id: <6m6n9c$t45$1@newsfeed.inetway.net>
Can any body help me or even learn me how to use the softs with win32 from
beggining to end. I don't know anything about it (I mean use it)
I know perl but not how to use the win32 things (set up to work)!
JC
------------------------------
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 2889
**************************************