QuestionQuestion

Part 1:
Write a Perl program to accomplish each of the following on the file solar.txt
1. Print all records that do not list a discoverer in the eighth field.
2. Print every record after erasing the second field. Note: It would be better to say "print every record" omitting the second field.
3. Print the records for satellites that have negative orbital periods. (A negative orbital period simply means that the satellite orbits in a counterclockwise direction.)
4. Print the data for the objects discovered by the Voyager2 space probe.
5. Print each record with the orbital period given in seconds rather than days.

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.
The fields in this file are:
1. Name of planet or moon [Adrastea]
2. Number of moon or planet (roman numerals) [XV]
3. Name of the abject around which the satellite orbits [Jupiter]
4. Orbital radius (semimajor axis) in kilometers [129000]
5. Orbital period in days [0.30]
6. Orbital inclination in degrees [0.00]
7. Orbital eccentricity [0.00]
8. Discoverer [Jewitt]
9. Year of discovery [1979]

Solar.txt file
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
Caliban XVI Uranus 7169000 -580 140. 0.08 Gladman 1997
Callirrhoe XVII Jupiter 24100000 ? ? ? Sheppard 2000
Callisto IV Jupiter 1883000 16.69 0.28 0.01 Galileo 1610
Calypso XIV Saturn 295000 1.89 0.00 0.00 Pascu 1980
Carme XI Jupiter 22600000 -692 163.00 0.21 Nicholson 1938
Chaldene XXI Jupiter 23387000 -733.7 165.2 0.238 Sheppard 2000
Charon I Pluto 20000 6.39 98.80 0.00 Christy 1978
Cordelia VI Uranus 50000 0.34 0.14 0.00 Voyager2 1986
Cressida IX Uranus 62000 0.46 0.04 0.00 Voyager2 1986
Deimos II Mars 23000 1.26 1.80 0.00 Hall 1877
Desdemona X Uranus 63000 0.47 0.16 0.00 Voyager2 1986
Despina V Neptune 53000 0.33 0.00 0.00 Voyager2 1989
Dione IV Saturn 377000 2.74 0.02 0.00 Cassini 1684
Earth III Sun 149600000 365.26 0.00 0.02 - -
Elara VII Jupiter 11737000 259.65 28.00 0.21 Perrine 1905
Enceladus II Saturn 238000 1.37 0.02 0.00 Herschel 1789
Epimetheus XI Saturn 151000 0.69 0.34 0.01 Walker 1980
Erinome XXV Jupiter 23279000 728 164.9 0.266 Sheppard 2000
Europa II Jupiter 671000 3.55 0.47 0.01 Galileo 1610
Galatea VI Neptune 62000 0.43 0.00 0.00 Voyager2 1989
Ganymede III Jupiter 1070000 7.15 0.19 0.00 Galileo 1610
Harpalyke XXII Jupiter 21132000 623.3 148.6 0.226 Sheppard 2000
Helene XII Saturn 377000 2.74 0.20 0.01 Laques 1980
Himalia VI Jupiter 11480000 250.57 28.00 0.16 Perrine 1904
Hyperion VII Saturn 1481000 21.28 0.43 0.10 Bond 1848
Iapetus VIII Saturn 3561000 79.33 14.72 0.03 Cassini 1671
Io I Jupiter 422000 1.77 0.04 0.00 Galileo 1610
Iocaste XXIV Jupiter 20216000 ? ? ? Sheppard 2000
Isonoe XXVI Jupiter 23078000 ? ? ? Sheppard 2000
Janus X Saturn 151000 0.69 0.14 0.01 Dollfus 1966
Juliet XI Uranus 64000 0.49 0.06 0.00 Voyager2 1986
Jupiter V Sun 778330000 4332.71 1.31 0.05 - -
Kalyke XXIII Jupiter 23745000 ? ? ? Sheppard 2000
Larissa VII Neptune 74000 0.55 0.00 0.00 Reitsema 1989
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
Nereid II Neptune 5513000 360.13 29.00 0.75 Kuiper 1949
Oberon IV Uranus 583000 13.46 0.00 0.00 Herschel 1787
Ophelia VII Uranus 54000 0.38 0.09 0.00 Voyager2 1986
Pan XVIII Saturn 134000 0.58 0.00 0.00 Showalter 1990
Pandora XVII Saturn 142000 0.63 0.00 0.00 Collins 1980
Pasiphae VIII Jupiter 23500000 -735 147.00 0.38 Melotte 1908
Phobos I Mars 9000 0.32 1.00 0.02 Hall 1877
Phoebe IX Saturn 12952000 -550.48 175.30 0.16 Pickering 1898
Pluto IX Sun 5913520000 90550 17.15 0.25 Tombaugh 1930
Portia XII Uranus 66000 0.51 0.09 0.00 Voyager2 1986
Praxidike XXVII Jupiter 20964000 ? ? ? Sheppard 2000
Prometheus XVI Saturn 139000 0.61 0.00 0.00 Collins 1980
Prospero XVIII Uranus 16568000 -2019 152. 0.44 Holman 1999
Proteus VIII Neptune 118000 1.12 0.00 0.00 Voyager2 1989
Puck XV Uranus 86000 0.76 0.31 0.00 Voyager2 1985
Rhea V Saturn 527000 4.52 0.35 0.00 Cassini 1672
Rosalind XIII Uranus 70000 0.56 0.28 0.00 Voyager2 1986
Saturn VI Sun 1429400000 10759.50 2.49 0.06 - -
Setebos XIX Uranus 17681000 -2239 158. 0.57 Kavelaars 1999
Sinope IX Jupiter 23700000 -758 153.00 0.28 Nicholson 1914
Stephano XX Uranus 7948000 -674 143. 0.24 Gladman 1999
Sun - - - - - - - -
Sycorax XVII Uranus 12213000 -1289 153. 0.51 Nicholson 1997
Taygete XX Jupiter 23312000 ? ? ? Sheppard 2000
Telesto XIII Saturn 295000 1.89 0.00 0.00 Smith 1980
Tethys III Saturn 295000 1.89 1.09 0.00 Cassini 1684
Thalassa IV Neptune 50000 0.31 4.50 0.00 Voyager2 1989
Thebe XIV Jupiter 222000 0.67 0.80 0.02 Synnott 1979
Themisto XVIII Jupiter 7507000 ? ? ? Sheppard 2000
Titan VI Saturn 1222000 15.95 0.33 0.03 Huygens 1655
Titania III Uranus 436000 8.71 0.00 0.00 Herschel 1787
Trinculo XXI Uranus 8578000 -759 167.0 0.208 Gladman 2001
Triton I Neptune 355000 -5.88 157.00 0.00 Lassell 1846
Umbriel II Uranus 266000 4.14 0.00 0.00 Lassell 1851
Uranus VII Sun 2870990000 30685.00 0.77 0.05 Herschel 1781
Venus II Sun 108200000 224.70 3.39 0.01 - -

Part 2:
Separate, count and sort the words in the example text file, electricity.txt. Sort in the following orders and your output should be nicely lined up in columns to the output file.
1. alphabetically (ignoring capitalization),
2. alphabetically with upper case words just in front of lower-case words with the same initial characters
3. by frequency, from high to low, (any order for equal frequency)
4. by frequency, with alphabetical order for words with the same frequency

Electricity.txt file
Today's scientific question is: What in the world is electricity and where does it go after it leaves the toaster?

Here is a simple experiment that will teach you an important electrical lesson: On a cool dry day, scuff your feet along a carpet, then reach your hand into a friend's mouth and touch one of his dental fillings. Did you notice how your friend twitched violently and cried out in pain? This teaches one that electricity can be a very powerful force, but we must never use it to hurt others unless we need to learn an important lesson about electricity.

It also illustrates how an electrical circuit works. When you scuffed your feet, you picked up batches of "electrons", which are very small objects that carpet manufacturers weave into carpet so that they will attract dirt. The electrons travel through your bloodstream and collect in your finger, where they form a spark that leaps to your friend's filling, then travel down to his feet and back into the carpet, thus completing the circuit.

AMAZING ELECTRONIC FACT: If you scuffed your feet long enough without touching anything, you would build up so many electrons that your finger would explode! But this is nothing to worry about unless you have carpeting.

Although we modern persons tend to take our electric lights, radios, mixers, etc. for granted, hundreds of years ago people did not have any of these things, which is just as well because there was no place
to plug them in. Then along came the first Electrical Pioneer, Benjamin Franklin, who flew a kite in a lightning storm and received a serious electrical shock. This proved that lightning was powered by
the same force as carpets, but it also damaged Franklin's brain so severely that he started speaking only in incomprehensible maxims, such as, "A penny saved is a penny earned." Eventually he had to be given a job running the post office.

After Franklin came a herd of Electrical Pioneers whose names have become part of our electrical terminology: Myron Volt, Mary Louise Amp, James Watt, Bob Transformer, etc. These pioneers conducted many important electrical experiments. Among them, Galvani discovered (this is the truth) that when he attached two different kinds of metal to the leg of a frog, an electrical current developed and the frog's leg kicked, even though it was no longer attached to the frog, which was dead anyway. Galvani's discovery led to enormous advances in the field of amphibian medicine. Today, skilled veterinary surgeons can take a frog that has been seriously injured or killed, implant pieces of metal in its muscles, and watch it hop back into the pond -- almost.

But the greatest Electrical Pioneer of them all was Thomas Edison, who was a brilliant inventor despite the fact that he had little formal education and lived in New Jersey. Edison's first major invention in 1877 was the phonograph, which could soon be found in thousands of American homes, where it basically sat until 1923, when the record was invented. But Edison's greatest achievement came in 1879 when he
invented the electric company. Edison's design was a brilliant adaptation of the simple electrical circuit: the electric company sends electricity through a wire to a customer, then immediately gets the electricity back through another wire, then (this is the brilliant part) sends it right back to the customer again.
This means that an electric company can sell a customer the same batch of electricity thousands of times a day and never get caught, since very few customers take the time to examine their electricity closely.
In fact, the last year any new electricity was generated was 1937.

Today, thanks to men like Edison and Franklin, and frogs like Galvani's, we receive almost unlimited benefits from electricity. For example, in the past decade scientists have developed the laser, an electronic appliance so powerful that it can vaporize a bulldozer 2000 yards away, yet so precise that doctors can use it to perform delicate operations to the human eyeball, provided they remember to change the power setting from "Bulldozer" to "Eyeball."

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

# Opening the file
open(FH, "solar.txt")or die "Sorry!! couldn't open";
print "Reading file \n";

my @fileContent=();
my $count=0;
# Reading the file till FH reaches EOF
while(<FH>)
{   
    $count++;
    # Adding records to an array to reuse it
    push(@fileContent, $_);
}
close(FH);

print "No. of records: $count \n";
print "======================================================\n";

# subroutine to print records without a discoverer
sub printNoDiscoverer
{   
    # passing argument   
    @recordArray = @{$_[0]};
    print "Finding records without a Discoverer \n";
    my $recordCount = 0;
    foreach my $line (@recordArray)
    {
       my @spl = split(' ', $line);
       # check discoverer column
       if ((@spl[7] eq '?') || (@spl[7] eq '-')) {
            print "$line";
            $recordCount++;
       }
    }
    print "No. of matching records: $recordCount...
$25.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Perl Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats