Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: I need help with opening a directory and reading files in that directory.

by wjw (Priest)
on Sep 04, 2015 at 23:21 UTC ( #1141071=note: print w/replies, xml ) Need Help??


in reply to I need help with opening a directory and reading files in that directory.

There are a few assumptions made here

  • Your file names have a '-' in them
  • You file names end in '.txt'
  • (odd for a music file)

I ran you code and it is fine as far as it goes. You are not using your '%songs' hash, so that must be just left over. The '%length' hash is fine as close as I can tell.

What is not happening? Use the debugger (perl -d 'your_perl_script') and watch to see if what you expect to happen does. Hope that helps.

...the majority is always wrong, and always the last to know about it...

A solution is nothing more than a clearly stated problem...

  • Comment on Re: I need help with opening a directory and reading files in that directory.

Replies are listed 'Best First'.
Re^2: I need help with opening a directory and reading files in that directory.
by brawal128 (Novice) on Sep 05, 2015 at 01:26 UTC

    Thanks for the response wjw. I issue that I was having was, I was able to open the directory and get the files based on the "-" and ".txt", but I was unable to figure out how to open the ".txt" files and pull the information out to print the total amount of music the artists had in each file. Honestly, the class that I'm taking is through Oreilly School of Technology and the instructions on the assignments are really vague. So, I get to spend most of my time trying to figure out what it is they are wanting. We only have a couple of guys at work that deal with Perl and I'm a third that is trying to learn without formal training.

    I appreciate you telling me about the debugger -d 'perlscript.pl'. I would not have been aware of that and I probably would have found out about it much later when I really needed yesterday(If you know what I mean). I figured that I was setting the $values of the $hash{$keys} properly and I was also told that you could add as many keys to a hash as you wanted. Is that true?

    Thanks, Brandon

      I was also told that you could add as many keys to a hash as you wanted. Is that true?
      The short answer is yes.

      With two caveats, though:

      1. Hashes can't have duplicate keys, so that if you have twice the same key in your input, you'll end up with only one entry (probably the last one, depending on how you populate the hash exactly) in your hash.

      2. The other limitation is sheer size of the data compared to the available memory on your computer. If you have tens of millions of hashes entries, you might end up at some point with an "out of memory" exception. To give a very rough idea of the limit, with one of the specific servers I am using at work, I can usually store 5 to 8 million hash entries (depending on the size of the keys and values), but usually not much more. But the limitation is only with the memory available on the platform, not with hashes or with Perl in general.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-11-13 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (147 votes). Check out past polls.

    Notices?