Help for this page

Select Code to Download


  1. or download this
    $string = "johnq.smith1"; $string =~ /(\d+$)/ or die "no number"; $1++
    +; print $string, $/; # WRONG
    
  2. or download this
    $string = "johnq.smith1"; $string =~ /(\d+$)/ or die "no number"; matc
    +h($string, 1)++; print $string, $/; 
    sub match : lvalue { my $n = $_[1] || 0; substr $_[0], $-[$n], $+[$n] 
    +- $-[$n]; }
    
  3. or download this
    { package Matched; sub TIEARRAY { bless \my$x, $_[0]; } sub FETCH { my
    + $n = $_[1]; substr $_, $-[$n], $+[$n] - $-[$n]; } sub STORE { my $n 
    += $_[1]; substr($_, $-[$n], $+[$n] - $-[$n]) = $_[2]; } tie @~, Match
    +ed::; } 
    local $\ = $/; $_ = "johnq.smith1"; /(\d+$)/ or die "no number"; $~[1]
    +++; print;