Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Perl Programming Use the splice function to replace the current phone number wit

ID: 3672961 • Letter: P

Question

Perl Programming Use the splice function to replace the current phone number with the new phone number, or use any of the other built-in array functions to produce output that resembles the following: Who are you searching for? Karen What is the new phone number for Karen? 530-222-1255 Karen’s phone number is currently 284-758-2857. Here is the line showing the new phone number: Karen Evich:530-222-1255:23 Edgecliff Place, Lincoln, NB 92086:7/25/53:85100 Karen was found in the array three times. All design base on data provided. __DATA__ John DeLoach:408-253-3122:123 Park St., San Jose, CA 04086:7/25/53:85100 Karen Evich:284-758-2857:23 Edgecliff Place, Lincoln, NB 92086:7/25/53:85100 Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200 Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200 Fred Fardbarkle:674-843-1385:20 Parak Lane, DeLuth, MN 23850:4/12/23:780900

Explanation / Answer

# the syntax and example usage of the splice function

splice list, begining, size, newList

splice list, begining, size

splice list, begining

# the splice function will get rid off a chunk of list elements, starting from the off set address "begining" for up to a length of "size"
# if newList is mentioned , the removed contents will be replaced with the contents from the new List
# when the size is not mentioned, the whole of the cotents from the array is removed

# example:
# !/usr/bin/perl -w

@myList = ("t", "h", "e", "f", "o", "x");
@elementsTakenAway = splice(@myList, 0, 4, ("r", "e", "d", "d"));

print "The taken away elements are: @elementsTakenAway ";


# output:
The taken away elements are: t h e f

# the list myList would have become:

# myList = reddox after the splice replacement call

# now to the question to replace the current phone number with the new phone number
# !/usr/bin/perl -w

@currentPhone = ("2", "8", "4", "7", "5", "8", "2", "8", "5", "7");
@oldNumbersRemoved = splice(@currentPhone, 0, 10, "5", "3", "0", "2", "2", "2", "1", "2", "5", "5");

The above can be implemented for user inpout interaction

print "Whom you are searching for?";
my $name = <STDIN>;
# read the name from the user
print " Searching for $name for you ........ ........... ";
print "What is the new phone number for $name?";
my $newPhone = <STDIN>;
$currentPhone # to be read out from the fiel storing the phone book
@currentPhone = ($currentPhone)
@oldPhone = $currentPhone
@removedNumbers = splice(@currentPhone, 0, 10, $newPhone);
print " $name 's phone number is currently $oldPhnoe . Here is the line showing the new phone number: $name: $currentPhone ");

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote