Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

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

Hey there kenosis. Sorry to bother you again. SO the program is no longer giving me error messages, but the pushing to the arrays here:

push @activline, "$1 | $2 | $activ{$1} \n" if $activ{$1}; push @antioxline, "$1 | $2 | $antiox{$1} \n" if $antiox{$1}; push @toxinline, "$1 | $2 | $toxin{$1} \n" if $toxin{$1};

isn't working properly. For example I selected a specific number from $activin, which was in $uniprot, but it wasn't in the final output. So @activline, @antioxline and @toxinline are much smaller than they should be. So a lot of the data that is supposed to be in the output is not there anymore. I tried testing with this:

if ($1 eq "E7F888"){print $2;}

and it gave me the correct $2, I tried this too:

next unless /(E7F888)\s+.+=([^\s]+)/; push @activline, "$1 | $2 | $activ{$1} \n" if $activ{$1}; print @activline;

and it printed the correct thing. But if I removed the tests i put, and ran the normal code, E7F888 is not in @activline. Is there anything I could do to figure out what's wrong with my code? Here's it again.

#!/usr/bin/perl use Modern::Perl; use File::Slurp qw/read_file write_file/; my $uniprot = 'uniprot-ACN'; my $activin = 'Activator-PFAM.txt'; my $antioxin = 'AntiOxidant-PFAM.txt'; my $toxinin= 'Toxin-PFAM.txt'; my $activout = 'ActivACNPF.txt'; my $antioxout= 'AntioxACNPF.txt'; my $toxinout= 'ToxinACNPF.txt'; my @activline; my @antioxline; my @toxinline; my %activ = map {s/\.\d+//g; /(.+)\s+\|\s+(.+)/ and $1 => $2 } grep / +\|\s+\S+/, read_file $activin; my %antiox = map { s/\.\d+//g; /(.+)\s+\|\s+(.+)/ and $1=>$2; } grep/\ +|\s+\S+/,read_file $antioxin; my %toxin = map { s/\.\d+//g; /(.+)\s+\|\s+(.+)/ and $1=>$2; } grep/\ +|\s+\S+/,read_file $toxinin; #if (exists $activ{"E7F888"}) { #print $activ{'E7F888'};} #else {print "LOL";} for ( read_file $uniprot ) { next unless /(.{6})\s+.+=([^\s]+)/; # if ($1 eq "E7F888"){print $2;} push @activline, "$1 | $2 | $activ{$1} \n" if $activ{$1}; push @antioxline, "$1 | $2 | $antiox{$1} \n" if $antiox{$1}; push @toxinline, "$1 | $2 | $toxin{$1} \n" if $toxin{$1}; } print @activline; write_file $activout, @activline; write_file $antioxout, @antioxline; write_file $toxinout, @toxinline;

THanks so much.


In reply to Re^12: Help with pushing into a hash by jemswira
in thread Help with pushing into a hash by jemswira

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 making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found