Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(switch say);
- use Data::Dumper;
- my $file = $ARGV[0] or die("Please specify a file to read\n");
- if (!-e $file) {
- die("File '".$file."' doesn't exist\n");
- }
- my %words;
- open(my $file_h, $file);
- my $content = join(' ', <$file_h>);
- for (split(' ', $content)) {
- $words{length($_)} = $_;
- }
- my @keys = sort(keys(%words));
- say "The longest word was $words{$keys[-1]} with $keys[-1] characters"
Add Comment
Please, Sign In to add comment