Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing the values ....

Status
Not open for further replies.

tarn

Technical User
Aug 19, 2001
534
GB
Ok so my head has now become so fuzzy I cant think straight, so I ask my mates to help me out of this hole I'm digging:

The code:
At the top I have this ....

$data_file="passfilelist1.txt";
open( TEST, "$data_file" ) or die;
chomp( %hash = map { split /,/ } <TEST> );
close TEST;
foreach( sort keys %hash ) {
$protect=&quot;\$protect{'$_'}='$hash{$_}'\;\n&quot;;
# print $protect;
}

Now that works fine standalone but this is to replace what was a list of vars defined in the script like this:

$protect{'Admin'}='/home/fred/paswd/.htusers1';
$protect{'Finance1'}='/home/bob/paswd/.htusers1';
$protect{'Telecare'}='/home/jill/paswd/.htusers1';
$protect{'newone'}='/home/jenny/paswd/.htusers2';

I now want to get the values from the external file (passfilelist1.txt) hence the first piece of code above

Later in the script it uses the values of %protect for:
## CREATE SELECT LIST ##
foreach $key (sort_hashs(\%protect)) {
$select .= &quot;<option value=\&quot;$key\&quot;>$key&quot;;
}

But I dont appear to be getting the value from the first piece of code into this next piece !!
Sorry its late and my head is spinning ...... HELP!

L.


 
You should post the [tt]sort_hashs()[/tt] subroutine. This is probably where the problem lies.

jaa
 
Um, actually what is the purpose of this loop?
Code:
foreach( sort keys %hash ) {
    $protect=&quot;\$protect{'$_'}='$hash{$_}'\;\n&quot;;
  # print $protect;
}
This doesn't actually assign anything to %protect.

You should just assign %hash to %protect
Code:
%protect = %hash;
or get rid of %hash entirely and load the data directly into %protect.

jaa
 
Cheers jaa,
Its crazy at work just too noisey to think, I've brought it home to have a look at and will probably rewrite that part, but basically I'm trying to get the two fields on each line (e.g. Admin , /home/fred/paswd/.htusers1) from each line of the (lets call it a control) file into the script to replace what was:
$protect{'Admin'}='/home/fred/paswd/.htusers1';
$protect{'Finance1'}='/home/bob/paswd/.htusers1';
$protect{'Telecare'}='/home/jill/paswd/.htusers1';
$protect{'newone'}='/home/jenny/paswd/.htusers2';

By building the same from the hash

Just got them old Friday blues, and can't think straight.

Thanks for your help, maybe I'll get bored tomorrow night and have another look. Doh!

Here's the sort_hashs anyway:

sub sort_hashs {
my $x = shift;
my %array = %$x;
sort { $array{$b} cmp $array{$a}; } keys %array;
}

Basically I'm hacking the Access Denied version 1.2 script to suit my needs of extensive .htaccess password managment.

cheers again
L.
 
Hey! jaa,

What did I say? 5 minutes out of bed this morning and its fixed, &quot;What A Plonker&quot; am I! You were right:

All I needed to do was change the chomp( %hash = map { split /,/ } <TEST> ); to
chomp( %protect = map { split /,/ } <TEST> );
and the rest:

foreach( sort keys %hash ) {
$protect=&quot;\$protect{'$_'}='$hash{$_}'\;\n&quot;;
# print $protect;
}

...... was dead code.

I must get some ear defenders for work then maybe I can concerntrate.

Thanks again for the pointer, might be back next Friday though :¬}

L.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top