El Monday 25 August 2008 11:30:19 Anirban Adhikary va escriure:
> Dear List
> I have write the The following code to check a file and print only distinct
> lines to a new file and skips the duplicate lines. My source file is as
> follows
>
> hello how are you?
> hello how are you?
> What language did you want to use?
> What language did you want to use?
> I am here
> You are there
> this is my first perl script
> What language did you want to use?
>
> ###########################################################################
>#### my code is as follows
>
>
> #use strict;
> #use warnings;
>
> print "Enter the Absolutepath of the file\t";
> my $input=<STDIN>;
> chomp($input);
>
> dup($input);
>
> sub dup
> {
> my $filename=shift;
> my $count=0;
> my @arr;
> my $el;
> my $element;
> open(FH,"$filename");
> while(<FH>)
> {
> chomp($_);
> $element = $_;
> if($count ==0)
> {
> push(@arr,$element);
> $count+=1;
> print "Count is $count\n";
> }
> else
> {
> foreach $el(@arr)
> {
> my $len=$#arr;
> chomp($el);
> # print "$element\n";
> #print "The length of arr is $len\n";
> if($el == $element)
> {
> print "\t######Inside If######\t\n";
> print $element."\n";
> next;
> #push(@arr,$_);
> }
>
> elsif($el != $element)
> {
> push(@arr,$element);
> print "\t########Inside Elseif\n";
> #next;
> }
> }
> }
> }
>
> ###############################################################
> The problems I am facing are
>
> 1) The code is not getting entered into elsif block
>
> 2) I am comparing between 2 strings but if I use "eq" or "ne" for
> comparison I am getting some horrible output so I am using numeric
> comparison.
>
> 3)If I am giving print the $element variable outside foreach loop it is
> getting printed but Inside foreach loop it is not showing anything.
>
> Can anybody Please suggest me where I am making the mistake?
>
> Thanks & Regards in Advance
> Anirban Adhikary.
Did you try to use uniq comand from the Unix bash? I think code would be much
easy (use exe or sytem to call the command).
Otherwise, $count always equals to zero when going into dup subroutine.
--
Xavier Mas
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y m�viles desde 1 c�ntimo por minuto.
http://es.voice.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/