Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: String searching in file

by poj (Abbot)
on Feb 10, 2018 at 07:51 UTC ( #1208881=note: print w/replies, xml ) Need Help??

in reply to Re^2: String searching in file
in thread String searching in file

###This takes counts the keys from the the in the hash previously populate from the file and puts it into scalar

my $oldsize = keys %old;

#Does the compare, and if the count of hash keys from the <$in> and different from the hash keys of @command has increased (i.e. new keys added)

if( keys %old > $oldsize ) # only write if new ips added

## If file is there then read contents into keys and associating a value of blank or () means new line?
## why wouldn't you do @old{<$in>} = undef; , would it be wrong?

  @old{ <$in> } = (); # note: keys have \n

In this case no difference but possibly misleading you to think @old{<$in>} = 1; would assign the value 1 to all the keys from <$in> which is not the case. Try this simple example

#!/usr/bin/perl use strict; use Data::Dumper; my @keys = ('a','b','c'); my %hash=(); @hash{@keys} = 1; print Dumper \%hash; __END__ $VAR1 = { 'c' => undef, 'a' => 1, 'b' => undef };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208881]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2020-09-24 05:52 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (132 votes). Check out past polls.