Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6571503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:53:28+00:00 2026-05-25T14:53:28+00:00

I am using Perl version 5.12.4 from active state on Windows XP(Version 5.1.2600).Installed ParseLex

  • 0

I am using Perl version 5.12.4 from active state on Windows XP(Version 5.1.2600).Installed ParseLex 2.20.
Trying to run this code from Pro Perl Parsing book from Apress.

#!/usr/bin/perl

use Parse::Lex;

#defines the tokens
@token=qw(  
BegParen [\(]
EndParen [\)]
Operator [-+*/^]
Number   [-?\d+|-?\d+\.\d*]
);
$lexer=Parse::Lex->new(@token); #Specifies the lexer
$lexer->from(STDIN); #Specifies the input source

TOKEN:
while(1){ #1 will be returned unless EOI
$token=$lexer->next;
if(not $lexer->eoi){
    print $token->name . " " . $token->text . " " . "\n";
}
else {last TOKEN;}
}

As this was not working I simplified by Number [-?\d+].
It is telling me “Can’t call method “name” on an undefined value “.It is not recognizing $token->name & $token->text.
What I am missing here? Please help.

As per Alexandar’s suggestion I have changed the code to $lexer->from(*STDIN); and able to successfully read from stdin.Also changed Number [(-?\d+)|(-?\d+.\d*)].Now when I feed 43.4*15^2 to the STDIN the output I get is:

Number 4
Number 3
Number .
Number 4
Operator *
Number 1
Number 5
Operator ^
Number 2
Can't call method "name" on an undefined value at listing1-1.pl line 20, <STDIN>.

Here line 20 is print $token->name, ” “, $token->text,”\n”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:53:29+00:00Added an answer on May 25, 2026 at 2:53 pm

    It should be “Number -?\d+|-?\d+.\d*” and to read from STDIN “from” method should be called this way:

    $lexer->from(\*STDIN);
    

    Update full code with better error handling and fixes:

    #!/usr/bin/perl
    
    use Parse::Lex;
    
    #defines the tokens
    my @token=(qw(  
    BegParen [\(]
    EndParen [\)]
    Operator [-+*/^]
    Number   -?\d+(?:\.\d*)?
    NEWLINE  \n
         ),
         qw(ERROR  (?s:.*)), sub {
           print STDERR "ERROR: buffer content->", $_[0]->lexer->buffer, "<-\n";
           die qq!can\'t analyze: "$_[1]"!;
         }
    );
    my $lexer=Parse::Lex->new(@token); #Specifies the lexer
    $lexer->from(\*STDIN); #Specifies the input source
    
    TOKEN:
    while(1){ #1 will be returned unless EOI
      my $token=$lexer->next;
      if (not $lexer->eoi){
        print $token->name . " " . $token->text . " " . "\n";
      }
      else {last TOKEN;}
    }
    

    Also see Parse::Lex documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a windows box with the latest version of ActivePerl installed from
I installed active perl same version on windows XP and windows 7. I have
I'm using this from the command line: perl -MDateTime::Format::DateManip -le 'print $Some::Module::VERSION' but only
I'm actually trying to install RRDTool on windows, using strawberry perl and it's nice
In an older version of our code, we called out from Perl to do
1.Download source from OpenSSL (openssl-1.0.0d). 2.Build it static using this: > perl Configure VC-WIN32
I'm looking for a Perl version of the code on this page: http://www.linuxquestions.org/questions/linux-general-1/how-to-bring-up-application-window-to-front-from-shell-script-83545/ So
Using Perl, how do I check if a particular Windows process is running or
At work I'm using Perl 5.8.0 on Windows. When I first put Perl on,
Replacing the Special Character using Perl while i am doing this . I got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.