From: [EMAIL PROTECTED]
> ------------------------------------------------
> On Tue, 4 Feb 2003 18:51:16 +0200 , "Zysman, Roiy"
> <[EMAIL PROTECTED]> wrote:
>
> > Hi All
> > Why does the command 'print (localtime(time))[4];' does not work And
> > the following 2 lines do work '[my $temp = (localtime(time))[4];
> > Print $temp;'
> >
> > Is there away to avoid the temporary variable ?
>
> print ((localtime(time))[4]);
To excplain what's going on ... if the first nonwhitespace character
after a subroutine name is an opening brace then the list enclosed by
this brace and the mathing closing brace is supposed to be the
parameter for the subroutine and anything that follows the closing
brace will be "applied" to the subroutine result.
Thus
print (localtime(time))[4];
is the same as
( print(localtime(time)) )[4];
Which causes the localtime to be evaluated in list context, the list
is passed to print and then Perl tries to the use result of print
(usualy 1) as an array.
It's the same issue as:
print (2 + 3) * 6;
HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]