jnarayan81 has asked for the wisdom of the Perl Monks concerning the following question:
I am again here for the Perl wisdom. Following script is miserably slow on big data. I am looking for a SMART/aternative way to achieve the same with speed !!
raaaammmmmaaaaaj -> ra3m4a4j and vice versa
use strict; use warnings; my @char; while (<DATA>) { @char = split //; } comp(\@char); #--------------------- my $com= "r0a3m4a4j0"; my @com = split //, $com; dcomp (\@com); #dcomp sub here sub dcomp { my ($com_ref)=@_; my @com=@$com_ref; my $car; for (my $aa=0; $aa<=$#com; $aa++) { if ($com[$aa]!~ /\D/) { print "$car" x ($com[$aa]);} else {print " +$com[$aa]"; $car = "$com[$aa]";} } print "\n"; } #comp sub here sub comp { my ($char_ref)=@_; my @char=@$char_ref; my $cnt=""; for (my $aa=0; $aa<=$#char; $aa++) { if ($char[$aa+1]) { if ($char[$aa] eq $char[$aa+1]) { $cnt++; } elsif ($cnt) { print "$char[$aa]"."$cnt"; undef $cnt;} else {print "$char[$aa]";} } } print "\n"; } __DATA__ raaaammmmmaaaaaj
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is there any alternative way to speed up ?
by Eily (Monsignor) on Jun 16, 2017 at 14:39 UTC | |
Re: Is there any alternative way to speed up ?
by tybalt89 (Monsignor) on Jun 16, 2017 at 15:18 UTC | |
Re: Is there any alternative way to speed up ?
by karlgoethebier (Abbot) on Jun 16, 2017 at 16:20 UTC | |
by AnomalousMonk (Archbishop) on Jun 16, 2017 at 17:49 UTC | |
by karlgoethebier (Abbot) on Jun 17, 2017 at 07:41 UTC | |
by AnomalousMonk (Archbishop) on Jun 17, 2017 at 14:28 UTC |
Back to
Seekers of Perl Wisdom