AkshaiShah
AkshaiShah

Reputation: 5939

Map Array to Hash Syntax error

I'm not too sure why, but I keep getting a syntax error with the following: near ") :"

my %temp =  map { /(\S+)\:x\:(\S+)\:(\S+)/ ? ($1 => $2) : (); 
                  ($1.'members' => $3) : ()
                } @output;

Ideally what I want to do, is assign $1 to $2, and then $1.'members' to $3. It seems ok to me, but I can't figure out what the issue is.

Any help is much appreciated!

Upvotes: 0

Views: 53

Answers (1)

tobyink
tobyink

Reputation: 13664

Forget the map for a moment, and just look at this code:

/(\S+)\:x\:(\S+)\:(\S+)/ ? ($1 => $2) : (); 
($1.'members' => $3) : ();

What's that supposed to mean? This line in particular is a syntax error:

($1.'members' => $3) : ();

I think you want:

/(\S+)\:x\:(\S+)\:(\S+)/
   ? ($1 => $2, $1.'members' => $3)
   : ();

Adding back in the map:

my %temp = map {
               /(\S+)\:x\:(\S+)\:(\S+)/
                   ? ($1 => $2, $1.'members' => $3)
                   : ();
           } @output;

Upvotes: 4

Related Questions