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

Esteemed Monks,

When I run the following code:

#!/usr/bin/perl -w use strict; use Data::Dumper; use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>1); $Registry->Delimiter("/"); my $swKey = $Registry->{"CUser/Software/"}; my $pamKey = $swKey->{"Pamela/Settings/1.0/"}; my $vmDir = $pamKey->{ "m_voiceMessagePath" }; print Dumper $vmDir;
Why do I get an array being returned? I take it that the path as returned is doubly delimited to escape the \, but why in a record with single quotes if that is the case?

Or is it just Friday and I am being dumb?

$VAR1 = [ 'C:\\Documents and Settings\\johnday.MERCURY\\My Documents\\Pamela\\Vo +icemsg\\', 1 ];

Replies are listed 'Best First'.
Re: Win32::TieRegistry question
by ikegami (Patriarch) on Mar 17, 2006 at 21:06 UTC

    As for your second question,

    Why in a record with single quotes if that is the case?

    You need to escape backslashes (\) and the string delimiter in non-interpolating strings.

    print('\\a\'b'); # Prints: \a'b

    For convenience, an exception was made in unambiguous situations. In other words, a backslash only needs to be escaped when it is followed by another blackslash or by the string delimiter.

    print('\\\\a'); # Prints: \\a print('\\\a'); # Prints: \\a print('\\a'); # Prints: \a print('\a'); # Prints: \a print('\\\\\''); # Prints: \\' print('\\\\''); # Syntax error print('\\\''); # Prints: \' print('\\''); # Syntax error print('\''); # Prints: '

    For a program, it's easier to escape backslashes and the string delimiter unconditionally (C:\\Docum...) while humans might opt to omit the optional backslashes for the sake of readability (C:\Docum...).

    The returned value (a *string*) doesn't have doubled slashes, just the output of Data::Dumper (a *string literal*).

Re: Win32::TieRegistry question
by davidrw (Prior) on Mar 17, 2006 at 21:01 UTC
    it's Friday :) It's because you have $key->ArrayValues( $newBool ) set -- from the Win32::TieRegistry pod:
    When off, Registry values fetched via a tied hash are returned as just a value scalar (the same as GetValue() in a scalar context). When on, they are returned as a reference to an array containing the value data as the [0] element and the data type as the [1] element.