Preparing data through a little bit of Perl
Archive - Originally posted on "The Horse's Mouth" - 2015-01-15 10:09:46 - Graham EllisA Java course - and yet I used Perl to sort out some incoming data for a new exericse overnight. That's not because Perl is "better" than Java - its just that it's more appropriate for the quick, one-off data reformat that I needed.
chop;
$lyne .= $_ . " ";
$k%=3;
$k++;
print "$lyne\n" if ($k == 3);
$lyne = "" if ($k == 3);
Run with the "-n" command line switch on my system, and passing in the data file I had, this combines groups of 3 lines into a single line. The perl is quick, easy to write and virtually unreadable later. Java would have been longer (much longer) but more readable (much more readable) later.
The data? It's at [here] for course download - it contains the names, weights and heights of a number of celebreties so that delegates can create star objects (perhaps with a special subclass for delegates who are know by something other that forname - surname (e.g. Ciara, and Catherine Zeta Jones).
Sample from the original file:
Courtney Love
5 feet 9 inches / 175.26 cms 123.46-134.48 lbs
Daniel Radcliffe
5 feet 5.5 inches / 166.37 cms 114.64-125.66 lbs
Sample from the data file (resulting):
Courtney Love 5 feet 9 inches / 175.26 cms 123.46-134.48 lbs
Daniel Radcliffe 5 feet 5.5 inches / 166.37 cms 114.64-125.66 lbs
Perl courses - see [here]