On Tue, Aug 16, 2011 at 11:00 AM, ANJAN PURKAYASTHA
<anjan.purkayas...@gmail.com> wrote:
> print("$bacteria->id\t$bacteria->name\n");
...
> and the following ouput:
> Bio::Taxon=HASH(0x158dbe0)->id    Bio::Taxon=HASH(0x158dbe0)->name

You appear to intend to call methods on $bacteria, but since you're
within a string what's really happening is $bacteria is being
converted to a string, which is where the "ClassName=HASH(0xaddress)"
output comes from, and the ->method_name part is just output literally
since Perl doesn't understand what you want. You can't normally call a
method embedded in a string like that. You have two (three) options:

* Call the methods separately and store the results in variables:

my $id = $bacteria->id;
my $name = $bacteria->name;
print "$id\t$name\n";

* Pass the result of each method call as a separate parameter to print:

print $bacteria->id, "\t", $bacteria->name, "\n";

* Use the "turtle operator" as a hack to achieve the method call
within the string:

print "@{[$bacteria->id]}\t@{[$bacteria->name]}\n";

The latter words because @{} attempts to dereference an arrayref and
[] creates a new anonymous arrayref; the contents of which are the
result of each method call. This way is probably least recommended
because it's somewhat obscure (obviously it's more difficult to read)
and it's probably less efficient too since Perl probably has to create
the arrayref only to dereference it right away and forget about it. So
you should probably use one of the former two options instead.

(I reserve the right to be completely wrong :D)


-- 
Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to