Here is the sample code:
my $test = "Mike Xavier Smith/123-45-1111/student";
my $name = substr( $test, 0, index($test, "/") );
my $ssn = substr( $test,index($test,"/"));
my $type = substr( $test,index($test, "/", 2) );
print "$name, $ssn, $type \n";
exit;
Output:
Mike Xavier Smith, /123-45-1111/student, /123-45-1111/student
This line substr( $test,index($test, “/”, 2) ); #offset should be from second occurrence of “/” which means it should print /student.
But why it is printing from first occurrence of “/”?
That’s not what the third argument of
indexis at all.Most people would just use
split.