Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@array making a name out of 2 variables

Status
Not open for further replies.

northernbloke

Programmer
Aug 9, 2000
29
0
0
GB
I am suffering badly,

What I am trying to do is pass a @array to a sub, but I want the @array to be obtained from 2 vars, like thus:

%arr_names = {
"01", "bill",
"03", "sam",
"06", "copies",
"08", "copies",
"09", "Steve" };
@arr_06 = ("John","Bill");
@arr_08 = ("John","Sam");
.
.
if ($arr_names{$who} == "copies" ) {
&copy_to(@arr_{$who});
}

lots of code is missing, $who is the key of arr_names.
basically, I want the sub to receive the contents of arr_06, or arr_08.

What have I missed,

Cheers for any guidance.
 
erm,

messy posting there.

the copyright notice is supposed to be
ampersand followed by
cc_to(@arr_{$who});

I dont know how to post an ampersand.....
 
You should rethink your data structures if you have to start kludging like this. You could have accomplished the same thing with
Code:
my %arr_names = (
    "01" => "bill",
    "03" => "sam",
    "06" => "copies",
    "08" => "copies",
    "09" => "Steve"
);
@arr[6,8] = (["John","Bill"],["John","Sam"]);
if ($arr_names{$who} eq "copies" ) {
  cc_to($arr[$who]);
}

Also, some errors in your code:
1) hashes are defined with () and not {} unless you are defining a reference to a hash.
2) when comparing strings use 'eq', '==' is for numerical comparisons.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top