Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
I'm making a series of lists that I want to cobble together and eventually be able to print out with some reasonable spacing and formatting. If the process works, eventually, this particular list of things I fear will grow smaller and more-manageable. For the purpose at hand, I am to read them to a third party when I'm done compiling them, so I will have to have a hard copy that would come from a windows-based machine. I notice that anything I print off now that I've written on this linux partition gets rendered without any carriage returns, so that's definitely an issue. I've decided to handle them as arrays, so I've made my lists to begin with 0:
$ cat fears2.txt 0. Dying 1. Abject poverty 2. Being homeless 3. Cancer, disease $ cat causes2.txt 0. It's everyone's greatest terror, likely laden with pain. 1. My earning power has been decreasing and a regime is on the ascenda +nce that wants to crush my class. 2. It's awful and the result of 1. 3. It runs in the family and can happen spontaneously with appreciable + probability. It's expensive. $
I zip these together with "exists because" between item and same-numbered cause. Here's the caller, callee, and output:
#!/usr/bin/perl -w use strict; use 5.010; use lib "template_stuff"; use steps1; # main data structure my %vars = ( fears => 'fears2.txt', causes => 'causes2.txt', width => 50, ); my $rvars = \%vars; my $return = pop_texts( $rvars ); say "returned was \n $$return"; __END__
package steps1; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( pop_texts ); sub pop_texts { use strict; use 5.010; use File::Slurp; my ($rvars) = shift; my %vars = %$rvars; my @fears = read_file( $vars{fears} ); my @causes = read_file( $vars{causes} ); for (@fears) { s/\s+$/ /; } for (@causes) { s/^\d+\./exists because/; } #say "causes are @causes"; my $text1 =''; for my $i ( 0 .. $#causes ) { $text1 = $text1 . $fears[$i] . $causes[$i] . "\n"; } my $reftext = \$text1; return $reftext; } 1;
$ perl fears1.pl returned was 0. Dying exists because It's everyone's greatest terror, likely laden + with pain. 1. Abject poverty exists because My earning power has been decreasing +and a regime is on the ascendance that wants to crush my class. 2. Being homeless exists because It's awful and the result of 1. 3. Cancer, disease exists because It runs in the family and can happen + spontaneously with appreciable probability. It's expensive. $
Q1) How do I change the unwanted capitalization of the beginning letter in the cause?
Q2) How do I constrain the text to the width indicated in the main data structure, and on a windows machine? Should I use a differing file extension?
Thanks for your comment,
|
|---|