Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Character Combinations

by esh (Pilgrim)
on Aug 23, 2003 at 06:53 UTC ( [id://286020]=note: print w/replies, xml ) Need Help??


in reply to Character Combinations

if you just want the 3 letter combinations of the 26 lowercase letters in the English alphabet, this is pretty simple and probably very fast:

#!/usr/bin/perl -w use strict; my $size = 3; # number of characters in the target string. my $string = 'a' x $size; my $end = 'z' x $size; do { print $string++, "\n"; } while $string ne $end;

This would also work for uppercase, but as soon as you want to mix cases, add numbers, and add punctuation it falls short as a solution.

The mechanism used here is the automagical increment operator (++) which does cool stuff when applied to a string starting with a letter and consisting of letters and numbers.

Update: If you want to start with 1 character strings and go up to N characters, just change the initialization to:

my $string = 'a';
-- Eric Hammond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found