Help for this page

Select Code to Download


  1. or download this
    (-e) ? doTheWork($_) : warn qq{"$_" doesn't exist!} for @ARGV;
    
  2. or download this
    @ages = (15, 18, 24);
    foreach $age (@ages) {
        print "At age $age you ", ($age >= 21 ? "can" : "can't"), " buy a 
    +beer.\n";
    }
    
  3. or download this
    At age 15 you can't buy a beer.
    At age 18 you can't buy a beer.
    At age 24 you can buy a beer.
    
  4. or download this
    Perl            English
    --------------------------------------------
    ...
    doTheWork($_)           do the work with it
    :                   else
    warn qq{...}            warn that it doesn't exist.
    
  5. or download this
    foreach $name (@all_names) {
        print "The next name is $name\n.";
    }
    
  6. or download this
    foreach (@all_names) {
        print "The next name is $_\n.";
    }
    
  7. or download this
    print "The next name is $_\n" for @all_names;
    
  8. or download this
    @names = qw(Alice Bob Charlie);
    print "$_ is a person.\n" for @names;
    ...
       # You can't buy a beer at age 19
       # You can't buy a beer at age 20
       # Congratulations! You can buy beer now, you're twenty-one!
    
  9. or download this
    Perl            English
    --------------------------------------------
    ...
    :                  else
    warn qq{...}          warn that it doesn't exist
    for @ARGV       for every single command line argument