Hi All, I am trying to learn how to use the HOP::Lexer module and am having trouble. I am receiving an error when I try to parse a document. Here is what I have tried.
use strict; use warnings; use HOP::Lexer 'string_lexer'; use Data::Dumper; my $document = join '', <DATA>; my @keywords = ( 'PRODUCT:', 'SUBJECT:', 'SUBMITTED BY:', 'SUBMITTED DATE:', 'IR #:', 'DOCUMENT ID:', 'PLATFORM:', 'OPERATING SYSTEM:', 'OS VERSION:', 'PRODUCT VERSION:' ); my @input_tokens = ( [ 'KEYWORD', qr/(?i:@{[join '|', map {$_} @keywords]})/ ], [ 'TEXT', qr/(.*)/, \&text ], ); my $lexer = string_lexer( $document, @input_tokens ); while ( defined( my $token = $lexer->() ) ) { my ( $label, $value ) = @$token; print $label, " => ", $value, "\n"; #print Dumper($token); } sub text { my ( $label, $value ) = @_; for ($value) { s/^\s+//; s/\s+$//; } return [ $label, $value ]; } __DATA__ PRODUCT: NX_Nastran SUBJECT: How can I multiply the displacement vector by a matrix? SUBMITTED BY: TOM ZHANG SUBMITTED DATE: 02/07/2006 IR #: 5395926 DOCUMENT ID: 001-5395926 PLATFORM: INTEL OPERATING SYSTEM: WINDOW OS VERSION: XP32_SP2 PRODUCT VERSION: V4.0 ====================================================================== +========= HARDWARE -------- Family : NX_NASTRAN Application : NASTRAN Function : DMAP Subfunction : ALL Release : V4.0 Platform : INTEL OS : WINDOW OS Version : XP32_SP2 SYMPTOM ------- This article discusses writing a DMAP that performs multiplication of +the displacement vector by a matrix. SOL 101 is used. The article discusse +s these concerns: 1. what data block is the displacement vector? 2. how to handle multiple subcases? 3. which print module to use SOLUTION -------- Answer: 1. The displacement vector is UG. It is generated in subDMAP SEDISP (y +ou can use DIAG 14 to print the whole thing in the f06 file and search for SE +DISP). You can put your alter in any place in SEDISP after it is created. A s +uggested entry point is after line 587. You can use something like ALTER 'CALL +SESUM' this is better than "ALTER 587' because the latter would break if the +subDMAP SEDISP changed. REFERENCES ---------------- ====================================================================== +========= -- End of document --
The error I receive is this:
D:\scripts>me4.pl KEYWORD => PRODUCT: TEXT => NX_Nastran TEXT => NX_Nastran KEYWORD => SUBJECT: TEXT => How can I multiply the displacement vector by a matrix? Can't use string (" How can I multiply the displace") as an ARRAY ref +while "str ict refs" in use at D:\scripts\me4.pl line 28, <DATA> line 52. D:\scripts>
Does anyone know what I am doing wrong? Thanks

Edited by planetscape - added readmore tags


In reply to Using HOP::Lexer to parse a document by monsterzero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.