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!

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

BBcode is very popular on forums, if you have never heard of it you may have seen it and don’t know it’s name

BBcode looks like [b][/b] for bold, [url=url]linktitle[/url] for links, etc
I will show you how to make that with Perl and PHP
You need a basic knowledge of regular expressions. I will explain some basic stuff here.

What are Regular Expressions?

Basically, Regular Expressions (also called regexp) are templates that matches a given string.
For example
PHP:

Those codes will look for fedekiller in the given string, in perl, we use // and put the pattern there, but that was because we did not specify we were matching, if you want to use other separators, you can use for example || or {} but you have to specify you are matching. We will use // here, we dont want to complicate it so much, we also use i after the / to indicate that its CaSe InSeNsItIvE, we also specify case insensitive in PHP after the @
As you have probably realised, to match something in perl we use $string =~/pattern/;
And in PHP we use preg_match(@pattern@,$string);

QuantifiersQuantifiers are used for repetition
* Matches 0 or more times
+ Matches 1 or more times
? Matches 0 or 1 time
{2} Matches exactly 2 times
{2,} Matches 2 or more
{2,5} Matches 2, 3, 4 or 5 times

Example:
Regex:

fe+dekil{2}er

Will Match:

feeeeeedekiller

GroupingYou can also match by group, using “(” and “)”, that will also make a variable with the content between the “(” and “)”
Example:
Regex:

(fede)+

Will Match:

fedefedefede

We can now acess to the content of the first () with the variable $1, for example if we did something like
Regex:

\[b\](.+?)\[\/b\]

Will Match:

[b]Something[/b]

And the variable $1 will contain SomethingAlternativesYou can also match one thing OR other thing, using the ‘|’ bar
Example:
Regex:

(fede|killer)+

Will Match:

killerkillerfedekillerfede

Modifiers:The modifiers are:
i – Will make it CaSe InSeNsItIvE
g – Global match
m – Multiple lines match
s – Single line match
x – Allow comments and white space in the pattern
e – Evaluate placement
U – Ungreedy patternEscape CharacterSometimes we want to use something for example () or {} but we dont want to use that function, for example in BBCode we want to match [b][/b] but no use the []’s function, so, we escape them with the \ character

AnchorsIf you want something to match only at the beggining or the end of an string, we can use anchors
^ – Start of a string
$ – End of a string
\b – Word boundary
\B – Not word boundary
\< – Start of a word
\> – End of a word

What is boundary?Word boundary is if we want to match that string only in a complete word, its for making sure for example we wont find cat in category.

We use the i after the @ to choose case insensitive, we also use the grouping function to get everything between the tags and then a variable wich contains that and put it inside the corresponding HTML tags
We do exactly the same in Perl
In Perl:

in PHP, preg_replace is like this preg_replace(regex,replace_with,string)
In Perl
string =~ /regex/replace_with/;
If we dont specify the variable in Perl it will automatically use $_, but we have to specify that we are replacing with the letter s
So it will look like
s/regex/replacement/;

Today i will explain the differences between PHP and Perl with Cookies.

PHP is way better than Perl for cookies (maybe mod_perl could do a better job but PHP is still better) anyways, its not a big deal to get or set a cookie in Perl.

In Perl cookies can have maximum 6 attributes, in PHP they can have 7, most of them are optional, but they ones we are going to explain here are 3 attributes, which are in both languages, name, value and expire, the most basic attributes ;3

Before we start, i want to write the possible attributes, just for you to know them

In PHP:

Name
Value
Expire
Path
Domain
Secure
Httponly

In Perl:

Name
Value
Expire
Domain
Path
Secure Flag

Okay, now we can start explaining the 3 basic attributes, value, name and expire

In PHP we use the time function and multiply till we add one month (60 seconds * 60 minutes * 24 hours * 30 days)
In Perl, we just set +1M to make it last 1 month, if we want to delete a cookie, we have to use a negative value in expires, for example, in PHP would me time()-60*60… and in Perl it would be -1M

Now, lets read a cookie, with PHP is very easy

In PHP:

$_COOKIE[‘user’];

That will read the cookie value (in this case, fedekiller)

In Perl:

my %cookies = fetch CGI::Cookie;
$cookies{‘user’}->value

We set all cookies to the cookies hash, and then we just request the value.

I made a little function to get cookies in Perl so its a little bit easier