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

Perl: How to Create an infinite loop using a for loop:

    #!/usr/local/bin/perl -w
    for (;;)
    {
       print "This is the loop that never ends...............";
    }

Perl: Using continue statement

#!/usr/bin/perl -w
$i = 0;
while ($i < 10)
 {
   print "Iteration $i.n";
} continue
{                
   $i++;
}

Perl: elseif statement

#!/usr/local/bin/perl
$x = 1;
if($x)
{
  # Expression
}
elsif($x)
{
  # Expression
}
elsif($x)
{
  # Expression
}
else
{
 #Expression
}

Perl: java break out of while loop using ‘last’ statement

#!/usr/bin/perl
while ()
{
  if (/__END__/) {
    last;            #Break
  } elsif (/me/) {
    print;
  }
}

Perl: Using do .. until statement

#!/usr/bin/perl -w
$i *= 2 until $i > $j;
print $j;

Perl: Using until loop

#! /usr/bin/perl#
until ($j > 20)
{
  $j += 2;
  print $j,"
";
}

Perl: Reading from Standard Input

#!/usr/bin/perl -w
{
  print "Tapez un nombre: ";
  chomp(my $n = );              #read from keyboard
  my $root = sqrt $n;  # Calculating the square

Perl: ternary operator

 #!/usr/local/bin/perl -w
print "Enter a number: ";
$line=;
# Check if a number is odd or even
print (($line % 2)?"odd":"even");

Perl: Find duplicates in a group of words

#!/usr/bin/perl
my @analog = qw{ Perl, used with java is effective, but perl with python is less effective than python with java };
my %seen;
@ne

Perl: How to Find even numbers using a do…while loop

#!/usr/bin/perl
use warnings;
use strict;
my $x = 0;
# Find even numbers between 0 and 1000
do {
  {
    next if ($x % 2);
    print $x, "n";
  }
} w

Perl: Using the do/until loop

#! /usr/bin/perl#
$counter = 100;
do
{
   print "Elem= $counter
";
} until ( --$counter == 0 );
print "Done.";

Perl: Using the do/while loop

$counter = 1;
do
{
   print "Counter= $counter ";
} while ( ++$counter < 100 );
print "Done.";

Perl: using for statement.

#!/usr/local/bin/perl
for ($i = 1; $i <= 10; $i++)
{
  print "$i 
";
}

Perl: using foreach loop

#!C:/perl/bin
for (1..10)
{
 print "$_ !
";
}