-----Original Message-----
>From: "Sayed, Irfan (Irfan)" <[EMAIL PROTECTED]>
>Sent: Feb 13, 2007 7:12 PM
>To: beginners@perl.org
>Subject: FW: Array manipulation
>
>
>Hi All,
>
>I have one array having values as follows
>
>User [EMAIL PROTECTED]
>User [EMAIL PROTECTED]
>User [EMAIL PROTECTED]
>
>Now I formatted above array as per your suggession as follows in order
>to remove duplicate value "User"
>@test = grep { ++$hash{$_} < 2 } @test;
>
>but output is as follows which is not proper
>
>User [EMAIL PROTECTED]
>
>[EMAIL PROTECTED]
>[EMAIL PROTECTED]
>
>I need output in this fashion
>
>[EMAIL PROTECTED]
>[EMAIL PROTECTED]
>[EMAIL PROTECTED]
>

Hello,

This is one way to do it.

use strict;
use warnings;

my @arr = qw(User [EMAIL PROTECTED]
  User [EMAIL PROTECTED]
  User [EMAIL PROTECTED]
  User [EMAIL PROTECTED]);

my %hash;
@arr = grep {++$hash{$_} < 2 && $_ ne 'User'} @arr;
print join ' ',@arr;

__END__

--
Jeff Pang
EMAIL: [EMAIL PROTECTED]  AIM: jeffpang

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


Reply via email to