Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Hash will not print if a value begins with 2 under certain conditions

by Anonymous Monk
on Jul 27, 2014 at 04:00 UTC ( [id://1095195]=note: print w/replies, xml ) Need Help??


in reply to Hash will not print if a value begins with 2 under certain conditions

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1095195]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found