Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: capture optional text

by tybalt89 (Deacon)
on May 17, 2017 at 22:12 UTC ( #1190509=note: print w/replies, xml ) Need Help??


in reply to capture optional text

#!/usr/bin/perl # http://perlmonks.org/?node_id=1190504 use strict; use warnings; use Data::Dumper; my %hosts = map /(\S+)\s+#*(.*)/, <DATA>; print Dumper \%hosts; __DATA__ XYZ1ADAIQ1 #AMI XYZ1ADECQ1 #OAG XYZ1ADEDQ1 XYZ1ADEDQ2 ##DMS Host

Replies are listed 'Best First'.
Re^2: capture optional text
by Lotus1 (Curate) on May 18, 2017 at 14:40 UTC

    I like the idea of the zero or more match, (.*), inside the capture to make it match even if the comment isn't there. Thanks.

      It will also match "malformed" comments without a leading #.

        I read it that the #'s are optional, so it's not really "malformed", although no test case for this was provided :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190509]
help
Chatterbox?
LanX "I put lipstick on a pig,"
[erix]: it does seem to get out of hand -- but then again, it looks like that for months already :)
[LanX]: the bets are rather who will leave office first Trump or May
[erix]: Harakiri with a nuke on the white house, that'd clean up the staff there a bit too ;)

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2017-08-18 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (302 votes). Check out past polls.

    Notices?