B::Deparse module bug?

R

refile

E:\813\bin>type test1.pl
my $envwin;
$ENV{OS} ? $envwin=$ENV{WINDIR} : $envwin=$ENV{USERPROFILE};
print "$envwin";
E:\813\bin>test1.pl
C:\Documents and Settings\y6cmE
E:\813\bin>Perl -MO=Deparse test1.pl > test2.pl
test1.pl syntax OK

E:\813\bin>test2.pl
Assignment to both a list and a scalar at E:\813\bin\test2.pl line 2,
near "};"
Execution of E:\813\bin\test2.pl aborted due to compilation errors.

E:\813\bin>type test2.pl
my $envwin;
$ENV{'OS'} ? ($envwin = $ENV{'WINDIR'}) : $envwin =
$ENV{'USERPROFILE'};
print "$envwin";
 
M

MikeGee

E:\813\bin>type test1.pl
my $envwin;
$ENV{OS} ? $envwin=$ENV{WINDIR} : $envwin=$ENV{USERPROFILE};
print "$envwin";
E:\813\bin>test1.pl
C:\Documents and Settings\y6cmE

Does $ENV{OS} really evaluate as false as this seems to indicate?


Try this simpler code:

my $envwin = $ENV{OS} ? $ENV{WINDIR} : $ENV{USERPROFILE};
print $envwin, "\n";


I can't help with the apparent bug in B::Deparse.
 
S

Sisyphus

MikeGee said:
Does $ENV{OS} really evaluate as false as this seems to indicate?

I don't think so. According to 'perldoc perlop' it looks to me that

$ENV{OS} ? $envwin=$ENV{WINDIR} : $envwin=$ENV{USERPROFILE};

is evaluated as:

($ENV{OS} ? $envwin=$ENV{WINDIR} : $envwin) = $ENV{USERPROFILE};

and that means that $envwin always ends up as $ENV{USERPROFILE}
irresepective of whether $ENV{OS} is true or false.

I tried both:

$x ? $y = 10 : $y = 2;
and
($x ? $y = 10 : $y) = 2;

and $y is always set to '2'. As soon as brackets are placed around '$y =
10', I get the error the op reports. I don't understand why that happens ...
but apparently it's not allowed, and I guess that B::Deparse should
therefore not do it.

Cheers,
Rob
 

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

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top