in reply to Help with split() function
#!/usr/bin/env perl use warnings; use strict; my $filename = shift; open my $test_fh, '<', $filename or die "Can not open file $filename: +$!\n"; while (<$test_fh>) { my @tokens = split; for my $token (@tokens) { if ($token =~ /\wp\w/i) { print $token, "\n" } } } close ($test_fh);
Prints out:
CPAN comprehensive expression. operator.
Please also note that I got rid of the @ARGV in the open line. While it is legal to do so, it is not usually done that way since @ARGV may contain several items, but open will only accept one filename. Please read about shift to understand what's going on there.
|
|---|