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

Perl: Accessing Subroutine Arguments

#!/usr/bin/perl
# Hypotenuse Calculator
sub hypotenuse
 {
    my ($side1, $side2) = @_;  #subroutine arguments    							 
    return sqrt( ($side1 *

Perl: How to define and use the subroutines

#!/usr/bin/perl -w
sub welcom
{
    $myVar++;
    print "Welcom to perl.tubedir.com";
}
# invok method
welcom();

Perl: loop examples

#!/usr/local/bin/perl
use strict;
#Letters of the Alphabe
for my $letter('a'..'z','A'..'Z')  
{
  print $letter,"n";
}

Perl: Detecting Return Context

#!/usr/bin/perl
printf("Called in");
if (wantarray( ))
{
    print "list context";
    return @maListe;
} elsif (defined wantarray( ))
{
    print "S

Perl: How to Multiline fields

#!/usr/bin/perl
# Declare the subroutine without defining
sub addUser (Str $name, Int $age) {}
# defining the subroutine
sub addUser (Str $name, Int

Perl: Finding index of word/character in a string

#!/usr/local/bin/perl
use strict;
my $hi="Welcom to perl.tubedir.com";
# find 'to' index
my $indic=index($hi, "to");
print "index of 'to' $indic ";

Perl: Get formatted text

#!/usr/local/bin/perl -w
#
my $myFormat= sprintf("%12.4e %12.4f %12.4gn",
			          0.0000001, 10.1, 10.00001, 100000.1);
print $myFormat,"n";
[/p

Perl: return the number of Hash key

#!/usr/local/bin/perl
my %hash = ("a" => 1, "b" => 2, "c" => 3);
# to get key count
my $key_number= keys %hash;
print "Hash contains $key_number clé(

Perl: sum of array

#!/usr/local/bin/perl -w
sub arraySum
{
    my ($num)= @_ ;      
    my $arraySum;
    foreach $number (@_)
    {
        $arraySum += $number;

Perl: How to access to subroutine Arguments

sub division
{
    # Divide arg1 by argument 2
    $_[0] / $_[1];
}
$quotient = division 5, 2; 
print $quotient;

Perl: How to run an external program

#!/usr/local/bin/perl
# launch Windows calculator
exec "calc";
die "Launch failed: $!";

Perl: Traversing a Hash using key-value pair

#!/usr/bin/perl
my %hash = ("a" => 1, "b" => 2, "c" => 3);
my @myKeys = keys %hash;                # Hash Keys
my @myValues = values %hash;

Perl: Read keyboard

#!/usr/local/bin/perl
while (defined($line = <>))
{
  chomp($line);
  print "You say=> $line!n";
}

Perl: varArg Example

#!/usr/local/bin/perl
# to get maximum value from the List
sub find_max
 {
  my($no_matter) = shift @_;  
  foreach (@_) {
    if ($_ > $no_matter) {