What you are thinking of is some kind of a closure, like this:
my $make_output = sub {
my ($Registration, $Rank) = @_;
return @{ $Data{$Registration}->{Name} }[$Rank], "\t";
};
print $make_output->($Registration1, $Rank1),
$make_output->($Registration2, $Rank2);
Though I guess that you might be able to simplify your code by using techniques such as OO.
Update: The following code shows what an OO variant would look like. Maybe you are trying to do something completely different; but according to your short line of code, I imagine that you could probably use this example.
my $data = Data->new( ... );
print $data->make_output($Registration1, $Rank1),
$data->make_output($Registration2, $Rank2);
# class definition
package Data;
sub new {
# set up data object
# ...
}
sub make_output {
my ($self, $Registration, $Rank) = @_;
return @{ $self->{$Registration}->{Name} }[$Rank], "\t";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.