Search code examples
perlhttp-redirectargsmason

Adding values to ARGS in perl mason


I want to add values to my ARGS before I pass that as a parameter in the redirect call.

I tried

%ARGS{session-id} = 'value1';

Gives syntax error. Can you please suggest the right away. And are the keys with hyphen in the name are not allowed ? If not how can I pass that to my redirect call as the component I am redirecting to is expecting a 'session-id' from %ARGS.


Solution

  • Use

    $ARGS{'session-id'} = 'value1';
    

    session-id is not a valid identifier in Perl; hash keys can only be used unquoted if they are valid identifiers.

    Also, use $ as the sigil (the de-referencing character in front of the variable name) when accessing a single element of a hash; @ when accessing multiple elements of a hash; and % only when accessing the entire hash (or in Perl 5.20 and up, when accessing both keys and values of part of a hash).