pike has asked for the wisdom of the Perl Monks concerning the following question:
here is my problem. I have a string, say 'E/stYna~ko/', and I want to split it into single letters, except '/' and '~' should be grouped with the preceding letter (they never appear at the beginning of the string) I.e. the desired output in the above case is 'E/ s t Y n a~ k o/'. Sounds like a job for split, right? Only that I can't get it to work properly. Here's what I have tried so far:
$x = 'E/stYna~ko'; print join (' ', split /(\w[^\/~])/, $x); #->E/ st Yn a~ ko / print join (' ', split /(\w(?!\/~))/, $x); #-> E / s t Y n a ~ k +o print join (' ', split /([^\/~])/, $x); #-> E / s t Y n a ~ k o print join (' ', split /(?!\/~)/, $x); #->E / s t Y n a ~ k o
Yes, I know I could first split into individual characters and then go through the array and join the '/' and '~' with the preceding characters, but can't split give me the correct solution right away?
Puzzled, pike
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: split this
by davorg (Chancellor) on Nov 06, 2001 at 17:52 UTC | |
by tye (Sage) on Nov 07, 2001 at 04:04 UTC | |
by dmmiller2k (Chaplain) on Nov 06, 2001 at 23:10 UTC | |
|
Re: split this
by Tyke (Pilgrim) on Nov 06, 2001 at 18:02 UTC | |
|
Re: split this
by Elliott (Pilgrim) on Nov 06, 2001 at 17:54 UTC | |
by pike (Monk) on Nov 06, 2001 at 18:04 UTC | |
by Fletch (Bishop) on Nov 06, 2001 at 18:06 UTC | |
by davorg (Chancellor) on Nov 06, 2001 at 18:13 UTC | |
by Fletch (Bishop) on Nov 06, 2001 at 18:31 UTC | |
|
Re: split this
by BrentDax (Hermit) on Nov 07, 2001 at 00:02 UTC |