in reply to converting txt to csv and formatting
You need to make some assumptions about the way your data is formatted. You have to check each line with something like the following:
if ( $line =~ /\A[0-9]/ ) { $phone = $line; # It's a phone number } elsif ( $line =~ /.*@.*/ ) { $email = $line; # It's an email address print "\"$name\",\"$phone\",\"$email\""; #Assumption - input data is + ordered name, phone, email. } elsif ( $line =~ /[\A[A-Z][a-zA-Z]+,/ ) { $name = $line; # It's a name } else { print "WARNING: I could not understand input line: $line\n"; }
Of course assumptions tend to be wrong the first time. You may have to adjust them later after checking the output. Also it's better to use a module to generate CSV, the print line above is for demonstrating the idea, not real production usage.
|
|---|