Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: pattern matching problem

by dga (Hermit)
on Jul 22, 2003 at 17:10 UTC ( [id://276822]=note: print w/replies, xml ) Need Help??


in reply to pattern matching problem

Something like this might work.

use strict; use warnings; while(<>) { chop; my($id) = /\\\\.+\\(.+)/; print "$id\n" if($id); }

In the regular expression I use ()'s to group and capture, then because I used ()'s on the my, it puts a list context onto the assignment and so the RE returns a list of the captured values. In this case the first captured element returned is assigned to $id. I then use $id normally to print out the ID if the RE matched. On a non match $id is undef.

I tested with a tiny test case of:

\\domca-prn01\DH4-2139-HP4 \\vlasd \\\dsasd \test\ing

Only the identifier from the first line of the test file is output.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found