Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: IF NOT! IF NOT!

by abstracts (Hermit)
on Aug 03, 2001 at 00:25 UTC ( #101782=note: print w/ replies, xml ) Need Help??


in reply to IF NOT! IF NOT!

Hello,

I think this is what you wanted to do:

my @list = qw/hello hunn I am home homealone myhome myhomealone/; print "$_\n" for grep {$_ !~ /home/} @list; # hello # hunn # I # am
Hope this helps,,,

Aziz,,,


Comment on Re: IF NOT! IF NOT!
Download Code
Re: Re: IF NOT! IF NOT!
by damian1301 (Curate) on Aug 03, 2001 at 03:48 UTC
    A bit excessive, this will work just fine.

    grep{$_!~/home/&&print"$_\n"} @list;
    Which results the same as yours.

    UPDATE: Changed map to grep so there would be no void context stuff, thanks runrig.

    $_.=($=+(6<<1));print(chr(my$a=$_));$^H=$_+$_;$_=$^H; print chr($_-39); # Easy but its ok.
      And that is using map in a void context (creating an array with map and throwing it away). Better to just use a for loop:
      /home/ and print "$_\n" for @list;
      Update: Damian's right (in reply below). reverse the logic:
      /home/ or print "$_\n" for @list;
        But you've got reverse logic too. You are NOT supposed to print it if it has home anywhere in it. So what you want is in Re: Re: Re: IF NOT! IF NOT!.

        $_.=($=+(6<<1));print(chr(my$a=$_));$^H=$_+$_;$_=$^H; print chr($_-39); # Easy but its ok.
      Hello

      You can go even with

      /home/||print"$_\n"for@list
      But this is not golf :-)

      Aziz,,,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (17)
As of 2014-12-18 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (58 votes), past polls