please i need some help here: i am suppose to translate this text!
i will take it step by step.
this is the text:
when the first "if" starts the command is &js; ...what does this mean in this language...and the other if has &generate;
#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$q= new CGI;
$action = $q->param('action');
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;
$yearnow = $year-100;
$yearnow = 2000 + $yearnow;
$mon=$mon+1;
$curdate = "$yearnow\-0$mon";
if($action eq "js"){
&js;
}
elsif($action eq "generate"){
&generate;
}
else{&list;}
############
sub list{
############
print $q->header;
print qq~<ul>~;
opendir(DIR, "$curdate")|| die("Can't read $curdate");
@dirlist = readdir(DIR);
closedir(DIR);
$curtime = time;
$curtime = $curtime - 86400;
foreach $diritem(@dirlist){
next if($diritem eq "." || $diritem eq ".." || -d $diritem);
($filesize, $filedate, $fileperm) = (stat("$curdate/$diritem"))[7,9,2];
next if($filedate < $curtime);
$filename=$diritem;
$filename =~ s/\_/ /ig;
print qq~<li><a href="$curdate/$diritem">$filename</a>~;
}
print qq~</ul><br>~;
}
############
sub js{
############
print $q->header;
print qq~document.write('<ul>');~;
opendir(DIR, "$curdate")|| die("Can't read $curdate");
@dirlist = readdir(DIR);
closedir(DIR);
$curtime = time;
$curtime = $curtime - 86400;
foreach $diritem(@dirlist){
next if($diritem eq "." || $diritem eq ".." || -d $diritem);
($filesize, $filedate, $fileperm) = (stat("$curdate/$diritem"))[7,9,2];
next if($filedate < $curtime);
$filename=$diritem;
$filename =~ s/\_/ /ig;
$filename =~ s/\.html//ig;
print qq~document.write('<li><a href="/vidgen/$curdate/$diritem">$filename</a>');~;
}
print qq~document.write('</ul><br>');~;
}
###################
sub generate {
###################
opendir(DIR, "$curdate")|| die("Can't read $curdate");
@dirlist = readdir(DIR);
closedir(DIR);
$curtime = time;
$curtime = $curtime - 86400;
open(FILE, ">vidlist.html");
foreach $diritem(@dirlist){
next if($diritem eq "." || $diritem eq ".." || -d $diritem);
($filesize, $filedate, $fileperm) = (stat("$curdate/$diritem"))[7,9,2];
next if($filedate < $curtime);
$filename=$diritem;
$filename =~ s/\_/ /ig;
$filename =~ s/\.html//ig;
print FILE qq~<li><a href="/vidgen/$curdate/$diritem">$filename</a>~;
}
close(FILE);
print $q->header;
print qq~List file generated~;
exit;
}
CGI translation into php
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: CGI translation into php
Do you know Perl? Because I don't. But I do know PHP
. If you can tell me what &js does I can tell you what the PHP equivalent is.
Also place surround your code in [syntax=perl]code here[/syntax] so that it's nice to read thanks
Also place surround your code in [syntax=perl]code here[/syntax] so that it's nice to read thanks
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: CGI translation into php
In Perl you prefix your sub-routine invocation with the '&' character. Stupid syntax and totally foriegn to most programmers, but Perl is wonky that way. To make matters worse I am pretty sure it's optional.
I don't think there is a return statement either, I believe it's whatever expression is evaluated last is what is returned. It's been so long since I used Perl though I couldn't tell you. Good thing too, cause I hated that language with a passion and I will forever hate regular expressions because of that language. 
Code: Select all
&callSubroutine