Help for this page

Select Code to Download


  1. or download this
    my $s = 'the quick brown fox';
    substr($s, 10, 0) = 'light-';          # result: 'the quick light-brow
    +n fox'
    substr($s, -3, 0) = 'female ';         # result: 'the quick light-brow
    +n female fox'
    substr($s,  0, 0) = 'I saw ';          # result: 'I saw the quick ligh
    +t-brown female fox'
    substr($s, -0, 0) = ' cross the road'; # ' cross the road.I saw the qu
    +ick light brown female fox' :(
    
  2. or download this
    sub insert_end_relative{
        my ($string, $pos, $insert) = @_;
    ...
        ? substr($string, -$pos, 0) = $insert 
            : $string .= $insert;
    }