![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl: howto print to screen & filehandle | Alalush | Shell Programming and Scripting | 2 | 08-05-2008 01:32 AM |
| Change FileHandle | findandy | High Level Programming | 3 | 07-09-2008 10:02 AM |
| Perl: Getting back reference from s modifier | cooldude | Shell Programming and Scripting | 8 | 03-19-2008 09:49 AM |
| Perl script to scan back lines | gholdbhurg | Shell Programming and Scripting | 3 | 03-18-2008 12:33 PM |
| Opening Perl | perleo | Shell Programming and Scripting | 2 | 08-26-2002 09:41 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I didn't know you were allowed to do stuff like that with file handles. Does it help if you upgrade to File::IO objects instead? They're supposed to make stuff like this doable without resorting to deep voodoo and hoping the symbol table stays sane.
|
|
||||
|
You localized a typeglob named SYSMAN in the loop where you build up
the filehandle array. I am still also used to localizing filehandles like that. But anyway, as current Perl releases allow to use lexically scoped variables as filehandles (see POD for open, or perlopentut) have you tried if using them would make a difference? May I ask why you are using two separate foreach loops in your subs? If you put it in one loop there was also no need for the @sysmanhandles array. Also I would assume that the backslashes that quote the single quotes in your su command are redundant here Quote:
Last edited by buffoonix; 08-11-2008 at 05:15 AM.. |
|
|||||
|
Quote:
Quote:
Quote:
) |
|
|||||
|
Quote:
![]() I got the idea from my own insane musings then found an example on PerlMonks - The Monastery Gates |
|
|||||
|
Interesting news on this:
Once again, I rewrote it (feeling sure it had to be a typo someplace as such a similar function elsewhere was working) and it's now working! The working code: Code:
sub getndstatus {
my %results;
my @nds=@{$_[0]};
my @sysmanhandles;
foreach my $check("EnableND","StartND") {
foreach my $nd(@nds) {
my $sysman="$config{'su'} - $config{'user'} -c \'$config{'sysman'} ${check}Check -m $nd\'";
local *SYSMAN;
open(SYSMAN, "$sysman|");
push(@sysmanhandles, *SYSMAN);
}
}
foreach my $check("EnableND","StartND") {
foreach my $nd(@nds) {
my $sysmanhandle=shift @sysmanhandles;
while(<$sysmanhandle>) {
if (/^<([^>]*)> <([^>]*)> (.*)$/) {
$ip=$1;
$result=$2;
$note=$3;
$results{$nd}{$check}="${result}:${note}";
}
}
close($sysmanhandle);
}
}
%results;
}
I can't actually see any differences in this version but I made a special effort to write it 'blind' - that is, I avoided looking at the old code when I wrote this. |
|
||||
|
Hi Smiling Dragon,
glad you could fix that. Because my eyes got too distracted I copied and pasted your buggy and fixed versions of the second sub and made a diff Code:
$ diff bla? 9c9 < open(SYSMAN, "$sysman|") || return; --- > open(SYSMAN, "$sysman|"); 15c15 < $sysmanhandle=shift @sysmanhandles; --- > my $sysmanhandle=shift @sysmanhandles; 23d22 < close($sysmanhandle); 24a24 > close($sysmanhandle); (though I would assume it to be better style after all if you couldn't reconcile with a die on that condition). However, what I think made the difference was the explicit lexical redeclaration of $sysmanhandle. I also would have advised to set the autoflush before the reading loop by squeezing in a Code:
$|++; Sorry, for ill-advising you on presumed redundancy of quotes. Even if I were right it is always better to be explicit. I just was thinking about a talk I once attended at a Perl conference or workshop held by Mark Jason Dominus (author of Higher Order Perl) where he ranted about cave men dwellers' useless quoting voodoo. He there brought onto my radar the wonderful Deparse module to check what Perl really makes out of your expressions. Have a look at Code:
$ perldoc B::Deparse Quote:
if I remember correctly. If your Perl is that old or even older then you should really consider an update ![]() |
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|