in reply to File Searching

Just split on each line with spaces-surrounded | as separator. You'll get a list with two elements, the first (element 0) is the IP and the second (element 1) is the text. You can store them in a hash to access it later.
my $entries; while (<DATA>) { chomp; my($ip, $text) = split /\s+\|\s+/; $entries{$ip} = $text; } print $entries{"192.168.0.1"}; # some text __DATA__ 192.168.0.1 | some text 192.168.0.2 | another text
Update: Anno makes it better for anticipating unexpected input. I did solely by the fact of the sample input. I know about \s* and limit in split.

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Replies are listed 'Best First'.
Re^2: File Searching
by Anno (Deacon) on Sep 13, 2007 at 18:22 UTC
    I agree with the split solution. To make it a little more robust, I'd make spaces around "|" optional (instead of requiring at least one on each side), and give split a limit of 2, so that the text can be allowed to contain "|". Thus:
    my($ip, $text) = split /\s*\|\s*/, $_, 2;
    Anno
Re^2: File Searching
by mattwortho (Acolyte) on Sep 13, 2007 at 15:43 UTC
    Thank you very much, that seems to work a lot lot lot faster!!