Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Perl to concatenate array elements between two indexes?

Tags:

perl

I have an array of strings: @array

I want to concatenate all strings beginning with array index $i to $j. How can I do this?

like image 983
Rohit Banga Avatar asked Mar 13 '10 06:03

Rohit Banga


People also ask

How do you concatenate elements in an array?

The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.

How do I join an array element in Perl?

Perl Array join() FunctionThe Perl programming language join() function is used to connect all the elements of a specific list or array into a single string using a specified joining expression. The list is concatenated into one string with the specified joining element contained between each item.

How do I concatenate in Perl?

Perl strings are concatenated with a Dot(.) symbol. The Dot(.) sign is used instead of (+) sign in Perl.

How do I append one array to another in Perl?

Use the array push() function to add an element to an array.


1 Answers

$newstring = join('', @array[$i..$j])
like image 105
xiechao Avatar answered Nov 15 '22 17:11

xiechao