LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   conting repeated substrings:SED perl (https://www.linuxquestions.org/questions/programming-9/conting-repeated-substrings-sed-perl-248695/)

anirudh 10-29-2004 06:01 AM

conting repeated substrings:SED perl
 
if i have a string say catbatcatbatcatdogebat
the program has to find and count all three letter substrings that are ouccurring more than once
such as
cat- 3
bat- 3
how can i do this with perl
i am a beginner
please help

jovo 10-29-2004 01:01 PM

#! /usr/bin/perl

use strict;

our $InputString=shift;

our %Substring;

while(length($InputString) >= 3) {
$Substring{substr($InputString,0,3)}++;
substr($InputString,0,1)="";
}
for my $key (sort keys %Substring) {
printf "%s %d\n",
$key,$Substring{$key}
if $Substring{$key} > 1;
}


All times are GMT -5. The time now is 04:46 PM.