in reply to Re^2: Switch.pm Failure ( CGI::Switch? )
in thread Switch.pm Failure

So why would the code be unacceptable now and it was not previously.

Well, what has changed on your server? Did you upgrade Perl, and/or the CGI module, or anything else?

  • Comment on Re^3: Switch.pm Failure ( CGI::Switch? )

Replies are listed 'Best First'.
Re^4: Switch.pm Failure ( CGI::Switch? )
by huck (Prior) on Feb 25, 2017 at 21:34 UTC

    "Did you upgrade Perl"

    probably, Further, Switch was removed from the core in Perl 5.14 http://stackoverflow.com/questions/2630547/why-is-the-switch-module-deprecated-in-perl

    so first they got the message Can't locate Switch.pm in @INC (you may need to install the Switch module), Searched the tree and found a Switch.Pm under CGI, and added use CGI::Switch;, which didnt help a bit.

    ok, so since Switch.pm is no longer core, and i didnt want to install it (being depreciated anyway), i took this http://cpansearch.perl.org/src/RGARCIA/Switch-2.16/Switch.pm and put it in its own directory, and then put this into the same directory

    #!perl -w use strict;use warnings; use Switch; sub Main { Switch {print "hi\n";return;} }
    and glory be got
    hi
    Why, i dunno?

    ok it wasnt that simple. first i tried

    #!perl -w use strict;use warnings; use Switch; Switch {my $a=1};
    and got
    Can't locate object method "Switch" via package "1" (perhaps you forgo +t to load "1"?) at switch.pl line 4.
    Thinking that all those returns were the reason i went to
    #!perl -w use strict;use warnings; use Switch; Switch {my $a=1;return};
    and got
    Can't return outside a subroutine at switch.pl line 4.
    AHAH, the reason for the sub Main {}

    so i cant figure out what Switch {} is doing. there is no sub Switch in Switch.pm (there is a sub switch tho). I figure it has something to do with use Filter::Util::Call and the import and filter subroutines. Can anyone give me a clue?

    edit:fixed case in "Can't locate switch.pm" from a typo/wrong-copy-paste

    edit2: ok i think i got it if a class is used to invoke the method, that argument will be the name of the class.http://docstore.mik.ua/orelly/perl/prog3/ch12_03.htm. so Switch {} is trying to invoke method Switch with an argument (without parens) that is the result of a block, but the block "never ends?" due to the return. Is that it?

      so Switch {} is trying to invoke method Switch with an argument (without parens) that is the result of a block, but the block "never ends?" due to the return. Is that it?

      Interesting theory, and I did forget about Indirect Object Syntax. It's easy to test, but as it turns out it's unlikely this is what's going on here, due to the returns used everywhere in that code. We still need more information from OP.

      sub Foo::new { bless {}, shift } sub Foo::Switch { print "Switch @_\n" } Main(); sub Main { Switch { "Foo" }; Switch { new Foo }; Switch { return }; # just returns } Switch { }; # this dies __END__ Switch Foo Switch Foo=HASH(0x24a5338) Can't call method "Switch" without a package or object reference at .. +.

        The proof is at Re^31: global var. It all started with use Switch;, and the subroutine/returns were to get around the initial invalid use of the Switch method.

      Ok. Thyanks. But what it the meaning of this: ", but the block "never ends?" due to the return. Is that it?" Best regards

        The return(s) in the block force the Main subroutine to terminate early, so control is never passed back to the Switch method. Just erase the Switch word, and delete use CGI::Switch; as i suggested before and all will be fine

        The question was very complicated, and by not telling us what was changed you just made it more complicated. If you had told us you were on a newer version of perl and you changed use Switch; to use CGI::Switch; it probably would have been much easier to figure out.

        And whomever "used a hammer to drive that screw in" to make Switch {...} work rather than determine the original problem did you no favors either. Im known to make furniture with a chainsaw and i dont think ive ever done anything that funky.

Re^4: Switch.pm Failure ( CGI::Switch? )
by tultalk (Monk) on Feb 25, 2017 at 23:18 UTC
    The host lowesthosting changes their servers and used cpanel and later version of perl. I have been trying to get it working again after a period of neglect. Other than the switch issue, everything ok but for a few minor adjustments.