in reply to Is it possible to get all tetra words with correct starting position using a better code within a loop?
Note that Perl uses 0 for the starting position, not 1. If you really need 1, just output $start + 1.#!/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."; }
|
|---|
| 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 |