in reply to Extract and print two specific keys and values using %
Like toolic I've replaced your duff quotes with double quotes. Here's a solution using the hash (as that looks to be an area confusing you):
#!/usr/bin/env perl use strict; use warnings; while (<DATA>) { my %aa = (); for my $key (qw/id name/) { ($aa{$key}) = (/$key (\S+)/); print "$key $aa{$key} "; }; print "\n"; } __DATA__ A B C . id "ABS0056"; D; E; F; G; name "SAM"; H; I; J; K; A B C . id "ABS0059"; D; E; F; name "JOE"; G; H; I; J; K; A B C . id "ABS0060"; D; E; F; G; name "MARY"; H; I; J; K; A B C . id "ABS0057"; D; E; F; G; H; name "BILL"; I; J; K; A B C . id "ABS0065"; D; E; name "RONIE"; F; G; H; I; J; K; A B C . id "ABS0061"; D; E; F; G; name "STEPHAN"; H; I; J; K;
Update: removed the g modifier as it isn't necessary here.
|
|---|