Professional Web Applications Themes

Help with deleting hash key? - PERL Beginners

I have been playing with ipblocker from ipblocker.org and modified it to take a list of attackers from an IDS. I wanted to do some error checking to pull out the "already blocked ip's" before sending it to the original script. I can't figure out why the delete $hash{'$x'} won't work in my script. Can someone tell why? 'query.outsidescanners.result': file contains (2 row affected) 1.1.1.1 3.3.3.3 #!/usr/bin/perl -w use diagnostics; use strict; our $dir='/usr/local/apache/ipblocker'; our $file='query.outsidescanners.result'; our nodes=(); our ($line)=0; our %hash=(); open (BLK, "$dir/$file") or die "Cannot open file: $!"; foreach $line(<BLK>){ if ($line =~/.*row.*/i){ }else{ $hash{$line}="new"; }} close(BLK); ...

  1. #1

    Default Help with deleting hash key?

    I have been playing with ipblocker from ipblocker.org and modified it to
    take a list of attackers from an IDS. I wanted to do some error checking
    to pull out the "already blocked ip's" before sending it to the original
    script. I can't figure out why the delete $hash{'$x'} won't work in my
    script. Can someone tell why?

    'query.outsidescanners.result': file contains
    (2 row affected)
    1.1.1.1
    3.3.3.3


    #!/usr/bin/perl -w
    use diagnostics;
    use strict;
    our $dir='/usr/local/apache/ipblocker';
    our $file='query.outsidescanners.result';
    our nodes=();
    our ($line)=0;
    our %hash=();
    open (BLK, "$dir/$file") or die "Cannot open file: $!";
    foreach $line(<BLK>){
    if ($line =~/.*row.*/i){
    }else{
    $hash{$line}="new";
    }}
    close(BLK);
    our $a='3.3.3.3';
    delete ($hash{$a});
    print keys %hash;

    *******The results of print keys %hash
    1.1.1.1
    3.3.3.3


    Thanks,

    Rich





    Arichmond Guest

  2. #2

    Default Re: Help with deleting hash key?

    On Fri, Jul 16, 2004 at 08:46:32AM -0400, arichmond(contr-ird) wrote:
     

    chomp $line;
     

    also, s/our/my/ unless you have a good reason not to.

    --
    Paul Johnson - net
    http://www.pjcj.net
    Paul Guest

  3. #3

    Default RE: Help with deleting hash key?

    Paul Johnson wrote:  
    chomp $line; 

    also, s/our/my/ unless you have a good reason not to.
     

    Thanks, I forgot the simple stuff!
    Arichmond Guest

Similar Threads

  1. deleting a hash ref's contents
    By Gary Stainburn in forum PERL Beginners
    Replies: 15
    Last Post: February 25th, 02:45 PM
  2. Sort a hash based on values in the hash stored as arrays of hashes
    By Tore Aursand in forum PERL Miscellaneous
    Replies: 3
    Last Post: September 16th, 10:14 AM
  3. Another reference question (hash of hash references)
    By Tim Musson in forum PERL Beginners
    Replies: 2
    Last Post: August 8th, 01:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139