[Solved] Read address from another file using Perl


I’m going to assume that the file will always only have one line in it…

First, always put use warnings; and use strict; at the top of your scripts. This catches the most common and basic problems before you even get going (like not declaring your variables with my for instance).

You need to open the file (using the three-argument form, and catching any errors with die), then you need to assign the line in the file to a variable, then chomp off any newline character.

use warnings;
use strict;

use LWP::Simple;

my $file="address.txt";

open my $fh, '<', $file
  or die "can't open the $file file!: $!";

my $url = <$fh>;
chomp $url;

my $content = get($url);
die "Couldn't get it!" unless defined $content;

solved Read address from another file using Perl