1 2 3 4 5 6 7 8 9 10 11 12 13
open (FILE, "Textdatei"); %hash = <FILE>; close (FILE); ($Vorname, $Nachname) = split/\s+/, $line; $hash{$Vorname} = $Nachname; chomp (%hash); open (OUT, ">neu"); while ( ($Vorname, $Nachname) = each %hash) { print $key => $value\n"; } close OUT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
use strict; use warnings; open my $in, '<', "Textdatei" or die $!; my %hash; while (my $line = <$in>) { chomp $line; my ($Vorname, $Nachname) = split/\s+/, $line; $hash{$Vorname} = $Nachname; } close $in; open my $out, ">", "neu" or die $!; while ( my ($Vorname, $Nachname) = each %hash) { print $out "$Vorname => $Nachname\n"; } close $out;