in reply to Re: Converting Python to Perl and back again
in thread Converting Python to Perl and back again

Good points. With regard to number 4, is there an alternative in Perl for something such as

a = [1, 2, 3] b = [1, 2, 4] if (a < b): print "a is less than b"

Or would I end up recursing through the array, comparing each element individually?

I should note that I've never found this useful, so I won't hold it against Perl if it doesn't have this feature :).

Replies are listed 'Best First'.
Re: Re: Re: Converting Python to Perl and back again
by Corion (Patriarch) on Apr 04, 2003 at 08:26 UTC

    There is no straightforward way in Perl, no. The way I go in Perl is most of the time using the is_deeply method from Test::More, but you end up doing the recursion manually. In Python, I've used this thing a lot in reporting sorted arrays - it's very convenient, but this is impossible under the current Perl due to the way sort works. Once could override sort to do the Right Thing whenever it encounters two arrays of references and no block is passed to it, but I don't know at what cost - and most code dosen't use that anyway.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: Re: Re: Converting Python to Perl and back again
by theorbtwo (Prior) on Apr 04, 2003 at 18:32 UTC

    Actualy, there is a way, though it's somwhat odd. Instead of using lists, use version-strings. In recent (>5.6, IIRC) versions of perl, v1.2.3 eq chr(1).chr(2).chr(3) (the v is optional if there are more then two elements, but be warned that there is a (fairly large) size limit on the elements), so what you're doing there is equivlent to

    $a = v1.2.3; $b = v1.2.4; if ($a lt $b) { print "a is less than b"; }


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).