Help for this page

Select Code to Download


  1. or download this
    if ($img =~ m#.*/(.*)#) {
        $name = $1;
    ...
    else {
        # didn't match!
    }
    
  2. or download this
    use Benchmark;
    
    ...
        'regexp' => sub { my($file) = $img =~ m#.*/(.*)# },
        'substr' => sub { my $file  = substr $img, rindex($img, '/') + 1 }
    });
    
  3. or download this
    Benchmark: timing 1000000 iterations of regexp, substr...
        regexp: 11 secs (11.18 usr  0.00 sys = 11.18 cpu)
        substr:  4 secs ( 5.67 usr  0.00 sys =  5.67 cpu)