hello need help with if statement working with regular expression

Help, I need to go through lines till I find something them stop

Page 1 of 1

2 Replies - 891 Views - Last Post: 18 December 2008 - 10:17 AM

#1 xesecre   User is offline

  • New D.I.C Head

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

hello need help with if statement working with regular expression

Posted 17 December 2008 - 05:35 PM

Hello, can someone please help me
I want the loop to end when it finds the line with STARTDBM in it and print those lines only
as soon as it finds that word it will stop the loop
thanks so much , keep in mind I release that if I was to use array[-1] I could take off that last row but that isnt what I am trying to accomplish, there will be many more rows following that header in a list




here is the data
 %!
XGF
[(solutionsinc) (abs132664)] SETPROJECT
500 SETBUFSIZE
(~) SETDBSEP
(abs132664.dbm) 3  STARTDBM
barcode1~endorse1~fullname1~company1~add11~add21~city1~st1~zip1~field11~field21~vis1~seq1~seq11




here is my code .......... this is just a speculation of some of the parts I need to accomplish this

foreach $string (@array)
{
if ($string == m/STARTDBM/g;)
{}
endif
}



thanks for your time, Johnny

Is This A Good Question/Topic? 0
  • +

Replies To: hello need help with if statement working with regular expression

#2 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: hello need help with if statement working with regular expression

Posted 17 December 2008 - 08:21 PM

What language are you using? Perl? There is no "== " regexp0 binding operator in perl and no "endif" command.

You bind a regexp to a scalar with =~ or other proper binding operator and use "last" to break out of a for/foreach/while loop.
Was This Post Helpful? 0
  • +
  • -

#3 xesecre   User is offline

  • New D.I.C Head

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

Re: hello need help with if statement working with regular expression

Posted 18 December 2008 - 10:17 AM

Hey Kevin
thanks for the help
you made me understand this one

this is what I did

@array = (<FILE>);



foreach $line (@array)

{
print OUT "$line";
if ($line =~ m/STARTDBM/g)  {last;}
}


I was not aware of the LAST command
you have been extemely helpful and I really appreciate it
John
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1