Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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 +"; } } }

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found