You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
443 B
Perl

#!usr/bin/perl
use warnings;
use strict;
my $string = "This is a test. Testing script is for test";
print $string, "\n";
my $foundAt = 0;
my $offset = 0;
my $label = 1;
my %positions;
while ( ( $foundAt = index( $string, 'test', $offset ) ) > -1 ) {
$positions{ $foundAt } = $label++;
$offset = $foundAt + 1;
}
foreach ( 0 .. length( $string ) - 1 ) {
print $positions{ $_ } ? $positions{ $_ } : " ";
}