Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: String searching in file

by poj (Monsignor)
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 };
poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-09-25 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (196 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!