Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concat value from array to one string

Status
Not open for further replies.

edwardsal

Technical User
Nov 3, 2006
13

I have array like

@array=("1","2","3");

and how I can make link where I'll have like this:

param1 = (number 1 is $array[0])

$link="param1&param2&param3";

but I dont know how long is array,sometimes is longer?
 
I'm a bit confused about what you want.
Code:
my $link;

for (my $i = 0; $i < @array; $i++ {
   $link .= '&param' . $i + 1 . '=' . $array[$i];
}

print "$link\n";
Alternatively, something as simple as
Code:
print join('&', @array);
might be all that is needed.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
or...
Code:
my ($link,$i);

for(@array){
   $i++;
   $link .= "&param$i=$_";
}

print "$link\n";

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Or:
Code:
my $link = join '&', map "number $_ is " . $array[ $_ - 1], 1 .. @array;
 
lol - [cat2] - that leaves the cat with 5 lives left!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top