in reply to Using HOP::Lexer to parse a document

Change your print loop to:

while ( defined( my $token = $lexer->() ) ) { next if ! defined $token or ! defined @$token; # Skip blank lines +- no tokens my ( $label, $value ) = @$token; print "$label => $value\n"; #print Dumper($token); }

to handle blank and non-token containing lines


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Using HOP::Lexer to parse a document
by runrig (Abbot) on Feb 09, 2006 at 16:46 UTC
    ! defined @$token

    A string is being returned from the lexer, and since it's not a reference, trying to dereference it is an error. Maybe you want:

     ! ref($token)

    But then the lexer is still returning too many TEXT tokens (line 2 and 3 of the output in the OP), so something else needs to be fixed. (update: and I think the fixing needs to be done in HOP::Lexer)(update2: nope, it was the TEXT regex that needed to be fixed)

      Hmm, a bit of C think showing through in my Perl :(. Better would be:

      next if 'ARRAY' ne ref $token; # Skip blank lines - no tokens

      DWIM is Perl's answer to Gödel
      Thanks for your reply :-) When I applyed your first suggestion it worked great!!