There's more than one way to do things | |
PerlMonks |
Re: Frequency occurence of same words in a file -- onelinerby Discipulus (Canon) |
on Mar 25, 2022 at 08:28 UTC ( [id://11142407]=note: print w/replies, xml ) | Need Help?? |
Hello geek12 and welcome to the monstery and to the wonderful world of perl! as you already get sane and wise answers, I propose you a oneliner solution (change " to ' around the code to run it on Linux):
You can use -MO=Deparse to have some clue on how to read it:
See perlrun for perl command line switches, but basically -l takes care of line ending (you are not chomp -ing lines!), -a does autosplit populating the @F array and -n wraps the code in a while loop without printing ( and -p does the same but printing). Braces in the part ..$F[1]}{print.. are a trick named Eskimo Greeting. See perlvar for $/ and @F You can explore these switches deparsing them one at time like in ( -e is for execute perl code, and -e 1 is just a null program): L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom
|
|