in reply to splitting headache

To use split, you can reverse the string with the names, only split enough times (6) so that the last string contains the '.', reverse the order of the elements in the foreach loop, then (un)reverse the string when you print it.

my @names = split(/\./, reverse("Pugh.Pugh.Barney.McGrew.Cuthbert.Dibb +le.Grub"), 6); foreach(reverse(@names)) {print reverse . "\n";} __RESULT__ Pugh.Pugh Barney McGrew Cuthbert Dibble Grub

Rich36
There's more than one way to screw it up...

Replies are listed 'Best First'.
Re: Re: splitting headache
by Wibble (Beadle) on Feb 26, 2002 at 14:43 UTC
    Thanks for the reply. I guess I should have explained that my "Pugh.Pugh.Barney.McGrew.Cuthbert.Dibble.Grub" string was just an example of a typical string that might occur. The 'word.groupings' could actually come anywhere, not just at the start, so this method won't work for me too. Thanks again though.