Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: script outputs nothing/nada

by bluethundr (Pilgrim)
on Jun 06, 2010 at 19:23 UTC ( [id://843354]=note: print w/replies, xml ) Need Help??


in reply to Re: script outputs nothing/nada
in thread script outputs nothing/nada

Hi and thanks for playing! :-)

Ok so it would seem (from the output..or lackthereof) of the debugging statements that the loop isn't even being entered. But _why_?

here's the current state of affairs:

#!/usr/bin/perl # use strict; # # my $workdir = "$ENV{HOME}/txt"; open (BADIPS), "< $workdir/bad_ips" or die "Couldn't open file: $!"; print "Can you hear me now?\n"; while (my $line = <BADIPS>) { chomp $line; print "add ns simpleacl bp-search-spammer DENY -srcIP $line -TTL + 43200"; print "Can you hear me now?\n"; } close BADIPS;
This is what the output looks like:

[bluethundr@lcent5-1:~/perl] $:./bad_ips.pl Can you hear me now?


And I hear what you're saying about the input file (bad_ips) potentially being empty. But I gotta tell ya, it sure doesn't look that way to me! I am able to open the file and here is the output of ls:

[bluethundr@lcent5-1:~/txt] $:ls -l bad_ips -rw-r--r-- 1 bluethundr bluethundr 822 Jun 5 04:24 bad_ips
any thoughts? tx again!

Replies are listed 'Best First'.
Re^3: script outputs nothing/nada
by FunkyMonk (Chancellor) on Jun 06, 2010 at 21:40 UTC
    open (BADIPS), "< $workdir/bad_ips" or die "Couldn't open file: $!";

    If that's the code you're really using (it's different to your OP), try adding use warnings; after use strict;. That usage of open does something you really don't want (hint: it isn't trying to open bad_ips).

    Try:

    open BADIPS, "<", "$workdir/bad_ips" or die "Couldn't open file: $!";

    instead.

    You should also check the contents of bad_ips. It could be full of newlines.

      Hello, I have tried stripping the newlines out of the bad_ips text file with the following command.

      grep -ri s/"\n"// ~/txt/bad_ips


      And made the following changes to the code.
      #!/usr/bin/perl # use strict; use warnings; # # my $workdir = "$ENV{HOME}/txt"; open BADIPS, "<", "$workdir/bad_ips" or die "Couldn't open file: $!"; my $i = 1; while (my $line = <BADIPS>) { chomp $line; print "add ns simpleacl bp-search-spammer$i DENY -srcIP $line -T +TL 43200\n"; $i++; } close BADIPS;<br><br>
      That worked BEAUTIFULLY! Thank you!!!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found