Re: uniq array creation

2015-11-29 Thread Paul Johnson
On Sun, Nov 29, 2015 at 03:30:53PM +0530, Pritish Pattanaik wrote: > *Remove duplicate elelments from an array, It will maintain the original > order* > > __CODE__ > @array = qw(11 2 3 4 55 4 3 2); > %hash = (); > for(my $i=0;$i<=$#array;$i++){ > # store the position from array. use array ele

Re: uniq array creation

2015-11-29 Thread Shlomi Fish
Hi Jitendra, some comments on your code: On Sun, 29 Nov 2015 13:09:42 +0530 Jitendra Barik wrote: > Hi Sunita, > > Please find the code snippet here: > > @array = qw(1 2 3 4 5 4 3 2); You are missing "use strict;", "use warnings;" and "my" declarations here: http://perl-begin.org/tutorials/

Re: uniq array creation

2015-11-29 Thread Pritish Pattanaik
Hi, *Remove duplicate from an array using hash, It will disorder the original position of an array * __CODE__ my @array = qw(11 2 3 4 55 4 3 2); my %hash; map { $hash{$_}++ } @array; @array = keys %hash; print "Array:@array\n"; __END__ *Remove duplicate elelments from an array, It will main

Re: uniq array creation

2015-11-28 Thread Jitendra Barik
Hi Sunita, Please find the code snippet here: @array = qw(1 2 3 4 5 4 3 2); foreach (@array){ $myhash{$_} = $myhash{$_} + 1; } while(($s,$k) = each(%myhash)){ push @res,$k; } print "Array in unique is : @res\n"; Regards, Jitendra On Thu, Nov 26, 2015 a

Re: uniq array creation

2015-11-26 Thread Mike Flannigan
See if this meets your needs: http://www.arl.wustl.edu/projects/fpx/references/perl/cookbook/ch04_07.htm Mike On 11/25/2015 1:53 AM, beginners-digest-h...@perl.org wrote: Hi I want to create a unique array . I have the code below. It is creating a array which will have duplicate data

Re: uniq array creation

2015-11-25 Thread Shlomi Fish
Hi Sunita, On Wed, 25 Nov 2015 13:23:24 +0530 Sunita Pradhan wrote: > Hi > I want to create a unique array . You probably mean an "array with unique elements". To do so, you should use a hash. See: http://perl-begin.org/topics/hashes/ > I have the code below. It is creating a array which wi

Re: Uniq from array ?

2005-04-13 Thread Chris Devers
On Wed, 13 Apr 2005, M. Kristall wrote: > Who do you think has more viewers? This particular thread or Google? Google links to things, in part, because people mention them online. When *Google* sees this thread, it will register that as a positive vote for the site in question, and will as a r

Re: Uniq from array ?

2005-04-13 Thread M. Kristall
Chris Devers wrote: On Wed, 30 Mar 2005, Peter Rabbitson wrote: Anyway my 2c - I myself use the [$elided] archives quite a bit, which does not prevent me from owning hard prints of the Cookbook, the Pocket Ref and recently Object Oriented Perl. It however prevents from owning 2 pcs of each of t

Re: Uniq from array ?

2005-03-30 Thread Chris Devers
On Wed, 30 Mar 2005, Peter Rabbitson wrote: > Anyway my 2c - I myself use the [$elided] archives quite a bit, which > does not prevent me from owning hard prints of the Cookbook, the > Pocket Ref and recently Object Oriented Perl. It however prevents from > owning 2 pcs of each of those not-so-

Re: Uniq from array ?

2005-03-30 Thread Peter Rabbitson
> > Not that I see why this came up in the first place... > How funny... By very same talking you can bring a gun to a social meeting and 10 minutes later yell "Huh?! WTF did this come from?!". Anyway my 2c - I myself use the unix.org.ua archives quite a bit, which does not prevent me from

Re: Uniq from array ?

2005-03-30 Thread JupiterHost.Net
As in free beer :) Thats mighty nice of you :) I like Guinness, I can send you my address off list :) Oh and I'd like you to do help on a project next week, 40 hours sound ok? I'll send the info you need so you can buy a plane ticket and get a hotel to come "share knowledge" for free... I appre

Re: Uniq from array ?

2005-03-30 Thread Chris Devers
On Wed, 30 Mar 2005, Michael Gale wrote: > Besides I am not sure where you are going with this ? Are you saying > that the content on the web page if pirated so I should not view it ? That's debatable, but you *definitely* shouldn't publicize it. > Information should be free, I believe all book

Re: Uniq from array ?

2005-03-30 Thread Michael Gale
Google returned the page from a search result, where it gets the pages from is not my fault. Besides I am not sure where you are going with this ? Are you saying that the content on the web page if pirated so I should not view it ? Information should be free, I believe all books and information

Re: Uniq from array ?

2005-03-30 Thread Alfred Vahau
Michael, I noted from your original posting that you quoted from a URL which is controversial in that the Perl-related books from O'Reilly are actually pirated copies. This was pointed out by one of the subscribers to this list in a recent thread. Alfred, Michael Gale wrote: Hello, I fi

Re: Uniq from array ?

2005-03-30 Thread Michael Gale
Hello, I fixed it, the string would initially contain special characters such as % signs. I strip out all the characters before the check, instead of after. Michael. On Wed, 2005-03-30 at 16:19 -0700, Michael Gale wrote: > Hello, > > I tried your example, it worked as expected,

Re: Uniq from array ?

2005-03-30 Thread Michael Gale
Hello, I tried your example, it worked as expected, here is the entire code: --snip-- my @servers; my $each_server; my $each_host; my %seen = ( ); print "List of systems being performance monitored\n"; print "Please select a host\n"; open

Re: Uniq from array ?

2005-03-30 Thread Offer Kaye
On Wed, 30 Mar 2005 15:53:25 -0700, Michael Gale wrote: > > But it is not working as expected, even if the array has the first three > entries the same, the function "show_host" gets called three time ? > > foreach $each_server(@servers) > { > unless ($see

Re: uniq elements of an array

2002-08-30 Thread Jeff 'japhy' Pinyan
On Aug 30, david said: >Ramprasad A Padmanabhan wrote: > >> Hi All, >>I have been using perl on linux for quiet some time now and I have >> found that Perl does not work the same in windows >> >>eg. To get all the unique elements of an array in linux I use a >> simple one liner >> >>

RE: uniq elements of an array

2002-08-30 Thread David . Wagner
PROTECTED]] Sent: Friday, August 30, 2002 12:07 To: Felix Geerinckx; [EMAIL PROTECTED] Subject: RE: uniq elements of an array Slice is simple and also faster ! Look: #!/usr/bin/perl use strict; use Benchmark; my @a=qw(a c b c a a b d c c); my @uniq=(); sub using_grep{ my %seen

RE: uniq elements of an array

2002-08-30 Thread NYIMI Jose (BMB)
(n=100) José. -Original Message- From: NYIMI Jose (BMB) Sent: Friday, August 30, 2002 9:07 PM To: Felix Geerinckx; [EMAIL PROTECTED] Subject: RE: uniq elements of an array Slice is simple and also faster ! Look: #!/usr/bin/perl use strict; use Benchmark; my @a=qw(a c b c a a b

RE: uniq elements of an array

2002-08-30 Thread NYIMI Jose (BMB)
ck secs (15.80 usr + 0.00 sys = 15.80 CPU) @ 63283.13/s (n=100) José. -Original Message- From: Felix Geerinckx [mailto:[EMAIL PROTECTED]] Sent: Friday, August 30, 2002 8:39 PM To: [EMAIL PROTECTED] Subject: Re: uniq elements of an array on Fri, 30 Aug 2002 18:26:03 GMT, Tom

Re: uniq elements of an array

2002-08-30 Thread Felix Geerinckx
on Fri, 30 Aug 2002 18:26:03 GMT, Tom Allison wrote: > david wrote: >> @hash{@all_elements} = (); >> >> now "keys %hash" gives you the unique elements. > > Would these exist but be undef? > > Why don't you write a little program to try it out, using the aptly named 'exists' and 'defined' fu

Re: uniq elements of an array

2002-08-30 Thread Tom Allison
david wrote: > Ramprasad A Padmanabhan wrote: > > >>Hi All, >> I have been using perl on linux for quiet some time now and I have >>found that Perl does not work the same in windows >> >> eg. To get all the unique elements of an array in linux I use a >>simple one liner >> >> @unique = gr

Re: uniq elements of an array

2002-08-30 Thread david
Ramprasad A Padmanabhan wrote: > Hi All, >I have been using perl on linux for quiet some time now and I have > found that Perl does not work the same in windows > >eg. To get all the unique elements of an array in linux I use a > simple one liner > >@unique = grep{!/$seen{$_}++/} @

Re: uniq elements of an array

2002-08-30 Thread Ramprasad A Padmanabhan
Dharmendra rai wrote: > have u seen the values in @unique when @all_elements contains (1,2,3,1,2) when u >apply @unique = grep { !$seen{$_}} @all_elements ??? > > its is not working > > > > > - > Get a bigger mailbox -- choose a size that fits your need

Re: uniq elements of an array

2002-08-30 Thread Sudarshan Raghavan
On 30 Aug 2002, Felix Geerinckx wrote: > on Fri, 30 Aug 2002 17:32:36 GMT, [EMAIL PROTECTED] (Sudarshan > Raghavan) wrote: > > > Why do you need to do a pattern match anyways? Just a > > @unique = grep{!$seen{$_}} @all_elements; > > should do > > You forgot to increment. The correct way is: >

Re: uniq elements of an array

2002-08-30 Thread Dharmendra Rai
have u seen the values in @unique when @all_elements contains (1,2,3,1,2) when u apply @unique = grep { !$seen{$_}} @all_elements ??? its is not working - Get a bigger mailbox -- choose a size that fits your needs.

Re: uniq elements of an array

2002-08-30 Thread Felix Geerinckx
on Fri, 30 Aug 2002 17:32:36 GMT, [EMAIL PROTECTED] (Sudarshan Raghavan) wrote: > Why do you need to do a pattern match anyways? Just a > @unique = grep{!$seen{$_}} @all_elements; > should do You forgot to increment. The correct way is: @unique = grep{!$seen{$_}++} @all_elements; -- feli

Re: uniq elements of an array

2002-08-29 Thread Sudarshan Raghavan
On Fri, 30 Aug 2002, Ramprasad A Padmanabhan wrote: > Hi All, >I have been using perl on linux for quiet some time now and I have > found that Perl does not work the same in windows > >eg. To get all the unique elements of an array in linux I use a > simple one liner > >@unique =

Re: uniq elements of an array

2002-08-29 Thread Omanakuttan
>eg. To get all the unique elements of an array in linux I use a > simple one liner > >@unique = grep{!/$seen{$_}++/} @all_elements; > The above expression did not work for me, I could not even found out how this should work. So I created a small file with... @all_elements = qw(hello al

Re: uniq

2002-05-23 Thread John W. Krahn
Craig Hammer wrote: > > I am working on a script to read in a firewall logfile, pull out the IP > addresses of denied packets, then give me a count per IP address, and > perform a whois on each address. > > This previously ran as a VERY SLOW shell script. In bourne, I used sort and > then uniq

RE: uniq

2002-05-23 Thread Jeff 'japhy' Pinyan
On May 23, Jeff 'japhy' Pinyan said: >Now you have %seen, which holds each element of @sorted and how many times >it appeared. Thus: > > @duplicates = grep $seen{$_} == 1, keys %seen; That should be != 1, not == 1. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japh

RE: uniq

2002-05-23 Thread Jeff 'japhy' Pinyan
On May 23, Elias Assmann said: >On Thu, 23 May 2002, Jeff 'japhy' Pinyan wrote: > >> On May 23, Craig Hammer said: >> >> >Very nice explanation. One thing though, I am not using uniq to remove >> >duplicates. I am using it to get a count of duplicates. In my case, I am >> >creating a threshhol

Re: uniq

2002-05-23 Thread A. Rivera
ra Webmaster, Pollstar.com / PollstarOnline.com - Original Message - From: "Elias Assmann" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: "Craig Hammer" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, May 23, 2002 9:51 AM Subject: RE: uniq > On Thu, 2

RE: uniq

2002-05-23 Thread Elias Assmann
On Thu, 23 May 2002, Jeff 'japhy' Pinyan wrote: > On May 23, Craig Hammer said: > > >Very nice explanation. One thing though, I am not using uniq to remove > >duplicates. I am using it to get a count of duplicates. In my case, I am > >creating a threshhold to determine when someone (malicious)

RE: uniq

2002-05-23 Thread Jeff 'japhy' Pinyan
On May 23, Craig Hammer said: >Very nice explanation. One thing though, I am not using uniq to remove >duplicates. I am using it to get a count of duplicates. In my case, I am >creating a threshhold to determine when someone (malicious) is scanning my >address ranges. Ah, I see. Well then,

RE: uniq

2002-05-23 Thread Craig Hammer
Jeff, Very nice explanation. One thing though, I am not using uniq to remove duplicates. I am using it to get a count of duplicates. In my case, I am creating a threshhold to determine when someone (malicious) is scanning my address ranges. --

Re: uniq

2002-05-23 Thread Jeff 'japhy' Pinyan
On May 23, A. Rivera said: >On May 23, Craig Hammer said: >> I am working on a script to read in a firewall logfile, pull out the IP >> addresses of denied packets, then give me a count per IP address, and >> perform a whois on each address. >> >> This previously ran as a VERY SLOW shell script.

Re: uniq

2002-05-23 Thread A. Rivera
I use this subroutine for uniq sub uniq { my @in=@_; my (%saw,@out); undef %saw; @out = grep(!$saw{$_}++, @in); return @out; } Unfortunately, I have no idea how it works. Regards, Agustin Rivera Webmaster, Pollstar.com / PollstarOnline.com - Original