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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.