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

I am using IO::Prompt to prompt the user for input (go figure!). I am also using the 'require' option, which continually prints the prompt until the user enters a required form of input.

The problem crops up when I run the script from an env PATH in any given directory. Instead of '/r'ing and reprinting require's string argument over the previous prompt, it outputs newlines. If I run the script using ./script.pl when in /usr/local/bin/, it runs fine and I get the expected behavior.

How can I eliminate the difference between running a script from a PATH or running it inside its directory?

Update with some code...

#!/usr/bin/perl use IO::Prompt; prompt "next: ", -integer, -require => { 'next (must be > 0):' => sub { $_ > 0 } }; print "[$_]\n";
This is actually from the examples included in the module. Typing ABC and pushing enter should simply overwrite the previous prompt with a new blank one. In my case, it's creating newlines.

Replies are listed 'Best First'.
Re: Cygwin/perl PATH oddities
by ikegami (Patriarch) on May 14, 2008 at 02:06 UTC
    What are the contents of %INC when it works and when it doesn't work? The only code in your snippet and IO::Prompt that depend on the path is use.

    Wouldn't hurt to tell us what $IO::Prompt::VERSION is (again, when it works and when it doesn't work).

    One possible source of newlines (in 0.99.4) is

    sub _clear { return unless $_[0]; open my $OUT, ">/dev/tty" or croak "Cannot write to terminal: $!"; print {$OUT} "\n" x 60; $clearfirst = 0; }
    But that requires -clear, -clearfirst or -f to be specified as far as I can tell.
Re: Cygwin/perl PATH oddities
by syphilis (Archbishop) on May 13, 2008 at 09:43 UTC
    How can I eliminate the difference between running a script from a PATH or running it inside its directory?

    I'm not sure that I understand that question. Do you mean that running the script as perl subdir/script.pl produces output that differs from what you get when you cd to subdir and run the script as perl script.pl ?

    Also, your chances of receiving good help would improve significantly if you went those few extra yards and provided us with a small, simple, self-contained script that demonstrates the problem - something that we could just download and run. (Some of us are quite happy to go to the trouble of installing a module simply in order to take a look at a problem - but draw the line at having to write our own test script.)

    Cheers,
    Rob
      Thanks Rob... Hopefully the code provided is adequate.

      Basically, when I put the script in /usr/local/bin/ (which is a PATH), I am allowed to run it in any directory without specifically enumerating the path to the script. For example, if I am in /home/mrdan/, I do not have to specify my path as ../../usr/local/bin/script.pl. Running it in this manner produces the problem.

      However, if I do navigate to /usr/local/bin and type ./script.pl, I do not encounter the problem.

      I am sure you were already familiar with the concept of PATHs, but hopefully this clears things up a bit.

        Yes, I understand. (I always run my scripts as perl script.pl.)

        If you draw a blank here you might get some help on the Cygwin mailing list.

        Cheers,
        Rob