in reply to Re: A Beginner Needs Homework help
in thread A Beginner Needs Homework help
Now that I've evaluated the code myself it is definitely missing things.. I just don't know how to build this kind of stuff. I'm such a novice that I had a hard time imagining how to put the pieces together.use strict; use warnings; #^^ for personal use to see where I've messed up open (FH,$ARGV[0]) || print "could not open file" ; my $info = <FH>; # ^^This opens whatever file is associates with the program # i.e - perl thisassignment documenthechooses # that file is placed into $info after it's read while ($info=~ /(\w+ (-?\d+ )+)/) { my $info =~ s/(\w+ (-?\d+ )+)//; } # Identifies the pattern in file. Identifies one or more words (\w+), +one or more #numbers(\d+),, also searches for new lines (-?) . my pro +fessor gave us this #pattern code so I might be totally wrong. I'm no +t very good with pattern yet.. my @nums = split(/:/,$info); #takes out colon where ever it may be in the $info scalar, @nums is a +array with #those values my $word = shift (@nums); # shifts first word my $sum = 0; # $sum is a empty scalar my $var = ($info); # i think $var is supposed to contain the numbers from $info foreach $var (@nums) { $sum = $sum + $var; } #this is to add the numbers together. Sum is empty, so with every new +number #that occurs it goes into sum and adds to whatever number is i +n var. i hope I'm #explaining that right. my %hash = ($word => $sum); #the new sum goes into the hash as a key and the color is in the list, + thats how #they associate with each other.. print @nums;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: A Beginner Needs Homework help
by Anonymous Monk on Apr 10, 2014 at 23:12 UTC | |
by Swizzlestix617 (Novice) on Apr 11, 2014 at 00:33 UTC | |
by Anonymous Monk on Apr 11, 2014 at 01:16 UTC | |
by Swizzlestix617 (Novice) on Apr 11, 2014 at 01:40 UTC | |
by Anonymous Monk on Apr 11, 2014 at 21:37 UTC | |
|
Re^3: A Beginner Needs Homework help
by Anonymous Monk on Apr 10, 2014 at 21:53 UTC | |
by Swizzlestix617 (Novice) on Apr 10, 2014 at 22:26 UTC | |
by Anonymous Monk on Apr 10, 2014 at 23:20 UTC |