2 Replies - 305 Views - Last Post: 07 January 2014 - 09:22 AM Rate Topic: -----

#1 xesecre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 29-July 08

How can I iterate though loop and print later after it finds my regex

Posted 07 January 2014 - 07:08 AM

I am using a foreach loop containing a regular expression.
I can not print lines one at a time before it finds the match for my regex
I need to go through the loop and gather up the lines
into a separate array so I can print the whole thing in my file of choice
Your help is appreciated



open (OUT_N, ">$file_out1") or die "$!";
open (OUT_9, ">$file_out2") or die "$!";




foreach $filtered (@array)
{


$filtered = @array2;             #this is the one I have having problems with because it just replaces each line with the next line instead of collecting them 

   if	($filtered =~ m/\s{1,}\d{1,}.\d{1,}\s{1,}\d{1,}.\d{1,}\s{1,}\d{1,}.\d{1,}\s{1,}(?<pattern>\d{1,}.\d{1,})\s{1,}\d{1,}.\d{1,}\s{1,}\d{1,}.\d{1,}/)
	{
	$winning_number =  "$+{pattern}"; 			
	last;
        }                
			
}

			
if ($winning_number =~ /^0.00$/)
{
print OUT_N @array2;
}			

elsif             


($winning_number =~ m/\d*[1-9]\d*/)

{
print OUT_9 @array2;
}

This post has been edited by xesecre: 07 January 2014 - 07:14 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How can I iterate though loop and print later after it finds my regex

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3614
  • View blog
  • Posts: 12,433
  • Joined: 12-December 12

Re: How can I iterate though loop and print later after it finds my regex

Posted 07 January 2014 - 08:36 AM

What is that? Perl?
Was This Post Helpful? 0
  • +
  • -

#3 xesecre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 29-July 08

Re: How can I iterate though loop and print later after it finds my regex

Posted 07 January 2014 - 09:22 AM

Yes
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1