There is an easier way to get last element on a split operation, save split result to an array and use $array[-1] and this will access last element of the arrays.
Example
$strings=”foo,bar,test”;
my @fields = split(/,/, $strings);
print $fields[-1] ; # the last str in $strings
Leave a Reply
You must be logged in to post a comment.