in reply to Getting unique data from search.

Try declaring a %seen hash outside your sub, and change the print line to this.
That should give you what youa re looking for.
print "Title = $1\n" unless $seen{$1}++;

P.S. Doesnt look like you are using strict.

Wonko

Replies are listed 'Best First'.
Re: Re: Getting unique data from search.
by Anonymous Monk on Nov 14, 2002 at 14:55 UTC
    this still not working, any suggestions?
    use File::Find; sub wanted { if( $_ =~ /\.html?$/) { my $name = $File::Find::name; open ( F, $name ) or die "$!: $name\n"; while($line = <F>) { if($line =~ /<title>(.+)<\/title>/i) { print "Title = $1\n"; } } close F; } } find( \&wanted, "/unixpath/webfiles" ); print "title = $1\n" unless $seen{$1}++;
      You didn't follow his advice; he said "change the print statement." Not "add this at the bottom." The code should look like this:
      use strict; use File::Find; my %seen; sub wanted { if ( /\.html$/) { open F, "< $File::Find:name" or die "read $File::Find::name: $!\n"; local $_; while (<F>) { if ( /<title>(.*?)<\/title>/si ) { print "Title = $1\n" unless $seen{$1}++; } } close F; } } find( \&wanted, "/unixpath/webfiles" );

      jdporter
      ...porque es dificil estar guapo y blanco.

        thanks, but not sure what and how this works???
        print "Title = $1\n" unless $seen{$1}++;
        Can someone explain it to me?