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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Am I referencing de-referencing properly? 1

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
US
I was reading the adding multiple value to a hash thread and I checked out the perldoc and I was wondering if this code is ok:

Code:
my @ticTblCnts = ();
my $tableIndex = 0;
foreach my $loc (@out_locations) {
	foreach my $crit(@out_priorities) {
		foreach my $ty (@out_types) {
			my $combin = ("$loc,$crit,$ty");
			$ticTblCnts[$tableIndex] = TicketTable ($combin, \@tic_vars);
			$tableIndex++;
	         }
        }
}

I am calling my function "TicketTable" that returns this:

Code:
return (\@sub_return);

my @sub_return array is getting re-initialized each time I call the function with my so I think I am ok, but should my code be:

Code:
my @ticTblCnts = ();
my $tableIndex = 0;
foreach my $loc (@out_locations) {
	foreach my $crit(@out_priorities) {
		foreach my $ty (@out_types) {
			my $combin = ("$loc,$crit,$ty");
			$ticTblCnts[$tableIndex] = [red] [ TicketTable ($combin, \@tic_vars) ] [/red];
			$tableIndex++;
	         }
        }
}

I am dereferencing this way:

Code:
	my @ticTblDeref = ();
	foreach (@ticTblCnts) {
		push (@ticTblDeref,@$_);
	}

????????


Nick

I got a Biz Degree! How the h*ll did I get here?
 
Code:
return (\@sub_return);
is returning a reference to the array, so you probably don't want to make another array reference containing only one element of that array ref....if that makes sense. Basically, calling it like that would mean you'd say
Code:
push (@ticTblDeref,@{$_->[0]});
so you're probably better off without the anonymous array ref, as you have in your first code snippet

________________________________________
Andrew

I work for a gift card company!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top