Help for this page

Select Code to Download


  1. or download this
    $a =~ $b
    
  2. or download this
    $a =~ m/$b/;
    
  3. or download this
    $p = '4+5*6';   $str =~ m/$p/;   # Doesn't perform arithmetic.
    $p = 'm/a/';    $str =~ m/$p/;   # Doesn't search for `a`.
    $p = 's/a/b/';  $str =~ m/$p/;   # Doesn't perform a substitution.
    
  4. or download this
    $p = '4+5*6';   $str =~ $p;      # Doesn't perform arithmetic.
    $p = 'm/a/';    $str =~ $p;      # Doesn't search for `a`.
    $p = 's/a/b/';  $str =~ $p;      # Doesn't perform a substitution.
    
  5. or download this
    $p = '4+5*6';   $re = qr/$p/;  $str =~ m/$re/;   # Still doesn't.
    $p = 'm/a/';    $re = qr/$p/;  $str =~ m/$re/;   # Still doesn't.
    $p = 's/a/b/';  $re = qr/$p/;  $str =~ m/$re/;   # Still doesn't.
    
  6. or download this
    $p = '4+5*6';   $re = qr/$p/;  $str =~ $re;      # Still doesn't.
    $p = 'm/a/';    $re = qr/$p/;  $str =~ $re;      # Still doesn't.
    $p = 's/a/b/';  $re = qr/$p/;  $str =~ $re;      # Still doesn't.
    
  7. or download this
    my $pat = 'a';
    
    ...
    $str =~ m/$pat/   # No need to compile in advance.
    $str =~ /$pat/    # Same
    $str =~ $pat      # Same
    
  8. or download this
    my $pat  = 'a';
    my $repl = 'b';
    ...
    $str =~ s/$re/$repl/    # Performs a substitution.
    
    $str =~ s/$pat/$repl/   # No need to compile in advance.