[H-GEN] Perl Question
Jason Parker-Burlingham
jasonp at uq.net.au
Tue Nov 12 19:24:50 EST 2002
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
Scott Pullen <spullen at optusnet.com.au> writes:
> #!/usr/bin/perl
Always, always, *always* run with -w; consider using -T, too. You're
not using strictures either, which isn't a good thing.
> open PROXY_PROC, "/opt/iplanet/proxy/extras/proxy/sitemon -u 0 -p 8080 -a
> 165.240.4.30 -t |" or die "Can't open sitemon filehandle";
> $select=IO::Select->new();
>
> # repeat next line for all filehandles to poll
> $select->add(*CPU_DISK);
> $select->add(*NET_INTF);
> $select->add(*PROXY_PROC);
> # Check which file handles have data on them
> while (@ready=$select->can_read(0)) {
> print "ready = ", at ready,"\n";
>
> # look at each handle that has data on it
> foreach $handle ( @ready ){
>
> SWITCH: {
>
> $handle =~ /CPU_DISK/ && do { print "CPU_DISK has data\n\n";
> $handle =~ /NET_INTF/ && do { print "NET_INTF has data\n\n";
> $handle =~ /PROXY_PROC/ && do { print "PROXY_PROC has data\n\n";
Consider testing for plain string equality or simply using C<index>;
regular expressions are overkill for simply testing if a string is the
same as some other string.
> while ($one_line = <PROXY_PROC> && ($PROXY_COUNT <= 3) ) {
> print "proxy one_line = ",$one_line,"\n";
So obviously this is the offending line?
I'm sorry I can't solve your problem by inspection, but I may be able
to come up with a simple test case of my own in half an hour or so.
Stay tuned.
> # Close filehandles
> close CPU_DISK;
> close NET_INTF;
> close PROXY_PROC;
Consider
close FILH
or die "Cannot close FILH: $!\n";
If the process has died or something, you should get some indication
at that point.
Also consider testing for errors after reading---many Perl scripts
never do this.
In summary: I dunno yet. Does the process that PROXY_PROC reads from
run correctly? Does the output of that command return a "1" as the
first line? Have you tried:
#!/usr/bin/perl -w
use strict;
open PROXY_PROC ... # as in your original script
@lines = <PROXY_PROC>
print @lines;
Cheers,
jason
--
||----|---|------------|--|-------|------|-----------|-#---|-|--|------||
| ``It's just a big electric typewriter.'' |
| |
||--|--------|--------------|----|-------------|------|---------|-----|-|
--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'. See http://www.humbug.org.au/
More information about the General
mailing list