I am reading in a file whose line looks like this:

userid:access_stuff:more_foo...

My script needs to match a string in a variable which happens to be a userid and I need to match the userid in the file...first "word" to that first colon.

example: userid matches userid so bale.

So, basically, the jist is: 1) the following code is my idea (it is paraprhased, because I am not going to actually write the code for opening files, etc here.) 2) I need to figure out the most efficient way to code the idea of: "if line to first colon matches variable".

if($linefraq eq $user) { return; #or otherwise abort from sub } else { #do whatever to the file }

The linefraq variable would hold just the userid "substring" from the line read from the file. Of course, in practice, each line will be read and checked for the userid.

Thank-you for your help!


In reply to Most Efficient Way to match this by jmneedhamco

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.