Anirban Adhikary wrote:

On Mon, Aug 25, 2008 at 5:34 PM, John W. Krahn <[EMAIL PROTECTED]> wrote:

The usual way to do what you want is to use a hash:

use strict;
use warnings;

print "Enter the Absolutepath of the file\t";
chomp( my $filename = <STDIN> );

open my $FH, '<', $filename or die "Cannot open '$filename' $!";

my %seen;
while ( <$FH> ) {
   unless ( $seen{ $_ }++ ) {
       print;
       }
   }

__END__

Thanks a lot John . I have a little question can u please dexcribe in detail
what this line is doing actually
 unless ( $seen{ $_ }++ )

$_ contains the current line from the file. ++ is the postfix auto-increment operator. The hash %seen contains the line from the file as the key and the number of times the line was "seen" as the value. The value of $seen{$_} is tested to see if it is true or false and after it is tested the value is incremented so if a line is not already in the hash the value will be false (undef) and that line will be printed.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to