in reply to Reguar expression
here's the data in a text file...
This is first sentence. This is second sentence.
You can try this for a start...
I have written the comments next to the pattern match so you can see what's happening at each line. If you want to know what the symbols mean, its better to look at a table of regular expression symbols in perl. There is no other short cut. however, this is only one of ways you could do this. I'm sure people can come up with shorter, fancier and even easier ways to do this kind of pattern match. This why you need to post your code, and provide better problem descriptions... so people can suggest different things, and then you learn much more.use strict; open (INP,"data.txt") || die "Cannot open data.txt\n"; while (my $line = <INP>) { if ($line=~/^This\b/i) { # first word This if ($line !~ /\bfirst\b/i) { # without word first if ($line =~ /\.$/) { # . at the end print $line; } } } }
perliff
-with perl on my side
"If you look at the code too long, the code also looks back at you"
|
|---|