Is this a bug in PERL or a subtle error by me?

  • Thread starter John W. Kennedy
  • Start date
J

John W. Kennedy

I'm developing a CGI web bulletin board from scratch. (The target
system has _none_ of the standard PERL library available except CGI.pm;
and won't run any kind of script in anything but PERL; I have no control
over this.) I've been doing PERL for years, but only in spurts, so my
knowledge is less exact than I wish it were.

I have the following statement.

$self->subenumerate ($$self{$_}, 0, $tree, $levels) foreach {@$index};

It blows up in "subenumerate", where the argument corresponding to
$$self{$_} turns up as undefined.

But if I change it to this, everything works as it should.

foreach (@$index) {
$self->subenumerate ($$self{$_}, 0, $tree, $levels);
}

At the moment, I'm developing components, running under ActivePerl 5.8.2
under XP.

Is this my fault, or is something broken?

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
R

Randal L. Schwartz

John> I have the following statement.

John> $self->subenumerate ($$self{$_}, 0, $tree, $levels) foreach {@$index};

Why the curlies there? You're turning a list into an anon hash! And
so you're passing an anon hash as a key into another hash. Not very
likely. :)

John> But if I change it to this, everything works as it should.

John> foreach (@$index) {
John> $self->subenumerate ($$self{$_}, 0, $tree, $levels);
John> }

Now you're looking at the elements of the array pointed at by $index.
Probably more like what you wanted, eh?

John> Is this my fault, or is something broken?

"It's all you, bay-bee!" :)

print "Just another Perl hacker,"
 
J

John W. Kennedy

John> I have the following statement.
John> $self->subenumerate ($$self{$_}, 0, $tree, $levels) foreach {@$index};
Why the curlies there? You're turning a list into an anon hash! And
so you're passing an anon hash as a key into another hash. Not very
likely.

That was it! That I put them there in the first place was a plain old
brain fart. That I didn't notice them is thanks to Bill Gates' crappy
screen fonts.

print "Thank you!\n" foreach (0..0x7FFFFFFE);

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
A

Andy Baxter

At earth time Sat, 03 Jan 2004 02:24:43 +0000, the following transmission
was received from the entity known as John W. Kennedy:
I'm developing a CGI web bulletin board from scratch. (The target
system has _none_ of the standard PERL library available except CGI.pm;
and won't run any kind of script in anything but PERL; I have no control
over this.) I've been doing PERL for years, but only in spurts, so my
knowledge is less exact than I wish it were.

You can put modules in your cgi-bin too - I've made 3 handrolled modules
for a site I'm building, and I just put them in cgi-bin and include them
with use LibraryName;

As long as the modules you want don't depend on native binaries, you
should be able to use them somehow.

andy.
 
S

Sam Holden

At earth time Sat, 03 Jan 2004 02:24:43 +0000, the following transmission
was received from the entity known as John W. Kennedy:


You can put modules in your cgi-bin too - I've made 3 handrolled modules
for a site I'm building, and I just put them in cgi-bin and include them
with use LibraryName;

That's assuming your cgi script will be executed with the working
directory being the directory the cgi-bin directory. That is not
guaranteed by the CGI specification and hence not something everyone
wants to rely on.

Better to use "use lib 'some directory';" and put the modules in 'some
directory' (which could well be the cgi-bin directory). Of course then
the scripts need that line changed when moved to another system, and so
in some ways become less portable :)
 
A

Andy Baxter

At earth time Mon, 05 Jan 2004 01:41:52 +0000, the following transmission
was received from the entity known as Sam Holden:
That's assuming your cgi script will be executed with the working
directory being the directory the cgi-bin directory. That is not
guaranteed by the CGI specification and hence not something everyone
wants to rely on.

Better to use "use lib 'some directory';" and put the modules in 'some
directory' (which could well be the cgi-bin directory). Of course then
the scripts need that line changed when moved to another system, and so
in some ways become less portable :)

Couldn't you write a custom module which did nothing but:

use lib 'some directory';
use Module::Ineed1;
use Module::Ineed2;
use Module::Ineed3;

and then have a use statement for this in each of the scripts? Then
you'd only have to change a single script if you moved. I'm not
sure if use statements work this way though.
 
S

Sam Holden

At earth time Mon, 05 Jan 2004 01:41:52 +0000, the following transmission
was received from the entity known as Sam Holden:


Couldn't you write a custom module which did nothing but:

use lib 'some directory';
use Module::Ineed1;
use Module::Ineed2;
use Module::Ineed3;

and then have a use statement for this in each of the scripts? Then
you'd only have to change a single script if you moved. I'm not
sure if use statements work this way though.

You would need to modify every script to include a "use lib" for the
directory that custom module is in, so you don't gain anything.
 
A

Andy Baxter

At earth time Mon, 05 Jan 2004 06:46:48 +0000, the following transmission
was received from the entity known as Sam Holden:
You would need to modify every script to include a "use lib" for the
directory that custom module is in, so you don't gain anything.

OK. If it was me, and there were enough scripts that it mattered, I'd put
a marker comment before the 'use lib' in each script, like:
#LIBDEF
use lib 'some directory';

and then run them through a text-processing script to change all the lines.

andy.
 
R

Rich Grise

gnari said:
"John W. Kennedy" <[email protected]> wrote in message

did you actually try to run this? :)

gnari

I dunno about the OP, but

#!/usr/bin/perl
print "Thank You!\n" foreach (0..0x7F);

does print out 'Thank You' more than 49 times. ;-)

Cheers!
Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

When will ruby181-11.exe be fixed? 7
Inheritance? 31

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top