Oh, hey, didn't see this response. Ignore mine. This is better. :) I
really need to start using substr(). One question, though. Are there any
caveats or down sides to using it?
-----Original Message-----
From: John W. Krahn
To: [EMAIL PROTECTED]
Sent: 3/22/02 12:46 PM
Subject: Re: string question
Pedro A Reche Gallardo wrote:
>
> Hi All,
Hello,
> I was trying to generate variations of the 8 character string
> "AAAAAAAA" by changing every character with the elements containing in
> an array @aa = ('A', 'B', 'C', 'D'). The way I did it was quite naive,
> using a "for" loop that changes the A character at position 1 of the
> AAAAAAAA string by all the characters in the @array, and repeating
> the for loop to change the remaining positions. Thus, I have 8 for
> loops in my code, and wonder how I can achieve the same whithout
having
> to write 8 times the for loop. The actual code I am using is
attached
> bellow. Any suggestion will be welcomed, and thanks in advance for the
> help.
>
> #!/usr/sbin/perl -w
> use strict;
> my @aa =
>
('A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V'
,'W','Y');
>
> my $i;
> my $l;
> $l = @aa;
> $l = $l -1;
>
> for ($i= 0; $i <= $l; $i++) {
> printf "%3s %8s\n", "p1$aa[$i]", "$aa[$i]AAAAAAA";
> }
>
> for ($i= 1; $i <= $l; $i++) {
> printf "%3s %8s\n", "p2$aa[$i]", "A$aa[$i]AAAAAA";
>
> }
>
> for ($i= 1; $i <= $l; $i++) {
> printf "%3s %8s\n", "p3$aa[$i]", "AA$aa[$i]AAAAA";
> }
>
> for ($i= 1; $i <= $l; $i++) {
> printf "%3s %8s\n", "p4$aa[$i]", "AAA$aa[$i]AAAA";
> }
> #
> for ($i= 1; $i <= $l; $i++) {
> printf "%3s %8s\n", "p5$aa[$i]", "AAAA$aa[$i]AAA";
> }
>
> for ($i= 1; $i <= $l; $i++) {
> printf "%3s %8s\n", "p6$aa[$i]", "AAAAA$aa[$i]AA";
> }
>
> for ($i= 1; $i <= $l; $i++) {
> printf "%3s %8s\n", "p7$aa[$i]", "AAAAAA$aa[$i]A";
> }
>
> for ($i= 1; $i <= $l; $i++) {
> printf "%3s %8s\n", "p8$aa[$i]", "AAAAAAA$aa[$i]";
> }
#!/usr/sbin/perl -w
use strict;
my @aa = ( 'A','C'..'I','K'..'N','P'..'W','Y' );
my $word = 'AAAAAAAA';
for my $pos ( 0 .. length($word)-1 ) {
for my $letter ( @aa ) {
substr $word, $pos, 1, $letter;
printf "%3s %8s\n", "p8$letter", $word;
}
substr $word, $pos, 1, 'A';
}
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------------------
This email may contain confidential and privileged
material for the sole use of the intended recipient.
If you are not the intended recipient, please contact
the sender and delete all copies.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]