in reply to user input behavior from within a subroutine

Hi bw,

What I would do (and often have done myself, either for a Perlmonks post, or just on my own), is to strip out parts of the code, a little bit at a time, and continuously retry it.  Your goal should be to make it as close to the original post as you can.  (And do, please, add "use strict;" and "use warnings;" at the top of the code first).

If at any point it starts working, assuming the changes you made were small each time, you will probably say "Aha!", and have reached enlightenment on your own.

If not, you can post the new, shortened, and hopefully less inelegant code here, and one of use will say "Aha!", and point you towards enlightenment.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
  • Comment on Re: user input behavior from within a subroutine

Replies are listed 'Best First'.
Re^2: user input behavior from within a subroutine
by bw (Novice) on Aug 02, 2006 at 20:30 UTC
    Thank you liverpole. I will indeed take this approach. Regarding strict and warnings, I do use the latter. I've tried the former but don't understand it very well. As a result, I end up using it very badly.

    I'm having a tough time getting my mind around what 'use strict' does (though I'm busily poring through various FAQs I can find to sort it out). Any good/understandable-for-the-newbie links you happen to know on the subject will be most appreciated!

    As a "for instance" regarding my lack of 'strict', whenever I use an array where I've specified 'strict', I have to refer to it during the rest of the script as main::@whatever. I'm sure that's not the right way to approach this, but I haven't found a better way to do this.
      Hi again, bw,

          I have to refer to it during the rest of the script as main::@whatever

      No, you're correct that you shouldn't have to do that.  Can you post or /msg me a very short example?  I'll be happy to show you how to fix it.

      Here is the Perl documentation for use strict;.


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
        I see in my earlier posting that I referred to the fully-qualified variable improperly. I should have said @main::whatever, not main::@whatever. I think that I understand that @main::whatever qualifies it, assuming I'm declaring the value in the 'main' part of the program and not in a subroutine somewhere, for the rest of the program.
        If I use it within a subroutine (declaring it first in the 'main' portion of the program), am I correct to understand that I should pass it to the subroutine as subroutine_name(\@main::whatever)?

        In any case, here's the answer to your question to me--

        Doing:
        use strict; use warnings; @existingattributes = ();
        Produces the error:

        Global symbol "@existingattributes" requires explicit package name at C:\Perl\scripts\configurator.pl line 5.
        Execution of C:\Perl\scripts\configurator.pl aborted due to compilation errors.

        But perl is happy when I do this:
        use strict; use warnings; # initialize arrays @main::existingattributes = ();