Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: palindrome using regular expressions

by Hofmator (Curate)
on Oct 10, 2006 at 12:11 UTC ( #577386=note: print w/replies, xml ) Need Help??

in reply to Re^2: palindrome using regular expressions
in thread palindrome using regular expressions

Yes, you are absolutely right. Thanks for the correction.

In fact, I also thought that reverse worked on strings and so I tried print reverse 'hello' which returns hello. From that I (incorrectly) concluded that it doesn't work ... well, got bitten by list context again, print scalar reverse 'hello' does the job OK :)

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^4: palindrome using regular expressions
by strat (Canon) on Oct 11, 2006 at 07:58 UTC


    reverse is aware of its context; if you use it in string context ($reverse = reverse ...), it reverses the string; but if you use it in list context (print reverse ... or @array = reverse ..), it reverses the list (and does nothing if the list only has one element

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://577386]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2016-10-22 09:50 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (294 votes). Check out past polls.