Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Is it possible to get all tetra words with correct starting position using a better code within a loop?

by choroba (Canon)
on Nov 22, 2012 at 08:51 UTC ( #1005080=note: print w/ replies, xml ) Need Help??


in reply to Is it possible to get all tetra words with correct starting position using a better code within a loop?

Use substr:

#!/usr/bin/perl use warnings; use strict; use feature 'say'; my $string = 'ABCDEFGH'; my $length = 4; for my $start (0 .. length($string) - $length) { say substr($string, $start, $length), " -> Starting at position $s +tart."; }
Note that Perl uses 0 for the starting position, not 1. If you really need 1, just output $start + 1.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Is it possible to get all tetra words with correct starting position using a better code within a loop?
Select or Download Code
Replies are listed 'Best First'.
Re^2: Is it possible to get all tetra words with correct starting position using a better code within a loop?
by supriyoch_2008 (Scribe) on Dec 03, 2012 at 06:21 UTC

    choroba

    Thank you very much for your prompt reply. I am sorry for late response as I did not have access to internet for quite a few days due to some technical problem.

    Regards,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2015-07-30 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls