Charliexyx
Charliexyx

Reputation: 147

Array Syntax in Perl

I have a question. I have to program a part in php but only got this Perl example and don't understand the exact Syntax:

#showGetInfo(
#   ['Customers/1001/Orders/1001'], #orders paths
#   ['Comment'],                    #additional order attributes
#   ['Street2'],                    #additional address attributes
#   ['TransID','Weight']            #additional lineitem attributes
#);

on another part in the file it says:

sub showGetInfo {
    my @Params = @_;
    my $ahResults = $OrderService->getInfo(@Params)->result;

    [...]
}

Except it is just a comment because of the #'s, I need to copy the structure to php.

I suppose there are arrays created, maybe even some arrays in another array but I don't understand especially how the arraystructure is built here. Can you help me and tell me what the variable @Params would look like in php?

Upvotes: 0

Views: 97

Answers (2)

simbabque
simbabque

Reputation: 54333

The sub showGetInfo gets a list of values passed as its arguments. Those end up in the array @_. That gets assigned to the new lexical array @Params. Lexical means, it's only available in this sub.

Next, the method getInfo() is called on the object $OrderService. It is passed the same arguments that shoGetInfo got.

From the call you showed, let's look at those parameters:

['Customers/1001/Orders/1001'], #orders paths

This is an array reference. It contains one value: The string 'Customers/1001/Orders/1001'.

['Comment'],                    #additional order attributes

Again, an array ref with one string in it.

['Street2'],                    #additional address attributes

Another of those.

['TransID','Weight']            #additional lineitem attributes

This array reference contains two entries. One is the string 'TransID', the other 'Weight'.


To translate this to PHP, you can just use normal arrays. No need for references like in Perl in PHP.

Upvotes: 4

mpapec
mpapec

Reputation: 50647

Can you help me and tell me what the variable @Params would look like in php?

In php $Params would be like in perl, array of array

array(
  array('Customers/1001/Orders/1001'), #orders paths
  array('Comment'),                    #additional order attributes
  array('Street2'),                    #additional address attributes
  array('TransID','Weight')            #additional lineitem attributes
);

Upvotes: 2

Related Questions