Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: Perl network programming

by jbert (Priest)
on Oct 03, 2007 at 09:27 UTC ( #642349=note: print w/replies, xml ) Need Help??

in reply to Re^2: Perl network programming
in thread Perl network programming

My money's on the config file. Perhaps a permissions problem?

If so, the script could probably benefit from better error detection. If an IP address is required (as it seems to be) the code should validate that it has an IP address early on, and give a more informative error message.

Some tools for chasing down the problem:

  • use 'strace' to see what the script does when it runs. If it fails to open() a config file, you'll see an error code (e.g. EPERM) which tells you why. The output of strace is voluminous, but you can send it to a file and grep it.
  • add some debugging to your script. log the value of the ip address at different stages of the processing.
  • make sure your script is handling errors correctly (a good way is to just 'die' if an unrecoverable problem occurs. e.g:
    my $cfg_file = "/my/config/file"; open(my $fh, "<", $cfg_file) or die "can't read config file [$cfg_file] for reading: $!";
    Note that we putting $! in your error handling gives you the reason why the open failed, which may help you track down the problem.
As others have noted, I'm speculating wildly because we can't see your code. On the other hand, if your script is large it may not be useful to see all of it.

If you can try reducing your script to the minimum amount which reproduces the problem that would be useful. You'll also often find that doing that helps you find the problem yourself.

Good luck.

Replies are listed 'Best First'.
Re^4: Perl network programming
by Viki@Stag (Sexton) on Oct 03, 2007 at 10:37 UTC
    $cfile = $ENV{'OCONFFILE'};
    open( CFILE, $cfile ) || return "FAIL0:No such file: $cfile!\n";

    The code given above is the actual part tht gets the config file path & opens the file for read.

    As u said the code is huge for me to post it. Anyway i got around the issue, it was with setting the global variable OCONFFILE to correct path.

    jbert, thanks once again

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://642349]
and the monks are chillaxin'...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-05-20 18:08 GMT
Find Nodes?
    Voting Booth?