Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reverse the print statement on this hash?

Status
Not open for further replies.

pedros007

Programmer
Nov 14, 2004
8
0
0
GB
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";
}
 
Code:
 for ($loop=$num_keys; $loop=0; $num_keys; $loop--) {

should be a start
--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top