Internally, PerlNET uses Perl interpreter. This allows us to incorporate all the standard Perl features and expressions in our PerlNET programs. This means that all samples that we introduced in Part 1 may be compiled and executed in the .NET environment without any changes. Let us demonstrate this by a simple Core Perl program, the standard Perl script freq.pl for counting word occurrences, which we presented in Chapter 4. Here is the code for the script.
# # freq.pl # while(<STDIN>) { @words = split; foreach $word (@words) { $words{$word}++; } } foreach $word (sort(keys(%words))) { print "$word occurred $words{$word} "; }
Now, we may run the script either using Perl interpreter,
perl freq.pl
or by compiling into a .NET assembly and running the assembly:
plc freq.pl freq.exe < text.txt
In any case, we get the same result: All word occurrences in text from standard input are calculated and printed. Here is the output for both cases when the input was originated from the following file:
Almost everybody can learn Perl programming Not everybody likes to learn
Output:
Almost occurred 1 Not occurred 1 Perl occurred 1 can occurred 1 everybody occurred 2 learn occurred 2 likes occurred 1 programming occurred 1 to occurred 1
18.117.234.225