Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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 };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208881]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2018-07-20 11:00 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (428 votes). Check out past polls.