[23491] in Perl-Users-Digest
Perl-Users Digest, Issue: 5704 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 23 14:10:54 2003
Date: Thu, 23 Oct 2003 11:10:23 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 23 Oct 2003 Volume: 10 Number: 5704
Today's topics:
Re: Perl and IIS - script runs but 'The page cannot be <jwillmore@remove.adelphia.net>
Re: Perl and IIS - script runs but 'The page cannot be <jurgenex@hotmail.com>
Re: Perl and IIS - script runs but 'The page cannot be <jurgenex@hotmail.com>
Re: Quick Perl question (Roy Johnson)
Re: Referring to a 'column' from a reference to an arra <jwillmore@remove.adelphia.net>
Re: Regex to extract row data from text <syscjm@gwu.edu>
Re: Simulating case sensitivity for win32 files (Roy Johnson)
Re: strange effect with [:lower:] in perl <abigail@abigail.nl>
Re: Strange file opening problem on WinNT <ddunham@redwood.taos.com>
Re: while each hash, why not array (Anno Siegel)
Re: while each hash, why not array (Malcolm Dew-Jones)
Re: while each hash, why not array <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 23 Oct 2003 15:35:56 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <20031023113558.193628d9.jwillmore@remove.adelphia.net>
On 23 Oct 2003 02:22:26 -0700
stewart@webslave.dircon.co.uk (stew dean) wrote:
<snip - getting long>
> > > > > > On 21 Oct 2003 03:53:24 -0700
> > > > > > stewart@webslave.dircon.co.uk (stew dean) wrote:
> > > > <snip>
> > > >
> > > > What happened when you ran the script at the command line?
> > >
> > > I've never run a perl script at the command line.
> >
> > Why not?
>
> Because I've never had to. Why would I want to?
[Sigh]
Because it _may_ give you a clue as to why you're not getting what you
want from the script. It's not a perfect solution, but it is a
healthy place to start. After all, the CGI can be considered a
server's STDIN, right?
<snip>
> > Maybe there _is_
> > something wrong with the script? A typo, maybe? Running the
> > script_at the command line_ will produce messages that _may_ not
> > be seen as errors, but as warnings that the web server is just
> > dismissing.
>
> All errors that are generated by the script are displayed in the
> output. It uses strict so all errors are picked up including
> variables not declared. If it finds more than one it stops running
> and tells me.
>
> Now there may be errors produced of a different kind but then this
> would be new to me and I'm trying to find out what kind of errors
> they may be. The code it's self is fine with no syntax errors.
>
> If I run it from the command line it can't find the input file as
> the file is relative to the web server. This is all about reading
> and writing files afterall.
Yes, I understand. Using the '-debug' switch for the CGI module will
allow you to run the script, from the command line, and allow you to
see what the script's output (the good, bad, and ugly) is. Using this
switch will allow you to send parameters to the script as if the
script is getting them through the CGI (aka the web server's STDIN).
So, if you are passing a file name as a param to the script, you can
type that in while running the script on the command line. I know all
this because I've done it :-)
>
> <snip>
>
> > > > For the time being - and to give a hint - try using CGI::Carp
> > > > (just not in a production environment).
> > >
> > > Well that's enigmatic. I suspect that it's also not the answer I
> > > seek but I will check it out.
> >
> > Like I mentioned before, maybe the code _is_ broke somewhere.
> > CGI::Carp can report the errors to the browser (since you seem to
> > not want to run the script at the command line). If something is
> > broke, the error will appear.
>
> If something is broke it gives me the error by passing me the
> headers. Will Carp give me any errors that I don't already receive
> (given that I'm not adding debug messages into the script)?
>
Yes. Read the documentation for CGI::Carp for other settings for the
module. It's rather robust and very useful for debugging CGI scripts.
The one caveat is _don't_ use it in a production environment. The
messages that can be created and used in development can be considered
a security risk in a production environment.
I've tried to make the effort to lend a hand to you in this task. I
know it may not seem like it. Consider the message, not the way the
message is being delivered and it, I hope, will appear that I have
made the effort. However, unless you can offer new information about
what's going on, I suggest you post to a CGI authoring group. There,
the group can offer assistance in configuration of IIS and all the
issues associated with IIS. I have 'zero' experience with IIS, but
lots with Perl and using it through the CGI. If this issue is IIS
related,
I can't offer anything more.
Good luck.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
I really hate this damned machine I wish that they would sell it.
It never does quite what I want But only what I tell it.
------------------------------
Date: Thu, 23 Oct 2003 16:24:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <TgTlb.34865$Ee6.21771@nwrddc01.gnilink.net>
stew dean wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:<mjFlb.28443$Ee6.26897@nwrddc01.gnilink.net>...
>> stew dean wrote:
>>> The perl script is not buggy - it's running fine.
>>
>> Then what is your problem? Apparently it has nothing to do with Perl
>> or has it?
>
> It's to do with the way perl is running on IIS -
I see. But at least to me this appears to be a question about IIS, not about
the programming language Perl.
Did you ask in a newsgroup that actually cares about IIS? It would be a mere
coincidence if someone in a Perl related newsgroup would know about IIS.
> that is for some
> reason it is running but the output is not reaching the browser.
And the programming language Perl has even less to do with 'browsers'.
Again, this seems to be a problem with IIS, not with Perl.
> It's also about finding out more about how Perl runs on windows.
Fair enough. The easiest way is probably to go to activestate.com and
install their pre-compiled ActivePerl.
> Perl doesnt naturaly have an error log on windows from what I can see
Well, do compilers for C or Haskell produce code that generates error logs?
Or do interpreters for Basic or Prolog or ... generate error logs? Not that
I am aware of. Typically any error message is sent to STDERR. Perl is in no
way different.
> and so far I have been relying on the errors given to me in the
> headers returned -that is the usualy syntax and other errors that are
> returned by using strict.
Well, once you've installed ActivePerl you may want to check "perldoc -q
500". It might be an eye opener.
jue
------------------------------
Date: Thu, 23 Oct 2003 16:34:31 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <rqTlb.34940$Ee6.9088@nwrddc01.gnilink.net>
stew dean wrote:
> There is no error from perl - that's my problem.
Then the chances that your problem is related to Perl are minimal.
Before waisting your time investigating most-likely-non-existing Perl
problems I strongly suggest you look into the other areas like the code
your script generates, IIS configuration, etc.
Chances are the root of your problem is there.
At this point the only way that you could convince me that it is a Perl
problem indeed would be if the problem does not happen if you write your
program in C or Prolog or any other programming language.
jue
------------------------------
Date: 23 Oct 2003 08:33:30 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Quick Perl question
Message-Id: <3ee08638.0310230733.71a8e405@posting.google.com>
Steve Grazzini <grazz@pobox.com> wrote in message news:<mmclb.9456$PZ1.6832@nwrdny03.gnilink.net>...
> Roy Johnson <rjohnson@shell.com> wrote:
> > (defined(fork()) || die "Cannot fork: $!") && exit;
>
> You actually need
>
> defined (my $pid = fork) or die "Cannot fork: $!";
> exit if $pid;
>
> Your version exits in the child as well...
Oops. Should have had:
(defined(fork() && exit)) or die "Cannot fork: $!\n";
for properly obscure, though correct, behavior. :-) I do tend to
forget that // returns the left side if it is defined, even if it is
false.
Actually, the correct translation of a//b is defined(a) ? a : b, so I
should have said
my $pid;
(defined($pid=fork()) ? $pid : die "Cannot fork: $!") && exit;
Here's another interesting way to approximate // behavior (in the
sense that the expressions look fairly similar):
${dref(fork()) || die "Cannot fork: $!"} && exit;
# Return a ref to the value, if it is defined.
sub dref {
(defined $_[0]) ? \$_[0] : undef;
}
But for something like
$a // $b // $c
you would need to be sure you returned references in each case:
${dref($a) || $dref($b) || \$c}
------------------------------
Date: Thu, 23 Oct 2003 15:22:20 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Referring to a 'column' from a reference to an array of array references
Message-Id: <20031023112221.63277ba5.jwillmore@remove.adelphia.net>
On 23 Oct 2003 01:38:39 -0700
obeseted@yahoo.com (fatted) wrote:
> The DBI module has a function fetchall_arrayref which returns a
> reference to an array of references to arrays. Its quite easy to
> refer to a row of the matrix:
>
> $row_ref = $array_ref->[0];
>
> (which would correspond to 1 row retrieved from database table), but
> I can't think of how to refer to a column of the matrix (corresponds
> to all the various values for a particular field / column).
> Is it possible to refer to a column using array referencing of some
> description? (I know how to iterate over the array and suck out each
> column value, I'm just wondering whether there is as easy a way as
> when referring to rows). I'd normally iterate using a
> foreach/while/for loop or maybe a map function, can anyone think of
> alternatives (some sort of array slice or something?).
>
Well ... you could use 'fetchrow_hashref' in a loop instead of
fetching all the rows at once. Not exactly what you are looking for,
but using 'fetchall_hashref', AFAIK, will only fetch for a single
field by name - unless that's what you want..
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
You may have heard that a dean is to faculty as a hydrant is to a
dog. -- Alfred Kahn
------------------------------
Date: Thu, 23 Oct 2003 13:02:50 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Regex to extract row data from text
Message-Id: <3F9809BA.2060005@gwu.edu>
Tore Aursand wrote:
> On Wed, 22 Oct 2003 06:25:55 -0400, Chris Mattern wrote:
>
>>When you're parsing input data, what is necessary is a true understanding
>>of its syntax, not samples which will almost invariably fail to cover
>>certain cases. "The data looks like such-and-so" or "The data is in
>>a form like this" is usually a red flag that the speaker doesn't understand
>>his input data well enough to parse it properly.
>
>
> Isn't that why Perl was created? :-)
Heh. Yeah, I guess so. Often, the best way to get a handle on understanding
your data is to go through several iterations of failing to parse it correctly.
That's not something a newsgroup can really do for you, of course...
Chris Mattern
------------------------------
Date: 23 Oct 2003 09:05:31 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Simulating case sensitivity for win32 files
Message-Id: <3ee08638.0310230805.2e37396e@posting.google.com>
mm-24@pobox.com (M&M) wrote in message news:<19372e8e.0310221336.5ee263a4@posting.google.com>...
> It works, but how could it be improved? (It doesn't even address
> directories...) Certainly others have dealt with this before. Any
> suggestions?
It can surely be improved. First of all, you call real_filename twice
every time you encounter it. Get rid of the really_exists sub. You
need the real filename, anyway, so having the really_exists sub throw
it away works against you.
if (-f $file) {
my $realname = real_filename($file);
if ($file ne $realname) {
#...renaming...
Now, in real_filename, you've chosen to grep through the entire
directory, with no possibility of short-circuiting. Ouch. Also,
caching is not so difficult to add:
my %file_cache;
sub real_filename {
my $filename = lc(shift); ## Compare as lowercase only
unless (exists $file_cache{$filename}) {
opendir DIR, '.' or die "Can't readdir: $!";
while (my $f = readdir DIR) {
if ($filename eq lc($f)) {
$file_cache{$filename} = $f;
last; ## When you find it, stop reading!
}
}
closedir DIR;
}
return $file_cache{$filename};
}
------------------------------
Date: 23 Oct 2003 15:05:36 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: strange effect with [:lower:] in perl
Message-Id: <slrnbpfrhv.ib0.abigail@alexandra.abigail.nl>
T. Sander (roetz7@unicum.de) wrote on MMMDCCV September MCMXCIII in
<URL:news:1b27f62d.0310230630.46157fd4@posting.google.com>:
** I have a strange problem with the following perl code.
** It produces the output :
**
** A : dEf
** B : dBf
** D : DbF
**
** Why is there no output for the case C?
**
** This must be a bug or what is the explanation for this behaviuor?
** When I change $c to "DgF" I get the output line for C.
** I think the problem always occur for lower when the lower character is the
** successor of the upper-case character.
** Why this doesn't happen with the same upper variant?
**
** I have tested this with different perl version 5.5, 5.8 on Solaris and Windows.
**
** --------------------
** $a="dEf";
** $b="dBf";
**
** if (not ($a=~/[:upper:]/)) {
** print "A : $a\n";}
**
**
** if (not ($b=~/[:upper:]/)) {
** print "B : $b\n";}
**
**
** $c="DeF";
** $d="DbF";
**
** if (not ($c=~/[:lower:]/)) {
** print "C : $c\n";}
**
** if (not ($d=~/[:lower:]/)) {
** print "D : $d\n";}
**
/[:lower:]/ matches if the string contains a ':', an 'l', an 'o', a 'w',
an 'e' or an 'r'. "DeF" contains an 'e', so it does match.
What you probably want is /[[:lower:]]/.
Abigail
--
CHECK {print "another "}
END {print "Hacker\n"}
INIT {print "Perl " }
BEGIN {print "Just " }
------------------------------
Date: Thu, 23 Oct 2003 17:43:31 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Strange file opening problem on WinNT
Message-Id: <7rUlb.8422$n17.77155486@newssvr21.news.prodigy.com>
Michael <mps25@cam.ac.uk> wrote:
> I've tried hard to google an answer to this without success. I'm using
> a perl script on Windows NT (Perl 5.8.0) that I've written (and
> executed with no problem) on a Linux machine. The script uses the
> command (acting on a plain text file):
> $comm=join("","output\\",$data_type,"_",$date,".mps");
Uhh, why don't you just write that as...
$comm = "output\\${data_type}_${date}.mps";
> open(INFILE,$comm);
> ....
> $close(INFILE);
$close instead of close? Methinks you are typing instead of cutting and
pasting, which leads to other errors.
> The file is read no problem (and, in fact, writes out to another file
> no problem). The strange thing about running it in Windows is that it
> ALSO "executes" the file it reads: in the same sense as if I double
> clicked on the file. So ".dat" files (associated with Excel here)
> cause lots of excel windows to pop up if I read in lots of files. I
> changed to an unassociated extension to avoid this and a pop-up
> appears to tell me (for each and every file) that the file cannot be
> executed as it is not associated with an application.
Can you cut that small section out and see the same behavior if you put
it in a separate script? If you can't, then it's not that section of
the code that is the problem.
If you can make a small standalone case that shows what is going on,
it's much easier to debug. I can't guess what else happens in the
script.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: 23 Oct 2003 15:16:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: while each hash, why not array
Message-Id: <bn8rcg$2lm$1@mamenchi.zrz.TU-Berlin.DE>
Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Greg Bacon (gbacon@hiwaay.net) wrote on MMMDCCV September MCMXCIII in
> <URL:news:vpfin2daahu832@corp.supernews.com>:
> `` In article <slrnbpfa8c.7uo.abigail@alexandra.abigail.nl>,
> `` Abigail <abigail@abigail.nl> wrote:
> ``
> `` : Nah, a hypothetical 'each' for arrays would be:
> `` :
> `` : while (my ($key, $value) = each @array) {
> `` : # $key is the index, $value the value.
> `` : }
> ``
> `` Sweet! Something like this?
>
> I thought of that myself, but it doesn't work. The problem is that
> memory addresses aren't unique over time; they are reused:
One could bless arrays when they are iterated over and take care of
the %iter entry in DESTROY.
Besides being absurd, it is fragile. Scratch that :)
Anno
------------------------------
Date: 23 Oct 2003 10:28:19 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: while each hash, why not array
Message-Id: <3f980fb3@news.victoria.tc.ca>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
: Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
: > Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMDCCV September
: > MCMXCIII in <URL:news:bn8gsj$n8a$2@mamenchi.zrz.TU-Berlin.DE>:
: > () Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
: > () >
: > () >
: > () > Nah, a hypothetical 'each' for arrays would be:
: > () >
: > () > while (my ($key, $value) = each @array) {
: > () > # $key is the index, $value the value.
: > () > }
: > ()
: > () That would be my idea too of what "each" should mean for an array.
: > () However, there are other interpretations. Besides Malcolm's (essentially
: > () equivalent to "foreach"), there was
: > ()
: > () while (my ($key, $value) = each @array) {
: > () # $key is an even-indexed element, $value an odd-indexed element
: > () }
: > ()
: > () which is also a plausible generalization of the behavior of "each",
: > () though, I believe, not a very useful one.
: > ()
: > () Maybe this ambiguity is another reason why "each" hasn't been generalized.
: >
: >
: > My guess the reason 'each' hasn't been generalized is that arrays don't
: > have slots to keep the state of the iterator. Hashes have them. Adding
: > them to arrays means adding an extra integer to all AVs. Considering that
: > 'each @array' will be used far less than 'each %hash', the price is not
: > worth paying.
: Having the iterator incorporated in the hash itself isn't ideal -- it's
: the reason why we can't nest "each"- and "keys"-loops over the same hash.
: One could also take the opportunity and implement both iterators differently.
: Not bloody likely, I know. I wonder how Perl 6 will behave in that respect.
perl 6, no idea, but the way other languages handle it would be to create
an iteration object, so you could imagine
my $iter1 = iterator_for %hash;
while ( my ($k,$v) = $iter->next ) or such like
OR
store a context handle or other identifier as an optional argument to the
each
while ( my ($k,$v) = each(%hash,$iter1) )
------------------------------
Date: Thu, 23 Oct 2003 18:02:08 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: while each hash, why not array
Message-Id: <x7ekx3de8v.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> That would be my idea too of what "each" should mean for an array.
AS> However, there are other interpretations. Besides Malcolm's (essentially
AS> equivalent to "foreach"), there was
AS> while (my ($key, $value) = each @array) {
AS> # $key is an even-indexed element, $value an odd-indexed element
AS> }
AS> which is also a plausible generalization of the behavior of "each",
AS> though, I believe, not a very useful one.
perl6 has that in the form of the un/zip function (it merges/splits
lists).
and it is useful when you have a set of pairs (maybe config stuff) that
needs to be processed in order. getting the next N elements into a list
of scalars (perl6 can do wierd combos of this as well) is a highly
desired function.
AS> Maybe this ambiguity is another reason why "each" hasn't been generalized.
well delete was changed to support (the soon to be dead)
pseudo-hashes. each could have been generalized to return the
index/value pair which is not a bad idea but i doubt i ever would need
it. it would be exteremely rare to find index driven code in any of my
source.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 5704
***************************************