I would do it like this:
#!/usr/bin/env perl + use strict; use warnings; use IO::All; my $file = shift || die qq(No file specified!); my @lines; my $line = 1; my @found = grep { $_->name =~ /.+\/$file$/i } io(q(.))->all; die qq($file not found) unless @found; @lines = map { $_ = $line++ . qq( $_) } io( $found[0] )->slurp; print for @lines; __END__ 1 #!/usr/bin/env perl 2 3 use strict; 4 use warnings; 5 use IO::All; 6 7 my $file = shift || die qq(No file specified!); 8 my @lines; 9 my $line = 1; 10 11 my @found = grep { $_->name =~ /.+\/$file$/i } io(q(.))->all; 12 13 die qq($file not found) unless @found; 14 15 @lines = map { $_ = $line++ . qq( $_) } io( $found[0] )->slurp; 16 17 print for @lines; 18 19 __END__ 20 21
Please see also IO::All, grep, map and TMTOWTDI.
Regards, Karl
«The Crux of the Biscuit is the Apostrophe»
In reply to Re: School assignment
by karlgoethebier
in thread School assignment
by mb92
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |