X hits on this document

PDF document

Running and Debugging Perl - page 28 / 30

105 views

0 shares

0 downloads

0 comments

28 / 30

Chapter 9

d - delete entry x - delete all entries

EOF; }

sub read { my $keyname = getkey();

if (exists $hash{"$keyname"}) { print "Element '$keyname' has value $hash{$keyname}"; } else { print "Sorry, this element does not exist.\n"}}

sub list {foreach (sort keys(%hash)) {print "$

=> $hash{$ }\n";}}

sub write { my $keyname = getkey(); my $keyval = getval(); if (exists $hash{$keyname})

{print "Sorry, this element already exists.\n"

} else {$hash{$keyname}=$keyval;}}

sub delete { my $keyname = getkey(); if (exists $hash{$keyname}) print "This will delete the

{ entry $keyname.\n";

delete $hash{$keyname};}}

sub clear {undef %hash;}

sub getkey {print "Enter key name of element: "; chomp($

= <STDIN>);)

sub getval {print "Enter value of element: "; chomp($

_

= <STDIN>);}

306

Document info
Document views105
Page views105
Page last viewedThu Jan 19 17:57:34 UTC 2017
Pages30
Paragraphs723
Words10014

Comments