Click here to get back home

\@ and \&

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
\@ and \& Rose 03-06-2008
---> Re: \@ and \& Joost Diepenmaa...03-06-2008
Posted by Ben Morrow on March 6, 2008, 9:46 pm
Please log in for more thread options

>
> Oh, thanks! It's "pass by reference"...

Well, yes, literally speaking. However, 'pass by reference' is more
usually used to indicate that the called sub modifies its parameters,
and is able to do so because they were passed by reference; that is not
the case here. Passing a subref is simply the only way to pass a sub
value into another sub.

[code moved up here, for clarity]
> if ($sorted_features) {
> $panel->add_track($sorted_features,
^^
I presume this is a typing error, and that line was supposed to end with
');'?

> $panel->add_track(-label => \&Label,);
> }
>
> sub Label
> {
> my $feature = shift;
>
> my @notes;
> foreach (qw(product result))
> {
> next unless $feature->has_tag($_);
> @notes = $feature->each_tag_value($_);
> last;
> }
> $notes[0];
> }

> But in my specific case that the subroutine "Label" is called in this
> way, is $sorted_features passed and $notes[0] returned?

Label returns $notes[0], yes. Whether, when, and with what arguments
Label is called, and what happens to that return value, are completely
under the control of the $panel object: that's the point of passing it
in, so the object can call it if it wants to. In this case I'd think
it's unlikely it would be called with $sorted_features, but I
couldn't tell without knowing what sort of object $panel is.

> The problem is that I'd like to call Label (the codes of Label can't
> be modified) but don't know how to receive its outputs.

I'm not sure exactly what you are trying to achieve, here. You can call
Label, yourself, with any arguments, and do what you like with the
return value; this is completely independant of the fact you have also
passed it into $panel->add_track. Can you post a *short* complete script
we can all run, and explain how it isn't doing what you want?

Ben


Posted by Rose on March 7, 2008, 12:00 am
Please log in for more thread options
> Label returns $notes[0], yes. Whether, when, and with what arguments
> Label is called, and what happens to that return value, are completely
> under the control of the $panel object: that's the point of passing it
> in, so the object can call it if it wants to. In this case I'd think
> it's unlikely it would be called with $sorted_features, but I
> couldn't tell without knowing what sort of object $panel is.
>
>> The problem is that I'd like to call Label (the codes of Label can't
>> be modified) but don't know how to receive its outputs.
>
> I'm not sure exactly what you are trying to achieve, here. You can call
> Label, yourself, with any arguments, and do what you like with the
> return value; this is completely independant of the fact you have also
> passed it into $panel->add_track. Can you post a *short* complete script
> we can all run, and explain how it isn't doing what you want?
>
> Ben
>

Although Label returns $notes[0], but it in turn depends on
$feature->each_tag_value($_); from where $feature is "shifted" in. I'm
unable to post a short complete script here because reproducing the
hierarchy of the data is impossible. Therefore my focus is try to understand
how to use the codes invented instead of reinventing the wheel.

That's the reason why I care about what is really passed into Label because
I have to ensure my object is in the correct structure to pass. In this
case, is $sorted_features shifted into Label? Or it depends on
add_track behaviour?

if ($sorted_features) {
$panel->add_track($sorted_features, -label => \&Label,);
}

sub Label
{
my $feature = shift;

my @notes;
foreach (qw(product result))
{
next unless $feature->has_tag($_);
@notes = $feature->each_tag_value($_);
last;
}
$notes[0];
}



Posted by Frank Seitz on March 7, 2008, 12:16 am
Please log in for more thread options
Rose wrote:
>
> That's the reason why I care about what is really passed into Label because
> I have to ensure my object is in the correct structure to pass. In this
> case, is $sorted_features shifted into Label? Or it depends on
> add_track behaviour?

It's impossible for us to know what your classes do.
Why don't you look at the source code, preferably of add_track()?

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Posted by Rose on March 7, 2008, 4:03 am
Please log in for more thread options
> It's impossible for us to know what your classes do.
> Why don't you look at the source code, preferably of add_track()?
>
> Frank
> --
> Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
> Anwendungen für Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Dear Frank,

You are correct. I have to get back to study add_track().



Posted by Ben Morrow on March 6, 2008, 9:26 pm
Please log in for more thread options

> Yesterday I was taught that I can use
>
> \@array to refer an array and it does not make a copy of itself.
>
> Indeed i don't quite understand what it means.
>
> Today, I encounter another mysterious symbol \&, could anybody tell me what
> \ and & are for?

\ takes a reference. &Label refers to the sub Label in the current
package. I believe I've already pointed you at perldoc perlreftut: it
explains things better than I could hope to here. Post again if you
still have trouble after reading that.

Ben



Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap