Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Adding to this

by Ido (Hermit)
on Nov 24, 2002 at 20:12 UTC ( [id://215534]=note: print w/replies, xml ) Need Help??


in reply to Adding to this

I'm not sure I fully understnad what you're trying to do and what exactly the problem is. (saying what you have and what you want to have is like saying "I want to get from point A to point B. Can you show me the path?", and of course, between point A and point B, there's an infinite number of paths.) But I will try my best shot. So..as far as I understand, the problem is you can't contain the additional data you want in the final result array (@ref) in the array you use to build it (@names) because @names is later used to grab the next results. Hence, we should build @ref directly from $res. Here's how I would write the code:
my @ref; my @names = $username = $mem_info[2]; #Scalar assignment returns the a +ssigned value, you can use it. my $base_sql=q{SELECT username,status FROM members WHERE referral }; while (@names) { #No scalar() needed - boolean context is just a speci +al kind of scalar context. my $sql=$base_sql.($#names?'in ('.join(',',map('?',@names)).')':'=?' +); my $sth=$dbh->prepare($sql); my $rv=$sth->execute(@names); my $res = $sth->fetchall_arrayref(); @names=map($_->[0],@$res); #Use map to map by each value of the arra +y, instead of by indices. push @ref, join '|',map("$_->[0]=$_->[1]",@$res) if @$res; #@names c +ontains as many values as @$res does. last if $#ref == 2 ; }
hth..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://215534]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2024-04-23 19:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found