I invite you to tear me new.
This code does its job. It receives a .txt file containing a list of IP addresses and writes a file containing the corresponding fully qualified domain names.
I want to know how this code is poorly written. What are bad habits here?
I am new to Perl and programming. I managed to put this together using google and trail and error. Achieving his work was satisfactory, but please tell me how I can improve.
use strict;
use warnings;
use Socket;
use autodie;
my $filename = 'IPsForFQDN.txt';
open(my $fh, '<:encoding(UTF-8)', $filename)
or die "Could not opne file '$filename' $!";
my $fqdn = '';
while (my $row = <$fh>) {
chomp $row;
print "$row\n";
$fqdn = gethostbyaddr(inet_aton($row), AF_INET);
print $fqdn;
print "\n";
open FILE, ">>fqdn.txt" or die $!;
print FILE $fqdn;
print FILE "\n";
close FILE;
}
print "done\n";
For example, do you need the string {chomp $ row;}? I have no IDEA what he is doing.
I am also puzzled by the whole {or die $ !;}.