How does grep {$field->$_} work?

Discussion in 'Perl Misc' started by Peng Yu, Jun 5, 2010.

  1. Peng Yu

    Peng Yu Guest

    Hi,

    In the bioperl Eutilities cookbook,
    http://www.bioperl.org/wiki/HOWTO:EUtilities_Cookbook

    I see the following code,

    print join(',', grep {$field->$_} qw(is_date
    is_singletoken is_hierarchy is_hidden is_numerical)),"\n
    \n";

    I'm not understand how $field->$_ work with. I'm trying to break the
    above code so that I can understand. But I failed. Could you please
    help generate a minimal example to help me understand the above usage
    of "grep {$field->$_}"?

    --
    Regards,
    Peng
    Peng Yu, Jun 5, 2010
    #1
    1. Advertising

  2. >>>>> "Peng" == Peng Yu <> writes:

    Peng> I'm not understand how $field->$_ work with. I'm trying to break the
    Peng> above code so that I can understand. But I failed. Could you please
    Peng> help generate a minimal example to help me understand the above usage
    Peng> of "grep {$field->$_}"?

    It'd help for you to explain what you *do* understand.

    Do you know what this does:

    $x = "foo":
    $field->$x;

    Do you know what this does:

    print join ", ", grep { $_ > 5 } 1, 2, 4, 8, 16;

    If you know both of them, you should be able to work out what the
    combination does.

    Which part of that is unclear?

    print "Just another Perl hacker,"; # the original

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
    See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
    Randal L. Schwartz, Jun 5, 2010
    #2
    1. Advertising

  3. Peng Yu

    Peng Yu Guest

    On Jun 4, 6:32 pm, (Randal L. Schwartz) wrote:
    > >>>>> "Peng" == Peng Yu <> writes:

    >
    > Peng> I'm not understand how $field->$_ work with. I'm trying to break the
    > Peng> above code so that I can understand. But I failed. Could you please
    > Peng> help generate a minimal example to help me understand the above usage
    > Peng> of "grep {$field->$_}"?
    >
    > It'd help for you to explain what you *do* understand.
    >
    > Do you know what this does:
    >
    >   $x = "foo":
    >   $field->$x;


    'foo' is a member function of $field, right?
    Peng Yu, Jun 5, 2010
    #3
  4. >>>>> "Peng" == Peng Yu <> writes:

    >>   $x = "foo":
    >>   $field->$x;


    Peng> 'foo' is a member function of $field, right?

    Perl doesn't have "member functions".

    However, if you mean "is this the same as $field->foo", yes. :)

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
    See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
    Randal L. Schwartz, Jun 5, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    1
    Views:
    418
    Paul Lutus
    Oct 20, 2004
  2. Carlos
    Replies:
    0
    Views:
    285
    Carlos
    Oct 23, 2008
  3. grocery_stocker

    What does 'grep -M' do?

    grocery_stocker, Apr 15, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    285
    Tad McClellan
    Apr 15, 2007
  4. Sound
    Replies:
    2
    Views:
    423
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    402
Loading...

Share This Page