Very Simple Need

Posted by creacon on 2017-08-28 09:43

I'm completely new to PERL, and here, so I don't know if this is even the correct forum for my need. If not, please let me know where to post.

I have a need that should be so super simple, yet I've been searching for every scripting product I can find but they're all so overwhelming the understand, and I'm in a great time crunch. Also this is for a zero budget volunteer organization that my wife uses. My need is as follows:

I'll have a text file which contains about 30 - 40 pages of "Conceptual" name, address and contact information, each consisting of 9 text lines, separated by a blank line. I need to read that file and concatenate the nine lines of each record into a tab separated string, then write the strings to a .csv text file.

I've done this sort of thing in various programming languages a gazillion times over my 58 year IT career, but now I'm stumped. I installed Strawberry PERL, and I can't even find its command set, let alone any real down to earth online help. What little code I have been able to find makes me think that I've never even seen a computer in my entire life, let alone having been programming them for over a half century (my first programming was on a UNIVAC I in machine language).

I normally don't ask for this kind of help, but I'm in a time crunch to get this project done for my wife.

ActiveState Staff
Tue, 2017-08-29 09:12

This one seems like it might be similar to what you want. There's a bit of mid-level discussion of the best mechanics that might be unnecessary.

Some Perl conventions are also helpful.
$fh is often used as the variable for a file handle
s/\s+/ / is a regular expression substitution - Think sed or vi with slightly different rules
$_ is one of the "Special Variables" that Perl is infamous for. Special Variables are shorthand for commonly used values:

A lot depends on the data itself, and a task that seems trivial can get insane if the data isn't predictable. The typical advice for anything other than super-basic data (no commas in the data, no unicode, no tabs or spaces in unexpected places) would be to use a well known module like Text-CSV (which you might have to add or not; it's likely to be pre-installed.)

Perl's docs are available online, even if you don't have local copies with your Perl

creacon | Wed, 2017-08-30 09:32

Hi and thank you for the links. The first one looks to be on all fours with my need, but Not being the least bit familiar with PERL, I'm confused about how to tailor it to my situation.

The other links are somewhat overwhelming to my 85 year old gray cells; I'd have to do a lot of studying which, for this project, I don't have time for, which is why I haven't just purchased a book to learn the product.