Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Basic Coding Tips: Parsimonious Parameterization

by BUU (Prior)
on Jan 29, 2005 at 04:18 UTC ( #426179=note: print w/ replies, xml ) Need Help??


in reply to Re: Basic Coding Tips: Parsimonious Parameterization
in thread Basic Coding Tips: Parsimonious Parameterization

Well, if you want a "WTF", I found this gem on cpan a while ago:

#merges the elements of two or more arrays together so that the values + of one # are appended to the end of the previous one sub array_merge{ my(@array1, @array2) = @_; foreach my $element (@array2){ @array1 = (@array1, $element); }#foreach return @array1; }#array_merge


Comment on Re^2: Basic Coding Tips: Parsimonious Parameterization
Download Code
Re^3: Basic Coding Tips: Parsimonious Parameterization
by Tanktalus (Canon) on Jan 29, 2005 at 05:09 UTC

    I have to admit - he couldn't do it much faster than that and still have a subroutine...

    (Anyone else notice that @array2 will always be empty since @array1 will get all of @_? Thus, the foreach will always be skipped!)

      Yes :) But it'd works this way:
      sub array_merge(\@\@){ my($array1, $array2) = @_; foreach my $element (@$array2){ @$array1 = (@$array1, $element); }#foreach return @$array1; }#array_merge my @t=array_merge(@liste1, @liste2);
        my @t = (@liste1, @liste2);
        works too. No need to reinvent what the core language already provides in a simple way.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-04-21 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls