genyded has asked for the wisdom of the Perl Monks concerning the following question:

I hope this is a no-brainer, but I cannot seem to figure it out:

#some code...
use Data::Type qw(:all +W3C);
#some more code...
$found++ if (dvalid($string W3C::STRING));
#dvalid is a function in Data::Type
#and even more code...

Works fine and increments $found if $string is a string.

#some code...
use Data::Type wq(:all +W3C);
#some more code...
$type = 'W3C::STRING';
$found++ if (dvalid($search, $type));
#and even more code...

Does not increment $found, but does not return any errors. I need to somehow pass a type to dvalid based on what type the user passed in that they wanted to check $string for.
Please tell me how abivously I am missing a dereference or something somewhere ;-) TIA!

Replies are listed 'Best First'.
Re: Passing values to external packages
by ikegami (Patriarch) on Oct 05, 2007 at 15:25 UTC
    The difference is the quotes around W3C::STRING. It's a function call in your first snippet, and a string literal in the second.

    By the way, using <c>...</c> around code to post is an easy way to handle posting code on PerlMonks. It saves you from putting all the line breaks and escaping characters such as <.

      That makes complete sense! Thanks for the fast response and advice on posting tags.
      It gets a bit more complicated now because I need to append the value of a variable coming from an XML file to part of the function call value as follows:
      #... $value = $verify->{content}; #string value pulled from XML file ($valu +e = STRING) $wc3_type = W3C::.$value #will not work
      How can I append the scalar $value to the function call without it being a quoted value?

      TIA AGAIN!
        You could use a lookup table.
        my %validators = ( string => W3C::STRING, ... ); my $type = $verify->{content}; my $validator = $validators{lc($type)}; if (!defined($validator) || !dvalid($search, $validator)) { die }
      Well - more code than I had hope to write for this, but it works wonderfully. Thanks for the quick and helpful responses.