Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: finding number of contiguous letters

by Marknel (Acolyte)
on May 23, 2007 at 04:48 UTC ( #616929=note: print w/replies, xml ) Need Help??


in reply to finding number of contiguous letters

The while loop worked fine with substring.
$in_string = "supercalifragic" $str_length = length($in_string); $stop_loop_num = $str_length - 2; $temp_counter = 0; while ( $temp_counter < $stop_loop_num ) { $three_chars = substr($in_string); push @str_elements, $three_chars; $temp_counter++; }

While it's functional, I'm certain there is a better way and I'm always striving to learn!

Replies are listed 'Best First'.
Re^2: finding number of contiguous letters
by blazar (Canon) on May 23, 2007 at 09:48 UTC
    The while loop worked fine with substring.

    no need for such a complex route when using substr; map is your friend:

    my @parts = map { substr $str, $_, 3 } 0..length($str)-3;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2020-10-21 19:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (223 votes). Check out past polls.

    Notices?