Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^6: Help with pushing into a hash

by jemswira (Novice)
on Aug 31, 2012 at 15:43 UTC ( #991030=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Help with pushing into a hash
in thread Help with pushing into a hash

Thanks again! I ran the check and had some blank lines:

No Match in File: Activator-PFAM.txt; Line: Q8UPQ0 | No Match in File: Toxin-PFAM.txt; Line: Q306M5 |

So i added the grep before the file read, and the error changed.

Odd number of elements in hash assignment at C:\Users\Jems\Desktop\Per +l\test\test2script.plx line 20. Odd number of elements in hash assignment at C:\Users\Jems\Desktop\Per +l\test\test2script.plx line 22. Odd number of elements in hash assignment at C:\Users\Jems\Desktop\Per +l\test\test2script.plx line 26. Odd number of elements in hash assignment at C:\Users\Jems\Desktop\Per +l\test\test2script.plx line 27. Odd number of elements in hash assignment at C:\Users\Jems\Desktop\Per +l\test\test2script.plx line 28.

Still same lines. And somehow line 21, which was for the file that did not give the error still did not give the error. Also Padre is warning me that the substitution will not replace anything.

thanks!


Comment on Re^6: Help with pushing into a hash
Select or Download Code
Re^7: Help with pushing into a hash
by Kenosis (Priest) on Aug 31, 2012 at 16:37 UTC

    Ah! Excellent, jemswira!! Here's what's happening... The regex trys to capture everything past " | " for use as a value. However, in the lines above, there are no values, so $2 is not initialized for those lines which creates errors. To fix this, change the grep to:

    grep /\|\s+\S+/

    You'll notice that the first part of the grep's regex is used in the map statement. The above adds \S+, which means that there need to be non-whitespace characters (i.e., values) beyond " | " for the line to pass. I'm assuming, here, that we can safely ignore lines that don't have anything past " | ". If this is the case, the above grep should resolve the errors.

      Thanks. That removed 2 of the error lines. The first 2. Now these are left:

      Use of uninitialized value $1 in hash element at C:\Users\Jems\Desktop +\Perl\test\test2script.plx line 26. Use of uninitialized value $1 in hash element at C:\Users\Jems\Desktop +\Perl\test\test2script.plx line 27. Use of uninitialized value $1 in hash element at C:\Users\Jems\Desktop +\Perl\test\test2script.plx line 28.

      lines 26, 27 and 28 are:

      for ( read_file $uniprot ) { /(.{6})\s+.+=([^\s]+)/; push @activline, "$1 | $2 | $activ{$1}\n" if $activ{$1}; #26 push @antioxline, "$1 | $2 | $antiox{$1}\n" if $antiox{$1}; #27 push @toxinline, "$1 | $2 | $toxin{$1}\n" if $toxin{$1};#28

      The format for $uniprot is the same as for $test. I.E.

      Q197F8 ORFNames=IIV3-002R Q197F7 ORFNames=IIV3-003L Q6GZX2 ORFNames=FV3-003R Q6GZX1 ORFNames=FV3-004R Q197F5 ORFNames=IIV3-005L Q6GZX0 ORFNames=FV3-005R ;PF02393 Q91G88 ORFNames=IIV6-006L ;PF12299;PF04383 Q6GZW9 ORFNames=FV3-006R

      Thanks again!

        The message:

        Use of uninitialized value $1...

        Means that the regex is not matching some lines in your data set. Here are two options:

        say if !/(.{6})\s+.+=([^\s]+)/;

        This will show you the lines that are not matching, so you can adjust your regex, if needed.

        next unless /(.{6})\s+.+=([^\s]+)/;

        This will just skip those lines that don't match the regex.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-09-23 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls