On Thu, 15 Jul 2004 16:26:28 -0600, John Black wrote:
Hi,
I need to match the following pattern with a file,
begin <some string>
<some thing this line>
<some thing this line>
......
end
I check the web, it says I should use pattern modifier s & m, so I
write it this way,
while (<MyFile>){
if (/^(\s*)begin(.*)^(\s*)end/smi){
... call my function...
}
}
But it never matches the pattern, do you see the problem?
Thanks!
Hi,
This won't work because you are reading the file one line at a time. You
may want to read the whole file at one time by using this:
local $/; # slurp mode ( to read the file into a string )
my $content = <MyFile>;
if ( $content =~ /^\s*begin\s+(.+?)\s+end$/smi ) { CallFunc(); }
Also, check the regular expression you are using as it doesn't seem
to be right. I've modified it in the example above but I'm not sure if it
is what you want.
Note that reading the file at one time can be memory-intensive if the file
is too big.
good luck,