السبت، فبراير 21، 2009

Perl: You don't want to miss! -1-

Assalamo Alikom,

This post is about Perl, a well known programming language, and you don't want to ask me about it! I'm still a beginner doing the book execrices, didn't finish my assignments yet.
Better you go google "Perl": A {Scripting Dynamic} Langauge

This post is intended mainly to mention the first facts I've learned about Perl, it'll be all about the "print" function and some Strings and Numbers!

Print:
Here's the first picture of "print":
print "Hello... you know!";
This will print: Hello... you know!

Trivial, hah? even this:
print 'Hello... World!'
This will print: Hello...World!

What if we embeded this (scalar) string $myName inside the first version of print:
$myName = "Muhammad";
print "Hello $myName"

The second version?
$myName = "Muhammad";
print "Hello $myName"

This didn't automatically convert my string, good!

What about this:
print `Hello World!`;

These are different quote styles: `
This should output something like: Command not found ... Yeah, this print will execute what's inside!
So you may try something like:
print `cp file1 file2`;

("cp" is the copy command for bash)

What about Strings/Numbers?

Strings in Perl are First-Class Citizens! users shouldn't treat them as a character array!

$stringOne = "1";
print $stringOne + 1;

This prints "2" ;)

What about this:
$stringAddress = "8A";
print $stringAddress + 8;

This will print a warning! and then? ... it will print "16" which is 8+8
Perl starts parsing the string until it finds a non-numeric value it terminates but it keeps the valid piece. Notice that if the address string was something like: "A8" it would be converted to "0"!

Incrementing strings:

print ++"A0";

This will output: A1
You should give it a try yourself ;)

Hopefully I'll have more to say later on :)

Assalamo Alikom

هناك تعليقان (2):

Haytham Alaa يقول...

nice post,
gr8 to have you back ;)

Mohammed A.Aziz يقول...

glad u liked it ;)
Thank you!