Search code examples
perldictionarymason

Mason - Passing a map of strings to a service call


I am trying to pass a map of string to a service call that I am making from my .mi file.

I am trying the below but it gives me syntax error at ");".

  my $serviceResult = PI::employee::register::Service->saveAttributes(
          attributesMap => map { ('session-id' => $Session->getSessionId())}
      );

If I instead try

 my $serviceResult = PI::employee::register::Service->saveAttributes(
          attributesMap => map { 'session-id' => $Session->getSessionId()}
      );

It says not enough arguments for map. :(


Solution

  • Perl's map function, as documented in perldoc -f map takes a BLOCK (or EXPR) and a LIST. You are not supplying a LIST, therefore your code does not compile.

    You can get rid of the parse error by supplying a list:

    map { ('session-id' => $Session->getSessionId()) } (1)

    This is almost certainly not what you want, though. You are using map in error. You want a map from keys to values, which is not what the map function is for.

    Instead of the call to map, it looks like you need a hashref like

    { 'session-id' => $Session->getSessionId() }

    .