Ausnahmenbehandlungen

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

Passwd4.pm
use Carp;

# ...

sub pwinit {
   my $passwd = shift;
   $passwd = "/etc/passwd" unless defined $passwd;
   open(PASSWD, $passwd) ||
      croak "Unable to read from $passwd";
   # ...
}

*Bibliotheksmodule schieben die Schuld gerne auf den Aufrufer und verwenden daher gerne croak aus dem Modul Carp anstatt die.
 
testpasswd4.pl
use Passwd4 qw(getpwent_by_login pwinit);

(my($cmdname) = $0) =~ s{.*/}{};
die "Usage: $cmdname login [passwd]\n"
   if @ARGV == 0 || @ARGV > 2;
my $login = shift;
pwinit(shift) if @ARGV > 0;
my $pwentry = getpwent_by_login($login);
theseus$ testpasswd4.pl root /no/such/file
Unable to read from /no/such/file at testpasswd4.pl line 9
theseus$ 

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 2000 Ingo Melzer, in HTML konvertiert am 10.11.2000