Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

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

Without knowing enough about VB, it's kind of difficult to solve the problem, but here are some pointers and suggestions...

For general cases, you could refer to all variables through objects. It might make it easier for your compiler to refer to variables, since they'd be accessable in a more VBScript-type way. It would be be a little less efficient, but would give you a way of dealing with the fact that the thing named 'x' could be a list, a hash, or a scalar. Like so:

use VBVar; use strict; # We have b_split return a VBVar object my $x = b_split('john,biran,someone',','); # Use value_of(), with optional arguments, to return # the value of the variable $response->write( $x->value_of(0), $x->value_of(2)); sub b_split { # not fully finished, needs $count and $compare my ($string, $delimiter, $count, $compare) = @_; $delimiter = quotemeta($delimiter); # Passes an array ref to the VBVar constructor, # which then creates the underlying object of the right # kind return VBVar->new([ split(/$delimiter/, $string) ]); }
And in
package VBVar; use strict; our %VarTypes = ( ARRAY => 'VBVar::Array', SCALAR => 'VBVar::Scalar', HASH => 'VBVar::Hash' ); ## Have our child classes refer to VBVar as needed @VBVar::Array::ISA = ('VBVar'); @VBVar::Scalar::ISA = ('VBVar'); @VBVar::Hash::ISA = ('VBVar'); ## ## Blesses the reference we pass in to the appropriate ## VBVar type. ## sub new { my $type = shift; my $self = shift; bless $self, $VarTypes{ref $self}; } ## Return the value of VBVar if contents are an array sub VBVar::Array::value_of { my $self = shift; my @indices = @_; # If someone passed in a list of indices to return if (@indices) { return $self->[@indices]; } # Otherwise, return the whole array else { return @$self; } } ## Return the value of VBVar if contents are ## a scalar sub VBVar::Scalar::value_of { return ${ $_[0] }; }

N.B. Code not tested, may not even compile, and should not be used directly; just trying to get the idea across.

The advantage to this is that you can have the function that returns the value decide what kind of variable it is. You could also do the same thing by just returning references all the time, and have all of your functions check for type with 'ref' and take whatever action is appropriate.

For information on tie, see perltie.


In reply to Re: A Tricky Problem with Context by stephen
in thread A Tricky Problem with Context by tlhf

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2022-01-17 05:16 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (51 votes). Check out past polls.