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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

++wfsp. For uniformity, I would store *every* value of %gp as an arrayref, rather than need conditional logic on every use of a value.

Here is my quick refactor, with ++hbm's test data (padded to 5 columns):

use strict; use warnings; my %gp = ( G11 => [qw( Galpha-11 )], G12 => [qw( Galpha-12 )], G13 => [qw( Galpha-13 )], G14 => [qw( Galpha-14 )], G15 => [qw( Galpha-15 )], G16 => [qw( Galpha-16 )], Gs => [qw( Galpha-s )], Gz => [qw( Galpha-z )], Golf => [qw( Galpha-olf )], Go => [qw( Galpha-o )], Gq => [qw( Galpha-q )], Gi => [qw( Galpha-i1 Galpha-i2 Galpha-i3 )], Gt => [qw( Galpha-t1 Galpha-t2 Galpha-t3 )], ); my $re = qr{ \A ( [^\t]* \t [^\t]* ) \t ( [^\t]* ) \t ( [^\t]* \t .* ) \z }msx; LINE: while ( my $line = <DATA> ) { chomp $line; my ( $col_1_2, $col_3, $col_rest ) = ( $line =~ /$re/ ) or do { warn "Line $. did not match: '$line'"; next LINE; }; $col_3 =~ tr{ }{}d; my $aref = $gp{$col_3} or do { # No replacement needed? Is line still wanted? warn "Did not find '$col_3' in %gp"; print $line, "\n"; next LINE; }; for my $val ( @{ $aref } ) { print join( "\t", $col_1_2, $val, $col_rest ), "\n"; } } __DATA__ biologist xargon Gi question col5 perl monks G11 answer? col5


In reply to Re: How to improve my code? main concern:array as hash element by Util
in thread How to improve my code? main concern:array as hash element by xargon

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (3)
    As of 2014-10-24 07:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (131 votes), past polls