0% found this document useful (0 votes)
7 views4 pages

Basic Perl Programs

The document contains several Perl scripts demonstrating basic programming concepts such as printing output, variable declaration, string manipulation, substring extraction and replacement, and conditional statements. It showcases the use of warnings and strict pragmas, as well as the foreach loop for iterating over an array. Overall, it serves as a simple introduction to Perl programming syntax and functionality.

Uploaded by

atharva.dc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Basic Perl Programs

The document contains several Perl scripts demonstrating basic programming concepts such as printing output, variable declaration, string manipulation, substring extraction and replacement, and conditional statements. It showcases the use of warnings and strict pragmas, as well as the foreach loop for iterating over an array. Overall, it serves as a simple introduction to Perl programming syntax and functionality.

Uploaded by

atharva.dc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PERL PROGRAM

#!/usr/bin/perl

use warnings;

print("Hello, World!\n");

#!/usr/bin/perl

use warnings;

$color = 'red';

print("my favorite #1 color is " . $color . "\n");

# another block

my $color = 'blue';

print("my favorite #2 color is " . $color . "\n");

# for checking

print("my favorite #1 color is " . $color . "\n");

#!/usr/bin/perl

use warnings;

use strict;

my $s= q/"Are you learning Perl String today?" We asked./;

print($s ,"\n");
my $name = 'Jack';

my $s2 = qq/"Are you learning Perl String today?"$name asked./;

print($s2 ,"\n");

my $s = "Change cases of a string\n";

print("To upper case:\n");

print(uc($s),"\n");

print("To lower case:\n");

print(lc($s),"\n");

#!/usr/bin/perl

use warnings;

use strict;

# extract substring

my $s = "Green is my favorite color";

my $color = substr($s, 0, 5); # Green

my $end = substr($s, -5); # color

print($end,":",$color,"\n");

# replace substring

substr($s, 0, 5, "Red"); #Red is my favorite color

print($s,"\n");

my $a = 1;

my $b = 2;

if($a == $b){

print("a and b are equal\n");

}else{
print("a and b are not equal\n");

my $a = 1;

my $b = 2;

if($a == $b){

print("a and b are equal\n");

}elsif($a > $b){

print("a is greater than b\n");

}else{

print("a is less than b\n");

my $a = 1;

my $b = 2;

if($a == $b){

print("a and b are equal\n");

}else{

print("a and b are not equal\n");

my $a = 1;

my $b = 2;

if($a == $b){

print("a and b are equal\n");

}elsif($a > $b){

print("a is greater than b\n");

}else{

print("a is less than b\n");


}

#!/usr/bin/perl

use warnings;

use strict;

my @a = (1..9);

foreach(@a){

print("$_","\n");

You might also like