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

For using IO::Prompt, PBP (chp. 17, p. 399) mentions using the -line option/flag for the prompt function. Here's a contrived example:
#!/usr/bin/perl use strict; use warnings; use IO::Prompt; my $resp = prompt -line, "Eh?: "; print "You said: ${resp}And here's a new line.\n";
But I'd expect perl to at least warn me about that "-line" in there. It's got no quotes around it, and it's not in front of a fat comma, so, doesn't that make it a bareword? Shouldn't I be getting a warning about it?
  • Comment on Why doesn't Perl warn me about this bareword? (IO::Prompt prompt -line)
  • Download Code

Replies are listed 'Best First'.
Re: Why doesn't Perl warn me about this bareword? (IO::Prompt prompt -line)
by fishbot_v2 (Chaplain) on Nov 15, 2006 at 19:53 UTC

    It's like the prefix equivalent of the fat arrow. Unary string minus.

    From perlop:

    Unary "-" performs arithmetic negation if the operand is numeric. If the operand is an identifier, a string con- sisting of a minus sign concatenated with the identifier is returned.

      Whoops! Thanks fishbot_v2. I don't know why my brain thought that minus sign was part of the identifier.

      Neat feature/trick. Makes function calls look somewhat like running shell commands.

        Well, the string returned by -word does include the -, so it's an easy mistake to make.

        >perl -e "print -word -word

        Aside, I prefer
        prompt -line => "Eh?: ";
        over
        prompt -line, "Eh?: ";
        since the two form a name-value relation.

        Update: Oops, I thought -line and "Eh?: " were related.