Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Re: Re: Re: Perl vs. Python: Looking at the Code

by buckaduck (Chaplain)
on Apr 03, 2002 at 15:26 UTC ( [id://156429]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Re: Re: Re: Perl vs. Python: Looking at the Code
in thread Perl vs. Python: Looking at the Code

We weren't talking about array concatenation, but if that's what you want to do:
array = array + list
I could do the same with Perl:
@array = (@array, @list);
But I don't see how that helps your case. Perl's push is shorter than either of these:
push @array,@list;
And Python's append() would also be shorter:
array.append(list)

But from your previous comment I presume that append() will not accept a list as a parameter. I think I probably want extend() for that last example.

Of course, the length comparisons vary, depending on your variable names and your willingness to sacrifice legibility. But I don't think that's an argument that anybody wants to make.

Slightly offtopic: I'm just amazed that Python allows more than one way to do something. I thought that was supposed to be evil or something...

buckaduck

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Perl vs. Python: Looking at the Code
by mothra (Hermit) on Apr 03, 2002 at 20:33 UTC
    You're way off.

    If you really want to try and see which language concatenates in fewer characters, beat this: array += foo

    Shorter than Perl's push(). And, yes the append() list method does accept a list (but appends it as the _last element_ in the list to which you're appending), but you wouldn't know that because you don't know Python, but decided your input was worthy anyway.

    Stop it already.

      array += foo

      I'm sure someday soon you will be able to say in perl:

      @array += @foo; # or even @array += $foo;
      But it won't have anything to do with pushing more elements on to the end of a list...(can anyone say APL?)
      ------------
      ooo  O\O  ooo tilly was here :,(
      
        I belive in Perl 6 it will be @array ^+= @foo;

        -Lee

        "To be civilized is to deny one's nature."
      use strict; my $array = new list qw(foo bar); my $list = new list qw(baz qux); $array += $list; print "@$array\n"; package list; use overload "+=" => sub { push @{$_[0]},@{$_[1]};$_[0] }; sub new { my $class = shift; my $self = [@_]; return bless $self, $class; }

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://156429]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.