Advertisement

12.24.2006 at 09:05PM PST, ID: 22102845
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Global symbol (scoping?) problem

Asked by DrKlahn in Perl Programming Language

Tags: , , ,

I've got a short script that downloads a bogons list for iptables blocking.  The script is relatively simple (bottom below).  At execution time, the following error occurs:

  shield:/etc/iptables# perl -Tw testbog.pl
  Global symbol "$blist" requires explicit package name at testbog.pl line 59.
  Execution of testbog.pl aborted due to compilation errors.

I believe this is a variable scoping problem.  I have tried several variations on the offending print statement without success.  I have no doubt the solution is simple and staring me in the face, but I can't see it.


use strict;
use LWP::UserAgent;

# Define the shell file name
my $filenam = '/tmp/bogonlist.sh';
# Location of bogon list in CIDR format
my $boglist = 'http://www.completewhois.com/bogons/data/bogons-cidr-all.txt';
# Number of retrieval attempts
my $rvtries = 2;

print("Update iptables bogon blocking\n");

while ($rvtries > 0) {

  print("Retrieve the bogon list\n");

  # Create an LWP user agent object
  my $ua = LWP::UserAgent->new;
  $ua->agent("Bogon block list retriever");

  # Create and submit an HTTP request for the document
  my $req = HTTP::Request->new(GET => $boglist);
  my $res = $ua->request($req);

  print("Status: ".$res->message."\n");

  # Store the list and exit the while loop if successful
  if ($res->is_success) {
    my $blist = $res->content;
    last;
  }

  # Count down retries and exit if exhausted
  print("Unable to retrieve the bogon list\n");
  $rvtries = $rvtries - 1;
  if ($rvtries == 0) {
    print("Retries exhausted - update failed\n");
    exit(1);
  }
}

print ("Retrieved the bogon list\n");
print("Create and open the block script file\n");

# Open the file for write
my $f1flag = open(F,"> $filenam");

# Exit if an error occurred
if (!($f1flag)) {
  print("Unable to create the block script file\n");
  print("Status: $f1flag\n");
  exit(1);
}

print("Created and opened the block script file\n");
print("Write the block script file\n");

# Write the file
$f1flag = print F $blist;                        <--- problem occurs here

# Exit if an error occurred
if (!($f1flag)) {
  print("Unable to write the block script file\n");
  print("Status: $f1flag\n");
  exit(1);
}

print("Wrote the block script file\n");
print ("Close the block script file\n");

# Close the file
$f1flag = close F;

if (!($f1flag)) {
  print("Unable to close the block script file\n");
  print("Status: $f1flag\n");
  exit(1);
}

print("Closed the block list file\n");

Start Free Trial
 
Loading Advertisement...
 
[+][-]12.24.2006 at 09:17PM PST, ID: 18195457

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: global, explicit, package, symbol
Sign Up Now!
Solution Provided By: mjcoyne
Participating Experts: 2
Solution Grade: A
 
 
[+][-]12.24.2006 at 09:19PM PST, ID: 18195460

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.24.2006 at 09:22PM PST, ID: 18195465

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32