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

Re: Palindrome array

by Athanasius (Chancellor)
on Dec 29, 2012 at 06:04 UTC ( #1010792=note: print w/replies, xml ) Need Help??

in reply to Palindrome array

The string comparison operator eq puts its operands into scalar context:

#! perl use warnings; use strict; use 5.010; say 'equal' if context('1') eq context('2'); sub context { my $c = (defined wantarray) ? (wantarray ? 'list' : 'scalar') : 'void'; say '(', shift, '): is in ', $c, ' context'; return 42; }


15:56 >perl (1): is in scalar context (2): is in scalar context equal 15:56 >

So, neither code snippet is doing what you want. The first compares the sizes of the two arrays. The second compares the size of @array with the value returned by reverse, which

In scalar context, concatenates the elements of LIST and returns a string value with all characters in the opposite order.

To compare the contents of the two arrays, use the smart match operator ~~. See How do I test whether two arrays or hashes are equal?

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010792]
[stevieb]: agreed. That's why I said at least a half-dozen. If enough of the different formats are present, the date/time folk may not have to request more. If they do, then at least there was a decent base to start with
[stevieb]: I do date and time transformations in both Perl and Python, but not frequently enough to not have to search for the format params etc ;)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2017-04-29 02:42 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.