Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Is for the wrong choice here?

by Masem (Monsignor)
on Jan 18, 2002 at 21:57 UTC ( #139885=note: print w/ replies, xml ) Need Help??


in reply to Is 'for' the wrong choice here?

grep is better here:

if ( grep { /($author)/i } @admin_users ) { print "$blah\n"; } else { print "$uber_blah\n"; }

Update -- Should be matching on $author, not $admin_user (the value from the loop in question).

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important


Comment on Re: Is for the wrong choice here?
Download Code
Re: Re: Is for the wrong choice here?
by jerrygarciuh (Curate) on Jan 18, 2002 at 22:04 UTC
    Well, that works better than what I had except that it apparently tests true every time. Every iteration is printing $blah even when $author is not a match. Advice?
    TIA
    jg
    _____________________________________________________
    If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.TvZ
      This code gets the same results:
      if ( grep { /($admin_user)/i } $author ) { print "$blah "; } else { print "$uber_blah"; }

      TIA
      jg
      _____________________________________________________
      If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.TvZ
Re: Re: Is for the wrong choice here?
by grep (Monsignor) on Jan 18, 2002 at 22:15 UTC
    This should work a little better
    #!/usr/bin/perl -w use strict; my $author = 'grep'; my @admin_users = qw/test that grep out/; if ( grep { /^$author$/i } @admin_users ) { print "blah\n"; } else { print "uber_blah\n"; }


    grep
    grep> cd pub
    grep> more beer

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (19)
As of 2015-07-02 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls