Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: How to use matched strings

by mikeraz (Friar)
on Apr 12, 2011 at 20:26 UTC ( [id://899049]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to use matched strings
in thread How to use matched strings

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

Replies are listed 'Best First'.
Re^4: How to use matched strings
by tophat (Initiate) on Apr 12, 2011 at 23:52 UTC
    Wow, this is amazing. I have to pore over this a bit to understand it, but it uses all the beginner's stuff I should know how to use already. I can't wait to try to localize this concept into my script. Thanks for this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://899049]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-23 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found