From PHP to Perl


Posted in Other by gosukiwi on December 6, 2006

Well, i think you all know how to redirect in PHP (header(‘Location: page.php’)) but, in perl, you have to set the header before the input, and what if you always include a header file, print the content, and then a footer file, or use some kind of “PHP” Navigation, including files?
Well, there is one way to do this, “Javascript”
You can redirect with Javascript from Perl!

First, you need to make a basic JS Code

function redirect(time, url)
$seconds = time*1000;
$url = url;

That will redirect in x seconds, to an x url
And, for some Perl integration, i made this simple function

sub redirect
print ‘<script language=”javascript” type=”text/javascript”>redirect(‘.$_[0].’,\”.$_[1].’\’)</script>’;

And thats all! Now, when you want to redirect, just make


Thats the equivalent of PHP’s

header(‘refresh: 1; url=mypage.php’);

Well, i hope you find this useful :] Bye!


Is In Array?

Posted in Programming by gosukiwi on December 3, 2006

I was searching if there was a function like in_array of PHP in Perl, but there is not such function, but, it is still very easy to check!
This was useful for me so i hope it is for you

$string = ‘fin_helm’;
$array = array(‘full_plate’,’manteau’,’boots’,’two_handed_sword’,’fin_helm’);
if(in_array($string, $array))
print “$string is in the array”;

In Perl:

my $string = ‘fin_helm’;
my @array = qw/full_plate manteau boots two_handed_sword fin_helm/;
if(grep $_ eq $string, @array)
print “$string is in the array”;

So, those codes do exactly the same.
If you don’t know much perl you will be wondering what does the grep function, the grep function examines each of an element of an array (represented with $_) and then we make a comparison or something with it, in this case $_ eq $string, grep, returns the elements with where true, in this case we are not requesting the elements, we are requesting a sacalar value, so, in perl 0 is false, and every other number is true, that will return 1, so its true, and the element is in the array 🙂
I hope you all find this useful, bye