Blob


1 #!/usr/bin/perl
3 #Write a subroutine named greet that welcomes the person you name by telling them the name of the last person it greeted:
5 use v5.10;
6 use warnings;
7 use strict;
8 use utf8;
10 sub greet {
11 state $lastperson;
12 if (!defined($lastperson)) {
13 print "Hi $_[0]! You are the first one here!\n";
14 } else {
15 print "Hi $_[0]! $lastperson is also here!\n";
16 }
17 $lastperson = $_[0];
18 }
20 greet("Fred");
21 greet("Barney");
23 #This sequence of statements should print:
25 #Hi Fred! You are the first one here!
26 #Hi Barney! Fred is also here!
28 # Modify the previous program to tell each new person the names of all the people it has previously greeted:
30 greet("Fred"):
31 greet("Barney"):
32 greet("Wilma");
33 greet("Betty"):