
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Transform Perl Arrays to Strings
We can use the join() function in Perl to rejoin the array elements and form one long scalar string. This function has the following syntax −
Syntax
join EXPR, LIST
This function joins the separate strings of LIST into a single string with fields separated by the value of EXPR and returns the string. Following is the example −
Example
#!/usr/bin/perl # define Strings $var_string = "Rain-Drops-On-Roses-And-Whiskers-On-Kittens"; $var_names = "Larry,David,Roger,Ken,Michael,Tom"; # transform above strings into arrays. @string = split('-', $var_string); @names = split(',', $var_names); $string1 = join( '-', @string ); $string2 = join( ',', @names ); print "$string1\n"; print "$string2\n";
Output
This will produce the following result −
Rain-Drops-On-Roses-And-Whiskers-On-Kittens Larry,David,Roger,Ken,Michael,Tom
- Related Questions & Answers
- Transform Perl Strings into Arrays
- Sorting Arrays in Perl
- Merging Arrays in Perl
- Perl Sequential Number Arrays
- Multiline Strings in Perl
- V-Strings in Perl
- How to transform JavaScript arrays using maps?
- Finding the intersection of arrays of strings - JavaScript
- How can I check JavaScript arrays for empty strings?
- Why to Learn Perl?
- Difference between Laplace Transform and Fourier Transform
- Relation between Laplace Transform and Fourier Transform
- Difference between Z-Transform and Laplace Transform
- How to run Perl Program?
- References to Functions in Perl
Advertisements