Help for this page

Select Code to Download


  1. or download this
      $name = $user[$idx]  -> {'name'};     # may create a hash
      $name = $user[$idx] ?-> {'name'};     # leaves @user alone
      $name = $person  -> name;             # chokes on undef
      $name = $person ?-> name;             # passes undef on
    
  2. or download this
     
    # If velocity is defined, use it, otherwise don't.
    # Note that just the concatenation arg is guarded,
    ...
    # so a nonexistent 'parent' component would be created.
    
    $c = $d^^ ->{'parent'}->{'name'};
    
  3. or download this
    # these two are equivalent:
    $a = foobar($b^^);
    ...
    
    # this would be safer:
    $a = defined($b)? foobar($b): undef;
    
  4. or download this
    $f = ($g | $h^^ | $i)^^ & $j;
    
  5. or download this
    # these two are equivalent:
    $a =              $b . $c^^;
    $a = defined($c)? $b . $c: undef;
    
  6. or download this
    # these two are equivalent:
    $a =         foo() ?? bar();
    $a = defined(foo())?  bar(): undef;
    
  7. or download this
    $a = "hello $b";       # may trigger a warning
    $a = "hello $b^^";     # does not help
    $a = 'hello ' . $b^^;  # may evaluate to undef
    
  8. or download this
    $a = $b^^++;        # error
    $a = $b++^^ * $c;   # ok
    $a = ++$b^^ * $c;   # ok but pointless