Click to See Complete Forum and Search --> : Perl string manipulation


spawn968
07-06-2003, 10:07 PM
Alright, here's my problem: I have very limited experience in perl, but I want to learn more. The idea of what I want to do is make a wordfile that includes every letter up to a certain number of letters as a variable. Sort of like this
AAAAAAAAAA
AAAAAAAAAB
AAAAAAAAAC
AAAAAAAAAD
...
AAAAAAAABA
On to ZZZZZZZZZZ. Can anyone help me with code snippets or a proper place to look? (Or even good keywords for google, for that matter. I tried string manipulation +perl, but I got to many results)

iDxMan
07-08-2003, 12:00 AM
....I shouldn't just give it away, but wtf.

for $str ('AAAAAAAAA' .. 'ZZZZZZZZZ') {
print "$str\n";
}


-r

rid3r
07-08-2003, 12:32 AM
[nabis@trinity: perl]$ cat text
AAAAAAAssdfsd
ss333AAAAAAAA
23AAAAAAAAAAA
[nabis@trinity: perl]$ cat replace_a_z
#!/usr/bin/perl
use strict;

my @text=<>;
foreach(@text) {
$_ =~ s/A/Z/g;
print "$_"
}
[nabis@trinity: perl]$ ./replace_a_z text
ZZZZZZZssdfsd
ss333ZZZZZZZZ
23ZZZZZZZZZZZ

There are probably 15 ways to do it (simple regex in this case).

iDxMan
07-08-2003, 09:06 AM
Originally posted by rid3r
$_ =~ s/A/Z/g;

There are probably 15 ways to do it (simple regex in this case).

This just translates all cap A's to Z's instead of generating all possible combinations.

-r

spawn968
07-08-2003, 02:26 PM
Thanks, guys, you've helped me a bunch :D