Write a Perl program to implement the following list of manipulating functions a) Shift b) Unshift c) Push
Aim:
☛ Write a Perl program to implement the following list of manipulating functions
a) Shift
b) Unshift
c) Push.
Solution :
PROGRAM: (list_functions.pl)
#!/usr/bin/perl
use strict;
use warnings;
# Initial list
my @numbers = (10, 20, 30, 40);
print "Original list: @numbers\n";
# a) Shift - removes first element
my $shifted = shift @numbers;
print "After shift (removed $shifted): @numbers\n";
# b) Unshift - adds element at beginning
unshift @numbers, 5;
print "After unshift (added 5 at beginning): @numbers\n";
# c) Push - adds element at end
push @numbers, 50;
print "After push (added 50 at end): @numbers\n";
OUTPUT:
Original list: 10 20 30 40
After shift (removed 10): 20 30 40
After unshift (added 5 at beginning): 5 20 30 40
After push (added 50 at end): 5 20 30 40 50
Related Scripting Languages Lab Programs
๐
Ruby Scripts
1.
Write a Ruby script to create a new string which is n copies of a given string where n is a non-negative integer.
View Solution โ
2.
Write a Ruby script which accept the radius of a circle from the user and compute the perimeter and area.
View Solution โ
3.
Write a Ruby script which accept the users first and last name and print them in reverse order with a space between them.
View Solution โ
4.
Write a Ruby script to accept a filename from the user print the extension of that.
View Solution โ
7.
Write a Ruby script to check two integers and return true if one of them is 20 otherwise return their sum.
View Solution โ
8.
Write a Ruby script to check two temperatures and return true if one is less than 0 and the other is greater than 100.
View Solution โ
10.
Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.
View Solution โ
๐งฉ
TCL Scripts
14.
Write a TCL script to
(i) create a list
(ii) append elements to the list
(iii) Traverse the list
(iv) Concatenate the list
View Solution โ
๐ช
Perl Scripts
17b.
b) Write a Perl script to print the multiplication tables from 1-10 using subroutines.
View Solution โ
18.
Write a Perl program to implement the following list of manipulating functions
a) Shift
b) Unshift
c) Push
Current
20.
Write a Perl script to print the file in reverse order using command line arguments.
View Solution โ