I cannot get the expected result from code similar to the following:

my @source = ();
@($source[0]){"host","port","dir"} = [($pSource =~ m/(\S+)(-\S+)?(:.*)?/)];

My intention is that:  First, the match expression returns a array of three
values, which are to be assigned to three hash elements.  The first array
element should be assigned to the hash element with key "host", etc.
The resulting hash will then have three elements.  A reference to this
anonymous hash will then be assigned to the first element of the array
@source.

Obviously, this syntax is not working for me.  The only way I have gotten
this to work is by introducing a extra temporary variable as follows:

{
  my %tt;
  @tt{"host","port","dir"} = ($pSource =~ m/(\S+)(-\S+)?(:.*)?/); 
  $source[0]=\%tt;
}

Is there a better way?  That is, shorter and/or without defining a temporary
variable?


A second but related question is that when I try something like:
my @source = ();
$source[0]{"host", "port"} = (1,2);
print Dumper(@source);

I get a result of:
$VAR1 = {
          'host?port' => 2
        };

Huh?  My intention was to assign to a slice.  Obviously, that is not how
perl interpreted the assignment, but why did it create a hash with the odd
key value of 'host<invalid char>port'?
 
**************************************************************************
The information transmitted herewith is sensitive information intended only
for use by the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to