Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: formatting output question (use of recursive subroutine?)

by Pancho (Pilgrim)
on Jul 29, 2008 at 14:07 UTC ( [id://700818]=note: print w/replies, xml ) Need Help??


in reply to formatting output question (use of recursive subroutine?)

Roger,

I think an iteration algorithm would be more straight forward (and this is subjective). I would break the task in two parts, first iterating through all of your strings to match and having an out1, out2, etc for each string to match. I would use a subroutine to perform this task of creating the out-n lines.

Then I would code another paragraph to collapse all of the out lines together in the least number possible output lines, once using iteration and an array to keep track of the output line 'depth' (i.e. output_line_1, output_line_2, etc)... there are dozens of ways to approach this though...

Good luck,

Pancho
  • Comment on Re: formatting output question (use of recursive subroutine?)

Replies are listed 'Best First'.
Re^2: formatting output question (use of recursive subroutine?)
by rogerd (Sexton) on Jul 29, 2008 at 22:54 UTC

    I have thought about this approach. I have already written the first part (the data is stored in the hash %details of match):

    my @output_lines; my $model_number=0; foreach my $gene_name (keys %details_of_match) { $output_lines[$model_number]= qw{ } x length($original_seq_string) +; for (my $i=0; $i< scalar( @{$details_of_match{$gene_name}} ); $i++ + ) { substr $output_lines[$model_number] # the new li +ne , $details_of_match{$gene_name}->[$i][0] # the +position , 21 # the length (constant) , $details_of_match{$gene_name}->[$i][2] #the patt +ern ; } $model_number++; }

    At this point, I have all the lines, each one with just one substring in the right position, stored in the array @output_lines. But then, I get stuck with the second part, because I don't imagine how to collapse all the lines into the least number of possible lines.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-07-23 18:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.