Hi Perl Monks,

Ok full disclosure, I am completely new to scripting. I am essentially trying to recreate Excel's vlookup function. I have a file with a list of names, and I am trying to use these names to match them to their IP addresses on a different file.To be clear, I have 2 files, one with user names and another with user names and IP addresses. The goal is to use a name and return their IP address From what I do understand it's a pattern matching problem but my string will vary depending on the user name. Any ideas how I can structure this script are welcome! Thank you for reading.

Edit: Update

Thank you all. Even writing this response is helping me solve this problem To clarify, I am not using excel files. I mentioned it, because it seemed to be the quickest way to describe what I am trying to do. But I am working with two txt files that are lists. Here is the snippet of code that has been working for me so far, the variable $flag1 is the string I used to generate my list of user names.I added the line iterator and the "xx" so I have a pattern to match if I needed it. Essentially this snippet creates my list of users, or if you will, the first file. I now wish to use this output and match it against my second file of user and IP addresses.

What I can do: match and return values for a known and fixed string pattern (in this case the string "failed for user [],"

What I am having trouble with: using my output in the first file as a pattern for finding results in the second file. Is this a foreach situation? Or perhaps I should do a while loop?

my $linenum2=1; open FORMATLOG, "<$outputfile" or die "Cannot open $outputfile $!\n"; open (REPORT, ">$badreport") or die "Cannot open $badreport $!\n"; my @line =<FORMATLOG>; print "lines that matched $flag1\n;"; for (@line) { if ($_=~ m/failed for user (.*?),/) { print REPORT $linenum2++; print REPORT " :$1xx\n"; } } close FORMATLOG; close REPORT;

In reply to How to use matched strings by tophat

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.