Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Algorithm for "Incrementing" strings

by pme (Monsignor)
on Feb 11, 2015 at 18:27 UTC ( [id://1116369]=note: print w/replies, xml ) Need Help??


in reply to Algorithm for "Incrementing" strings

++ operator can be applied to strings and then skip vowels:
use strict; use warnings; sub consinc { my $str = shift; my %vowels = ( 'a' => 1, 'e' => 1, 'i' => 1, 'o' => 1, 'u' => 1, ); do { $str++; } while (exists $vowels{substr($str, -1 , 1)}); return $str; } my $str = $ARGV[0]; print "$str - " . consinc($str) . "\n";
update

'if' can do:

$str++ if exists $vowels{substr($str, -1 , 1)};

Replies are listed 'Best First'.
Re^2: Algorithm for "Incrementing" strings
by ibm1620 (Hermit) on Feb 11, 2015 at 18:32 UTC
    True, although the more digits $val has, the longer your do loop will have to spin to get past 'XAAAAAAAAAAAA' and up to 'XBBBBBBBBBBBB', won't it?
      If we always skip vowels then we never have vowels in the string. Should we replace vowels in the string in the very beginning?

        Ok, change 'XAAAAAAAAAAAA' to 'WZZZZZZZZZZZZ': perl -E '$a="WZZZZZZZ"; $a++; say $a' => 'XAAAAAAA'

        --MidLifeXis

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found