I am learning the basics of Perl, after finishing learning the basics of Groovy, Python, C#, Scala and adding onto my Java this semester.
My main goal is to have a program read in a file that contains a number on each line like
1 2 3 3 2 2 1 2
and take those numbers and print them out in order with a "*" mark for every occurrence, making a histogram type program. I can post my code in Java or something else if it would help anyone understand what I am talking about.
The output I need looks like:
1:**
2:****
3:**
open(FILE, '/location/data/p4.txt') or die "Cant't open file: $!\n"; my %myhash = (); my @data = (); chomp(@data = <FILE>); foreach (@data) { %myhash = (@data => $k++); } foreach $k (sort {$a <=> %b} keys %myhash) { print "$myhash{$k} : ". '*' x $myhash{$k} . "\n"; }
This is what I have done so far from using code in another problem I made. How do I up the count? It doesn't seem like my loop is working properly on this problem either.
In reply to Learning Perl, Hashes Help by learningmanylang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |