Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: string manipulation

by meraxes (Friar)
on Jan 12, 2009 at 23:44 UTC ( #735837=note: print w/ replies, xml ) Need Help??

in reply to Re^2: string manipulation
in thread string manipulation

Fair enough. :) I'll see your improvement and raise you this:

use strict; use warnings; my @testStrings = qw{ abc. bnnn. this.that. }; foreach my $testString ( @testStrings ) { my @parts = split m{\.}, (scalar reverse $testString), 5; my $rest = scalar reverse $parts[4]; my $digits = join q{.}, map{ scalar reverse $_ } reverse @parts[0..3]; print qq{$rest -- $digits\n}; }

If the digits could also be > 10, yours will reverse them (like the this.that in this example is 12, yours would print 21).


Comment on Re^3: string manipulation
Download Code
Re^4: string manipulation
by johngg (Abbot) on Jan 13, 2009 at 10:37 UTC

    Good catch with the reversed digits. I'm peeved with myself because I've done a similar thing before and should have remembered. Corrected code.

    use strict; use warnings; my @testStrings = qw{ abc. bnnn. this.that. }; foreach my $testString ( @testStrings ) { my( $rest, $digits ) = map { scalar reverse( $_->[ 4 ] ), join q{.}, reverse map { $_ = reverse } @$_[ 0 .. 3 ] } map { [ split m{\.}, $_, 5 ] } scalar reverse $testString; print qq{$rest -- $digits\n}; }

    And output.

    abc -- bnnn -- this.that -- --



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-05-25 15:00 GMT
Find Nodes?
    Voting Booth?

    In my home, the TV remote control is ...

    Results (485 votes), past polls