- * (list context)
-
The elements of argument lists for formats are now evaluated in list context. This means
you can interpolate list values now.
@fmt = ("foo","bar","baz");
format STDOUT=
@<<<<< @||||| @>>>>>
@fmt;
.
write;
# perl4 errors: Please use commas to separate fields in file
# perl5 prints: foo bar baz
|
|
- * (scalar context)
-
The caller() function now returns a false value in a scalar context if there
is no caller. This lets library files determine if they're being required.
caller() ? (print "You rang?\n") : (print "Got a 0\n");
# perl4 errors: There is no caller
# perl5 prints: Got a 0
|
|
- * (scalar context)
-
The comma operator in a scalar context is now guaranteed to give a scalar context to its
arguments.
@y= ('a','b','c');
$x = (1, 2, @y);
print "x = $x\n";
# Perl4 prints: x = c # Thinks list context interpolates list
# Perl5 prints: x = 3 # Knows scalar uses length of list
|
|
- * (list, builtin)
-
sprintf() is prototyped as ($;@), so its first argument is given scalar
context. Thus, if passed an array, it will probably not do what you want, unlike Perl 4:
@z = ('%s%s', 'foo', 'bar');
$x = sprintf(@z);
print $x;
# perl4 prints: foobar
# perl5 prints: 3
|
|
printf() works the same as it did in Perl 4, though:
@z = ('%s%s', 'foo', 'bar');
printf STDOUT (@z);
# perl4 prints: foobar
# perl5 prints: foobar
|
|
|
|