Jul 24, 2008 3:59 am
NoahHi there,
I loaded a bunch of configuration lines into a hash called $Input
now I am searching the hash to make sure specific lines are there.
I want to print "NO" unless there is a match to the following ""check
$ip here";
but $ip could be the range as shown below.
so a key like "check 2.2.2.2 here" would be accepted and NO would *not*
be printed and if the hash has a key with "check 2 here" then a NO
*would* be printed.
my $ip = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+";
print CHANGE "NO\n" unless exists $Input{"check $ip here"};
Cheers,
Noah
Jul 24, 2008 4:07 am
YitzleOn Thu, Jul 24, 2008 at 3:59 AM, Noah <admin2@enabled.com> wrote:
>
> Hi there,
>
> I loaded a bunch of configuration lines into a hash called $Input
> now I am searching the hash to make sure specific lines are there.
>
> I want to print "NO" unless there is a match to the following ""check $ip
> here";
>
> but $ip could be the range as shown below.
>
> so a key like "check 2.2.2.2 here" would be accepted and NO would *not* be
> printed and if the hash has a key with "check 2 here" then a NO *would* be
> printed.
>
> my $ip = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+";
> print CHANGE "NO\n" unless exists $Input{"check $ip here"};
>
>
> Cheers,
>
> Noah
> Hi there,
>
> I loaded a bunch of configuration lines into a hash called $Input
> now I am searching the hash to make sure specific lines are there.
>
> I want to print "NO" unless there is a match to the following ""check $ip
> here";
>
> but $ip could be the range as shown below.
>
> so a key like "check 2.2.2.2 here" would be accepted and NO would *not* be
> printed and if the hash has a key with "check 2 here" then a NO *would* be
> printed.
>
> my $ip = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+";
> print CHANGE "NO\n" unless exists $Input{"check $ip here"};
>
>
> Cheers,
>
> Noah
Untested code.
# Always...
use strict;
use warnings;
my %ip = ...;
#Get the lines as an array.
my @lines = keys %ip;
# Slight modification to the regex. Someone else's reply will probably
have a more elegant method.
my $ipSearch = qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/;
# Use variables for filehandles.
open my $CHANGE, "> $changeFile" or die;
print CHANGE "NO\n" unless ( grep ( $ipSearch, @lines ) );
Jul 24, 2008 4:56 am
Noahyitzle wrote
> Untested code.
>
> # Always...
> use strict;
> use warnings;
>
> my %ip = ...;
>
> #Get the lines as an array.
> my @lines = keys %ip;
>
> # Slight modification to the regex. Someone else's reply will probably
> have a more elegant method.
> my $ipSearch = qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/;
>
> # Use variables for filehandles.
> open my $CHANGE, "> $changeFile" or die;
> print CHANGE "NO\n" unless ( grep ( $ipSearch, @lines ) );
>
>
> # Always...
> use strict;
> use warnings;
>
> my %ip = ...;
>
> #Get the lines as an array.
> my @lines = keys %ip;
>
> # Slight modification to the regex. Someone else's reply will probably
> have a more elegant method.
> my $ipSearch = qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/;
>
> # Use variables for filehandles.
> open my $CHANGE, "> $changeFile" or die;
> print CHANGE "NO\n" unless ( grep ( $ipSearch, @lines ) );
>
Hi there,
okay I am trying to figure this out.
when I perform the following:
there is a space at the beginning of each line printed:
print "@lines";
there is no space at the beginning of the line:
for $line (@lines) {
print "$line";
}
Cheers,
Noah
Jul 24, 2008 4:44 am
Noah>> Noah
> > Untested code.
>
> # Always...
> use strict;
> use warnings;
>
> my %ip = ...;
>
> #Get the lines as an array.
> my @lines = keys %ip;
>
> # Slight modification to the regex. Someone else's reply will probably
> have a more elegant method.
> my $ipSearch = qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/;
>
> # Use variables for filehandles.
> open my $CHANGE, "> $changeFile" or die;
> print CHANGE "NO\n" unless ( grep ( $ipSearch, @lines ) );
>
Hi there,
okay I have a strange issue. all the lines as part of "my @lines = keys
%ip;" have a space at the beginning of the line of each key.
cheers,
Noah
Previous Thread: How to convert the date ?
Next Thread: Diamond operator and quoted word?
Related Forum Topics
- Ways to get a mapping of values versus keys in a hash where there is one-to-one mapping between the keys and the values !
- RegExp Searching within
- Query in searching
- Automatic searching
- Searching the array
- A problem of searching through directories
- Searching Hash for contents of Array
- Searching arrays - more optimal code
- Searching a script that use HTTP::Proxy
- Hash keys