brajesh agrawal wrote:
Hi,
Hello,
My input file (string) has strings as below
asfd1-asfd2-asfd3
asfd2-asfd3-asfd1
asfd1-asfd4-asfd3
(Create a file named string with above lines as a testcase for program)
each line represents a loop, for example for line-1 asfd1 to asfd2 to asfd3
and back to asfd1,
In that sense line-1 and line-2 represent the same loop.
I was writing a program in perl to detect same loops in the file.
Also i am using array of array for this purpose.
This may do what you want:
use warnings;
use strict;
my $total = 0;
my @AoA;
while ( <DATA> ) {
chomp;
push @AoA, [ $., $_ ];
print "$AoA[-1][1]\n";
$total += 1 + $AoA[ -1 ][ 1 ] =~ tr/-//;
for my $entry ( @AoA ) {
if ( $. != $entry->[ 0 ] && 0 <= index "$_-$_", $entry->[ 1 ] ) {
print "$entry->[1] on line $entry->[0] and $_ on line $. are the
same.\n";
last;
}
}
}
print " Total = $total\n";
__DATA__
asfd1-asfd2-asfd3
asfd2-asfd3-asfd1
asfd1-asfd4-asfd3
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/