in reply to How can I keep the first occurrence from duplicated strings?
You could just reverse the order of the lines in the file...
use strict; use warnings; my @lines = reverse(<DATA>); my %test; foreach (@lines) { my ($name, $number) = split / /; $test{$name} = $number; } print %test; __DATA__ nick 5 nick 10 nick 20 john 78 erik 9 erik 12
This gives the result...
nick5 john78 erik9
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How can I keep the first occurrence from duplicated strings?
by afoken (Chancellor) on Aug 30, 2023 at 07:58 UTC | |
by haukex (Archbishop) on Aug 30, 2023 at 10:54 UTC | |
by Bod (Parson) on Aug 30, 2023 at 11:10 UTC | |
by hippo (Archbishop) on Aug 30, 2023 at 13:15 UTC | |
by eyepopslikeamosquito (Archbishop) on Sep 01, 2023 at 02:06 UTC | |
by marto (Cardinal) on Aug 30, 2023 at 11:16 UTC | |
by eyepopslikeamosquito (Archbishop) on Aug 30, 2023 at 13:48 UTC |