Hi Peeps,

Can you tell me the quickest way to check if a user exists on my *nix box?

I am currently using the following code:
if(defined(getpwnam($username))) { $message = $message.'<p>The Chosen Username Already Exists.</p>'; $found_err = 1; }
Is There a quicker way than this, or is this as good as it gets?


Also, i want to perfom the fastest possible search of a file (sample shown below), to see if it contains the the contents of $username in the the first field (myusername):
Mon Jun 16 01:01:03 2003:myusername:mypassword:my@old.email:111.222.33 +3.444 Mon Jun 16 01:01:04 2003:myusername2:mypassword2:my@old.email:213.111. +231.444
....and would the code for this search be quicker if the file only contained 'myusername', and no other data?
Cheers Peeps.

In reply to Quick User Existance Check? by Anonymous Monk

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.