I have been tasked with writing a basic package to map drives to NT and Windows 2000 servers. Based upon the domain that the server is located in, I simply use one of two different connection strings. To facilitate this, I simply perform 'nslookup' and call the appropriate syntax for Win32::NetResource::AddConnection. The problem that I am experiencing, is when I try to format a hash within a scalar to call AddConnection properly.

use Win32::NetResource qw(:DEFAULT AddConnection GetError); my $connex_string = null; my $win2k_uid = "uid"; my $win2k_pwd = "pwd"; my $persist = "/persistent:no"; if ($domain =~m/^domainOne$/i) { print "domainOne\n"; $net_resource = { "RemoteName" => "\\\\$object_md{MAP_SERVER}\\$argOne", "LocalName" => "$drive_letter", }; $connex_string = $net_resource; } elsif($domain =~m/^domainTwo$/i) { print "domainTwo\n"; $net_resource = { "RemoteName" => "\\\\$object_md{MAP_SERVER}\\$argOne", "LocalName" => $drive_letter, "Type" => "RESOURCETYPE_ANY", "Provider" => "", }; $connect_string = "$net_resource,$win2k_uid,$win2k_pwd,$persis +t"; } else { print "Undefined domain\n"; } if(AddConnection($connex_string)) { print "Connection work.\n"; } else { print "Connection did not work.\n"; }

This snippet of code gives me problems: $connect_string = "$net_resource,$win2k_uid,$win2k_pwd,$persist";

I know that it is the way that I am referencing the hash in the scalar.

This is the error that I am experiencing: "AddConnection: HASH reference required at C:/Perl/site/lib/Win32/NetResource.pm line 267."

I know how to reference the values of a hash with while and for loops. However, I just seem to have problems with hash references (i.e., \%hash, $$hash, %$hash, etc.). Can anyone offer some help? Also, in an effort to become a more competent programmer, is this the best way to accomplish the drive mappings to NT and Win 2K server?

Thanks in advance for any and all help!

TCF


In reply to Hash Reference for Win32::NetResource::AddConnection by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.