user2089651
user2089651

Reputation: 1

Perl in calling methods

Please tell me what does this mean

my ( $keepers, $bogus, $unknown ) =
   TCO::Test::Param::test_params('session' => $s, 'expected' => $allowed_params);

on test method

my %base_profile = TCO::Test::Param::std_profile();
my $profile      = {
    'session'  => $base_profile{'session'},
    'expected' => $base_profile{'params'},
};
my %config = validate( @_, $profile );

my ( $s, $gooduns ) = @config{ 'session', 'expected' };

my ( $keepers, $bogus, $unknown ) =
    scrub_base( 'raw_params' => $s->{_raw_params}, 'expected' => $gooduns );

foreach ( keys %{$keepers} ) {
    $keepers->{$_} = $keepers->{$_}->[-1];
}

clean_params( { 'params' => $keepers } );

# These are sometimes passed in by carts and must be squashed if they are.
delete $unknown->{x_exp_date} if ( $unknown->{x_exp_date} );

delete $unknown->{x_card_num} if ( $unknown->{x_card_num} );

delete $bogus->{x_exp_date}   if ( $bogus->{x_exp_date} );

delete $bogus->{x_card_num}   if ( $bogus->{x_card_num} );

delete $keepers->{x_exp_date} if ( $keepers->{x_exp_date} );

delete $keepers->{x_card_num} if ( $keepers->{x_card_num} );

return ( $keepers, $bogus, $unknown );

2) $sale->{state}{ind} = 0; what does this mean?

I tried to print $keepers to STDERR . then it gives a Hash. Can't i access the value in it. How can I access it. Please reply.

Upvotes: 0

Views: 108

Answers (3)

cdarke
cdarke

Reputation: 44344

Your question 2:

$sale->{state}{ind} = 0; 

what does this mean?

$sale must be a reference to a hash. Why? Because it is followed by ->{ }. Try:

use Data::Dumper;
print Dumper($sale);

The hash that $sale refers to has at least one key, called state. The value of key state is a reference to another hash. That other hash has at least one key, called ind, and the statement sets its value to zero.

This statement can be run even if the key state does not already exist. The statement would create the key, and it's value, and the second hash, all automagically, in a process known as autovivification.

Suggestion: only ask one question at a time. It makes the answers clearer and easier for others to reference. Just as a subroutine should only do one thing, so should your question, and for the same reasons.

Upvotes: 0

ikegami
ikegami

Reputation: 385496

what does this mean

It's a call to subroutine TCO::Test::Param::test_params. Four arguments are passed to it. The first three values returned are stored in $keepers, $bogus, and $unknown.


then it gives a Hash.

It's a reference to a hash. A sub can't return hashes, just a list of scalars.


How can I access it.

keys(%$keepers)

$keepers->{$key}

Upvotes: 5

gpojd
gpojd

Reputation: 23055

The TCO::Test::Param::test_params subroutine returns a list. The line that you are asking about unpacks the return value into three different variables, $keepers, $bogus, and $unknown.

To see what is in $keepers, you can dump the hash:

use Data::Dumper;
warn Dumper( $keepers );

Upvotes: 0

Related Questions