in reply to regular expression for filename
Now, if you need to find all the files in a directory that end in .txt, you could use glob:#!perl #xyz.pl use strict; use warnings; my $file = '3-4-111.txt'; open FH, '<', $file or die $!; my(@lines) = <FH>; @lines = sort @lines; foreach my $line(@lines) { print $line, "\n"; } close FH;
To answer your first question---A regex for finding a file with the extension .txt would simply be: /\.txt$/.#!/usr/bin/perl use strict; use warnings; my @files = glob('/your/dir/*.txt'); foreach my $file(@files) { print $file, "\n"; }
|
|---|