Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to prevent duplicated entry in array of the hash

Reply
Thread Tools

How to prevent duplicated entry in array of the hash

 
 
Jürgen Exner
Guest
Posts: n/a
 
      12-21-2006
Cyrus wrote:
> Got it


Got what?

> thank for verification...something like this one right?


Like what?
Please quote some context when replying or nobody will have a clue what you
are talking about.

jue


 
Reply With Quote
 
 
 
 
Cyrus
Guest
Posts: n/a
 
      12-21-2006
Jürgen Exner wrote:
> Cyrus wrote:
> > Got it

>
> Got what?

Are you guys polling my leg I was replying back to Keith concern!
anyway I haven't got any solution for the problem I'm facing any body
out there can help me on this or just call it quit?
>


 
Reply With Quote
 
 
 
 
Cyrus
Guest
Posts: n/a
 
      12-21-2006
> An easier approach is to take advantage of the fact that hash keys are
> unique - in fact, whenever I hear the words "unique" or "duplicate" with
> respect to managing entries in a collection, I immediately think of a
> hash. Example:
>
> # Hash, and key to add
> my %test_hash;
> my $new_value = 'foo';
>
> # Just add it - dups are eliminated automatically because it's a hash
> $test_hash{$new_value} = 0;
>
> sherm--


Thanks... below is the out puthere is output from Dumper, & here is my
appand to hash of array.
push @{$DiskErr{$sys}}, {disk => [$el->{'id'}], status =>
[$el->{'status'}] };

As you can see there is duplicated entries for disk 5 and a ststem can
have up 20 disks that's why I used above push! any idea how to prevent
a duplicate entry?
The DiskErr is $VAR1 = {
'BR5500' => [
{
'disk' => [
'5'
],
'status' => [
'NOT-IN-SERVICE'
]
},
{
'disk' => [
'5'
],
'status' => [
'NOT-IN-SERVICE'
]
},
{
disk' => [
'2'
],
'status' => [
'NOT-IN-SERVICE'
]
},

],

>
> --
> Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net


 
Reply With Quote
 
Cyrus
Guest
Posts: n/a
 
      12-21-2006
>
> $DiskErr->{$sys}->{$el->{'id'}} = { status => $el->{'status'} };
>
> That will give you a data structure that looks like this:
>
> {
> 'BR5500' => {
> '5' => {
> 'status' => 'NOT-IN-SERVICE',
> }
> },
> }
>
>

Thank you so much Sherm, I will use the above per your request as one
disk can have only one status at a time...before I rest my case How do
I access disk , is it sompthing like this:

my $diskStatus = $DiskErr->->{$sys}->{$el->{'id'}} ;

Again thank you & you are my hero & life saver....Oh by the way How am
I doing with reply with toping

 
Reply With Quote
 
Cyrus
Guest
Posts: n/a
 
      12-21-2006
>
> Like I said, I'd use a hash, with the disk number as the key:
> $DiskErr->{$sys}->{$el->{'id'}} = { status => $el->{'status'} };
>

I get an error: Global symbol "$DiskErr" requires explicit package name
at....
I declare that as: my %DiskErr;

> sherm--
>


 
Reply With Quote
 
Cyrus
Guest
Posts: n/a
 
      12-21-2006
> I declare that as: my %DiskErr;
>
> Sorry 'bout that. Your original code didn't declare it, so I figured were
> declaring it somewhere else.
>
> sherm--


Still getting error even after declaring my %DiskErr;
any idea..
Global symbol "$DiskErr" requires explicit package name a

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-21-2006
Sherm Pendley wrote:
> "Cyrus" <(E-Mail Removed)> writes:
>
> > Still getting error even after declaring my %DiskErr;
> > any idea..
> > Global symbol "$DiskErr" requires explicit package name a

>
> You're declaring it, but not in the same scope in which you're using it.


No, he's not declaring it. He's declaring %DiskErr, when he's using
$DiskErr. Two completely unrelated variables.

Paul Lalli

 
Reply With Quote
 
Cyrus
Guest
Posts: n/a
 
      12-21-2006
> You're declaring it, but not in the same scope in which you're using it.

There was extra ->, it should be like below I fixed it...thanks a lot:
Coorect: $DiskErr{$sys}->{$el->{'id'}} = { status => $el->{'status'}
};
WRONG: $DiskErr->{$sys}->{$el->{'id'}} = { status => $el->{'status'}
};

Cheers & Have Great Holiday...

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      12-22-2006
Cyrus <(E-Mail Removed)> wrote:

> Still getting error even after declaring my %DiskErr;
> any idea..
> Global symbol "$DiskErr" requires explicit package name a



Don't declare %DiskErr (a hash).

Instead declare $DiskErr (a scalar).


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Cyrus
Guest
Posts: n/a
 
      12-22-2006
> Don't declare %DiskErr (a hash).
>
> Instead declare $DiskErr (a scalar).
>

Thanks..

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
How to prevent duplicated entry in array of the hash Cyrus Perl Misc 1 12-20-2006 11:47 PM
Part 2: How to prevent duplicated entry in array of the hash ...please Cyrus Perl Misc 1 12-20-2006 11:45 PM



Advertisments