Just read your update. foreach? while? up to you, both could work here. One approach to your query:

#!/usr/bin/perl use strict; use warnings; open my $CUR, "<", "tdat_cur" or die "no tdat_cur"; open my $IPS, "<", "tdat_ips" or die "no tdat_ips"; my @cur = map { chomp ; $_ } <$CUR>; my %ips; foreach ( <$IPS> ) { # if there's a chance of $nam recurring you need to check for it. my ($nam, $ip) = split; $ips{$nam} = $ip; } foreach my $curious_about ( @cur ) { if( defined $ips{$curious_about} ) { print "$curious_about has IP addr $ips{$curious_about}\n"; } else { print "No IP addr information for $curious_about\n"; } }
tdat_cur contains: michael joe renee
tdat_ips contains: rose 10.100.100.12 michael 10.100.100.13 renee 10.100.100.14 nizar 10.100.100.15

As you can see I'm a foreach kinda guy. That data is very simplified and you'll probably need to handle a slightly more complex match and split.


Be Appropriate && Follow Your Curiosity

In reply to Re^3: How to use matched strings by mikeraz
in thread 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.