Dear Brethren,
I have been working on a small script that is supposed to take a text that has been formatted into two columns (with spaces in between the columns) and convert this text into single-column format.
So far, the script does what it is supposed to do... mostly...(ahem) What it does not do properly is handle non-existent left-hand columns--ones that are just spaces. When it processes those lines, the actual right-hand text lands in my @left array.
So, can someone point me in the right direction?
Oh, yes. And a bit of conceptual help...no, no smoove music.
LHC RHC 111111111111 222222222222 444444444444 555555555555 666666666666 777777777777 888888888888
In other words, it puts "4" into the slot for "3" (which is a bunch of spaces). I tried prefiltering with a substitution regexp, something like s/(\s{31,})/x$1x/;, but it didn't work.
'Nuff said
#!/usr/bin/perl use strict; use warnings; my $input = shift; my @first; my @second; my $counter = 0; if (!$input) {die "\nUsage: $0 inputfile\n"}; print STDERR "\nConverting file $input.\n"; open (INFILE, "< $input") or die "\nThe input file cannot be opened: \ +!\n"; while ( <INFILE> ) { chomp; s/^\s+//g; # get rid of leading spaces s/\n//g; ($first[$counter],$second[$counter]) = split(/[ ]{3,30}/,$_); # pr +etty much arbitrarily defined min and max $counter++; } close(INFILE); print "First column output:\n\n@first\n\n"; print "Second column output:\n\n@second\n\n";
Any other suggestions for the improvment of my code are welcome, too.
--
Allolex
In reply to making a single column out of a two-column text file by allolex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |