Home > Archive > PERL Beginners > March 2008 > Re: Concatenating Strings
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Concatenating Strings
|
|
|
|
---- Bobby <cybercruiserz@yahoo.com> wrote:
> Hi all,
>
> I'm trying to write a simple do until loop to print out the value of $strA0 through $striA3. What i'm doing is replacing the value of 0 through 3 in the $strA by joining two strings (my $strB = "strA" . $count;). Right now my script is printing $strB a
s below. How do i get perl to print the value of $strA0 through $strA3 inside of my do until loop? i.e.:
>
> Desired Outcome:
> VarB: A0
> VarB: A1,b,c
> VarB: A 2
> VarB: A3,d,e
>
> Current Outcome:
> VarB:strA0
> VarB:strA1
> VarB:strA2
> VarB:strA3
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $strA0="A0";
> my $strA1="A1,b,c";
> my $strA2="A2";
> my $strA3="A3,d,e";
>
> my $count = 0;
> until ($count == 4){
> my $strB = "strA" . $count;
> print "VarB:$strB\n";
> $count++;
> }#end until loop
>
> Thanks,
>
> Mike
You can either turn them into an array and walk the array with your count
You are setting $strB as the string strA instead of $strA($count) which is where you are getting hosed up.
My perl server is down or I'd play with the code a bit to get it the exact answer, but that should point you in the right direction.
HTH,
Wolf
| |
|
| Wolf,
I still don't understand, so set my $strB = "$strA($count)"; ? That didn't worked.
Wolf <lonewolf@nc.rr.com> wrote:
---- Bobby wrote:
> Hi all,
>
> I'm trying to write a simple do until loop to print out the value of $strA0 through $striA3. What i'm doing is replacing the value of 0 through 3 in the $strA by joining two strings (my $strB = "strA" . $count;). Right now my script is printing $strB a
s below. How do i get perl to print the value of $strA0 through $strA3 inside of my do until loop? i.e.:
>
> Desired Outcome:
> VarB: A0
> VarB: A1,b,c
> VarB: A 2
> VarB: A3,d,e
>
> Current Outcome:
> VarB:strA0
> VarB:strA1
> VarB:strA2
> VarB:strA3
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $strA0="A0";
> my $strA1="A1,b,c";
> my $strA2="A2";
> my $strA3="A3,d,e";
>
> my $count = 0;
> until ($count == 4){
> my $strB = "strA" . $count;
> print "VarB:$strB\n";
> $count++;
> }#end until loop
>
> Thanks,
>
> Mike
You can either turn them into an array and walk the array with your count
You are setting $strB as the string strA instead of $strA($count) which is where you are getting hosed up.
My perl server is down or I'd play with the code a bit to get it the exact answer, but that should point you in the right direction.
HTH,
Wolf
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
| |
| Jenda Krynicky 2008-03-24, 7:05 pm |
| > ---- Bobby wrote:
> Hi all,
>
> I'm trying to write a simple do until loop to print out the value of
> $strA0 through $striA3. What i'm doing is replacing the value of 0
> through 3 in the $strA by joining two strings (my $strB = "strA" .
> $count;). Right now my script is printing $strB as below. How do i get
> perl to print the value of $strA0 through $strA3 inside of my do until
> loop? i.e.:
I think you meant $strA0 through $strA3. And no, you don't want to do
that.
Please read
Why it's stupid to `use a variable as a variable name' - by M-J.
Dominus
http://perl.plover.com/varvarname.html
Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
|
|
|
|
|