programminglearner
programminglearner

Reputation: 542

Perl Split at Double Hyphen or Alphanumber

I would like to split a string in Perl at the double hyphen "--" or alphanumeric character (a-z/0-9).

Sample inputs are:

98.0 234.2 34.2 first
234.3 -- 3.5 third
 -- -- -- fourth
23.3 5.4 100.00 second

I tried doing my @linesplit = split(/[--\s]+/, $line); but this does not work. I'm having trouble matching a regex to take a group of possible splits.

i'm expecting an output such as:

@linesplit = [23.3 ,5.4 ,100.00 ,second]
@linesplit = [--, -- ,-- ,fourth]

Upvotes: 1

Views: 72

Answers (1)

ikegami
ikegami

Reputation: 385917

You appear to want to split on whitespace.

my @fields = split ' ', $line;

Upvotes: 4

Related Questions