Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: global var

by haukex (Archbishop)
on Apr 06, 2017 at 14:08 UTC ( [id://1187293]=note: print w/replies, xml ) Need Help??


in reply to Re^3: global var
in thread global var

use xxx (); #imports all of the symbols in @EXPORT use xxx qw(OpenConnection $LoggedOn_user_id); # imports # all of the symbols in @EXPORT AND subroutine OpenConnection # AND the scalar $LoggedOn_user_id from @EXPORT_OK

Sorry, but those two are incorrect. As per use, use Foo (); is exactly equivalent to BEGIN { require Foo }, so nothing is exported at all. When you say use Foo qw/bar/;, Exporter exports only that, regardless of what's in @EXPORT.

Update: Hm, my posting seems to have overlapped with an update to the node.

Replies are listed 'Best First'.
Re^5: global var
by tultalk (Monk) on Apr 06, 2017 at 21:11 UTC

    Not impressed with EXPORT_OK. Have spent the last 4 hours adding functions to use xxx qw(....) and screwing lots of things up. Calls to cgi? action invoked functions calls that I then had to ad.

    Not worth it??

    My underlying problem still remains with one scalar value that will not import.

    Yuck!!!

      Have spent the last 4 hours adding functions to use xxx qw(....) and screwing lots of things up.

      It would be better if you tried to understand what's going on. Doing the same thing over and over again and expecting a different output is tantamount to madness (paraphrasing Einstein).

      I would be glad if I could help you (call it helper syndrome if you want, or let it be as is.)

      Refactoring a shitty old codebase requires skills surpassing the ability to write the stuff, even if it is just restricting what Exporter exports, and fixing the subsequent importing mantras. As computing lore says:

      Debugging code is much harder than writing it in the first place. If you write your code as smart as you can, you are, by definition, too dumb to debug it.

      So, fixing that ol'crap requires. Use it as it is, and if you don't want to - or are told to not to: build the required skills. Read the docs. We won't spoonfeed them to you.

      Did you read the documentation of Exporter?

      I won't fix your stuff, even if I could, that ain't. I'm not being lured into teaching you basics. That has been your parents job, and if they didn't cope, it's yours now. Read the docs. Read the docs!

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Rather than trying in your application, make a SSCCE. I got one working in 10min, and I don't usually export scalars, so don't have much experience with it.

      pm1187349.pm

      package pm1187349; use warnings; use strict; use Exporter 'import'; our @EXPORT_OK = qw($someScalar someFunction); our $someScalar = "Scalar Text"; sub someFunction { print "I am some function\n"; }

      pm1187349_a.pl

      use warnings; use strict; use lib '.'; # don't import anything into the main:: namespace; must prefix everyth +ing with pm1187349:: use pm1187349; # use them pm1187349::someFunction(); print "someScalar = ${pm1187349::someScalar}\n";

      pm1187349_b.pl

      use warnings; use strict; use lib '.'; # import both a function and a scalar variable, so you don't need to p +refix with pm1187349:: use pm1187349 qw(someFunction $someScalar); # use them someFunction(); print "someScalar = ${someScalar}\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-11-13 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (39 votes). Check out past polls.