ArifS has asked for the wisdom of the Perl Monks concerning the following question:
OUTPUTmy $directory = ".\\folder"; opendir (DIR, $directory) or die $!; while (my $fldr = readdir(DIR)) { if ($fldr =~ m/log?/){ print $fldr, "\n"; } }
I am only interested in the first file. How can I print the first match only that ends with .log? Tried with $fldr[0], didn't work. Tried, m/log?/... thinking that ? symbol will trigger not to be greedy, but still didn't work.(10.10.10.1).log (10.10.10.2).log .................. .................. Press any key to continue . . .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex 1st match only
by davido (Cardinal) on Oct 28, 2014 at 16:55 UTC | |
by Laurent_R (Canon) on Oct 28, 2014 at 20:05 UTC | |
by BillKSmith (Monsignor) on Oct 28, 2014 at 21:49 UTC | |
by Laurent_R (Canon) on Oct 28, 2014 at 22:25 UTC | |
|
Re: regex 1st match only
by ww (Archbishop) on Oct 28, 2014 at 16:18 UTC |