Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Perl: Reversing a text by Word

$text="Welcom to www.tubedir.com";
print("Before :n",$text,"
");
@myWords    = split(" ", $text);
#start reversing
$reversedWords   = join(" ", rever

Perl: increment a string

#!/usr/bin/perl -w
$a = "al";
print ++$a, "n";   # "am"
$a = "Xs";
print ++$a, "n";    #"Xt"

Perl: Converting Between Characters and Values

#!/usr/bin/perl
foreach $elem(0..255)
{
 # print the character represented by a given number
 printf("$elem==>%sn",chr($elem))
}
foreach $elem("a".."

Perl: Scalars Examples

$string = "Welcom to perl.tubedir.com?";
$int = 150;
$float = 3.14159;
$tabref = [ "Perl", "Python", "Java" ];
$hashref = { "Perl" => 2500, "Java" =>

Perl: case insensitive compare

#!/usr/local/bin/perl
$a="welcom to perl.tubedir.com";
$b="WELCOM TO PERL.MESEXEMPLES.COM";
if (uc($a) eq uc($b))
 {
    print "OK";
}

Perl: assignment and incrementation examples

foreach $val(1..9) 
{
  $x+=$val;
  printf("$x
");
  $x*=$val;
  printf("$x
");
  $x-=$val;
  printf("$x
");
}

Perl: Controlling Case

#!/usr/local/bin/perl
# converting to uppercase
print uc("welcom perl.tubedir.comn");
print "Uwelcom perl.tubedir.comn";
# converting to lowercase
pr

Perl: Using auto-increment operator for a alphanumeric value

#!/usr/bin/perl -w
$a = "x9";    #alphanumeric
#After pre-increment
print ++$a, "n";         # "y0"
$a = "z5";
$a++;
#After post-increment
print $a,

Perl: Accessing Substrings

#!/usr/bin/perl
$string = "Perl Examples and tutorial";
$first  = substr($string, 0, 1);
printf("First character from index 0=%sn",$first);
$start  =

Perl: How to supply a default value to a scalar variable

# use $x if $x is true, else $y
$a = $x || $y;
# set $a to $b unless $a is already true
$a ||= $b;
# use $b if $b is defined, else $c
$a = defined($b

Perl: Example of post and pre increment

$c = 5;
$d = 5;
printf("Before post increment 'c'=%dn",$c);
printf("post increment 'c' =%dn",$c++);  # $c=5
printf("After post increment 'c'=%dn",$c)

Perl: Finding Today’s Date

use Time::localtime;
$tm = localtime;
($day, $month, $year) = ($tm->mday, $tm->mon, $tm->year);

Perl: Left shift Example

print 2 << 4,"
";
print 0b01000000 << 4,"
";

Perl: calculate power using **

foreach $val(1..9)  
{
   printf("2 power $val=%d
",2**$val);
}