String::Random

String::Random is a Perl module to generate random strings based on a pattern.
Download

String::Random Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Steven Pritchard
  • Publisher web site:
  • http://search.cpan.org/~steve/String-Random-0.22/lib/String/Random.pm

String::Random Tags


String::Random Description

String::Random is a Perl module to generate random strings based on a pattern. String::Random is a Perl module to generate random strings based on a pattern.SYNOPSIS use String::Random; $foo = new String::Random; print $foo->randregex('ddd'); # Prints 3 random digits print $foo->randpattern("..."); # Prints 3 random printable charactersor use String::Random qw(random_regex random_string); print random_regex('ddd'); # Also prints 3 random digits print random_string("..."); # Also prints 3 random printable charactersThis module makes it trivial to generate random strings.As an example, let's say you are writing a script that needs to generate a random password for a user. The relevant code might look something like this: use String::Random; $pass = new String::Random; print "Your password is ", $pass->randpattern("CCcc!ccn"), "n";This would output something like this: Your password is UDwp$tj5If you are more comfortable dealing with regular expressions, the following code would have a similar result: use String::Random; $pass = new String::Random; print "Your password is ", $pass->randregex('{2}{2}.{2}d'), "n";PatternsThe pre-defined patterns (for use with randpattern() and random_pattern()) are as follows: c Any lowercase character C Any uppercase character n Any digit ! A punctuation character |:;"'.?/#,] . Any of the above s A "salt" character b Any binary dataThese can be modified, but if you need a different pattern it is better to create another pattern, possibly using one of the pre-defined as a base. For example, if you wanted a pattern A that contained all upper and lower case letters (), the following would work: $foo = new String::Random; $foo->{'A'} = ;or $foo = new String::Random; $foo->{'A'} = ;The random_string function, described below, has an alternative interface for adding patterns.Requirements:· Perl Requirements: · Perl


String::Random Related Software