in reply to Regex matching part of one hash key to another

It would help a lot if we could see some sample input - doesn't have to be the real thing, just the real structure. Meanwhile, just for the heck of it, here's a bit of cleanup for your code. I got queasy looking at all those hard 'or's and square brackets. :)

#!/usr/bin/perl -w use strict; my %oui; open my $list1, "oui.txt" or die "oui.txt: $!\n"; while (<$list1>){ if (/^(.*?) {5}\(base 16\)\t\t(.*)$/) { $oui{$1} = $2; } } close $list1; while (<>){ if (/((?:\d+\.){3}\d+).*([\w.]{14})/i){ (my $temp = $2) =~ tr/.//d; print "$1 mapped to $temp for company ", $oui{substr $temp, 0, + 6}, "\n"; } }
-- 
Education is not the filling of a pail, but the lighting of a fire.
 -- W. B. Yeats

Replies are listed 'Best First'.
Re^2: Regex matching part of one hash key to another
by KevinNC (Initiate) on Jan 07, 2011 at 15:34 UTC

    Sorry for the double post :s

    Here is a sample of the data im trying to search on. The IPs and MACs were changed from what the actual data to be able to continue working here. I have been at perl for approximately 1 month off and on and haven't written any programs since school 18 years ago so I know my code is quite rough around the edges. I used the Learning Perl "Llama" book from O'Reilly and most of this is taken from the examples and adapted to this program. This is something I learned to help with an inventory project and I hope to get better and find more uses for perl as I am hooked on its power, I know Ineed to learn much much more than I already do and I'm hoping I didn't bite off more than I can chew with this project. Thanks for the replies :)

    Internet 10.10.10.1 - 000b.462d.2846 ARPA FastEthernet0

    Internet 10.10.10.2 1 0013.2004.acde ARPA FastEthernet0

    Internet 10.10.10.3 7 0800.4ec8.94ac ARPA FastEthernet0

Re^2: Regex matching part of one hash key to another
by KevinNC (Initiate) on Jan 07, 2011 at 16:05 UTC

    I get the same output when running this, it matches only one of the iterations then just blanks afterwards. I'm starting to see the code within the compactness, much more effecient than what I blew up :). I'm wondering if somehow the substr is changing the key and causing the iterations to fail? Again, I'm very very new to this. Thanks!

    OUTPUT

    10.10.10.1 mapped to 000b462d2846 for company

    10.10.10.2 mapped to 00132004acde for company Intel Corporate

    10.10.10.3 mapped to 08004ec894ac for company

    INPUT

    Internet 10.10.10.1 - 000b.462d.2846 ARPA FastEthernet0

    Internet 10.10.10.2 1 0013.2004.acde ARPA FastEthernet0

    Internet 10.10.10.3 7 0800.4ec8.94ac ARPA FastEthernet0