Re: From VB to Perl
by BrowserUk (Patriarch) on Jul 10, 2003 at 19:11 UTC
|
GUID's are 128-bit integers, which perl has no built-in mechanism for handling. I don't know much about VB but from the snippet you showed, it seems that it does know how to manipulate these mathematically.
However, do not dispair:). As usual, perl does have a package to deal with this. Math::BigInt to the rescue.
use Math::BigInt
my $guid = Math::BigInt->new( '0x0420060000000000C000000000000046' );
print $guid;
5483187177070399899585805862446301254
print $guid & 0x8083;
2
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
| [reply] [d/l] |
Re: From VB to Perl
by halley (Prior) on Jul 10, 2003 at 18:57 UTC
|
I'm not sure what you're expecting for colFields() to take as arguments; I've never seen someont try to do bitwise arithmetic or string manipulation on GUIDs (Globally Unique Identifiers). Maybe you want string concatenation ($guid . $address)?
If you want an integer from a hex number constant, it's $num = 0x1234ABCD; don't put quotes around it or you have a string instead of a number. If you have a VB-style hex constant as a string, you might need to do a little conversion:
$foo = '&H3A16001E';
$foo =~ s/ \&H / 0x /x;
$num = eval $foo;
-- [ e d @ h a l l e y . c c ] | [reply] [d/l] [select] |
Re: From VB to Perl
by CountZero (Bishop) on Jul 10, 2003 at 21:42 UTC
|
Unless I have forgotten all my VB/VBA-know-how, the & operator is the string concatenation operator in VB/VBA, which in Perl is the "." (dot) operator. So in Perl myAddress = colFields(strItemGUID & ptag_EMAIL_ADDRESS) will become $myAddress = $colFields[strItemGUID . ptag_EMAIL_ADDRESS] I'm assuming your variable colFields refers to an array (@colFields in Perl) and that the concatenated result of the UID and the ptag is somehow an index into it. Without knowing the rest of your program, it may be that you better use a hash (%colfields) instead of an array.CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] [d/l] [select] |
Re: From VB to Perl
by sauoq (Abbot) on Jul 10, 2003 at 19:18 UTC
|
Converting from one language to another via trial and error is bound to be a painful experience. Have you considered buying a book on Perl to help you learn? I'd recommend The Camel as it seems you already have programming experience and will need a book that you can both read straight through and use as a reference.
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
|
|
I have been programming in various languages for about 20 years now and I have been programming in Perl for a few years now but still consider myself a "Perl newbie". I do have the Camel book, "Programming Perl" as well as "Advanced Perl Programming", "Perl Cookbook", "CGI Programming", "Perl DBI", "Network Programming with Perl" (not an O'Reily book but still a good one), etc. I just couldn't get it to work. If I've learned one thing programming it is that eventually you have to ask for help. If for nothing else but to get a fresh perspective on the problem.
Thanks, Chris
| [reply] |
|
|
I have been programming in Perl for a few years now but still consider myself a "Perl newbie".
Please excuse my assumption that this was your first foray into Perl programming then. It just seemed that way to me because you supplied us with five examples of things you tried, none of which made much sense even when you disregard the fact that they were presumably assignments to variables which weren't prefixed with a sigil ($, @, or %).
I see that BrowserUk was seemingly able to interpret your problem and provide a solution though. I'm glad you got help.
If I've learned one thing programming it is that eventually you have to ask for help.
Of course!
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
|
|
Re: From VB to Perl
by bm (Hermit) on Jul 11, 2003 at 09:54 UTC
|
You also need to tell us what colFields is. Is it a function? If so, native or user defined? Or is it a data structure of some sort, defined by you?
I suspect colFields is defined like this
Dim colFields As MAPI.Fields
- a MAPI object - in which case I suggest Win32::OLE , specifically the section "Hints for Microsoft Office Automation" may be a possible approach. Hope this helps.
| [reply] [d/l] [select] |
Re: From VB to Perl
by ChrisR (Hermit) on Jul 11, 2003 at 18:21 UTC
|
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
| [reply] [d/l] |
|
|
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
| [reply] [d/l] [select] |