Re: searching an array reference

2005-07-16 Thread John W. Krahn
John W. Krahn wrote: Angie Ahl wrote: I've got a way to do this but I thought someone more experienced than me might have a better way. I have a class that is a hash and one of the hash values is an array ref. I'd like to search that array and push to it if a value isn't there. At the moment

Re: searching an array reference

2005-07-16 Thread John W. Krahn
Angie Ahl wrote: > Hi List Hello, > I've got a way to do this but I thought someone more experienced than > me might have a better way. > > I have a class that is a hash and one of the hash values is an array ref. > > I'd like to search that array and push to it if a value isn't there. > At the

Re: searching an array reference

2005-07-16 Thread Peter Rabbitson
> I'd like to search that array and push to it if a value isn't there. > At the moment I'm dereferencing the array, searching/pushing it and > the passing it back to the class as an array ref again. So this mean > copying the array. Code: > > my @used_images = @{$_[0]->{_used_images}}; > foreach (

searching an array reference

2005-07-16 Thread angie ahl
Hi List I've got a way to do this but I thought someone more experienced than me might have a better way. I have a class that is a hash and one of the hash values is an array ref. I'd like to search that array and push to it if a value isn't there. At the moment I'm dereferencing the array, sear

Re: searching an array (using map)

2002-03-30 Thread Kim, Kiseok
you can use map function, too :) $a = 5; @arr = qw( 7 9 3 6 ); %search = map { $_ => 1 } @arr; if ( $search{$a} ) { print "Found $a in the list \n"; } else { print "Did not find $a in the list\n"; } Mahendra Thacker wrote: > Hi, > > A question from a relative newbie. > > How does one

Re: Grep (WAS RE: searching an array)

2002-03-30 Thread Jenda Krynicky
From: "John W. Krahn" <[EMAIL PROTECTED]> > Jenda Krynicky wrote: > > And if you want 6 unique : > > > > my @myarr; > > { # this block is here just to restrict the availability > > # of %seen > > my %seen; > > while (@myarr < 6) { > >

Re: Grep (WAS RE: searching an array)

2002-03-30 Thread John W. Krahn
Jenda Krynicky wrote: > > From: "Mahendra Thacker" <[EMAIL PROTECTED]> > > > > # Cash5 Lotto: draw of 6 unique non-zero numbers from 1..35 > > > > my $top = 36; # rand gives a rand numb less than top, hence > > my @myarr = (); > > my $myrand; > > > > while ( @myarr < 6 ) { > >$myrand = rand $

Re: Grep (WAS RE: searching an array)

2002-03-30 Thread Jenda Krynicky
From: "Mahendra Thacker" <[EMAIL PROTECTED]> > I was trying to poplulate an array with 6 non-zero unique random > numbers from 1 to 35; I thought this search a list for a number is so > much being used in various tasks that there would exist some such > function > search ( $myvar, @myarr ) > w

Re: Grep (WAS RE: searching an array)

2002-03-30 Thread Mahendra Thacker
an array? > > -Original Message- > From: Wagner-David [mailto:[EMAIL PROTECTED]] > Sent: Friday, March 29, 2002 4:20 PM > To: 'Mahendra Thacker' > Cc: [EMAIL PROTECTED] > Subject: RE: searching an array > > > Here is one shot: > > #!perl -w >

Re: searching an array

2002-03-29 Thread John W. Krahn
Mahendra Thacker wrote: > > Hi, > > A question from a relative newbie. > > How does one search an array of numbers for a number? > (without using foreach; is there any function?) > > Say, I want to do something like this: > > == > > $a = 5; > @arr = ( 7 9 3 6 ); > > if ( seach( $a, @arr ) )

RE: Grep (WAS RE: searching an array)

2002-03-29 Thread Wagner-David
;) -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED]] Sent: Friday, March 29, 2002 16:16 To: Wagner-David; 'Mahendra Thacker' Cc: [EMAIL PROTECTED] Subject: Grep (WAS RE: searching an array) I've heard that grep is fairly resource-intensive. Is there any trut

Grep (WAS RE: searching an array)

2002-03-29 Thread Timothy Johnson
7;Mahendra Thacker' Cc: [EMAIL PROTECTED] Subject: RE: searching an array Here is one shot: #!perl -w my $a = 5; my @arr = qw( 7 9 3 6 5); my @MyHits = grep(/$a/ , @arr ); if ( @MyHits ) { print "Found $a in the list \n"; } else { print "Did not find $a in the list\n

RE: searching an array

2002-03-29 Thread Wagner-David
al Message- From: Mahendra Thacker [mailto:[EMAIL PROTECTED]] Sent: Friday, March 29, 2002 16:09 To: [EMAIL PROTECTED] Subject: searching an array Hi, A question from a relative newbie. How does one search an array of numbers for a number? (without using foreach; is there any function?

searching an array

2002-03-29 Thread Mahendra Thacker
Hi, A question from a relative newbie. How does one search an array of numbers for a number? (without using foreach; is there any function?) Say, I want to do something like this: == $a = 5; @arr = ( 7 9 3 6 ); if ( seach( $a, @arr ) ) { print "Found $a in the list \n"; } else { print

Re: help on searching an array

2002-03-27 Thread Adam Wesselink
I'd split up the foreach loop and the conditional it might be a little clunky, but here's the basic idea. bolFound = false foreach (@members) { if (/($enqmem)/i) { bolFound = true; } } if (bolFound) { do stuff } else { do other stuff } At 18:54 27-03-02 +

RE: help on searching an array

2002-03-27 Thread Timothy Johnson
ely $enqmem is not a member of our club!\n"; } print "Thankyou for your enquiry."; -Original Message- From: Wytch [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 27, 2002 10:55 AM To: [EMAIL PROTECTED] Subject: help on searching an array Hi, I am new to this list and t

RE: help on searching an array

2002-03-27 Thread Nikola Janceski
- > From: Wytch [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 27, 2002 1:55 PM > To: [EMAIL PROTECTED] > Subject: help on searching an array > > > Hi, I am new to this list and to Perl. I decided after years > of promises to > my self that I would finally tackle program

help on searching an array

2002-03-27 Thread Wytch
Hi, I am new to this list and to Perl. I decided after years of promises to my self that I would finally tackle programming. I started reading up on it and think I have got the basics but I am still very much a Perl virgin! I decided to try to write a little script [no practical application just

Re: FOLLOWUP Question: RE: Help: Searching an array question++

2001-07-11 Thread Paul
--- Bob Bondi <[EMAIL PROTECTED]> wrote: > Thanks for the feedback, everyone. > My goal for this script is to make "this.gif" and "that.gif" change > places in the file. I.E. > - > this.gif > that.gif > this.gif > - > > after running the script I would have >

Re: FOLLOWUP Question: RE: Help: Searching an array question++

2001-07-11 Thread Jeff 'japhy' Pinyan
On Jul 11, Bob Bondi said: >Thanks for the feedback, everyone. >My goal for this script is to make "this.gif" and "that.gif" change places >in the file. I.E. >- >this.gif >that.gif >this.gif >- > >after running the script I would have >- >that.gif >

FOLLOWUP Question: RE: Help: Searching an array question++

2001-07-11 Thread Bob Bondi
Thanks for the feedback, everyone. My goal for this script is to make "this.gif" and "that.gif" change places in the file. I.E. - this.gif that.gif this.gif - after running the script I would have - that.gif this.gif that.gif - usin

Re: Help: Searching an array question++

2001-07-10 Thread Stephen P. Potter
Lightning flashed, thunder crashed and "Bob Bondi" <[EMAIL PROTECTED]> w hispered: | Yep, another newbie at Perl. I have come to a wall. What I need to do is | open a file, find a value in the file and substitute a value. | I've gotten to the point of what to do with an open file. I have been tryi

Re: Help: Searching an array question++

2001-07-10 Thread Aaron Craig
At 08:32 10.07.2001 -0700, Bob Bondi wrote: >Yep, another newbie at Perl. I have come to a wall. What I need to do is >open a file, find a value in the file and substitute a value. >I've gotten to the point of what to do with an open file. I have been trying >the @array = statement. >I then wante

Help: Searching an array question++

2001-07-10 Thread Bob Bondi
Yep, another newbie at Perl. I have come to a wall. What I need to do is open a file, find a value in the file and substitute a value. I've gotten to the point of what to do with an open file. I have been trying the @array = statement. I then wanted to verify the contents of the array and tried p