Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: frequency strings 2 files

by xyzzy (Pilgrim)
on Jul 06, 2012 at 04:21 UTC ( #980206=note: print w/replies, xml ) Need Help??

in reply to frequency strings 2 files

Zerost: until you are comfortable enough to code blindfolded, every program you write should start with the following two lines:

#!/usr/bin/perl -w use strict;

First: go over the problem, separate it into individual components. what do you need to do? what values do you need to keep track of? what are the steps that need to be taken? this is basic programming 101 stuff. before you write a single line of code, you need to be able to explain the exact procedure step by step (in pseudocode, English, pictures, whatever).

Second: look at the specific features of the problem and the language and how they work together. The files are given in a certain order, maybe that is telling you something. Perl has a handy mechanism to read input line by line, maybe you should use that.

Third: you have an incredibly useful resource at your disposal if you run into problems. It is called perldoc, and you can run if from the shell (it even works with windoze implementations of perl) or browse it online. It has sections for every topic and very detailed explanations for every built-in function, every operator, every special variable. READ IT!

Finally: do not ask the monks to do your assignment. Even if they give you a solution, it will most likely be obfuscated or use an overly-elegant, roundabout way to do it, and if your prof looks at it he will instantly know that you have no idea how or why it works. However, if you read the docs, used strict and warnings, tried an approach that seems to be valid and your code still does things you do not expect or understand, post it as a specific question, such as "Errors reading from filehandle" or "Hash keys aren't matching", provide your code, your expected output, your actual output, and your reasoning as best as you can understand the issue. Then you actually will get an answer explaining how that specific function or operator works, and you will learn how to use the language.

At the risk of being ostracized from the community, I will give you two huge hints.

  1. You can solve the problem with just two variables: a filehandle and a hash
  2. If you try to modify the value of a key that doesn't exist, it is autovivified (automatically created)

$,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
Happy, sober, smart: pick two.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980206]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2021-04-20 15:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found