We don't bite newbies here... much | |
PerlMonks |
Re: questionsby dvergin (Monsignor) |
on Mar 05, 2003 at 08:23 UTC ( [id://240552]=note: print w/replies, xml ) | Need Help?? |
Let's speculate on a context that might help make sense of this snippet:
Prints: demo example from interesting is of perlmonks post this In answer to your specific question, exists $stopwords{$l}?():$l uses the ? : trinary operator to say: If $l exists in the %stopwords hash return nothing (specifically, a null list), otherwise return $l itself. (Note that it is dollar-el, not dollar-one.) Considering my imagined context for this snippet, we have a list of common (uninteresting) words commonly called stopwords. These we want to ignore. So we read through the file (I used the DATA filehandle) a line at a time. For each line we split out the words, force each one to lowercase, drop the stopwords, and then use the others to specify a hash slice on the hash called %D2. Every key in that slice (whether new or pre-existing at that point) is set to an empty value (I'm skipping over some nuances here). When we have finished with all the data, the %D2 hash contains an entry for every "interesting" word in the data set (ignoring duplicates). Update: Trying to stay focused on the stated problem, I avoided the issue of the variable name $l (dollar-ell). Nkuvu is correct to point this out. I would also add that this code will return odd results for text containing words with apostrophes or hyphens: "isn't" and "good-by" will be reported as: "isn", "t", "good", "by". So this code is not recommended for Real Text in a situation where accuracy of results matters.
------------------------------------------------------------
In Section
Seekers of Perl Wisdom
|
|