Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Do you only need the first username/password or all of them. If you want all of them I would do something like this.
use Data::Dumper; my %ids=map { chomp; #Get rid of the \n (split(/=/))[0,1] } grep( !(/^\s*#/||!/=/), <DATA>); print Data::Dumper->Dump([\%ids]); exit; __DATA__ #user=passwd test=prrft5142 tester=foo #This is a comment foo
The reason why the grep has 2 patterns to match is for some error checking.
The first checks to see if it is a comment. And the second checks to see if it has an = sign in it.You probly want to put a bit more checking there like at least 1 leal character on both sides or something. 8)
Update: added the \s* to the first condition on the grep.
also added a test case for the \s* comment and the
conditiosn where there is no =.
--
Pug

In reply to Re: Better way to read "configuration" files by Pug
in thread Better way to read "configuration" files by LameNerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found