* [gentoo-dev] perl question
@ 2001-08-03 22:35 Chad M. Huneycutt
2001-08-04 7:32 ` Terje Kvernes
0 siblings, 1 reply; 6+ messages in thread
From: Chad M. Huneycutt @ 2001-08-03 22:35 UTC (permalink / raw
To: gentoo-dev
Can anyone explain to me why this I can't see $dir inside the unless
block in the code fragment below?
sub recurse {
my $dir = shift;
print "dir: $dir\n";
unless ( defined($exceptions{$dir}) ) {
print "$dir is not an exception
}
}
basically, dir is correct in the first print statement, and then gone
inside the unless block (even if I do a "unless (0)", the second print
shows $dir as undefined).
I basically want to make sure that the problem is not that I am unaware
of some scoping rule of perl. I believe that this code is just acting
unexpectedly, but I want to make sure before I spend any more time
debugging it. And yes, this is a gentoo-related program.
Thanks,
Chad
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-dev] perl question
2001-08-03 22:35 [gentoo-dev] perl question Chad M. Huneycutt
@ 2001-08-04 7:32 ` Terje Kvernes
2001-08-04 10:14 ` Chad M. Huneycutt
0 siblings, 1 reply; 6+ messages in thread
From: Terje Kvernes @ 2001-08-04 7:32 UTC (permalink / raw
To: gentoo-dev
"Chad M. Huneycutt" <chad.huneycutt@acm.org> writes:
> Can anyone explain to me why this I can't see $dir inside the unless
> block in the code fragment below?
>
> sub recurse {
> my $dir = shift;
>
> print "dir: $dir\n";
> unless ( defined($exceptions{$dir}) ) {
> print "$dir is not an exception
> }
> }
I expect you've left out a " on the second print statement? :)
> basically, dir is correct in the first print statement, and then
> gone inside the unless block (even if I do a "unless (0)", the
> second print shows $dir as undefined).
it shouldn't. unless you've tied %exception into something that
resets the keys on read.
$ perl -le '$foo="foo"; print $foo; unless( 0 ) { print $foo }'
foo
foo
--
Terje
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-dev] perl question
2001-08-04 7:32 ` Terje Kvernes
@ 2001-08-04 10:14 ` Chad M. Huneycutt
2001-08-04 11:53 ` Terje Kvernes
0 siblings, 1 reply; 6+ messages in thread
From: Chad M. Huneycutt @ 2001-08-04 10:14 UTC (permalink / raw
To: gentoo-dev
Terje Kvernes wrote:
>"Chad M. Huneycutt" <chad.huneycutt@acm.org> writes:
>
>>Can anyone explain to me why this I can't see $dir inside the unless
>>block in the code fragment below?
>>
>>sub recurse {
>> my $dir = shift;
>>
>> print "dir: $dir\n";
>> unless ( defined($exceptions{$dir}) ) {
>> print "$dir is not an exception
>> }
>>}
>>
>
> I expect you've left out a " on the second print statement? :)
>
Yeah, this was a typo in the e-mail only.
>
>
>
>>basically, dir is correct in the first print statement, and then
>>gone inside the unless block (even if I do a "unless (0)", the
>>second print shows $dir as undefined).
>>
>
> it shouldn't. unless you've tied %exception into something that
> resets the keys on read.
>
I don't know why I was seeing this behavior, but I downloaded the
program again, and the problem I was seeing here went away.
The actual problem was that the @#$@#%@# configuration file for my
program (the file where $dir gets its value) was in MS-DOS format
(newline and carriage return), which was causing some very strange
behavior. Kudos to kabau for helping me diagnose it!
Chad
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-dev] perl question
2001-08-04 10:14 ` Chad M. Huneycutt
@ 2001-08-04 11:53 ` Terje Kvernes
2001-08-05 17:22 ` Chad M. Huneycutt
0 siblings, 1 reply; 6+ messages in thread
From: Terje Kvernes @ 2001-08-04 11:53 UTC (permalink / raw
To: gentoo-dev
"Chad M. Huneycutt" <chad.huneycutt@acm.org> writes:
> Terje Kvernes wrote:
>
> > I expect you've left out a " on the second print statement? :)
>
> Yeah, this was a typo in the e-mail only.
manual copy-paste. scary.
> > it shouldn't. unless you've tied %exception into something that
> > resets the keys on read.
>
> I don't know why I was seeing this behavior, but I downloaded the
> program again, and the problem I was seeing here went away.
interesting.
> The actual problem was that the @#$@#%@# configuration file for my
> program (the file where $dir gets its value) was in MS-DOS format
> (newline and carriage return), which was causing some very strange
> behavior.
you shouldn't notice this from perl. how are you parsing the
configuration file?
> Kudos to kabau for helping me diagnose it!
:)
--
Terje
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-dev] perl question
2001-08-04 11:53 ` Terje Kvernes
@ 2001-08-05 17:22 ` Chad M. Huneycutt
2001-08-05 18:36 ` Terje Kvernes
0 siblings, 1 reply; 6+ messages in thread
From: Chad M. Huneycutt @ 2001-08-05 17:22 UTC (permalink / raw
To: gentoo-dev
Terje Kvernes wrote:
>>The actual problem was that the @#$@#%@# configuration file for my
>>program (the file where $dir gets its value) was in MS-DOS format
>>(newline and carriage return), which was causing some very strange
>>behavior.
>>
>
> you shouldn't notice this from perl. how are you parsing the
> configuration file?
>
I did not write the application. I am not sure why the carriage return
at the end of the line was causing a problem as an argument to opendir,
but the most irritating part was that when I printed out $dir, strange
things could happen, which inhibited my debugging. :-)
Chad
P.S. if you want to see the code, it is a package called petrovich
(hosted at sourceforge), and I will be checking it into app-misc
sometime this weekend.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-dev] perl question
2001-08-05 17:22 ` Chad M. Huneycutt
@ 2001-08-05 18:36 ` Terje Kvernes
0 siblings, 0 replies; 6+ messages in thread
From: Terje Kvernes @ 2001-08-05 18:36 UTC (permalink / raw
To: gentoo-dev
"Chad M. Huneycutt" <chad.huneycutt@acm.org> writes:
> I did not write the application. I am not sure why the carriage
> return at the end of the line was causing a problem as an argument
> to opendir, but the most irritating part was that when I printed out
> $dir, strange things could happen, which inhibited my debugging. :-)
hm. maybe opendir didn't like getting a ^M as a part of its
argument. :)
of course, printing it just might show it as "\n". that would be the
cute part.
> P.S. if you want to see the code, it is a package called petrovich
> (hosted at sourceforge), and I will be checking it into app-misc
> sometime this weekend.
I'll see if I'll bother. honestly, perl _should_ be transparent when
it comes to newline habits.
--
Terje - just another perl hacker.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-08-06 0:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-08-03 22:35 [gentoo-dev] perl question Chad M. Huneycutt
2001-08-04 7:32 ` Terje Kvernes
2001-08-04 10:14 ` Chad M. Huneycutt
2001-08-04 11:53 ` Terje Kvernes
2001-08-05 17:22 ` Chad M. Huneycutt
2001-08-05 18:36 ` Terje Kvernes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox