Hi Monks!
I have a subroutine that essentially stores all of the text from files held in a specific folder into a hash (%corpus). The idea is that you specify the folder when you call the subroutine. This subroutine has been written and used by someone with a lot more coding experience than me, so I can be sure that it is not the problem.
What I want to do is 1) call the subroutine (getCorpus); 2) specify the folder that I want it to work on; 3) instruct it to store its output into a new hash (%mycorpus), and then I want to print out the contents of this hash.
I’ve been browsing the PerlMonk archives for any similar situations to see if I could solve the problem myself, and I’ve managed to cobble together the code below from various places (notably Re: easiest way to print the content of a hash?), but I am quite obviously making some big mistakes that I don't have the skills, as of yet, to spot (as evidenced by the various error messages it returns (reproduced below the code)
I haven't uploaded the original subroutine here because I'm not sure about the etiquette of making someone else's code available without their consent. But essentially the subroutine comes first and then I write:
%mycorpus = getCorpus("C:\Users\li\test") #line 1 foreach (sort keys %mycorpus) { print "$_ : $mycorpus{$_}\n"; }
In line 1, I am trying to call the subroutine (named getCorpus), tell getCorpus what folder I want it to operate on, and store the output of the subroutine into a new hash named %mycorpus. Then in lines 2 and 3, I attempt to print the contents of %mycorpus. The error messages returned for this particular attempt are as follows:
Any guidance on this would be greatly appreciated.Operator or semicolon missing before %mycorpus at get_corpus.pl line + 51. Ambiguous use of % resolved as operator % at get_corpus.pl line 51. Can't modify modulus (%) in scalar assignment at get_corpus.pl line 52 +, near ") foreach " syntax error at get_corpus.pl line 52, near ") {" Execution of get_corpus.pl aborted due to compilation errors.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |