in reply to Creating Perl5 plugin for Intellij IDEA (Camelcade)

It's really awesome that perl still has a lot to teach after years of programming experience :)

Encountered a code, which i can't interpret (so as my parser). This is a part of PPI::Lexer. We've got an array:

@CURLY_LOOKAHEAD_CLASSES = ( {}, # not used { ';' => 'PPI::Structure::Block', # per perlref '}' => 'PPI::Structure::Constructor', }, { '=>' => 'PPI::Structure::Constructor', }, );
And somewhere else we have such code:
elsif ( my $class = $CURLY_LOOKAHEAD_CLASSES[$position] {$Next->content} )
How does it work? We are assigning list element to the class and what is $Next block?

Thanks in advance

Replies are listed 'Best First'.
Re: Learning perl, after years... (deref)
by tye (Sage) on May 03, 2015 at 18:44 UTC

    You seem to be paying way too much attention to the line break.

    $position is either 1 or 2. $Next->content() is expected to return ';' or '}' when $position is 1 and to return '=>' when $position is 2.

    The code is a rather simple array look-up followed by a hash look-up:

    my $class = $CURLY_LOOKAHEAD_CLASSES[$position]->{ $Next->content() };

    - tye        

      Crap, till now didn't know that $hashref->{key1}->{key2}->{key3} can be written as $hashref->{key1}{key2}{key3} Thank you very much :)