blob: a1e1d686c5388a2d16f4d76a3c40cdee22829b98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
Challenge 1: "Count instances: Create a script that either reads standard
input or one or more files specified on the command-line. Count the number
of times and then print a summary, sorted by the count of each entry.
So with the following input in file example.txt
apple
banana
apple
cherry
cherry
apple
the script would display something like:
apple 3
cherry 2
banana 1
For extra credit, add a -csv option to your script, which would generate:
apple,3
cherry,2
banana,1
My notes: Straightforward use of a hash.
Challenge 2: "ASCII bar chart: Write a function that takes a hashref
where the keys are labels and the values are integer or floating point
values. Generate a bar graph of the data and display it to stdout.
The input could be something like:
$data = { apple => 3, cherry => 2, banana => 1 };
generate_bar_graph($data);
And would then generate something like this:
apple | ############
cherry | ########
banana | ####
If you fancy then please try this as well: (a) the function could let you specify whether the chart should be ordered by (1) the labels, or (2) the values.
My notes: easy, especially using a histogram module I wrote recently.
|