Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Using STDIN in object creation (Moose)

by Anonymous Monk
on Apr 13, 2016 at 22:12 UTC ( [id://1160354]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am starting to test a module that uses Moose, after a long time from not doing any moose (not that I did much before). Builder routines are calling named subroutines to show the user a prompt on STDOUT, and they read a response on STDIN.

sub _get_anyStr { my $prompt = shift; print "To not give any data, just hit return.\n"; print "$prompt: "; my $resp = <STDIN>; chomp( $resp ); return _suckSpaces( $resp ); }

Taking inspiration from an older country and western movie, I entered 'Comments? We don't need no stinking comments.'. I am single stepping perldb in emacs, and what I see is:

"no" not allowed in expression at (eval 226)[/usr/share/perl/5.20/perl +5db.pl:732] line 2, at end of line syntax error at (eval 226)[/usr/share/perl/5.20/perl5db.pl:732] line 2 +, near "need no stinking "

I am guessing that it is the token 'need' that is causing problems, but I don't know why. I see things being eval'd a lot while single stepping, is this subroutine running in a big eval? This is about the 5th builder I have stepped through, and none of the others caused any problem. It seems my joke for input tickled something.

What happened? Should I be doing something else? The entire reason for doing this in an old command line fashion, is that I don't seem to get the GUI methods. Thanks.

Replies are listed 'Best First'.
Re: Using STDIN in object creation (Moose)
by choroba (Cardinal) on Apr 13, 2016 at 22:33 UTC
    It seems you entered the string into the debugger's STDIN rather than the program's one.

    Verification:

    $ perl -d -e1 Loading DB routines from perl5db.pl version 1.44 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(-e:1): 1 DB<1> Comments? We don't need no stinking comments. "no" not allowed in expression at (eval 6)[/usr/lib/perl5/5.20.1/perl5 +db.pl:732] line 2, at end of line syntax error at (eval 6)[/usr/lib/perl5/5.20.1/perl5db.pl:732] line 2, + near "need no stinking "

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Okay, I'll just add a comment to myself to not enter the word "need" as input when single stepping perldb in emacs. I've been doing Perl since the 80's, and this error was just strange to me. Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1160354]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-30 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found