0% found this document useful (0 votes)
2 views

PERL String

The document is a Perl program demonstrating various string manipulation functions, including length, case conversion, substring extraction, and searching for substrings. It also showcases splitting strings based on delimiters and comparing string equality. Additionally, it includes examples of obtaining the ASCII value of a character.

Uploaded by

atharva.dc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PERL String

The document is a Perl program demonstrating various string manipulation functions, including length, case conversion, substring extraction, and searching for substrings. It also showcases splitting strings based on delimiters and comparing string equality. Additionally, it includes examples of obtaining the ASCII value of a character.

Uploaded by

atharva.dc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

# Perl program to demonstrate

# string length function

# string
my $s = "PERL";

# using length function &


# displaying length
print("Length: ", length($s));

# Converting to Uppercase
print("\nTo Upper Case: ");
print(uc($s), "\n");

#!/usr/bin/perl

# String to be passed
$string = "TYCO";

# Calling substr() to find string


# without passing length
$sub_string1 = substr($string, 4);

# Printing the substring


print "Substring 1 : $sub_string1\n";

# Calling substr() to find the


#!/usr/bin/perl

# Original String containing both


# lower and upper case letters
$original_string = "HELLO";

# Converting the string to Lower case


$changed_string = lc($original_string);

# Printing the original String


print "Original String : $original_string\n";

# Printing the Changed String


print "Changed String : $changed_string\n";

#!/usr/bin/perl

# String from which Substring


# is to be searched
$string = "pearls are the best";

# Using index() to search for substring


$index = index ($string, 'the');

# Printing the position of the substring


print "Position of 'the' in the string: $index\n";

# Perl program to demonstrate the splitting on character

#!/usr/bin/perl
use strict;
use warnings;

# Here character is comma(, )


my $str = 'Geeks, for, Geeks';

# using split() function


my @spl = split(', ', $str);

# displaying result using foreach loop


foreach my $i (@spl)
{
print "$i";
}

# Perl program to demonstrate the


# splitting among string without Limit

#!/usr/bin/perl
use strict;
use warnings;

# string which is separated by !! sign


my $str = 'he!!hello!!55!!tyco';
# using split function without Limit
my @spl = split('!!', $str);

# displaying string after splitting


foreach my $i (@spl)
{
print "$i\n";
}

my $string1 = "Ana";
my $string2 = "Ana";
if($string1 eq $string2) {
print "Match!\n";
}
my $string3 = "Ana";
my $string4 = "Christian";
if($string3 eq $string4) {
print "Match\n!";
}else{
print "Missmatch!\n";
}

An integer value which represents the ASCII value of the first character in the
string passed to this function as a parameter.

#!/usr/bin/perl -w
# ASCII value of 'G' is printed
print(ord('HELLOPERL'));

#!/usr/bin/perl

# Original String containing


# lower and upper case letters
# as well as numerics
$original_string = "Thank You";

# Converting the string to Lower case


$changed_string = lc($original_string);

# Printing the original String


print "Original String : $original_string\n";

# Printing the Changed String


print "Changed String : $changed_string\n";

You might also like