patman has asked for the wisdom of the Perl Monks concerning the following question:

I'm a little new to perl, and I'm trying to figure out how to accomplish this sort of thing: If I have a text string such that
$text = "data - data2 - data3" how can I split it up so that @field[0] = data, @field[1] = data2, @field[2] = data3
I'm sure this is quite easy in perl, I'm just having a little trouble figuring out how to do it. Any help?

Replies are listed 'Best First'.
RE: parsing a line into a list/array
by Anonymous Monk on Jan 11, 2000 at 22:26 UTC
    Do the following:
    @variable = split /<split link>/ <your string>
Re: parsing a line into a list/array
by patman (Initiate) on Jan 10, 2000 at 04:01 UTC
    Of course, immediately after posting that question, I found the 'split' function. Ah, well.
Re: parsing a line into a list/array
by Anonymous Monk on Jan 12, 2000 at 07:34 UTC
    Well, just to offer another way to do it:
    $text =~ /(.*) - (.*) - (.*)/; @field = ($1, $2, $3);
    This is better if the delimiters aren't likely to stay the same forever ...