(-e) ? doTheWork($_) : warn qq{"$_" doesn't exist!} for @ARGV;
####
@ages = (15, 18, 24);
foreach $age (@ages) {
print "At age $age you ", ($age >= 21 ? "can" : "can't"), " buy a beer.\n";
}
##
##
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.
##
##
Perl English
--------------------------------------------
(-e) does (it) exist?
? then
doTheWork($_) do the work with it
: else
warn qq{...} warn that it doesn't exist.
##
##
foreach $name (@all_names) {
print "The next name is $name\n.";
}
##
##
foreach (@all_names) {
print "The next name is $_\n.";
}
##
##
print "The next name is $_\n" for @all_names;
##
##
@names = qw(Alice Bob Charlie);
print "$_ is a person.\n" for @names;
# Prints:
# Alice is a person.
# Bob is a person.
# Charlie is a person.
@fruits = qw(Apple Banana Cherry);
print shift(@fruits), " is a fruit.\n" while @fruits;
# Prints:
# Apple is a fruit.
# Banana is a fruit.
# Cherry is a fruit.
$age = 18;
print "You can't buy a beer at age $age\n." until ++$age >= 21;
print "Congratulations! You can buy beer now, you're twenty-one!\n" if $age == 21;
# Prints:
# 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!
##
##
Perl English
--------------------------------------------
(-e) does (it) exist?
? then
doTheWork($_) do the work with it
: else
warn qq{...} warn that it doesn't exist
for @ARGV for every single command line argument