Starting from:

$25

CIS2250-Lab 5 Solved

You have been using arrays in perl for some weeks now, however all of these arrays
have been populated by calling a function from Text::CSV. We have not modified the
contents of the array ourselves.
You can add elements to an array in perl using the push function.
For example, the following code creates an empty array, and then adds two values
to it:
sub p rin tA r r a yCon t en ts {
# place the f i r s t argument i n t o the v a r i a b l e @array_argument
my @array_argument = @_;
i f ( $#array_argument = 0 ) {
p r i n t " Array has " . $#array_argument . " values : \ n " ;
fo reach my $i (0 . . $#array_argument ) {
p r i n t " Value " . $i . " i s ’ " .
$array_argument [ $i ] . " ’\ n " ;
}
} els e {
p r i n t " Array i s empty\n " ;
}
}
my @li s t _ o f _ v al u e s ;
p rin tA r r a yCon t en ts ( @li s t _ o f _ v al u e s ) ;
push ( @lis t _ o f _v al u es , "one " ) ;
p rin tA r r a yCon t en ts ( @li s t _ o f _ v al u e s ) ;
push ( @lis t _ o f _v al u es , " two " ) ;
p rin tA r r a yCon t en ts ( @li s t _ o f _ v al u e s ) ;
Note the push function adds the new value to the end of the array, without disturbing
the order of any of the other values.
Task 1 Description: Collecting Unique Values
For this lab, you are asked to write a program printUniqueColumnValues.pl that
will work as follows:
• it will take as arguments the name of a csv file to process, and a column to
examine, for example:
perl printUniqueColumnValues.pl WorldBank_EducationData.csv 2
• in the column of data within the .csv file, a list is collected of any value not yet
seen
• at the end, this list is printed.
This will provide a summary of what the values are within a given “column” of data
in the file.
You will find the WorldBank_EducationData.csv file on CourseLink. This file describes rates of education around the world.

Overview
Learning objectives: # Managing lists
of values H# Dealing with large data
sets Extracting and examining
fields

Image description
A pair of work socks. Image source
freebie.photography CC BY 3.0
If the file is run as in the example above:
perl printUniqueColumnValues.pl WorldBank_EducationData.csv 2
then the expected output is this:
S e ri es
Adjus ted net enrolment ra te , primary , female (%)
Adjus ted net enrolment ra te , primary , male (%)
Adjus ted net enrolment ra te , upper secondary , both sexes (%)
Adjus ted net enrolment ra te , primary , both sexes (%)
Adjus ted net enrolment ra te , upper secondary , female (%)
Adjus ted net enrolment ra te , upper secondary , male (%)
Adjus ted net i n t a k e r a t e to Grade 1 o f primary education , both sexes (%)
Adjus ted net i n t a k e r a t e to Grade 1 o f primary education , female (%)
Adjus ted net i n t a k e r a t e to Grade 1 o f primary education , male (%)
Adul t i l l i t e r a t e popula tion , 15+ years , % female
Adul t i l l i t e r a t e popula tion , 15+ years , both sexes ( number )
Adul t i l l i t e r a t e popula tion , 15+ years , female ( number )
Adjus ted net enrolment ra te , lower secondary , both sexes (%)
Adjus ted net enrolment ra te , lower secondary , female (%)
Adjus ted net enrolment ra te , lower secondary , male (%)
Adul t i l l i t e r a t e popula tion , 15+ years , male ( number )
Be sure to upload your printUniqueColumnValues.pl to CourseLink

More products