Re: Foreach question.
On Fri, 11 Jul 2003, Beckett Richard-qswi266 wrote: Guys, This is one I don't know how to approach at all. I've read a text file into @lines. I then process it like this... foreach (@lines) { last if /Next section$/; next unless (/match$/); chomp; process $_; } My data is random, but in this form: A line I want data from ending in match http://some.link/ A line I don't want data from ending in something else http://some.other.link/ ... A line I do want data from, light a match http://whatever ... Next section Everything was working fine, I was pulling out the required data, and doing what I wanted with it. Unfortunately, now they've decided that they want me to process the url on the next line as well as the first line, but only provided the line before matches. I have no idea where to start with this. Is it possible to pull 2 lines at a time from @lines, or something? Sure, just to a : $second_line=shift(@lines) ; when the first line matches. But in gereral, it's not good technique to read all the lines into an array so that you can work on each line. Instead just loop reading a single line, e.g. while(FH) { and then when you find a match you can do: $second_line=FH; [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Foreach question.
Whenever I need matches over multiples lines I generally read the text into one string (assuming its not too large) and then just match over newlines: $foo = some input text with newlines... @matches = $foo =~ /some pattern/sg; read up on the modifiers (s will match newlines), adjust your patten and you should be set. - Original Message - From: Beckett Richard-qswi266 [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, July 11, 2003 10:19 AM Subject: Foreach question. Guys, This is one I don't know how to approach at all. I've read a text file into @lines. I then process it like this... foreach (@lines) { last if /Next section$/; next unless (/match$/); chomp; process $_; } My data is random, but in this form: A line I want data from ending in match http://some.link/ A line I don't want data from ending in something else http://some.other.link/ ... A line I do want data from, light a match http://whatever ... Next section Everything was working fine, I was pulling out the required data, and doing what I wanted with it. Unfortunately, now they've decided that they want me to process the url on the next line as well as the first line, but only provided the line before matches. I have no idea where to start with this. Is it possible to pull 2 lines at a time from @lines, or something? Thanks. R. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs