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