CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
please help

 



jam
stranger

Feb 12, 2001, 6:03 AM

Post #1 of 3 (171 views)
please help Can't Post

Hi,

I cant understand why this wont work.

key_one:value_one|key_two:value_two ###This is an example of what $rotate_data[0] holds which is taken from a text file


This DOES work..

my @all_image_fields = split (/\|/, $rotate_data[0]);
foreach $i(@all_image_fields)
{
my ($key, $value) = split (/\:/, $i);
$image_files{$key} = $value;
}

$tee = "key_one";
print "$image_files{$tee}\n";


This does NOT work....


somewhere in <PAGE> there is <image src=" tee-key_one ">

####SAME AS BEFORE####
my @all_image_fields = split (/\|/, $rotate_data[0]);
foreach $i(@all_image_fields)
{
my ($key, $value) = split (/\:/, $i);
$image_files{$key} = $value;
}


open (PAGE, "<$page") || &file_open_error("$page", "$routine", $file, $line);#open file

while (<PAGE>)
{

if ($_ =~ /tee-/i) # finds <image src=" tee-key_one ">
{
chomp($_);
$tee = $_; # put $_ into $tee so i dont loose $_
$tee =~ s/.*?tee-//; # now $tee = key_one ">
$tee =~ s/\s.*//; # now $tee = "key_one"
}

######I have checked and $tee is equal to "key_one"
######IT IS THIS NEXT LINE WHICH DOES NOT WORK, IT WILL NOT RECOGNISE $image_files{$tee} but will recognise $image_files{'key_one'}

s/tee-$tee/$image_files{'$tee'}/g; # replace "tee-key_one" with the value of $image_files{'key_one'}

print $_; # prints out the line of <PAGE> to the browser with any amendments

}


IN SHORT why does this work...

s/tee-$tee/$image_files{'key_one'}/g;

and this does not.......

$tee = "key_one";
s/tee-$tee/$image_files{$tee}/g;


sorry if this is a bit confusing and i am sure it can be done with greater ease
but i still cant understand why this wont work.

any help is appreciated

jamie



japhy
Enthusiast

Feb 12, 2001, 10:34 AM

Post #2 of 3 (165 views)
Re: please help [In reply to] Can't Post

The problem is you are doing $hash{'$variable'} which is very different from $hash{$variable}. The first uses the actual 9 character string '$variable' as the hash key. The second uses the value of the variable $variable as the hash key.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


izzy
stranger

Feb 12, 2001, 10:36 AM

Post #3 of 3 (165 views)
Re: please help [In reply to] Can't Post

try using:
s/tee-$tee/$image_files{$tee}/eg;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives