in reply to Unique key identifer?
This yields the following output:use strict; use warnings; my (%plus, %minus); while (<DATA>) { my ($fruit, $sign) = split; if ($sign eq '+') { $plus{$fruit} = 1; } else { $minus{$fruit} = 1; } } print "Positives are : ", (map "$_, ", keys %plus), "\n"; print "Negatives are : ", (map "$_, ", keys %minus), "\n"; __DATA__ apple + cherry - cherry + peach + banana -
As you can see, real code is about 12 lines or so.$ perl plus_minus.pl Positives are : peach, cherry, apple, Negatives are : banana, cherry,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unique key identifer?
by LanX (Saint) on Jun 27, 2014 at 21:44 UTC | |
by Laurent_R (Canon) on Jun 27, 2014 at 23:00 UTC | |
by roboticus (Chancellor) on Jun 28, 2014 at 00:21 UTC | |
by Jim (Curate) on Jun 29, 2014 at 04:06 UTC | |
by Laurent_R (Canon) on Jun 29, 2014 at 15:33 UTC | |
|
Re^2: Unique key identifer?
by lecb (Acolyte) on Jun 28, 2014 at 12:41 UTC | |
by Laurent_R (Canon) on Jun 28, 2014 at 19:10 UTC |