M
mt35
Hello,
I'm trying to pass a lexical variable down from one subroutine to
another. I have read perlfaq7 on closure (among others) and grasp the
concept for the situation they gave, however I think I'm trying to do
something else entirely. Also I'm only two weeks old in perl so if I'm
going about this in totally the wrong way pointers on the right way to
go are appreciated.
I have an array of an ipfilter log (@fwlog) and a separate array of 10
addresses (@hirate), each of which will have an entry in the ipfilter
log more than 15 times. I want to make an additional array (@hirate1)
of the full log entry foreach address, thus weeding out all entries
that do not correspond to the 10 address array (@hirate).
The original code with no closure performed on it:
foreach (@hirate) {
$y = $_;
foreach (@fwlog) {
push (@hirate1, $_) if ($_ =~ $y);
}
}
Example Variables:
$y = 192.168.1.81
@fwlog = Jan 4 03:01:02 host0 ipmon[51]: 03:01:01.088578 xl0 @0:1 b
192.168.1.81,1047 -> 192.168.1.100,53 PR udp len 20 61 OUT
The original problem I was having was @hirate1 would come out with a
count of approx. 3000 when the original firewall log had a count of
approx 1900.
Here is what I tried:
foreach (@hirate) {
$y = $_;
$q = max($y);
&$q();
sub max {
return sub {
foreach (@fwlog) {
push (@hirate1, $_) if ($_ =~ $y);
}
}
}
}
However, this brings back approx 3000 entires as well? Do I have some
syntax wrong or am I way off point?
Thanks,
-SLM
I'm trying to pass a lexical variable down from one subroutine to
another. I have read perlfaq7 on closure (among others) and grasp the
concept for the situation they gave, however I think I'm trying to do
something else entirely. Also I'm only two weeks old in perl so if I'm
going about this in totally the wrong way pointers on the right way to
go are appreciated.
I have an array of an ipfilter log (@fwlog) and a separate array of 10
addresses (@hirate), each of which will have an entry in the ipfilter
log more than 15 times. I want to make an additional array (@hirate1)
of the full log entry foreach address, thus weeding out all entries
that do not correspond to the 10 address array (@hirate).
The original code with no closure performed on it:
foreach (@hirate) {
$y = $_;
foreach (@fwlog) {
push (@hirate1, $_) if ($_ =~ $y);
}
}
Example Variables:
$y = 192.168.1.81
@fwlog = Jan 4 03:01:02 host0 ipmon[51]: 03:01:01.088578 xl0 @0:1 b
192.168.1.81,1047 -> 192.168.1.100,53 PR udp len 20 61 OUT
The original problem I was having was @hirate1 would come out with a
count of approx. 3000 when the original firewall log had a count of
approx 1900.
Here is what I tried:
foreach (@hirate) {
$y = $_;
$q = max($y);
&$q();
sub max {
return sub {
foreach (@fwlog) {
push (@hirate1, $_) if ($_ =~ $y);
}
}
}
}
However, this brings back approx 3000 entires as well? Do I have some
syntax wrong or am I way off point?
Thanks,
-SLM