Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: A Tricky Problem with Context

by RSevrinsky (Scribe)
on Apr 08, 2002 at 08:37 UTC ( [id://157386]=note: print w/replies, xml ) Need Help??


in reply to A Tricky Problem with Context

I don't think that a second parse or using tie would make any difference here. Bear in mind that Visual Basic is not that smart either. I also thought that an unexplicitly-defined variable, like x in your example, is treated by VB as the omnivorous Variant, but MSDN claims that it automatically becomes an object. Strange -- that might be a difference between VB6 and VB.NET.

You are clearly building your own namespace table -- that's how you determined in the first example that x was an array. In nonstrict code, you're just going to have to determine a variable's type based on assignment. In the second example, that's not too difficult: split would imply an array. But what if the unknown Object is returned from a function:

x = FetchSomethingStrange(a) Function FetchSomethingStrange(p as Integer) If p < 5 Then FetchSomethingStrange = split("my,array,result", ",") Else FetchSomethingStrange = "my string result" End If End Function

Now, in this case, there's no way of knowing until runtime whether FetchSomethingStrange is going to return a String or an array. That leaves you with 2 options (as I see it):

  • a VBVar object, like stephen suggested
  • translating all VB arrays to Perl listrefs.

The listrefs would translate your nonstrict code as follows:

$x = b_split('john,biran,someone',','); print($x->[0] . $x->[2]); sub b_split { # not fully finished, needs $count and $compare my ($string, $delimiter, $count, $compare) = @_; $delimiter = quotemeta($delimiter); return [ split(/$delimiter/, $string) ]; }

My code translates well, too:

$x = FetchSomethingStrange($a); sub FetchSomethingStrange { my($p) = @_; my $FetchSomethingStrange; # Autogenerated return value for VB funct +ions if ($p < 5) { $FetchSomethingStrange = b_split("my,array,result", ","); } else { $FetchSomethingStrange = "my string result" } return $FetchSomethingStrange; # Autoreturn }

Again, you should be fine as long as the Perl translation is always talking in scalars, be they adapted VB scalars (String, Integer, Double) , Variant or Object types, or listrefs derived from Variant/Object auto-arrays or even from explicitly Dimed arrays.

- Richie

Replies are listed 'Best First'.
Re: Re: A Tricky Problem with Context
by Juerd (Abbot) on Apr 08, 2002 at 09:40 UTC

    * translating all VB arrays to Perl listrefs.

    arrayrefs.

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

Re: Re: A Tricky Problem with Context
by tlhf (Scribe) on Apr 08, 2002 at 14:34 UTC
    Wow, I've done some testing with that, and I seem to be able to get some of it working :-). I'm still unsure of whether to go with the 'VBVar' idea or the listref idea - the listref seems faster, but VBVar seems like it would provide more compatibility.

    tlhf
    xxx
    btw, my converter is for VBScript, not VB. Think ASP.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-28 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found