==== Образец задания к уроку 2 ==== #!/usr/bin/perl %account = qw( vova 123 vasya 456 admin admin ); $account{'guest'} =''; open (VISITLIST, 'visit.txt') || die "cannot open file visit.txt ",$!; foreach $i (sort keys(%account)) { chomp($visit{$i} = ); }; close(VISITLIST); open (DATELIST, 'date.txt') || die "can't open file date.txt ", $!; foreach $i (sort keys(%account)) { chomp($date{$i} = ); }; close(DATELIST); system "clear"; print "\n Hi! Anytime you can type 'exit' to escape!"; print "\nLogin:"; chomp ($login = ); if ($login eq 'help') { help(); exit }; unless ( exists($account{$login}) ) { print "\nSorry, no such login\n"; exit; }; do { print "\Password:"; chomp ($password = ); if ( $password eq 'exit' ) { print "\n Ok. You may exit"; exit; }; } while ( $account{$login} ne $password ); # increase number of visit counter $visit{$login}++; open(VISITLIST, '>visit.txt') || die "I can't write in file visit.txt! $!"; foreach $i (sort keys(%account)) { print VISITLIST "$visit{$i}\n"; }; close(VISITLIST); # set current date $date{$login} = time(); open(DATELIST, '>date.txt') || die "I can't wirte in file visit.txt! $!"; foreach $i (sort keys(%account)) { print DATELIST "$date{$i}\n"; }; close(DATELIST); ######################################## ######################################## system("clear"); print "\nYou're in system now."; do { print "\nType about, list, date, visit (to show date of last visit or numbers of visits).". "\nType exit to escape:"; chomp ($i = ); if ( $i eq 'list' ) { help(); } elsif ( $i eq 'visit' ) { visit(); } elsif ( $i eq 'date' ) { visit_date(); } elsif ( $i eq 'exit' ) { print "\nGoodbay!\n"; exit; } elsif ( $i eq 'about' ) { about()}; } while (1); ######################################### # S U B s ######################################### sub help { my($login, $password); system("clear"); print "\nALL logins:"; while( ($login, $password) = each(%account) ) { print "\n$login\t$password"; }; }; sub visit { my($login, $number, $i); my @sorted_logins = sort by_visited keys (%visit); system("clear"); print "\nSorted by visits"; foreach $i (@sorted_logins) { print "\n $i\t$visit{$i}"; }; }; sub by_visited { ($visit{$a} <=> $visit{$b}) || ($a cmp $b); }; sub visit_date { my($i); my @sorted_logins = sort by_time keys (%date); system("clear"); print "\nSorted by time of visits"; foreach $i (@sorted_logins) { print "\n $i\t".localtime($date{$i}); }; }; sub by_time { ($date{$a} <=> $date{$b}) || ($a cmp $b); }; sub about { system("clear"); print <