๐Ÿ“œ
B.TECH III YEAR โ€ข II SEMESTER โ€ข R22

Scripting Languages - Lab Manual

Scripting Languages Laboratory โ€ข Program 19a Solution

๐Ÿ“˜ R22 Regulation ๐ŸŽ“ III Year ๐Ÿ“š II Semester ๐Ÿ“œ Scripting Languages ๐Ÿ’Ž Ruby โ€ข TCL โ€ข Perl ๐Ÿงช Lab Program
Aim of Program 19a

a) Write a Perl script to substitute a word, with another word in a string.

โ† All Programs
Solution

Aim:

☛   a) Write a Perl script to substitute a word, with another word in a string.

Solution :

PROGRAM: (replace_str.pl)

 
$sentence = "Perl is great at manipulating strings, naturally."; 
print "$sentence \n\n"; 
$replacement = "is totally awesome"; 
substr($sentence, 5, 8) = $replacement; 
print "Substituting $replacement staring at 5 and going 8 words \n"; 
print "$sentence \n\n";


OUTPUT:

 
Perl is great at manipulating strings, naturally. 

Substituting is totally awesome staring at 5 and going 8 words 
Perl is totally awesome at manipulating strings, naturally. 



โ† Back to Scripting Languages Lab Programs ๐Ÿ“š All Lab Manuals