>>>>> "SV" == Saral Viral <thesaral.p...@gmail.com> writes:

  SV> I could solve it. Able to store in array, sort it, remove duplicates and
  SV> print it. Sure there may be better ways to do it, but it seems to
  SV> work.  Amazing power of perl in so few lines.

see my posted comments. you could reduce this by about half easily. and
also make it much better in many many ways. don't settle for something
just working. learn how to make it better which will help all your
future perl programs as well.

also you don't say what the fix was which isn't helpful to others.

  SV> Fixed Script below:
  SV>  ============
  SV> #!/usr/bin/perl -w
  SV> #use strict
  SV> use File::Find;
  SV> my $dir_to_process = "C:/Mydir";
  SV> #opendir DH, $dir_to_process or die "Cannot open $dir_to_process:$1";
  SV> print "Files in $dir_to_process are:\n";
  SV> $i = 0;
  SV> my @url_array ;
  SV> find (\&wanted, $dir_to_process);
  SV> my %hash = map { $_ => 1} @url_array;

hash is a very bad name for a hash. it says nothing about the contents
of the hash.

  SV> my @unique_url_array = keys %hash;
  SV> my @sorted_url_array = sort(@unique_url_array);

no need for the temp array:

        my @sorted_url_array = sort keys %hash;

  SV> print "Printing sorted_url_array:\n";
  SV>  for ($j=0; $j <= $#sorted_url_array; $j++)

no need for even the sorted temp array:

        foreach my $url ( sort keys %hash ) {

learn to use foreach loops vs index loop. they are better in every way.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to