Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: my vs. local subtlety

by davidrw (Prior)
on Jul 03, 2006 at 16:57 UTC ( #559019=note: print w/replies, xml ) Need Help??


in reply to my vs. local subtlety

There are obviously a number of ways to improve the code

You probably don't want to be using variable variable names (which makes your root problem go away).. A bunch of nodes, including the following two, refer to the reasons:
Have to also throw out the obligatory comment about avoiding the use of $a and $b because of their special global-ness w/sort

Could you also provide sample input & output to this sub? I strongly suspect this could be written w/ map & join .. something like (note the hash slice usage):
sub meld_columns { my ($arrays, @arrNames) = @_; my ($maxIdx) = sort { $b<=>$a } map {$#$_} @{$arrays}{@arrNames}; my @outarray = map { my $i = $_; # keep track of the current "row" to use in inner map + block # get the respective element from each array. # If we're beyond the individual array length, just use "\t". # Also glue all cols together w/a "\t" join "\t", map { $i <= $#$_ ? $_->[$i] : "\t" } @{$arrays}{@arrNam +es} } 0..$maxIdx; } my %arrayHolder = map { $_ => [] } 'a' .. 'z'; # build the initial d +ata structure (instead of named arrays) my @out = meld_columns( \%arrayHolder, 'a' .. 'h' ); # meld just A th +rough H my @out = meld_columns( \%arrayHolder, 'f', 'a', 'c' ); # meld just F + A C, in that order.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://559019]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2018-06-18 23:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (111 votes). Check out past polls.

    Notices?