Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
As crazyinsomniac points out you might want to become a bit more familiar with the Perl array and hash data structures. %varname denotes a hash, @varname an array. If you were generating a list of all users or performing some task(s) for more than one user, then using an array or hash would be appropriate. Why store all that data you're not even going to use?

However, if what you are trying to do is to perform some task if a user is in your authentication file, you probably don't need either structure. The following code illustrates this approach:

use strict; use warnings; my $searchfor = "somebody"; my ($login, $pass, $email, $some, $other, $stuff); open PASSWD, "<passwd.ini"; while (<PASSWD>) { if ((split/\|/)[0] eq $searchfor) { chomp; ($login, $pass, $email, $some, $other, $stuff) = split /\|/; last; } print "nomatch: ", (split/\|/)[0], "\n"; } if ($login) { # match was found. 'print' verifies we got the right stuff. print "match found: $login, $pass, $email, $some, $other, $stuff\n" +; # do whatever else . . . }
Contents of file: passwd.ini
nobody|nopass|nobody@home.com|some1|other1|stuff1 anybody|anypass|anybody@home.net|some2|other2|stuff2 somebody|somepass|somebody@home.org|some3|other3|stuff3 everybody|everypass|everybody@home.gov|some4|other4|stuff4
Resulting output:
nomatch: nobody nomatch: anybody match found: somebody, somepass, somebody@home.org, some3, other3, stu +ff3
HTH,

--Jim


In reply to Re: Auth System by jlongino
in thread Auth System by emcb

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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found