in reply to Regex Split and Formatting
Read perlre. If you're in a rush read perlrequick. And if you find the learning curve too steep, take a step back and start with perlretut
Note, this isn't perfect. It assumes your end of line character is a linefeed. It also doesn't handle linefeeds in the 4th field. But then in the sample provided, it wasn't significant.
use strict; use warnings; my $data; localscope: { local $/; $data = <DATA>; my $i=1; while ($data =~ /\G((?:(?:[^,]*),){3}(?:[^\n]*\n))/g) { my $entry = $1; print "$i $entry"; $i++; } } 1; __DATA__ "123", "DEF123","this is test","C:\Abhinav\test.jpg" "456", "DEF456","this is test","C:\Matt\test.jpg" "726", "DEF726","this is test","C:\Matt\test.jpg"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex Split and Formatting
by thirdm (Sexton) on Apr 03, 2013 at 17:39 UTC |
In Section
Seekers of Perl Wisdom