233k views
0 votes
Write a Perl program to accomplish each of the following on the file solar.txt (see link at the class homepage) 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 day

User SevenDays
by
5.7k points

1 Answer

3 votes

Answer:

see explaination

Step-by-step explanation:

use strict;

use warnings;

my $filename = 'data.txt';

open(my $fh, '<:encoding(UTF-8)', $filename)

or die "Could not open file '$filename' $!";

while (my $row = <$fh>) //Q1

chomp $row;

atfields = split(/:/, $row);

if($fields[7] eq "?"

while (my $row = <$fh>) { //Q2

chomp $row;

atfields = split(/:/, $row);

print '$fields: ' , replace($fields[1],"",$fields[1]) , "\\";}

}

while (my $row = <$fh>) { //Q3

chomp $row;

atfields = split(/:/, $row);

if (index($fields[2], "-") != -1) { //Looking out for negative sign in the field

print "$row\\";

}

while (my $row = <$fh>) { //Q4

chomp $row;

atfields = split(/:/, $row);

if($fields[7] eq "Voyager2")

print "$row\\";

}

Note: replace at anywhere in the program with the at symbol

User Matanya
by
5.2k points