Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by toolic (Bishop)
on Oct 30, 2017 at 14:46 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-25 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found