in reply to backward split
#!/usr/bin/perl -w use strict; my $string = "foo.bar.foobar"; my @array = rev_split($string, '.', 2); print "$_\n" foreach (@array); sub rev_split { return 0 unless (@_ > 1); my ($string , $split , $quantity) = @_; $string = reverse($string); $split =~ /^(.)/; $split = quotemeta $split; my @things = $quantity ? split /$split/ , $string , $quantity : spl +it /$split/ , $string; $_ = reverse($_) foreach(@things); return @things; }
Cheers - L~R
Update: I misread and assumed the split should be done first, not the reverse and I have modified code to work as desired.
Update 2: I realized this isn't as a general solution as I thought since it will only work if the split criteria is a single character. I would be interested in someone coming up with an all purpose reverse split.
|
|---|