Understanding perl statement

can someone help me how to interpret this line?

my ($class, $hashref) = @_;

my $portfolio = {};

if \($hashref->\{portfolio_id\}\) \{

($portfolio) = GEmySQL->get ("select * from portfolio where portfolio.id=$hashref->{portfolio_id}");
}

Question: how do you read statement four? From left to right? or Right to left?

@_ is the parameters passed to the subroutine, so it's putting the passed-in parameters into the local $class and $hashref variables.

$hashref is presumably a reference to a hash, so you can look up names inside it like ->{index}

I don't quite understand your question about statement four. I'll try and break it down.

# GEmySQL is an object here, which contains various different
# function calls which you can access with ->
# Then the result of this function call is assigned to a variable.
($portfolio) = GEmySQL->get (...);

Where ... means

"select * from portfolio where portfolio.id=$hashref->{portfolio_id}"

The $hashref->{portfolio_id} gets substituted before get() is even called.

1 Like

Nested scripts are read from the inside, out. Find the innermost script/command/calculation that doesn't depend on the results of another command/function. Once you have that value, work your way back out.

1 Like