in reply to Re^2: Help with Creating a Table from array ref I parsed in
in thread Help with Creating a Table from array ref I parsed in
Hi TIMTOWTDI,
I am a little lost trying to figure out how your script works.
I read Perl #sprintf FORMAT, LIST and could not understand how your "format STDOUT" works. Can you explain it? The Perldocs I read do not have the format you presented here for your script
Say, if I were to "left-justify" each column, how can I add the "-" to your "format STDOUT" statement and be left-justified? Also, how to manipulate the spacing in between columns?
I's like the table to look like this below, perhaps, I can understand your format statement works if I see it...maybe?
MM_STD_gate 152.401574 -22.047244 mils 3871.000000 -560.000000 microns RFN_a 337.244094 0.787402 mils 8566.000000 20.000000 microns RFN_b 366.181102 0.787402 mils 9301.000000 20.000000 microns RFN_c 376.929133 0.787402 mils 9574.000000 20.000000 microns RFLR 366.181102 -10.6299921 mils 9301.000000 -270.000000 microns MM_STD2_gate 259.488188 -22.047244 mils 6591.000000 -560.000000 microns RBASE_right_2 -366.181102 -33.464566 mils -9301.000000 -850.000000 microns
This is your code below with the edit to allow a longer string for the 1st column
#!/usr/bin/env perl use strict; use warnings; my @fields; # For the longer 1st Column name, I added some more spaces so it won't + concat the name. NOt sure how the left-justify can be done with this + format STDOUT statement? format STDOUT = @<<<<<<<<<<<< -@#####.###### @####.###### @<<<<<< @fields . while (my $line = <DATA>) { chomp $line; @fields = split /\s+/, $line, 4; unshift @fields, ' ' if 4 > @fields; write; } # All four columns should be left-justified and should line up whether + it is a positive or negative number. __DATA__ MM_STD_gate -61.771653 -45.472441 mils -1569.000000 -1155.000000 microns RFN_a -91.102362 68.307087 mils + -2314.000000 1735.000000 microns RFN_b -62.165354 68.307087 mils + -1579.000000 1735.000000 microns RFN_c -51.417322 68.307087 mils + -1306.000000 1735.000000 + microns MM_STD2_gate 259.488188 -22.047244 mils 6591.000000 -560.000000 microns RBASE_right_2 366.181102 -33.464566 mils 9301.000000 -850.000000 microns
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Help with Creating a Table from array ref I parsed in
by hippo (Archbishop) on May 16, 2022 at 08:40 UTC | |
Re^4: Help with Creating a Table from array ref I parsed in
by dbuckhal (Chaplain) on May 16, 2022 at 04:57 UTC |