in reply to From VB to Perl

Here is the complete script. I'm running it using ActiveState ver 5.6.1 on NT 4.0 with Exchange Server 5.5.
#!\perl\bin\perl.exe -w use strict; use warnings; use Win32::OLE; use Win32::OLE::Const; use Math::BigInt; # Names have been changed to protect the innocent my $server = "servername"; my $fname = "foo"; my $lname = "bar"; my $alias = "fbar"; # MAPI won't work without this Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE); # Load the constants my $CDO_CONST = Win32::OLE::Const->Load('Microsoft CDO.*Library'); # Create a MAPI session my $MAPI = Win32::OLE->new('MAPI.Session'); die "Could instantiate MAPI Session: " . Win32::OLE::LastError() if (! + defined($MAPI)); # Create a temporary profile my %LogonParms = ( 'ProfileInfo' => "$server\n$alias" ); # Logon to the MAPI session $MAPI->logon(\%LogonParms); die Win32::OLE::LastError() if (Win32::OLE::LastError()); # Just a debug statement print "USER: " . $MAPI->{CurrentUser}->Value . "\n"; # get the Contacts folder of the active mailbox my $Contactsfolder = $MAPI->GetFolder($MAPI->{Inbox}->{Fields}->Item(0 +x36D10102),$MAPI->{Inbox}->{StoreID}); #get the contacts my $contacts = $Contactsfolder->{Messages}; # Get the number of contacts found in the folder my $ncon = $contacts->{'Count'}; # Just a debug statement print "\tContacts - $ncon\n"; my ($con, $field1, $field2, $num, $email1, $x); # Everything above this line works or at least I think it's working # Iterate through the object for my $x (1 .. $ncon) { #get the contact object (I think) $con = $contacts->Item($x); #print out the counter and the display name of the contact print "# $x - $con->{'DisplayName'}\n"; ################################################ # Each of the follwing print statements print # # out the name of the contact. I'm trying # # get the email address. Since I get the # # same output even though I'm using different# # values, I'm very confused. I may actually # # be a simple syntax error but I'm not sure. # ################################################ print "email is $con->{'Email1Address'}\n"; print "email is $con->{0x8083}\n"; print "email is $con->{'0x8083'}\n"; $field1 = "{0420060000000000C000000000000046}"; $field2 = "0x8083"; print "email is $con->{$field1 . $field2}\n"; print "email is $con->{$field1 & $field2}\n"; $field1 = Math::BigInt->new('0x0420060000000000C000000000000046'); $field2 = "0x8083"; print "email is $con->{$field1 . $field2}\n"; print "email is $con->{$field1 & $field2}\n"; $field1 = '&H3A16001E'; $field1 =~ s/\&H/0x/x; print "email is $con->{$field1}\n"; $num = eval $field1; print "email is $con->{$num}\n"; } exit;
I hope this thread is still alive...
Chris

Replies are listed 'Best First'.
Re: Re: From VB to Perl
by BrowserUk (Patriarch) on Jul 11, 2003 at 21:38 UTC

    I only just caught up on this thread, and noticed the post above saying that & is VB for string concatenation.

    I was not aware of this and took & to be bitwise AND. The pretty much renders the Math::BigInt stuff I showed in my previous post not just wrong but greviously so. For this I apologise. My only defense is that I did say that I knew little about VB.

    By way of recompence for misdirecting you I have an observation and a recommendation that may or may not help, but that should be sufficiently quick to try that it won't matter too much if they don't pan out.

    As & means concatenate then the result of

    strItemGUID = "{0420060000000000C000000000000046}" ptag_EMAIL_ADDRESS = "0x8083" strTemp = strItemGUID & ptag_EMAIL_ADDRESS print strTemp ' Is that the VB syntax for print?

    ought to be the value that you need to pass. So, if you have the ability to run that under VB, you should then see what it is that you are trying to achieve.

    My best guess is that you will either get

    {0420060000000000C000000000000046}0x8083

    or {0420060000000000C000000000000046}32899

    I suspect the former is more likely, but if VB interprets the contents of a string as a number and then converted it back to (decimal) ascii representation, it is conceivable that the latter could be the result. In any case, once you print the result of the expression you will (should?) know one way or the other (or the third way I haven't conceived of:). And once you know what you are aiming to produce, it should be relatively simple to reproduce it in perl.

    I truely hope that this helps and will make up for my earlier misinterpretation.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller