Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by choroba (Cardinal)
on Nov 22, 2012 at 08:51 UTC ( [id://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 (Monk) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1005080]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2024-04-23 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found