Front page | perl.perl5.porters |
Postings from November 2003
[perl #24508] Wrong assignment in nested assignment together with subroutine ca ll
Thread Next
From:
Moeller Wolf-Dietrich
Date:
November 17, 2003 15:46
Subject:
[perl #24508] Wrong assignment in nested assignment together with subroutine ca ll
Message ID:
rt-24508-67557.5.43139696619242@rt.perl.org
# New Ticket Created by Moeller Wolf-Dietrich
# Please include the string: [perl #24508]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24508 >
Wrong assignment in nested assignment together with subroutine call.
Given one assignment with a concatenation on the right hand side.
The first term of this concatenation is an assignment of a concatenation,
enclosed in parentheses.
If the inner assignment concatenates two constant strings or scalar
variables, everything is okay. Example statement:
$x2 = ($x1 = '##'.'**').'++';
If the inner assignment assigns the concatenation of a string and the result
of a subroutine call, then the parentheses are not honored correctly.
Example statement:
$x2 = ($x1 = '##'.fct('**')).'++';
The "inner" result variable $x1 has (incorrectly) the value of the "outer"
result varable ($x2).
If a "dummy" empty string is concatenated at the beginning of the outer
concatenation, then the behaviour is correct. Example statement:
$x2 = ''.($x1 = '##'.fct '**' ).'++';
Working test examples, sample output, and Perl version info see test program
below.
######################### start test program #######################
#!/usr/local/bin/perl
# test-script to show error
# Wolf-Dietrich Moeller, 2003-11-14,
<mailto:wolf-dietrich.moeller@siemens.com>
# tested on Perl 5.8.0_806 and 5.8.1_807 Win32 ActiveState,
# also on Perl 5.6.1 under Apache webserver and freeBSD (source
distribution)
# output is (for command line and CGI-script):
#######################################################
#1 x1=##** x2=##**++
#2 x1=##**++ x2=##**++
#3 x1=##**++ x2=##**++
#4 x1=##** x2=##**++
#5 x1=##** x2=##**++
# error in lines 2 and 3: x1 should always equal '##**'
#######################################################
use strict;
binmode STDOUT;
sub fct ($) {
my $c = shift;
return $c
}
my ($x1,$x2);
print "Content-Type: text/plain\x0D\x0A\x0D\x0A";
#
# compound statement without sub
$x2 = ($x1 = '##'.'**').'++';
print '#1 x1=',$x1,' x2=',$x2,"\x0D\x0A";
#
# compound statement with sub
$x2 = ($x1 = '##'.fct '**' ).'++';
print '#2 x1=',$x1,' x2=',$x2,"\x0D\x0A";
#
# compound statement with sub (parentheses for parameters added)
$x2 = ($x1 = '##'.fct('**')).'++';
print '#3 x1=',$x1,' x2=',$x2,"\x0D\x0A";
#
# (empty) concatenation in front of inner assignment added
$x2 = ''.($x1 = '##'.fct '**' ).'++';
print '#4 x1=',$x1,' x2=',$x2,"\x0D\x0A";
#
# two simple statements
$x1 = '##'.fct('**');
$x2 = $x1.'++';
print '#5 x1=',$x1,' x2=',$x2,"\x0D\x0A";
#
print "# error in lines 2 and 3: x1 should always equal '##**'\x0D\x0A";
###################### end test program #############################
----------------------------------------
Dr. Wolf-Dietrich Moeller
Siemens AG, CT IC 3, D-81730 München
Corporate Technology Department Security
Mch P, Tel. +49 89 636-53391, Fax -48000
mailto:wolf-dietrich.moeller@siemens.com
Intranet https://security.ct.siemens.de/
Thread Next
-
[perl #24508] Wrong assignment in nested assignment together with subroutine ca ll
by Moeller Wolf-Dietrich