Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

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

Far better solutions have been presented, but here is another. I was considering how to do if we had tail recursion. I had been hoping to place all code in the argument list...

sub parts { my ( $cnt, $ra_out, $ra_val, $ra_in ) = @_; if( $#$ra_val != $cnt ){ #working array not full if( $#$ra_in > -1 ){ #fill it up push(@$ra_val, shift(@$ra_in)); parts( $cnt, $ra_out, $ra_val, $ra_in ); } else { #done with list return; } } else { push(@$ra_out, join('',@$ra_val)); #add to outp +ut array, joined ltr string shift(@$ra_val); #rip off fir +st ltr push(@$ra_val, shift(@$ra_in)) if($#$ra_in > -1); #add new ltr +, if any remaining parts( $cnt, $ra_out, $ra_val, $ra_in ); } } my @in = split( '', "computer" ); # input array of individual letters my @out; # out array of strings each of $cnt ++1 ltrs my @val; # working array of individual lette +rs, $cnt+1 elements parts( 2, \@out, \@val, \@in ); #results in @out

..Otto


In reply to Re^2: finding number of contiguous letters by otto
in thread finding number of contiguous letters by Marknel

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 examining the Monastery: (4)
As of 2024-04-19 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found