Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Is there any alternative way to speed up ?

by karlgoethebier (Abbot)
on Jun 16, 2017 at 16:20 UTC ( [id://1192959]=note: print w/replies, xml ) Need Help??


in reply to Is there any alternative way to speed up ?

Good formatting is half the job:

#!/usr/bin/env perl use strict; use warnings; my @char; while (<DATA>) { @char = split //; } comp( \@char ); my $com = "r0a3m4a4j0"; my @com = split //, $com; dcomp( \@com ); 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"; } 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

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Furthermore I consider that Donald Trump must be impeached as soon as possible

Replies are listed 'Best First'.
Re^2: Is there any alternative way to speed up ?
by AnomalousMonk (Archbishop) on Jun 16, 2017 at 17:49 UTC

    An unambiguous specification helps a bit, too: "raaaammmmmaaaaaj -> ra3m4a4j and vice versa" explicit in the OP text,  my $com= "r0a3m4a4j0"; implicit in the code. :)


    Give a man a fish:  <%-{-{-{-<

      "An unambiguous specification helps a bit, too..."

      Definitely. But I had another basic theme. If you know what a basic theme is ;-)

      Reading well formatted code is a bit similar to reading a well typesetted book or score: It's a pleasure.

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      Furthermore I consider that Donald Trump must be impeached as soon as possible

        Reading well formatted code is a bit similar to reading a well typesetted book or score ...

        Yea and amen, brother, yea and amen!


        Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1192959]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found