T
Traveller2003
Hi All ,
I am a bit stuck. I have only recently started using perl and trying
to get to grips with the references , scalar and list contexts. I
realise if I can understand these and spot them than I am on my way to
learning perl.
The following is the script I am using and need help as to what I am
doing wrong or better still a perl way of writing it.
I have defined a Record sturcture and would like to use it through my
whole program. As such I am getting all the details I require into the
record structure "UserInfoRec".
#!/usr/bin/perl -w
##### User Info Structure #######
$UserInfoRec = {
PASSWDINFO => { LOGINNAME => "",
PASSWORD => "",
USERID => "",
USERGRP => "",
RESERVED => "",
WORKINGDIR=> "",
SHELL => "" },
DATABASEINFO => {%DBEnv}
}; # End user record
######################################################################################
# sets up the Var used within program.
######################################################################################
sub setenv {
open(PASSWD,"/etc/passwd") or die "Cannot read passwd file ? ($?)";
$UserInfoRec = () ; # Initialise the Record
while (<PASSWD>) {
chomp;
if (/^root:/) { # Found root entry user entry
@UserInfo = split(/\:/,$_);
$counter=0;
print $UserInfoRec{PASSWDINFO};
==============> My comment <===============
Never enters the while loop. I have a feeling I am looking at the
reference as opposed to what I really want to get. i.e LOGINNAME,
PASSWORD etc. I want to populate the values in the while loop but not
sure how to do it.
==============> End my Comment <===============
while ( ($param ) = each %{$UserInfoRec{PASSWDINFO} } ) {
print "PARAM = $param \n";
$UserInfoRec{PASSWDINFO}{$param}= $UserInfo[$counter];
++$counter;
print "Counter = $counter param = $param \n";
} # While each
} # End if
} # End While
while ( ( $pwinfo ) = each %{$UserInfoRec{PASSWDINFO}} ) {
print "$pwinfo = $UserInfoRec{PASSWDINFO}{$pwinfo} \n";
}
} #=======(End setenv)=======#
TIA.
Traveller2003.
I am a bit stuck. I have only recently started using perl and trying
to get to grips with the references , scalar and list contexts. I
realise if I can understand these and spot them than I am on my way to
learning perl.
The following is the script I am using and need help as to what I am
doing wrong or better still a perl way of writing it.
I have defined a Record sturcture and would like to use it through my
whole program. As such I am getting all the details I require into the
record structure "UserInfoRec".
#!/usr/bin/perl -w
##### User Info Structure #######
$UserInfoRec = {
PASSWDINFO => { LOGINNAME => "",
PASSWORD => "",
USERID => "",
USERGRP => "",
RESERVED => "",
WORKINGDIR=> "",
SHELL => "" },
DATABASEINFO => {%DBEnv}
}; # End user record
######################################################################################
# sets up the Var used within program.
######################################################################################
sub setenv {
open(PASSWD,"/etc/passwd") or die "Cannot read passwd file ? ($?)";
$UserInfoRec = () ; # Initialise the Record
while (<PASSWD>) {
chomp;
if (/^root:/) { # Found root entry user entry
@UserInfo = split(/\:/,$_);
$counter=0;
print $UserInfoRec{PASSWDINFO};
==============> My comment <===============
Never enters the while loop. I have a feeling I am looking at the
reference as opposed to what I really want to get. i.e LOGINNAME,
PASSWORD etc. I want to populate the values in the while loop but not
sure how to do it.
==============> End my Comment <===============
while ( ($param ) = each %{$UserInfoRec{PASSWDINFO} } ) {
print "PARAM = $param \n";
$UserInfoRec{PASSWDINFO}{$param}= $UserInfo[$counter];
++$counter;
print "Counter = $counter param = $param \n";
} # While each
} # End if
} # End While
while ( ( $pwinfo ) = each %{$UserInfoRec{PASSWDINFO}} ) {
print "$pwinfo = $UserInfoRec{PASSWDINFO}{$pwinfo} \n";
}
} #=======(End setenv)=======#
TIA.
Traveller2003.