You didn't read all of what I wrote. If you ask me, your line is already getting very laden, and if you actually account for the kicker I added, it's likely to get.. ugly. That is, what happens if it's not always the same column, but changes depending on some field in $row?

For my version, fixed column:

my @cols; for my $row (@array) { my @f = split /,/, $row; $f[2] = $b[$f[2]]; push @{$cols[$_]}, $f[$_] for 0 .. $#f; }

Only a very simple line to add. Same change, only more complex code, for varying column:

my %col_for = ( foo => 2, bar => 4, baz => 5, ); my @cols; for my $row (@array) { my @f = split /,/, $row; splice @f, $col_for{$f[1]} || 6, 0, shift @b; push @{$cols[$_]}, $f[$_] for 0 .. $#f; }
(Yes, I realize I introduced a side effect. You can just as easily have do by assigning slices to my @ff or something though, it doesn't change the structure of the code.)

Makeshifts last the longest.


In reply to Re^7: Arrays manipulation (no $i either) by Aristotle
in thread Arrays manipulation by hotshot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.