too much code , too many file system operations

Where is the problem?

Is the problem with the data structure , or the subroutine doing the printing?

When you Data::Dump::dd()umper up the data structure and read it with your eyes, is everything there?

If you really want more help, you should whittle down your program to this

my %ref; my $threelinefakein = "...\n..."; fillRef( \%ref, \$threelinefakein ); my @fakes = ( "1\n2\n3", "1\n2\n3" ); for my $fake ( @fakes ){ refLogic( \%ref, \$fake ); }

subroutines save the day, its very easy to debug subroutines, you don't need files on the harddisk and other stuff we don't have (and don't really want :)

Here is how you might start writing refLogic and fillRef

## Usage: fillRef( $hashref, $infilename ); sub fillRef { ## so you can keep using $ref{blah} ## less rewriting when you copy/paste local *ref = shift; ## open the string as file open IN, '<', shift; ... } ## Usage: refLogic( $hashref, $infilename ); sub refLogic { local *ref = shift; ## open the string as file open IN, '<', shift; ## fake out for testing local *OUT = \*STDOUT; }

Eliminate file system operations for files we don't have, include three lines files that replicate the problem, include them as strings

update: finally I read the whole thing you posted, just dumper up two variables and we can start debugging these two loops

my %ref = ... ; ## Data::Dump::dd(%ref) output here my @probes = ... ; ## Data::Dump::dd(@probes) output here ## foreach my $key ( sort keys %ref ) { #intended function print OUT $ref{$key} . "\t" . $probes[$key]; #testing my @temp = split "\t", $ref{$key}; foreach (@temp) { if ( $temp[0] == 2 ) { print $key. "\t" . $ref{$key} . "\t" . $probes[$key]; } } } ## foreach my $key ( sort keys %ref ) { print OUT $ref{$key} . "\t" . $probes[$key]; my @temp = split "\t", $ref{$key}; foreach (@temp) { if ( $temp[0] == 2 ) { print $key. "\t" . $ref{$key} . "\n +"; } } }
[download]

update: now that I've looked at these two loops, well, the inner foreach is completely unneeded .... and aside from the different things you print (one has probles the other doesn't), they're pretty much the same thing

Hope this help, if it doesn't, well, take a break, post short code, we'll figure it out


In reply to Re: Hash will not print if a value begins with 2 under certain conditions by Anonymous Monk
in thread Hash will not print if a value begins with 2 under certain conditions by pimperator

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.