On Fri, Oct 04, 2002 at 03:59:10PM +0100, nemesis wrote: > >Hi all, > >I have a bunch of jokes that people have forwarded me over the years[1] and >they all have really bad formatting [2]. I am lazy and want to do as much >formatting of the jokes as I can automatically. I have tried this piece of >code to get rid of any '>' or whitespace charachters before the 'beginning' >of each line of the text, but it just returns the same text as before: > >foreach my $line (@body) { > $_ = $line; > s/^(?:>|\s)*(.*)$/$1/g; > print; >} > >Any ideas what I am doing wrong here[3]
This is rather more complex than it needs to be. Why not: foreach (@body) { # it goes into $_ automatically s/^(>\s*)+//; print; } ? (It works on your example.) Or even s/^[>\s]+//; (as Nick's pointed out while I was writing this)? The short answer is that it's not your regex that's wrong, it's messing about with $_. Roger