in reply to and a simple reg exp poser
1) All lines starting with a particular IP.
2) Assuming "bung"="add" that it's an additive thing, not an overwrite thing.
From your code, the 'g' modifier means match as many times as possibe.my @ip while (<LOG>) { #assuming you are looping through a log file my $log = $_; #making this blatent push(@ip, $log) if $log =~ /^192\.168\.1\.10/;
From mine, '^' is an anchor to the begining of the string.
From your code, '@ip = $log' overwrites the values of $ip[0] each time.
From my code, 'push(@ip, $log)' adds the entire line to the end of the array.
Update: diotalevi's concept of using index instead of a regexp was an excellent suggestion that avoids regex engine overhead, so . . .
Which gives you those that start with the ip in question.push(@ip, $log) if 0 == index($log,'192.168.1.10');
|
|---|