I don't think my perl skills are that bad these days, but I have a terrible mental block thing going on with hashes. I want to be able to do something now that I know can only be sensibly done with a hash.
This isn't the actual problem - but it explains what I want to do. I just need a kick in the right direction so that I can implement this in my own script now and others in the future.
Imagine I have a text file that looks like this.
HIT: code2
HIT: code3
HIT: code1
HIT: code90
HIT: code2
HIT: code34
HIT: code90
I would like to be able to create a hash that, for when, for example, code90 is first hit, its 'counted' (i.e. a variable is increased by one) and goes into the hash and is stored. As I am only interested in whether code90 exists, rather then how many times it exists, if I then encounter it again, I need to check the hash to see whether I have already counted it. If I have, I want to ignore that entry and move onto the next in the text file.
How do I go about doing this please?
Any help much appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.