Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

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

Below is part of a script that I think should read a file into a hash, so I can look up the record using the key from other parts of the program. The print statements include are for trying to find out what's wrong! The program finds the name successfully (based on the print in the if loop), and creates the hash with the right values, but the keys are always empty (based on the output of the while loop that prints the hash)

open (NOV, '<', $novo); my %denovo; while (my $line = <NOV>){ chomp $line; if ($line =~ /([^,]*)$/){ my $name = "$1"; print "name is $name\n"; $denovo{$name} = "$line"; } } print "hash denovo is:\n"; while( my( $key, $value ) = each %denovo ){ print "$key: $value\n"; } close NOV;

I've tried changing the presence of / types of commas around $name when defining each hash entry. The keys should look like following: R2b.9138.9138.2(intensity=1341005.0692)_2 so I've tried using simpler names in case there were some illegal characters or something - but nothing works! I think I must be misunderstanding something fairly fundamental. Any help would be enormously appreciated.


In reply to Why are my hash keys undefined? by biologistatsea

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: (1)
As of 2024-04-25 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found