Attempting to break up the line
#!/usr/bin/perl -w
with the following code
use strict;
use warnings;
my %words;
while (my $line = <>)
{
foreach my $word (split /:|,\s*|\/|!|\#|-/, $line)
{
$words{$word}++;
}
}
foreach my $word (keys %words)
{
print "$word: $words{$word}\n";
}
Is there an easier way to have the split command only split at words, numbers and underscores? Rather than setting all of these delimiters.
Attempting to get the output
usr: 1
bin: 1
perl: 1
Don't split, extract.
++$words{$_} for $line =~ /\w+/g;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With