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:
hello again! can anyone help?

 



Aquilo
journeyman

Jul 11, 2001, 12:26 AM

Post #1 of 3 (874 views)
hello again! can anyone help? Can't Post

It's been months since I did anything with Perl and I knew so little that I can't remember much of it anymore :(

I've tried changing this sub so it will not chop the hole template into a big mess but can't get everything to work together " while & foreach " can anyone show me how to pull this off?? :) thanks!


Code
########################################################## 
sub load_template {
my($filename,$text,%values,$name,$value);
$filename=shift;
$name=shift;
%values=%$name;
$text="";
open(IN,"<$templates/$filename") or error("Cannot open $templates/$filename : Reason $!");

@in = <IN>;

#while(<IN>){
#chomp;
#$text.=$_;
#}

close IN;

#while(($name,$value)=each %{values}) {
#$value=$values{$name};
#$text =~ s/<\%$name\%>/$value/g;
#$text =~ s/<\%qtip\%>/$in{'search'}/g;
#}

foreach $line (((@in)$name,$value)=each %{values}) {

$value=$values{$name};
if($line =~ /\<\%$name\%\>/) { print "$value"; }
elsif($line =~ /\<\%qtip\%\>/) { print "$in{'search'}";
} else { print "$line"; }
}
#return $text;
}
##########################################################




mhx
Enthusiast / Moderator

Jul 11, 2001, 2:09 AM

Post #2 of 3 (872 views)
Re: hello again! can anyone help? [In reply to] Can't Post

A little more detailed information would be quite helpful ;-)

Why is most of the subroutine commented out? Are the comments the original code and is the foreach the new thing you tried to do?

What is the routine supposed to do? How do its input arguments look like? How does the input file look like?

I'm sure not all of this information is required, but at least to me it would be a lot easier to figure out some correct code for your problem.

Currently I can only say that the routine will not work (for several reasons), but I cannot tell you how to fix it the right way, since I don't know what the purpose of the routine should be.

-- Marcus



Aquilo
journeyman

Jul 11, 2001, 3:22 AM

Post #3 of 3 (868 views)
Re: hello again! can anyone help? [In reply to] Can't Post

Hello mhx!

I have changed *some* of the original code but the sub will work with just the while loop.

Why is most of the subroutine commented out? Are the comments the original code and is the foreach the new thing you tried to do?

The commented code is the original code!

The script is "CSV manager" in the archive.

the sub opens a template fill - chop's it and replaces all <%*%> tags and my own with a value in a certain field of a database that corresponds to the number in the tag - the problem is it destroys the HTML formatting of the page and messes every thing up like Javascript & table </td> tags, I've gotten the foreach code to work befor but not the "while" stuff.

I try not to ask for help but I’ve never tried to combine “foreach” with “while” routines.



 
 


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

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