Skip to Content
Perl Debugged
book

Perl Debugged

by Peter Scott, Ed Wright
March 2001
Intermediate to advanced
288 pages
4h 56m
English
Addison-Wesley Professional
Content preview from Perl Debugged

6.4. Saturation Testing

For string inputs, Perl can succinctly generate random strings of a given length:

{
my @visible = grep /[[:print:]]/, map chr, 0..255;
sub randstring { join '', map $visible[rand @visible],
                              1 .. shift }
}

and the entire set of alphabetic strings of a given length:

sub permstring { 'a'x$_[0] .. 'z'x$_[0] }

although the memory required won't make this useful for a length of more than about five.[5] See also the CPAN module String::Random.

[5] You could avoid the memory problem (in version 5.005 or later) by using the expression inside a foreach loop instead of a subroutine, but then you'd get clobbered by the amount of time to go through the loop. The finite nature of the universe has a way of catching up with you.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe
Pro Perl

Pro Perl

Peter Wainwright
Intermediate Perl

Intermediate Perl

Randal L. Schwartz, brian d foy, Tom Phoenix
Perl Testing: A Developer's Notebook

Perl Testing: A Developer's Notebook

Ian Langworth, Chromatic

Publisher Resources

ISBN: 0201700549Purchase book