in reply to Re: newkid confused
in thread newkid confused: reverse then unreverse a string

I've been always using my $oof = reverse $foo; is there any particular reason for the scalar? isn't it already in a scalar context? will it break someday?


He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re:(3) newkid confused
by swiftone (Curate) on Apr 07, 2002 at 17:09 UTC
    Your way is fine. Many people make it an explicit scalar reverse because it isn't always a scalar context. Take for example:
    my $foo = "This is not a palindrome"; print reverse $foo;
    print implies a list context, so reverse will take the list ($foo), and reverse it to ($foo) and print that result. Probably not what is intended. It also can take a while to debug, when the perfectly acceptable-looking reverse statement "doesn't work".

    Thus, if you get in the habit of being explicit about your context, you don't get caught.