I am new to Perl and I have these codes but I am not quite understand the regular expression here. Can any1 please explain to me?
Code:
$csv = "test.csv";
open(DAT, $csv) || die("Cannot Open File");
while (<DAT>) {
my @new = ();
push(@new, $+) while $_ =~ m{ #what does these means
"([^\"\\]*(?:\\.[^\"\\]*)*)",?
| ([^,]+),?
| ,
}gx;
push(@new, undef) if substr($_, -1,1) eq ',';
my $string = format_string(@new);
my $query = qq{Insert into person_info VALUES ($string)};
print $query, "\n";
}
sub format_string {
my $string;
foreach (@_) {
if (/[^\d]/) { #what does these mean
$string .= qq{"$_",};
} else {
$string .= qq{$_,};
}
}
return substr($string, 0, -1);
}
Comment