Note that there are some explanatory texts on larger screens.

plurals
  1. POSplit file in columns, filter and print them
    primarykey
    data
    text
    <p>I have been given an assignment to do. Here are the instructions:</p> <p>Write a Perl program to accomplish each of the following on the file solar.txt (see link at the class homepage)</p> <ol> <li>Print all records that do not list a discoverer in the eighth field.</li> <li>Print every record after erasing the second field. Note: It would be better to say "print every record" omitting the second field.</li> <li>Print the records for satellites that have negative orbital periods. (A negative orbital period simply means that the satellite orbits in a counterclockwise direction.)</li> <li>Print the data for the objects discovered by the Voyager2 space probe.</li> <li>Print each record with the orbital period given in seconds rather than days.</li> </ol> <p>About solar.txt file: This file contains lines of 9 items, the first being: Adrastea XV Jupiter 129000 0.30 0.00 0.00 Jewitt 1979 in alphabetical order by the name of the planet or moon (first field). The text in [] is the corresponding field from the line above.</p> <p>The fields in this file are:</p> <ol> <li>Name of planet or moon [Adrastea]</li> <li>Number of moon or planet (roman numerals) [XV]</li> <li>Name of the abject around which the satellite orbits [Jupiter]</li> <li>Orbital radius (semimajor axis) in kilometers [129000]</li> <li>Orbital period in days [0.30]</li> <li>Orbital inclination in degrees [0.00]</li> <li>Orbital eccentricity [0.00]</li> <li>Discoverer [Jewitt]</li> <li>Year of discovery [1979]</li> </ol> <p>I am stuck on the first instruction. I can read in the "solar.txt" file, but after that I can't do it or can't figure it out. Splitting the array seems like the best option, but is not working for me at the moment. Here's the code:</p> <pre><code>#usr/bin/perl use warnings; use strict; open (SOLAR_FILE, "C:/perl_tests/solar.txt") or die "Could not open the file!"; my @array = (&lt;SOLAR_FILE&gt;); close (SOLAR_FILE); for (my $i = 0; $i &lt; 8; $i++) { my @tempArray = split(/ /, $array[$i]); if ($tempArray[$i] eq "-") { print "@tempArray"; } } open (SOLAR_FILE, "C:/perl_tests/solar.txt") or die "Could not open the file!"; my @array = (&lt;SOLAR_FILE&gt;); close (SOLAR_FILE); for my $record (@array) { my @tempArray = split(/ /, $record); if ($tempArray[2] eq qw(Jupiter, Uranus, Saturn, Pluto, Mars, Sun, Neptune, Earth) s//???/" "/g; #I know something goes where the (???) are, but I'm not sure how to do it. { print "@tempArray"; } } </code></pre> <p>Also, I'm not sure how to start the other 4. If anyone could point me in the right direction, that would be helpful.</p> <p>EDIT: Here's the info from the file:</p> <pre><code>Adrastea XV Jupiter 129000 0.30 0.00 0.00 Jewitt 1979 Amalthea V Jupiter 181000 0.50 0.40 0.00 Barnard 1892 Ananke XII Jupiter 21200000 -631 147.00 0.17 Nicholson 1951 Ariel I Uranus 191000 2.52 0.00 0.00 Lassell 1851 Atlas XV Saturn 138000 0.60 0.00 0.00 Terrile 1980 Belinda XIV Uranus 75000 0.62 0.03 0.00 Voyager2 1986 Bianca VIII Uranus 59000 0.43 0.16 0.00 Voyager2 1986 ... Leda XIII Jupiter 11094000 238.72 27.00 0.15 Kowal 1974 Lysithea X Jupiter 11720000 259.22 29.00 0.11 Nicholson 1938 Mars IV Sun 227940000 686.98 1.85 0.09 - - Megaclite XIX Jupiter 23911000 ? ? ? Sheppard 2000 Mercury I Sun 57910000 87.97 7.00 0.21 - - Metis XVI Jupiter 128000 0.29 0.00 0.00 Synnott 1979 Mimas I Saturn 186000 0.94 1.53 0.02 Herschel 1789 Miranda V Uranus 130000 1.41 4.22 0.00 Kuiper 1948 Moon I Earth 384000 27.32 5.14 0.05 - - Naiad III Neptune 48000 0.29 0.00 0.00 Voyager2 1989 Neptune VIII Sun 4504300000 60190.00 1.77 0.01 Adams 1846 ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload