The form generally has input as follows: Comment: comment 1 then a new line then comment two then a new line then comment three
I am trying to capture all three lines of this Comment: field. The script looks like: $/ = undef; while <>; if /^Comment:(\s*)(\w*)/ print $2; Hope this helps; Thanks Marc Morrison --- Michael Kelly <[EMAIL PROTECTED]> wrote: > On 2/23/02 3:52 PM, Marc Morrison > <[EMAIL PROTECTED]> wrote: > > > I have an online form that has a "Comments" field. > I > > need to extract ALL of the information from the > > comments field. > > > > Each "Comments" line begins with Comment: so the > > /^Comments/ works to match that, however the user > may, > > or may not enter a new line in their comments and > they > > may or may not start from the line where > "Comments" is > > written. > > It would help if you could give us some sample data, > but I think I know what > you're talking about. Is it something along the > lines of this? > > Comment: line 1 > Comment: line 2 > Comment: line 3 > > > Also there are no delimiting characters to search. > > And one more problem is that they rarely end the > > sentence with a period. The only good news is > that > > there are never more than 4 lines. But because > there > > is almost always a newline, I can't use: > > > > while <> > > > > because it searches line by line. > > > > I posted on line and got a very helpful response > to > > use: > > > > local $/ = undef; > > > > However I put this at the beginning of my script > and > > nothing matched. I am still using the while<>. > Is > > this what is messing it up? > > It might help if you posted the code you're using > right now. > > I'm really not sure if this is right (sample data > and code would help), but > this might work: > > ##### START CODE ##### > > # assuming this is the kind of data you're talking > about > $comments = <<_COMMENTS_; > Comment: line 1 > Comment: line 2 > Comment: line 3 > _COMMENTS_ > > my $data; > > # run through each line and collect the data > while ($comments =~ /^Comment: (.+)$/gm){ > > $data .= "$1\n"; > > } > > print "$data"; > > ##### END CODE ##### > > To examine the regex itself: > > /^Comment: (.+)$/gm > > The 'm' switch allows the ^ and $ to match at the > beginning and end of > lines, instead of the entire string, and the 'g' > option allows global > matching. The '(.+)' traps one or more of anything, > and sets it to $1. > > NOTE: This regex assumes there's a space after the > "Comment:". If you can't > be sure that there will be either remove the space > or replace it with " ?" > (space-question mark; matches 0 or 1 spaces). > > That said, I may have totally misunderstood your > problem. If so, just ignore > this email :) > > Hope that helps, > > -- > Michael > > > -- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > __________________________________________________ Do You Yahoo!? Yahoo! Sports - Coverage of the 2002 Olympic Games http://sports.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]