Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

do() oddity

by earthboundmisfit (Chaplain)
on Sep 24, 2001 at 16:35 UTC ( [id://114298]=perlquestion: print w/replies, xml ) Need Help??

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

I originally intended to post this as a Meditation because a true Meditation is something that leads to enlightenment. But I've come to the realization that I don't undertstand this at all. So I come to you seeking Wisdom.

# tested with Perl 5.6.x perl -e "do(!$var);"
The somewhat amusing error message resulting from this implies that I'm asking Perl to accomplish some superhuman (supercomputational?) feat. I'm going on the assumption that this is being read as a deprecated subroutine call based on the current edition of the camel book, and that perhaps the negated class is doing something weird with the parser, but other than that, I cannot come up with an explanation for why this happens. Can someone enlighten me?

Interestingly, adding a warnings switch squashes the error.

Replies are listed 'Best First'.
Re: do() oddity
by clintp (Curate) on Sep 24, 2001 at 17:12 UTC
    It'd be nice if you would have posted the error message. I assume you mean the error below. Trying this under 5.6.0, changing the quotes to keep the $ and the ! from my shell I get:
    Perl v49.0.4294967295 required--this is only v5.6.0
    And this isn't too hard to figure out.

    The syntax "do(5.7)" essentially does the same thing as "require(5.7)" which causes perl to ensure that the version of the interpreter is at least 5.7. That's where the "required" message comes from. What about that number?

    vstrings: they're buggy nasty little creatures that should have been squished when first proposed for Perl 5. Nontheless, we've got them and in certain corners of perl the implementation is less than stellar.

    If we agree to that, where'd the number come from? Well, try this:

    perl -e 'print ~1'
    Okay, the string I get is 4294967294. That's part of the version string that prints out. What I suspect is that the !$var is getting 1-complemented into this string, do's trying to use that as a version number, and the vstring implementation has decided that it's really version 49.0.429... for display purposes. There's probably some odd conversion in there to get 49.0 out of that number.

    update: The "49" comes from 1 being ASCII 49. The 429... from the 1's complement. The 0? The arrangement? Still a mystery. And since vstrings and do are involved, should probably remain that way.

Re: do() oddity
by japhy (Canon) on Sep 24, 2001 at 17:15 UTC
    The do() function is really broken. It does too much. It's interpreting your code as do(v1) for some weird reason -- not just 1, but a v-string containing the character "1". That v-string represents 49.0.0.

    Why does it do this? The function is really broken.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

(crazyinsomniac: do {}) Re: do() oddity
by crazyinsomniac (Prior) on Sep 25, 2001 at 11:19 UTC
    Yup, i see the same thing, but what that ain't is the only way to invoke do.
    If you call it blocky like perl -Mstrict -we"print do{!$ARGV}", you don't get that amusing error message (you just get 1).

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Re: do() oddity
by buckaduck (Chaplain) on Sep 25, 2001 at 00:39 UTC
    I have no idea if this is related to your problem, but...

    When I try any variation of your command from the csh shell in UNIX, the !$ symbol is expanded to the last argument of my previous shell command. This happens whether you use single or double quotes around the Perl code.

    Example using Perl v. 5.005:

    % cd /etc % perl -e 'do (!$var)' perl -e 'do (/etcvar)' Search pattern not terminated at -e line 1

    The exact error message depends on whatever the previous command was, of course.

    buckaduck

Re: do() oddity
by earthboundmisfit (Chaplain) on Sep 25, 2001 at 03:38 UTC
    Yet another reason to avoid do and a much simpler explanation than I had imaginied. Thanks for the information. Sorry for the dumb question.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found