Question

SHOW INPUT AND OUTPUT OF EVERYTHING .ALSO SCREEN SHOT THE RESULTS. PROGRAMMING IN PERL 2.8 Special...

SHOW INPUT AND OUTPUT OF EVERYTHING .ALSO SCREEN SHOT THE RESULTS. PROGRAMMING IN PERL

2.8 Special Literals

Three special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that point in your program.

They may be used only as separate tokens and will not be interpolated into strings.

#!/usr/bin/perl print

"File name ". __FILE__ . "\n";

print "Line Number " . __LINE__ ."\n";

print "Package " . __PACKAGE__ ."\n";

# theycan not be interpolated

print "__FILE__ __LINE__ __PACKAGE__\n";

Output_________________________

2.9 Accessing Array Elements When accessing individual elements from an array, you must prefix the variable with a dollar sign ($) and then append the element index within the square brackets after the name of the variable.

Array indices start from zero, so to access the first element you need to give 0 as indices. You can also give a negative index, in which case you select the element from the end, rather than the beginning, of the array.

#!/usr/bin/perl

@days = qw/Mon Tue Wed Thu Fri Sat Sun/;

print "$days[0]\n";

print "$days[1]\n";

print "$days[2]\n";

print "$days[6]\n";

print "$days[-1]\n";

print "$days[-7]\n";

Output_________________________

2.10 Sequential Number Arrays

Perl offers a shortcut for sequential numbers and letters. Rather than typing out each element when counting to 100

#!/usr/bin/perl

@var_10 = (1..10);

@var_20 = (10..20);

@var_abc = (a..z);

print "@var_10\n"; # Prints number from 1 to 10

print "@var_20\n"; # Prints number from 10 to 20

print "@var_abc\n"; # Prints number from a to z

Output_________________________

2.11 Array Size The size of an array can be determined using the scalar context on the array - the returned value will be the number of elements in the array –

#!/usr/bin/perl

@array = (1,2,3);

$array[50] = 4;

$size = @array;

$max_index = $#array;

print "Size: $size\n";

print "Max Index: $max_index\n";

Output_________________________

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM 1:

#!/usr/bin/perl

print "File name ". __FILE__ . "\n";

print "Line Number " . __LINE__ ."\n";

print "Package " . __PACKAGE__ ."\n";

# theycan not be interpolated

print "__FILE__ __LINE__ __PACKAGE__\n";

OUTPUT:

File name 1.pl
Line Number 5
Package main
__FILE__ __LINE__ __PACKAGE__

PROGRAM 2:

#!/usr/bin/perl

@days = qw/Mon Tue Wed Thu Fri Sat Sun/;

print "$days[0]\n";

print "$days[1]\n";

print "$days[2]\n";

print "$days[6]\n";

print "$days[-1]\n";

print "$days[-7]\n";

OUTPUT:

Mon
Tue
Wed
Sun
Sun
Mon

PROGRAM 3:

#!/usr/bin/perl

@var_10 = (1..10);

@var_20 = (10..20);

@var_abc = (a..z);

print "@var_10\n"; # Prints number from 1 to 10

print "@var_20\n"; # Prints number from 10 to 20

print "@var_abc\n"; # Prints number from a to z

OUTPUT:

1 2 3 4 5 6 7 8 9 10
10 11 12 13 14 15 16 17 18 19 20
a b c d e f g h i j k l m n o p q r s t u v w x y z

PROGRAM 4:

#!/usr/bin/perl

@array = (1,2,3);

$array[50] = 4;

$size = @array;

$max_index = $#array;

print "Size: $size\n";

print "Max Index: $max_index\n";

OUTPUT:

Size: 51
Max Index: 50


SCREEN SHOT OF OUTPUT:

Add a comment
Know the answer?
Add Answer to:
SHOW INPUT AND OUTPUT OF EVERYTHING .ALSO SCREEN SHOT THE RESULTS. PROGRAMMING IN PERL 2.8 Special...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++. please show screenshots of output This project will continue to familiarize the student with using...

    c++. please show screenshots of output This project will continue to familiarize the student with using arrays. Store all the function proto-types in project11_funch and store all the functions in project11_func.cpp. Make sure you have proper header comments in each.h,.cpp file. When you run your program, your sample output should show your name. Your report should include the following: 1) project11_func.h 2) project11_func.cpp 3) project11.cpp 4) sample output Write the following functions: a) void fill_array_with_random_nums(int array(), int N): Fill array...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • In C++ This program will read a group of positive numbers from three files ( not...

    In C++ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the scores in the order that they were input, showing each number and what percentage it is above or below the average for each file. Note: Finding the average doesn’t require an array. Finding...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Thank you!!! 4.1 [2 pts. int rollO Define a function roll() that takes no arguments, and...

    Thank you!!! 4.1 [2 pts. int rollO Define a function roll() that takes no arguments, and returns a random integer from 1 to 6. Before proceeding further, we recommend you write a short main method to test it out and make sure it gives you the right values. Comment this main out after you are satisfied that roll() works. Remenber:texibook Seciion 49 is on randormness, and Chapier 5is on functions. int getKandomNumber return 4 l chosen by fair dice roll....

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

  • I need help solving this question from the practice final exam given to us to prepare...

    I need help solving this question from the practice final exam given to us to prepare for the final in C++ #include <iostream> using namespace std; /* The following is code for an OrderedCollection container and its related iterator. The container has a capacity determined by a constructor parameter. The container does not grow. Code that adds elements to the container ensures that the capacity of the container is never exceeded. An attempt to add an item to a full...

  • Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...

    Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT