On Wed, Jan 07, 2004 at 06:00:51PM +0100, Jan Kesten wrote: > # Datei lesen > open DATEI, "<$dateiname" or die "$dateiname laesst sich nicht oeffnen\n";
Use the $! variable (man perlvar; perldoc perlvar; www.perldoc.com): open DATEI, "<$dateiname" or die "Datei `$dateiname' laesst sich nicht oeffnen: $!\n"; > @zeilen = <DATEI> or die "$dateiname ist nicht lesbar\n" > close DATEI; close DATEI or warn "Cannot close file `$dateiname': $!\n"; > # sortieren You can sort just by reading: @sorted_zeilen = sort <DATEI> or die $!; > - ---- SNIP ---- > > And the python way looks like this: > > # Datei lesen > try: > datei = open(dateiname, 'r') > zeilen = datei.readlines() > datei.close() > except IOError: > print dateiname, "ist nicht lesbar" > sys.exit( 1 ) That's not what is above in perl. I understand especially: you are saying that Python has exceptions. But Perl also has! Read about `eval' in man perlfunc or `perldoc -f eval'. The advantidge of using "die" for each part of code is that you can give more precise error message, even more if combined with the `$!' variable. Above Python code would be almost ekvivalently rewritten into Perl: eval { open DATEI, "<$dateiname" or die $!; @zeilen = <DATEI> or die $!; close DATEI; } die "Datei `$dateiname' ist nicht lesbar: [EMAIL PROTECTED]" if $@; > Some other thing is that python knows about classes :-) But I do not Perl also knows about classes (perldoc -f bless; man perlboot, perltoot, perlobj). > want to start a discussion about pro perl or python :-) Nor want I, but be precise. Best regards Hans Ginzel