RE: regular expression in a variable
- From: tjohnson@xxxxxxxxxxxx (Timothy Johnson)
- Date: Tue, 28 Feb 2006 12:29:32 -0800
You're not being very clear what it is you're trying to do. I can see
two ways of interpreting this.
Regular expressions are mostly for checking the format of text to see if
certain conditions "match". You might be asking how to do this:
########################
use strict;
use warnings;
opendir(DIR,".") or die("Couldn't open the current directory!\n");
my @files = readdir(DIR);
foreach my $file(sort @files){
if($file =~ /(.*test.*)/i){
print "MATCH: $file\n";
}
}
#########################
You can also use the $1 variable to capture the last text string that
matched the part of the regular expression between the parentheses.
If, on the other hand, you're trying to generate file names, then
regular expressions aren't what you're looking for.
my $prefix = "123";
my $postfix = "456";
my $filename = $prefix."test".$postfix;
print $filename."\n";
-----Original Message-----
From: Curt Shaffer [mailto:cshaffer@xxxxxxxxx]
Sent: Tuesday, February 28, 2006 12:20 PM
To: beginners@xxxxxxxx
Subject: regular expression in a variable
I need to set a variable to a filename where only 1 section of the file
is
static.
For example:
$filename =~ /test/;
Where the following:
Print "$filename\n";
Would produce:
123test456.txt
.
- Follow-Ups:
- RE: regular expression in a variable
- From: Curt Shaffer
- RE: regular expression in a variable
- Prev by Date: Re: num to alpha
- Next by Date: Re: regular expression in a variable
- Previous by thread: CPAN for the first time
- Next by thread: RE: regular expression in a variable
- Index(es):
Relevant Pages
|
|