Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi there. Thanks everyone for all your help so far today. I have noe more question if thats ok. At the moment, my perl scripts output is this:
>ca106a84b6c03260e9e38b730b137664/1-17_107-243 1283 0.000 # - 0.331 # W 0.370 # D >a1b9ed2221c16448ebe19883994fa2db/1-95_130-213 1026 0.000 # M 0.331 # K 0.370 # N >fdecbdbac2f7f88b0cb666b87a69753a/76-219 209 0.000 # M 0.331 # T 0.370 # E
But I want it to be like this.
0.000 # -MM 0.331 # WKT 0.370 # DNE
But I'm not sure how to organise the print statements. code so far is as follows.
#!/usr/local/bin/perl use strict; use English; use Data::Dumper; use UNIVERSAL qw(isa); use FileHandle; use Exception; my $names = shift; my $alignment = shift; my $scorecons = shift; #my $lineno = 0; if (!$names || ! -e $names) { die new Exception("couldnt open names file $names"); } if (!$alignment || ! -e $alignment) { die new Exception("couldnt open names file $alignment $!"); } if (!$scorecons || ! -e $scorecons) { die new Exception("couldnt open names file $scorecons"); } warn "# Reading alignment data"; my $alignData = getAlignData($alignment); warn "# Got alignment data: ".scalar (keys %$alignData); #warn "# Reading scorecons data"; #my $scoreData = getScoreData($scorecons); #warn "# Got scorecons data: ".scalar (keys %$scoreData); warn "# Reading scorecons data\n"; my $scoreData = getScoreData($scorecons); warn "# Got scorecons data ".scalar @$scoreData; my $fhnames = new FileHandle($names) or die "Couldn't create file handle for $names"; while(my $line = $fhnames->getline) { my @cols = split /\s+/, $line; my $header = $cols[0]; my $align = $alignData->{$header}; my $number = $align->{line}; print "$header $number\n"; foreach my $item(@$scoreData) { # split each line of array into fields my @fields = split(/\s+/, $item); my $scorecons = $fields[0]; my $alignment = $fields[2]; my $align = substr($alignment, $number, 1); print "$scorecons # $align\n"; } #print "\n"; } ################################################# sub getAlignData { my ($fIn) = @ARG; my $fh = new FileHandle($fIn) or die ""; my $count = 0; my $hData = {}; while (my $line = $fh->getline) { my @cols = split /\s+/, $line; # search only for lines with identifier my $field = $cols[0]; my $test = substr($field, 0, 1); if("$test" eq ">") { # $count++; my $hEntry = { 'identifier' => $cols[0], 'line' => $count, }; $count++; #print "$cols[0] $count\n"; my ($record) = sort ($hEntry->{identifier}); $hData->{$record} = $hEntry; } } return $hData; } #################################################### sub getScoreData { my ($fIn) = @ARG; open(FILE, "$fIn") || die "Unable to open file\n"; my @data = <FILE>; return (\@data); }
Any advice much appreciated.

In reply to how to format print statements with data from array by Angharad

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 rifling through the Monastery: (6)
As of 2024-03-28 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found