- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Strings into Arrays
Let's look into a Perl function called split(), which has the following syntax −
Syntax
split [ PATTERN [ , EXPR [ , LIMIT ] ] ]
This function splits a string into an array of strings and returns it. If LIMIT is specified, splits into at most that number of fields. If PATTERN is omitted, splits on whitespace. 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); print "$string[3]\n"; # This will print Roses print "$names[4]\n"; # This will print Michael
Output
This will produce the following result −
Roses Michael
- Related Articles
- Transform Perl Arrays to Strings
- Perl Sequential Number Arrays
- Sorting Arrays in Perl
- Merging Arrays in Perl
- Multiline Strings in Perl
- V-Strings in Perl
- How to compare two strings in Perl?
- How to transform JavaScript arrays using maps?
- How to compare two arrays for equality in Perl?
- Transform nested array into normal array with JavaScript?
- Finding the intersection of arrays of strings - JavaScript
- How to transform JSON text into a JavaScript object?
- How to transform a JavaScript iterator into an array?
- How can I check JavaScript arrays for empty strings?
- How to Convert Perl Compatible Regular Expressions (PCRE) into Lua

Advertisements