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:
4 # Modify the previous program to tell each new person the names of all the people it has previously greeted:
6 use v5.10;
7 use warnings;
8 use strict;
9 use utf8;
11 sub greet {
12 state @seen;
13 if (@seen) {
14 print "Hi $_[0]! I've seen: @seen\n";
15 } else {
16 print "Hi $_[0]! You are the first one here!\n";
17 }
18 push @seen, $_[0];
19 }
21 greet("Fred");
22 greet("Barney");
23 greet("Wilma");
24 greet("Betty");
26 #This sequence of statements should print:
28 #Hi Fred! You are the first one here!
29 #Hi Barney! I've seen: Fred
30 #Hi Wilma! I've seen: Fred Barney
31 #Hi Betty! I've seen: Fred Barney Wilma