I read in some values from a file containing 2 peices of data to create a hash.
I am having trouble trying to create a dynamic reference to this hash based on scalars in the script. I suspect my interpolation is to blame. I have tried a variety of protections etc using \ and so on.
Any help around?
sample values file
sapuser 1.2.3.4
sapuser 1.2.3.6
eof
#!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);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.