LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-29-2004, 06:01 AM   #1
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Rep: Reputation: 15
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
 
Old 10-29-2004, 01:01 PM   #2
jovo
LQ Newbie
 
Registered: Jul 2003
Location: Amersfoort Netherlands
Distribution: SuSe 8.1
Posts: 8

Rep: Reputation: 0
#! /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;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on sed and perl needed. cash_05 Programming 7 09-03-2005 04:33 PM
using sed with parentheses in perl beebop Linux - General 2 07-21-2005 10:41 PM
substrings and Sed marri Programming 3 01-21-2005 10:34 AM
SED + perl !!! letmein Linux - General 9 10-07-2003 05:10 PM
perl with sed !!! letmein Linux - General 1 08-18-2003 05:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration