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

P

Peng Yu

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->$_}"?
 
R

Randal L. Schwartz

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
 
P

Peng Yu

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?
 
R

Randal L. Schwartz

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. :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top