need help with my little script...

merlin's picture

They have: 410 posts

Joined: Oct 1999

i'm trying to set a new website up with a template-system. i have two scripts, one taking out the content of a txt-file (read.pl), another one filling it in in my template.html (show.pl).
for every page i have an own txt-file and an own subroutine, opening it.
now: i'd like to have an if-function in show.pl, that opens the right subroutine, when a user clicks on a link. how do i tell the script 'require read.pl, subroutine &band'?
i saw something like
if ($action eq "band") { require "read.pl"; &band; }'
and well, that's not working (of course, i do have to tell the script, what $action is, am i right?)
thank you for any advise

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Well I am supposing that all of the subroutines are contained within "read.pl". So you only have to specify it's requirement once at the top of your script. Then you can use your if statement like this.

if ($action eq "band") {
&band;
} elsif ($action eq "suckyband") {
&suckyband;
} else {
print "Your band must really suck";
}

The script knows that it needs to find the subroutine, and it knows that it is either contained within itself or within one of the required perl files.

Then in your link just make it like this
href="read.pl?$action=band"

alternating the value of the action scalar.

I think that should work.

VulKen
I know it smells in here...because I'm the ****

Pimpin like a pimp with an electrofied pimpin machine!

merlin's picture

They have: 410 posts

Joined: Oct 1999

thanks vulken for your fast answer.
well, it sounds quite ok, but somehow it doesn't work... i suppose it doesn't find the subroutine...

please have a look at:
http://www.greenbreak.ch/htbin/show.pl that's the 'final' site (at about)...
http://www.greenbreak.ch/redesign/show.txt that's the show.pl-file (with your modifications)
http://www.greenbreak.ch/redesign/read.txt that's the read.pl-file
http://www.greenbreak.ch/redesign/temp.html that's the html-template

thanks!

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Why not just copy and paste those subroutines into the show.pl file?

Try that out and see if it works. In reality it should be importing the subroutines from the required file. Make sure that they are chmoded correctly. Put an error routine to evaluate whether it is finding read.pl.

if that fails...include your subroutines in your if statements...ie.

if ($action eq "band") {
  sub band {
  my $file = "band.txt";
  ### Open file ###
  open (FILE, "$file") || die "No such file: $file";
  while (<FILE&gt;) {
$content = "$content$_";
}
close (FILE);
return;
}
1;
} elsif ($action eq "thanks") {
#do the thanks subroutine
} else {
#so on and so forth
}
'
Hope this helps.
Vulken
dookie

Pimpin like a pimp with an electrofied pimpin machine!

merlin's picture

They have: 410 posts

Joined: Oct 1999

yes, i got it...
i 'simply' forgot the

use CGI;

$query = new CGI;
@parname = $query->param;
foreach $n (@parname) {
   $list{$n} = $query->param($n);
}

$action = $list{'action'};
'
part....
now it's working...

thnx vulken

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.