SHOW SCREEN SHOTS OF THE INPUT AND OUTPUT AS WELL AS THE RESULTS PROGRAMMING IN PERL Task 2:...

50.1K

Verified Solution

Question

Programming

SHOW SCREEN SHOTS OF THE INPUT AND OUTPUT AS WELL AS THERESULTS

PROGRAMMING IN PERL

Task 2: Variables

2.1 Scalar Variables

A scalar is a single unit of data. That data might be an integernumber, floating point, a character, a string, a paragraph, or anentire web page. Simply saying it could be anything, but only asingle thing.

#!/usr/bin/perl

$age = 35; # An integer assignment

$name = \"Gary Mann\"; # A string

$salary = 5445.50; # A floating point

print \"Age = $age\n\";

print \"Name = $name\n\";

print \"Salary = $salary\n\";

Output__________________

2.2 Array Variables

An array is a variable that stores an ordered list of scalarvalues. Array variables are preceded by an \"at\" (@) sign. To referto a single element of an array, you will use the dollar sign ($)with the variable name followed by the index of the element insquare brackets.

#!/usr/bin/perl

@ages = (25, 30, 40);

@names = (\"John Paul\", \"Lisa\", \"Kumar\");

print \"\$ages[0] = $ages[0]\n\";

print \"\$ages[1] = $ages[1]\n\";

print \"\$ages[2] = $ages[2]\n\";

print \"\$names[0] = $names[0]\n\";

print \"\$names[1] = $names[1]\n\";

print \"\$names[2] = $names[2]\n\";

Output______________________

2.3 Hash Variables

A hash is a set of key/value pairs. Hash variables are precededby a percent (%) sign. To refer to a single element of a hash, youwill use the hash variable name followed by the \"key\" associatedwith the value in curly brackets.

#!/usr/bin/perl

%data = ('John Paul', 45, 'Lisa', 30, 'Kumar', 40);

print \"\$data{'John Paul'} = $data{'John Paul'}\n\";

print \"\$data{'Lisa'} = $data{'Lisa'}\n\";

print \"\$data{'Kumar'} = $data{'Kumar'}\n\";

Answer & Explanation Solved by verified expert
3.8 Ratings (572 Votes)
Screen    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students