Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Monks,

My last question turned out to be a basic RTFM, but this one has me truly stymied. I seek your wisdom...

Before I start, I know there is inherent danger in what I am asking. So hear me out before you flame me. As you could probably guess from my previous question, I'm creating a custom dialog in Windows. That dialog will drive a number of reports based on report name. Two widgets are disabled for certain users based on an XML configuration file. The schema of the XML is such that it's possible to describe behavior of the widget even if it is not enabled. However, trying to alter the behavior of the disabled widget causes issues in my program.

I've already worked out a way to avoid problems, but the conditional clause is pretty ugly. Basically I take in a name from the XML, and compare the name to the two known problem widgets. If it's neither name, I pass through. If it's one or the other name, and the widget with that name is enabled, I pass through. If the widget is disabled, I jump out. The condition looks something like this:

# Check if this is a problem widget, and if it is, is it visible if( ($widget_name ne "problem1" && $widget_name ne "problem2") || ($widget_name eq "problem1" && $problem1->IsVisible()) || ($widget_name eq "problem2" && $problem2->IsVisible()) ) { ... }

What would be much cleaner would be if I could get a reference to the original widget scalar based on the scalar's name. Something akin to getting a reference to a routine using my $ref = \&{'mysub'}; . I could then dereference the original widget scalar based on name and check if it's visible. Something along the lines of:

#Get reference to widget based on name then check if it's visible my $ref = \${$widget_name}; if($$ref->IsVisible()) { ... }

And before you object, the XML schema is such that the XML will be invalid if some wag puts in Robert'); DROP TABLE STUDENTS; -- or similar. Only actual valid widget names will work, otherwise the XML is invalid.

So is such a thing possible? Or is there some obvious other path that I'm too inexperienced to see?


In reply to Is it possible to get reference to scalar based on scalar name by mrider

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [thezip]: Amazing speed and stealth in that one.
    [GotToBTru]: You can't tunafish, but some seafood companies can tunafish. More fun with English.
    [virtualsue]: a veterinarian told me to cut down on my cat's food. i said, when i do that she just catches more mice
    [thezip]: My dogs are also excellent mousers, at least that's what they tell me.
    [GotToBTru]: our beagle has dispatched 3 rabbits to the Great Hutch in the Sky since March.
    [thezip]: I can always tell when the dogs have been mousing, as there is a concentric ring of mud around the end of their snouts when they do.
    [thezip]: As for more physical evidence, that always seems to be missing somehow
    [Rabbi Bob]: We have a Jack Russell: off the leash she is a torpedo against mice, rats, chipmunks and squirrels
    [Rabbi Bob]: Doesn't eat them, just snaps, kills, drops and moves on.
    [thezip]: Efficient, that one.

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (15)
    As of 2017-11-17 19:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:













      Results (272 votes). Check out past polls.

      Notices?