The document contains examples of Perl programs and their outputs. It discusses concatenating variables using dot (.) and newline characters, assigning multiple variables using qw(), substituting a substring within a string, and replacing every 5th word in a text with asterisks. The key lessons are that dot concatenates while newline is treated as line break, qw() assigns multiple variables, substr allows extracting and replacing substrings, and a program can systematically replace words in a text.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
40 views
Programs Write The Output Here Observation
The document contains examples of Perl programs and their outputs. It discusses concatenating variables using dot (.) and newline characters, assigning multiple variables using qw(), substituting a substring within a string, and replacing every 5th word in a text with asterisks. The key lessons are that dot concatenates while newline is treated as line break, qw() assigns multiple variables, substr allows extracting and replacing substrings, and a program can systematically replace words in a text.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
1
1. Key in the following programs and fill in the table.
Programs Write the output here Observation Program 1 #!/usr/bin/env perl use warnings; use strict; my $firstname = "hari\n"; my $lastname = "prasad\n"; print "my first name is $firstname $lastname\n"; Program 2 #!/usr/bin/env perl use warnings; use strict; my $firstname = "Hariprasad\n"; my $lastname = "Maramraj\n"; chomp($firstname); print "my first name is $firstname $lastname\n";
Programs Write the output here Observation Program 1 #!/usr/bin/env perl use warnings; use strict; my $firstname = "Hariprasad"; print my first name is $firstname\n; Program 2 #!/usr/bin/env perl use warnings; use strict; my $firstname = "hariprasad"; print "my first name is $firstname\n";
2
Programs Write the output here Observation Program 1 #!/usr/bin/env perl use warnings; use strict; my $firstname = "Hariprasad"; my $lastname = "Maramraj"; my $profession = teaching; print "my name is $firstname $lastname\n"; Program 2 #!/usr/bin/env perl use warnings; use strict; my ($firstname,$lastname, $profession) = qw(Hariprasad Maramraj teaching); print "my name is $firstname. $lastname \n";
Programs Write the output here Observation Program 1 #!/usr/bin/env perl use warnings; use strict; my $fullname = 'hari' 'prasad'; print $fullname; Program 2 #!/usr/bin/env perl use warnings; use strict; my $fullname = 'hari'.'prasad'; print $fullname;
3
Question Try using a full stop (.) between two variables and see if it concatenates the values.
Programs Write the output here Observation Program 1 #!/usr/bin/env perl use warnings; use strict; my $nameh = "Hariprasad" x 10; print $nameh;
Program 2 #!/usr/bin/env perl use warnings; use strict; my $chunk = substr('the rain in Hyderabad', 9, 2); print "chunk is '$chunk'";
Program 3 #!/usr/bin/env perl use warnings; use strict; my $string = 'the rain in Hyderabad'; substr($string, 9, 2) = 'beyond'; print "string is '$string'";
2. Write a program to replace every 5 th word with a **** in the following text. The workshop aims to provide an in-depth technical foundation to the design and implementation of National Knowledge Network. In Particular, the workshop will provide participants with the knowledge and resources required to analyze, plan, design, and implement NKN within their organizations infrastructure.