Chris

    scalar reverse "forwards"

is the same as

    scalar reverse ( "forwards" )

It explicitly puts the call to reverse() into scalar context. Whereas

    reverse scalar "forwards"

is the same as

    reverse ( scalar "forwards" )

which only forces the already scalar string "forwards" to be scalar.


When called in scalar context, reverse() reverses the characters in its
parameter list. If called in list context, it returns the list itself in
reverse order. So that

    ( reverse ( "abcd", "efgh" )      gives      ( "efgh", "abcd" )

while

    scalar reverse ( "abcd", "efgh" )      gives      "hgfedcba"


HTH,

Rob


----- Original Message -----
From: "Chris Game" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, November 30, 2002 9:55 PM
Subject: Re: reverse?


> In an earlier post, Paul Johnson  wrote:
>
> > On Sat, Nov 30, 2002 at 09:26:29PM -0000, Chris Game wrote:
> >
> >> Can anyone explain why
> >> perl -e 'print reverse "forwards" ' prints "forwards"; and to get
> >> what I want I have to use
> >> perl -e 'print $var= reverse "forwards" ' which yields "sdrawrof" ?
> >> Why do I have to introduce the extra variable just to get the print
> >> I was after?
> >
> > Because your first example is in list context.
> >
> > perl -e 'print scalar reverse "forwards"'
>
> Blimey that was quick! Thanks for the response Paul. Why doesn't
> perl -e 'print reverse scalar "forwards" ' work (I tried that earlier)?
>
> --
> ===========================================
>
> Chris Game <chrisgame@!yahoo!dotcodotuk>
> ===========================================
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to