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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |