in reply to A Split Question

Yes, you can definitely use a regular expression in split. In fact, that's what split expects you to give it.

For example, I could say

my $string = "foo , bar"; my @pieces = split /\s*,\s*/, $string;
to split $string on a comma surrounded by optional whitespace.

A regular expression is different than a substitution, though. So I'm not sure exactly what you're trying to do. Could you give a little more context for the particular problem you're working on?

Replies are listed 'Best First'.
RE: Re: A Split Question
by perlcgi (Hermit) on May 18, 2000 at 22:59 UTC
    It's btrott who responded so I know he knows, but does the questioner know about the greedy default behaviour of * and +, and the dangers when used in conjunction with .
    Its just that I spent a long time figuring that one out, and would'nt wish that headache on Xxaxx or anyone else. So, check out p29 of your Camel, unless you know all about regexes, and I'm wasting both your time and mine. :-)