Re: Choosing grouping of split items
From: John W. Krahn (krahnj_at_acm.org)
Date: 02/16/04
- Next message: Alan Secker: "Re: configure problem"
- Previous message: Guru03: "[MIME] How to attach eMails?"
- In reply to: fishfry: "Choosing grouping of split items"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 16 Feb 2004 11:32:29 GMT
fishfry wrote:
>
> If I have
>
> $text = 'abc - def - ghi - jkl";
>
> then
>
> @tokens = split(/-/, $text, 3);
>
> splits the line into abc, def, ghi - jkl (ignoring leading and trailing
> spaces).
>
> I have an application where there may be 3 or 4 items separated by '-'
> but if there are 4, I want them returned as abc - def, ghi, and jkl.
>
> Is there a one-liner for that?
$ perl -le'
$text = "abc - def - ghi - jkl";
@tokens = $text =~ /(.+)-(.+)-(.+)/;
print for @tokens;
'
abc - def
ghi
jkl
John
-- use Perl; program fulfillment
- Next message: Alan Secker: "Re: configure problem"
- Previous message: Guru03: "[MIME] How to attach eMails?"
- In reply to: fishfry: "Choosing grouping of split items"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|