From e40fd1529a0f1a6bff445ec9d157c1f1b8109c4f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 20 Oct 2012 05:23:43 -0500 Subject: another solution --- SUBS.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 SUBS.pl diff --git a/SUBS.pl b/SUBS.pl new file mode 100644 index 0000000..1084877 --- /dev/null +++ b/SUBS.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.016; + +chomp(my $string = <>); +chomp(my $substr = <>); +my @positions; + +my $start = 0; +while((my $pos = index($string, $substr, $start)) != -1) { + push @positions, $pos + 1; + $start = $pos + 1; +} + +say join(' ', @positions); -- cgit v1.2.3-54-g00ecf