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

Hello Kind Monks:

I have again painted myself into a corner with a variant array. Below please find the output from dumper from the following code. I need to get at the string within the array.

please what am I doing wrong

use IO::File; use Data::Dumper; use Win32::ODBC; use Win32::OLE; use Win32::OLE::Variant; $blpData = Win32::OLE->new('Bloomberg.Data.1') or die "can NOT load t +he blpData" ; $aSec = Variant(VT_BSTR, "MMM US equity"); $aFields = Variant(VT_ARRAY|VT_BSTR, 1); $aFields->Put(0,"RELATED_EQUITIES") ; $bbData = Variant(VT_EMPTY,1) ; $bbData = $blpData->BLPSubscribe($aSec, $aFields ); print "Error: " . Win32::OLE->LastError . "\n"; #** print " ** ** ** Dumper " . "\n"; print Dumper $bbData; print "\n\nbbdate 0 0 " . "\n"; print $bbData->[0][0]. "\n"; print " ** ** ** Dumper bbdata 0 0 " . "\n"; print Dumper $bbData->[0][0] ; #**print "\n\nbbdata 0 0 0 " . "\n"; #**print $bbDate->[0][0][0] ; #**for my $e (@$bbDate->[0][0]) { #** for my $e2 (@$e ) { #** print "e2: " . $e2 . "\n"; #** } #**}

This is the output.

Error: 0 ** ** ** Dumper $VAR1 = [ [ [ [ 'MMM US' ], [ 'MMM-W US' ], [ 'MMN LI' ], [ 'MMM LN' ], [ 'MMMU NA' ], [ 'MH FP' ], [ 'MMM GR' ], [ 'MMM NA' ], [ 'MMM SW' ], [ 'MMM ES' ], [ 'MMM* MM' ], [ '4851 JP' ], [ 'MMM AR' ], [ 'MMMB AR' ], [ 'MMMC AR' ], [ 'MMMD AR' ], [ '2900086QUS' ], [ 'MTSI GR' ], [ 'RNIC US' ], [ 'AIV CN' ], [ 'AITYF US' ], [ '287476Z US' ], [ '290207Z SS' ], [ '366565Z US' ], [ 'CUNO US' ], [ '877720Q GR' ], [ '342637Z US' ], [ 'WTCO US' ], [ 'IZ3 GR' ], [ '690410Z US' ], [ '761812Z US' ], [ '763279Z US' ], [ '763287Z US' ], [ '791479Z US' ], [ '821743Z US' ], [ '192906Z CN' ], [ 'MMGG IX' ], [ '844550Z US' ], [ '898395Z US' ], [ '957861Z US' ], [ '957845Z US' ], [ '974396Z CI' ], [ 'EWD LN' ], [ 'EWD PO' ], [ 'TDC LN' ], [ 'TDC PO' ], [ 'TCPMF US' ], [ 'TYCRF US' ], [ '1272Q LN' ], [ 'UKW GR' ], [ 'EWD IX' ], [ 'EWDA LN' ], [ '990860Z US' ], [ 'BOI LN' ], [ 'BOI PO' ], [ '1018596QGR' ], [ 'BEIOF US' ], [ '217486Z DC' ], [ '346309Z AU' ], [ '699471Z IM' ], [ 'BOI PZ' ], [ 'BOIA LN' ], [ 'BOI IX' ], [ 'BOI VX' ], [ '2232585ZUS' ], [ '2237391ZBZ' ], [ '2253959ZUS' ], [ '2279872ZUS' ], [ '2270846ZPW' ], [ '2283548ZUS' ], [ '2315340ZUS' ], [ '2725398ZUS' ], [ '2751472ZUS' ], [ '2811825ZUS' ], [ '2884739ZAU' ], [ '2818278ZUS' ], [ '2853196ZGR' ], [ '2971317ZUS' ], [ '2912083ZSW' ], [ '2909838ZFP' ], [ '2909830ZFP' ], [ '244895Z US' ], [ '3085285ZNO' ], [ '3092795ZIM' ], [ '3041954ZFP' ] ] ] ]; bbdate 0 0 ARRAY(0x1abebe8) ** ** ** Dumper bbdata 0 0 $VAR1 = [ [ 'MMM US' ], [ 'MMM-W US' ], [ 'MMN LI' ], [ 'MMM LN' ], [ 'MMMU NA' ], [ 'MH FP' ], [ 'MMM GR' ], [ 'MMM NA' ], [ 'MMM SW' ], [ 'MMM ES' ], [ 'MMM* MM' ], [ '4851 JP' ], [ 'MMM AR' ], [ 'MMMB AR' ], [ 'MMMC AR' ], [ 'MMMD AR' ], [ '2900086QUS' ], [ 'MTSI GR' ], [ 'RNIC US' ], [ 'AIV CN' ], [ 'AITYF US' ], [ '287476Z US' ], [ '290207Z SS' ], [ '366565Z US' ], [ 'CUNO US' ], [ '877720Q GR' ], [ '342637Z US' ], [ 'WTCO US' ], [ 'IZ3 GR' ], [ '690410Z US' ], [ '761812Z US' ], [ '763279Z US' ], [ '763287Z US' ], [ '791479Z US' ], [ '821743Z US' ], [ '192906Z CN' ], [ 'MMGG IX' ], [ '844550Z US' ], [ '898395Z US' ], [ '957861Z US' ], [ '957845Z US' ], [ '974396Z CI' ], [ 'EWD LN' ], [ 'EWD PO' ], [ 'TDC LN' ], [ 'TDC PO' ], [ 'TCPMF US' ], [ 'TYCRF US' ], [ '1272Q LN' ], [ 'UKW GR' ], [ 'EWD IX' ], [ 'EWDA LN' ], [ '990860Z US' ], [ 'BOI LN' ], [ 'BOI PO' ], [ '1018596QGR' ], [ 'BEIOF US' ], [ '217486Z DC' ], [ '346309Z AU' ], [ '699471Z IM' ], [ 'BOI PZ' ], [ 'BOIA LN' ], [ 'BOI IX' ], [ 'BOI VX' ], [ '2232585ZUS' ], [ '2237391ZBZ' ], [ '2253959ZUS' ], [ '2279872ZUS' ], [ '2270846ZPW' ], [ '2283548ZUS' ], [ '2315340ZUS' ], [ '2725398ZUS' ], [ '2751472ZUS' ], [ '2811825ZUS' ], [ '2884739ZAU' ], [ '2818278ZUS' ], [ '2853196ZGR' ], [ '2971317ZUS' ], [ '2912083ZSW' ], [ '2909838ZFP' ], [ '2909830ZFP' ], [ '244895Z US' ], [ '3085285ZNO' ], [ '3092795ZIM' ], [ '3041954ZFP' ] ];

Replies are listed 'Best First'.
Re: variant array
by ELISHEVA (Prior) on Jul 01, 2009 at 18:28 UTC

    $bbData->[0][0][0][0] should return 'MMM     US'. Based on your dumper output, your array is four levels deep so you need to have four indices, not 3 or 2.

    Best, beth

      Yes we just hacked a bit of code that got us to that.

      But it is ugly. maybe you could provide a loop that get the strings.

      many many thanks

      KD
        Getting you started is pretty much where I stop. This isn't a code writing service. Make an attempt to write the loop yourself and if you have problems getting it right, you are more than welcome to post a question with your code.

        Next time though, please

        • Put <readmore>...</readmore> tags around long code samples and output
        • Better yet, give a short sample rather than your entire data set. You can leave out the middle bits and just show the start and end of the data dumper if you have another long array like the one you displayed.
        • Explain and give samples of what you want to happen; not just what did happen. I had to spend a lot of time reading your code just to figure out which string in which array was interesting to you.

        Best, beth