mcudmore has asked for the wisdom of the Perl Monks concerning the following question:
#!d:\perl\bin\perl.exe sub initials { $ComDir='.\\'; $Inputfile='ProxyFTP'; $Outputfile='ftpreport.txt'; $Permsfile='userperms.txt'; } sub datacollect { open(PERF, "<$ComDir$Permsfile") || die ("died opening source +file $Permsfile") ; # Open the file @plines = <PERF>; chop (@plines); close(PERF); $pmax=scalar (@plines); } sub cleanupline { my($linein) =@_ ; $linein =~ s/[\n\r]//g, $linein; $linein =~ s/^[ \t]+//g,$linein; $linein =~ s/[ \t]+/ /g, $linein; } $ComDir='.\\'; &initials; &datacollect; open(NUREP, ">$Outputfile") || die ("died opening $Outputfile file") ; for($pindex=0; $pindex<$pmax; $pindex++) { # build permissions hash $plines[$pindex]=&cleanupline($plines[$pindex]); ($name,$value) = split/ /, $plines[$pindex],2; $name{$value}=1; } # next 3 lines should print Exists $nam='sapuser'; $val='1.2.3.4'; print "Exists\n" if exists $nam{$val}; # next 3 lines should not print Exists $nam='sapuser'; $val='1.2.3.7'; print "Exists\n" if exists $nam{$val}; close(NUREP);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: creating hash name from variables
by davorg (Chancellor) on Oct 09, 2002 at 15:10 UTC | |
by mcudmore (Initiate) on Oct 09, 2002 at 15:37 UTC | |
by davorg (Chancellor) on Oct 09, 2002 at 15:57 UTC | |
by mcudmore (Initiate) on Oct 09, 2002 at 22:04 UTC |