Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Switch.pm Failure ( CGI::Switch? )

by tultalk (Monk)
on Feb 25, 2017 at 19:07 UTC ( [id://1182834]=note: print w/replies, xml ) Need Help??


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

Hi: The question I think is not complicated and does not involve all the reasons I should not be using switch. This program was working for years. Now the message: Can't call method switch without a package or object reference. I have done searches all over on this message and find nothing but elaborate answers. I have used CGI::Search and the package is in my system. So why would the code be unacceptable now and it was not previously. I did comment out use strict to see if that was the culprit. It was not. I am dead in the water.

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

    "This program was working for years."

    I doubt it, somebody changed something

    "I have used CGI::Search"

    even if you meant CGI::Switch, that has nothing to do with "Switch" the way you used it. CGI::Switch was a way to replace the $query=new CGI; statement you have somewhere. my $query = new CGI::Switch; "Per default the new() method tries to call new() in the three packages Apache::CGI, CGI::XA, and CGI. It returns the first CGI object it succeeds with." http://search.cpan.org/~chips/perl5.004/lib/CGI/Switch.pm. CGI::Switch has nothing to do with how the word "Switch" was used here. If you have some sort of versioning system i would go back and look at what existed in the past.

    My bet is that once there was a colon after Switch, or what @haukex noted about a Switch subroutine somewhere Re^5: Switch.pm Failure

    A lot of places ive worked that dont have versioning systems ive created a simple program to make a new backup copy of production code everytime the modified date changed. And everytime someone came to me saying "It stopped working and i didnt change anything" i was able to go into this archive and show them the change THEY made that made it stop working now.

Re^3: Switch.pm Failure ( CGI::Switch? )
by haukex (Archbishop) on Feb 25, 2017 at 19:44 UTC
    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?

      "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 .. +.
        Ok. Thyanks. But what it the meaning of this: ", but the block "never ends?" due to the return. Is that it?" Best regards
      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2024-03-28 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found