Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Extract and print two specific keys and values using %

by toolic (Bishop)
on Oct 30, 2017 at 14:46 UTC ( #1202332=note: print w/replies, xml ) Need Help??


in reply to Extract and print two specific keys and values using %

Here is one way to get the output you specify:
use warnings; use strict; while (<DATA>) { if (/(id "\w+";).+(name "\w+";)/) { print "$1 $2\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;

I made a change to your input data: I changed the funky quotes to simple quotes. Read perlre to understand the capturing parentheses and $1 nd $2.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1202332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2022-01-16 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?