Hi, I am trying to reverse the print statement on both option 1 and 2. Any ideas how to do it?
#! /usr/bin/perl
#User enters in the name of the file, of which they would like to be checked for HTML Links
print "Please enter the file name including the extension of the file\n";
$file = <STDIN>;
chomp ($file);
open (file, "$file") or die "Can't find the file";
@content=<file>;
close(file);
print "Please choose either option 1 or 2 \n";
print "1 - Save the extracted links to file \n";
print "2 - Print the HTML links on Screen \n";
$UserChoice = <STDIN>;
$loop=0;
foreach(@content){
if (m!^<a\s.*?href.*?\/a>$!) {
$Links{$loop++}= $_ ;
}
}
if ($UserChoice==1){
open (NEWFH, ">HTML_Links.txt") || die "Can't create file: $!";
print NEWFH values %Links;
close (NEWFH);
exit;
} elsif ($UserChoice==2){
$num_keys=keys %Links;
for ($loop=1; $loop<= $num_keys; $loop++) {
print $Links{$loop};
}
} else {
print "Please enter choose either option 1 or 2 \n";
}
#! /usr/bin/perl
#User enters in the name of the file, of which they would like to be checked for HTML Links
print "Please enter the file name including the extension of the file\n";
$file = <STDIN>;
chomp ($file);
open (file, "$file") or die "Can't find the file";
@content=<file>;
close(file);
print "Please choose either option 1 or 2 \n";
print "1 - Save the extracted links to file \n";
print "2 - Print the HTML links on Screen \n";
$UserChoice = <STDIN>;
$loop=0;
foreach(@content){
if (m!^<a\s.*?href.*?\/a>$!) {
$Links{$loop++}= $_ ;
}
}
if ($UserChoice==1){
open (NEWFH, ">HTML_Links.txt") || die "Can't create file: $!";
print NEWFH values %Links;
close (NEWFH);
exit;
} elsif ($UserChoice==2){
$num_keys=keys %Links;
for ($loop=1; $loop<= $num_keys; $loop++) {
print $Links{$loop};
}
} else {
print "Please enter choose either option 1 or 2 \n";
}