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 |
#! /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. |