Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: pattern matching problem

by dga (Hermit)
on Jul 22, 2003 at 17:10 UTC ( #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
Node Status?
node history
Node Type: note [id://276822]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-06-15 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (72 votes). Check out past polls.

    Notices?