I haven't seen hash used in this format. $data{ $val1 }{ $val2 }++; Can yor please tell what this means?
It worked for me.. I was also trying with exists command which returns boolean value. Thanks all. ----- Original Message ----- From: "John W. Krahn" <[EMAIL PROTECTED]> Date: Thursday, April 17, 2008 1:50 am Subject: Re: CSV duplicate To: Perl Beginners <beginners@perl.org> > Manoj wrote: > > Hello List, > > Hello, > > > Scenario: > > CSV file > > Host=Nirus,TCPIP,inxcp011,connected,Serv=rxmcpp1 > > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp2 > > Host=Rome,TCPIP,inxcp011,connected, Serv=rxmcpp1 > > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1 > > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp3 > > Host=Spring,TCPIP,inxcp011,connected, Serv=rxmcpp > > Host=Spring,TCPIP,inxcp011,connected, Serv=rxmcpp1 > > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1 > > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1 > > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1 > > Host=Nirus,TCPIP,inxcp011,connected, Serv=rxmcpp1 > > > > Required output is > > Nirus > > Spring > > > > There is one more requirement I need to sort the 5th column and > sort them > > and fetch which ever is duplicate. So in this one I need to print > > rxmcpp1 to screen. > > This should be close to what you want: > > my %data; > while ( <FILE> ) { > chomp; > for ( map [ split /=/ ], ( split /\s*,\s*/ )[ 0, -1 ] ) { > $data{ $_->[ 0 ] }{ $_->[ 1 ] }++; > } > } > > for my $type ( keys %data ) { > print "Duplicate $type\n"; > for my $key ( keys %{ $data{ $type } } ) { > print "$key\n" if $data{ $type }{ $key } > 1; > } > print "\n"; > } > > > > 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/ > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/