PrePAN

Sign in to PrePAN

String::Incremental Generates incrementable string with your rule

Good

Synopsis

use String::Incremental;

my $str = String::Incremental->new(
    format => 'foo-%2=-%=',
    orders => [
        [0..2],
        'abcd',
    ],
);

# or

use String::Incremental qw( incremental_string );

my $str = incremental_string(
    'foo-%2=-%=',
    [0..2],
    'abcd',
);

print "$str";  # prints 'foo-00-a'

$str++; $str++; $str++;
print "$str";  # prints 'foo-00-d'

$str++;
print "$str";  # prints 'foo-01-a'

$str->set( '22d' );
print "$str";  # prints 'foo-22-d';
$str++;  # dies, cannot ++ any more

Description

This module provides generating "incrementable" string, in accordance with your "format"and "rule".

Main features are as follows:

  • can "increment" with ++
  • supports increase in digit

and very simple sample code:

use String::Incremental qw(incremental_string);
my $str = incremental_string( '%2=', ['a'..'z'] );
$str->set( 'az' );
print "$str";  # prints 'az'
$str++;
print "$str";  # prints 'ba'

Comments

Interesting idea. I think it deserves to be released and I have no comments on the name, seems fine.


Only one thing, you might want to add the extra bits about the custom format and individual counters to the Description. When I first glanced through the description on the first page, I got that "I can show someone on the internet something basic he should know about" feeling, since the example in the description is already supported, $foo="az"; $foo++; # is now "ba".

Then again it made me click.
@torbjorn

Thanks for your advice!

As you say, Description might give misunderstanding. So I've updated that, adding simple code.

And one thing, `$foo = "az"` usage is not implemented at present (just use `$foo->set( "az" )), but I want make it available :)
Um...

perl -e "$foo='az';$foo++;print $foo;"

prints "ba"

The addition of formatting and rules looks very useful.

Please sign up to post a review.