How to use split on spaces AND tabs?

G

Guest

The following split command will perform the
split on one or more spaces. How can I perform
the split on one or more spaces AND tabs? Or
for that matter, ANY whitespace? This reads input
from a file, and you can't trust someone's text
editor to enter tabs or spaces!

my @arr = split(/ +/, $_, 2);


-Thanks
 
J

Jürgen Exner

nospam wrote:

Hi nospam
The following split command will perform the
split on one or more spaces.

The first argument to split() is a good old plain regular expression. To
find out more about regular expression please see The Fine Manual: "perldoc
perlre" or for an introduction "perldoc perlretut"
How can I perform
the split on one or more spaces AND tabs?

Just use a character class instead of the single space
/[ \t]+/
Details see The Fine Manual
Or
for that matter, ANY whitespace?

Did you Read The Fine Manual for the features you are using? Just use "\s""
\s Match a whitespace character

[...]
my @arr = split(/ +/, $_, 2);

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top