Skip to content

Instantly share code, notes, and snippets.

@rebx
Created August 9, 2013 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebx/6190869 to your computer and use it in GitHub Desktop.
Save rebx/6190869 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl -w
use strict;
use Data::Dumper qw(Dumper);
sub _right_split {
my ( $strstr, $delim, $ary ) = @_;
$ary ||= [];
return $ary unless $strstr;
my $rindex = rindex( $strstr, $delim ) or return $ary;
if ( $rindex == -1 ) {
push @{$ary}, $strstr;
return $ary;
}
push @{$ary}, substr( $strstr, $rindex + 1 );
return _right_split( substr( $strstr, 0, $rindex ), $delim, $ary );
}
print Dumper(_right_split("foo:bar:baz:1972", "\:")) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment