in reply to Re: Re: Re: Need method to create Regular expression for known pattern in the middle of a line
in thread Need method to create Regular expression for known pattern in the middle of a line
The only change you need to make to the code I suggested would be to to use Text::CSV or similar to split your CSV elements up. This will correctly deal with commas,"within, quotes,",,,and,only,split,on,the,unquoted,commas
use Text::CSV; my $csv = Text::CSV->new(); while(<DATA>) { my ($name, $data) = split "="; $csv->parse($data); my @data = $csv->fields(); for my $i ( 0.. $#data ) { next unless $data[$i] eq 'ResGen'; # found a ResGen so see what we had 3 commas ago (do bounds chec +k to0) next if $i -3 < 0; my $back_a_bit = $data[$i -3]; print chop($back_a_bit) eq '"' ? "$name: Found quote\n" : "$name +: No quote\n"; } }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|