in reply to trivial wrapping
If you don't mind destroying the strings as you output them, then this will do the job. If you need them for further processing then you could copy the array first. However, from the use of $genome as a variable name, it could well be that your strings are of extreme length, in which case copying them may be prohibitively expensive on memory. In which case, say so and someone will suggest a non-destructive way. Its not much harder
#! perl -sw use strict; my @strings = map{"$_" x 200} 1 .. 3; while( length "@strings" > 2 ) { print substr( $strings[$_], 0, 60, '') . "\n" for 0 .. $#strings; print "\n"; } __END__ c:\test>213729 111111111111111111111111111111111111111111111111111111111111 222222222222222222222222222222222222222222222222222222222222 333333333333333333333333333333333333333333333333333333333333 111111111111111111111111111111111111111111111111111111111111 222222222222222222222222222222222222222222222222222222222222 333333333333333333333333333333333333333333333333333333333333 111111111111111111111111111111111111111111111111111111111111 222222222222222222222222222222222222222222222222222222222222 333333333333333333333333333333333333333333333333333333333333 11111111111111111111 22222222222222222222 33333333333333333333 c:\test>
Update: I noticed the mention of $genome1 after my first attempt at this and then disliked the destructive nature of the code and also that the loop condition would be exspensive on memory for large strings and/or arrays, so here's a better version without those caveats. The output is the same.
#! perl -sw use strict; my @strings = map{"$_" x 200} 1 .. 3; my ($total, $p) = (0, 0); do { $total = 0; print substr( $strings[$_], $p, 60 ) . "\n" for 0 .. $#strings; print "\n"; $p+=60; $total += length($_) - $p for @strings; } while( $total > 0 ); __END__
Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: trivial wrapping
by GhodMode (Pilgrim) on Nov 18, 2002 at 14:46 UTC | |
by BrowserUk (Patriarch) on Nov 18, 2002 at 14:52 UTC | |
by GhodMode (Pilgrim) on Nov 18, 2002 at 17:20 UTC | |
|
Re: Re: trivial wrapping
by Anonymous Monk on Nov 18, 2002 at 13:55 UTC | |
by BrowserUk (Patriarch) on Nov 18, 2002 at 13:57 UTC |