Mark Sony wrote: > Hi all, > > I am writing a program which will print variety of matches > having > keywords like insert,delete etc from another file .For this I > wrote a couple of sub routines one of which returns an > array(having the comments removed ).Then I face the problem : > A part of that array is : > > CURSOR c_efc(l_worker_id IN NUMBER) > insert into awk_losers( > l_total_workers IN NUMBER, > l_pk1 IN NUMBER, > l_bg IN NUMBER) IS > SELECT * from dual; > insert > into awk_managers (aba.rowid, > aba.absence_attendance_id, > aba.abs_information15, > aba.abs_information9, > aba.abs_information11, > > And I want to get the two tablenames (awk_managers and > awk_losers) > .So I am using this : > > sub find { > my $pcount =0; > foreach $line(@array){ > if ($line =~/insert(.*)into/gi){ > print "$'\n"; > }else { > $pcount++ > } > } > } > > It so happens that I get awk_losers but not awk_managers.It > seems > that multiple line matching is not happening.Is this because I > am > inputting an array? Can anyone guide me in the correct > direction...Also whats the best methhod for matching multiple > lines which may have any space or tab or newline in between them
Two reasons why your match isn't working: - First, you're trying the match on only on line at a time, so /insert(.*)into/ is being found correctly in the line "insert into awk_losers(\n" but not in either "insert\n" or "into awk_managers (aba.rowid,\n" - Second, even if you were matching the full text of the file, the /./ metacharacter won't match a newline, so you still won't find "insert\ninto awk_managers (aba.rowid,\n" You could correct this by using the /s modifier like this if ($line =~/insert(.*)into/gis) but why not put what you really mean, which is to match contiguous whitespace if ($line =~/insert\s+into/gis) which will also match "\n" for you. Of course you need all of the SQL file in a single string for it to find both 'insert' and 'into', which is fine unless your file is huge. Try this my @tables = do { local $/ = undef; <DATA> =~ /insert\s+into\s+(\w+)/gi; }; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]