NAME

Scalar::MultiValue - Create a SCALAR with multiple values.

DESCRIPTION

This module create a SCALAR with multiple values, where this values can be randomic or can change by a defined period.

USAGE

With a period of 2:

my $s = new Scalar::MultiValue( [qw(a b c d)] , 2 ) ;

for(0..8) {
  print "$s\n" ;
}

Output:

a
a
b
b
c
c
d
d

With randomic values:

my $s = new Scalar::MultiValue( [qw(a b c d)] , '*' ) ;

for(0..8) {
  print "$s\n" ;
}

Output:

c
d
c
b
a
d
c
c

NEW (LIST , PERIOD)

The arguments of new are a LIST and the PERIOD (optional):

LIST

Can be a ARRAYREF or a string that will be splited by /\s/, like on qw():

## this is the same
my $s = new Scalar::MultiValue( 'a b c d' ) ;
## of that:
my $s = new Scalar::MultiValue( [qw(a b c d)] ) ;
PERIOD

The PERIOD can be a integer value, that will define how many times a value will be repeated before change to the next value. PERIOD also can be '*', that will change randomically the values.

SETTING THE VALUES

You can use the scalar as a ARRAYREF and set it's values

my $s = new Scalar::MultiValue( 'a b c d' ) ;

Redefining a single value:

$$s[0] = 'A' ;

Redefining all the values:

@$s = qw(w x y z) ;

METHODS

reset()

Reset the internal counter for the PERIOD.

period(VAL)

Return the period or define it when VAL is defined.

EXAMPLE

A common example of use for this module is for multiple colors on a table:

use Scalar::MultiValue ;

my $colors = new Scalar::MultiValue('#CCCCCC #999999') ;

my @users = qw(a b c d) ;

print "<table>\n" ;
foreach my $users_i ( @users ) {
  print "<tr><td bgcolor='$colors'>$users_i</td></tr>\n" ;
}
print "</table>\n" ;

Output:

<table>
<tr><td bgcolor='#CCCCCC'>a</td></tr>
<tr><td bgcolor='#999999'>b</td></tr>
<tr><td bgcolor='#CCCCCC'>c</td></tr>
<tr><td bgcolor='#999999'>d</td></tr>
</table>

SEE ALSO

Scalar::Util.

AUTHOR

Graciliano M. P. <gm@virtuasites.com.br>

I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.