Concatenation

G

Greg

Can someone give me any insight into why

my $s = undef() . '';

executes without complaint in my Perl 5.6 installation. But

my $s = '' . undef();

emits

"Use of uninitialized value in concatenation (.) or string"

Seems to me that I'm using an uninitialized value in either case.

Just curious.

Any information appreciated.

TIA.

Greg
 
T

Tad McClellan

Greg said:
Can someone give me any insight into why


It must have been a bug.

my $s = undef() . '';

executes without complaint in my Perl 5.6 installation. But

my $s = '' . undef();

emits

"Use of uninitialized value in concatenation (.) or string"

Seems to me that I'm using an uninitialized value in either case.


5.6.1 does that for me too.

5.8.0 issues warnings for either one.
 
T

Tassilo v. Parseval

Also sprach Greg:
Can someone give me any insight into why

my $s = undef() . '';

executes without complaint in my Perl 5.6 installation. But

my $s = '' . undef();

emits

"Use of uninitialized value in concatenation (.) or string"

Seems to me that I'm using an uninitialized value in either case.

Yes, in both cases it's uninitialized. But the former works because it is
treated specially. There is no warning because it would make things like
this clumsy:

my $var;
for (0 .. 50) {
# in the first iteration this is:
# $var = undef . something()
$var .= something();
}

So it's really just a convenience thing that perl wont warn when you
append something to an unitialized variable.

Tassilo
 
G

Greg

Tassilo v. Parseval said:
Also sprach Greg:


Yes, in both cases it's uninitialized. But the former works because it is
treated specially. There is no warning because it would make things like
this clumsy:

my $var;
for (0 .. 50) {
# in the first iteration this is:
# $var = undef . something()
$var .= something();
}

So it's really just a convenience thing that perl wont warn when you
append something to an unitialized variable.

Tassilo

Thanks for the explanation. That makes sense after a fashion, though I
wonder if the value of this convenience balances the cost of the
difference in behavior in the two cases.

I guess I'm still not comfortable with the level of 'help' that Perl
gives one.

Greg
 

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
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top