Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Braino - why is this not working?

by suhailck (Friar)
on Oct 19, 2010 at 01:29 UTC ( [id://866086]=note: print w/replies, xml ) Need Help??


in reply to Braino - why is this not working?

You are using $_ from @res instead of using $_ from outer for loop in grep statement.
Instead try this
perl -le '@arr=qw(a b a c); my @res; foreach(@arr) { $__=$_;$ans= grep /^$__$/,@res; print "\$_: $_ ans: $ans";push @res,$_ unless $ans;} print "@res"' $_: a ans: 0 $_: b ans: 0 $_: a ans: 1 $_: c ans: 0 a b c

Replies are listed 'Best First'.
Re^2: Braino - why is this not working?
by perl-diddler (Chaplain) on Oct 19, 2010 at 04:22 UTC
    Yup -- the grep's use of $_ was over-writing my 'for' loops usage.

    Thanks much for...helping me get this problem out of my head (like a song that gets stuck....). I could work around, it, but till bugged me if ya know what I mean, as it had to be something obvious staring me in my face that I couldn't see...

    Hate it when that happens...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found