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

If I do:
$string = "c:/inetpub/vcaserver/miniV/section$in{'pSection'}/p$in{'pSe +ction'}_$in{'pNum'}.html";
for a path, the varibles are left out. So if I print out $string I get:

c:/inetpub/vcaserver/miniV/section/p_.html

as the outout. How do I get those babies in there? I tried:
print "c:/inetpub/vcaserver/miniV/section@{[$in{'pSection'}]}/p$in{'pS +ection'}_$in{'pNum'}.html";
That works fine, so my varibles are cool, what's wrong here?

Replies are listed 'Best First'.
Re: inserting varibles into a string
by greenFox (Vicar) on Mar 17, 2001 at 19:48 UTC
    -w and use strict :)
    $string probably isn't the best name for your variable and if the directory part is used elsewhere it is probably better as a seperate variable as well.
    so try constructing your string like this
    my $dir= 'c:/inetpub/vcaserver/miniV/section'; $html_file = $dir . $in{'pSection'} . '/p' . $in{'pSection'} . '_' . $ +in{'pNum'} . '.html';
    if it still doesn't work you better give us the code where you initialise %in.

    Perl is my chainsaw

Re: inserting varibles into a string
by Chady (Priest) on Mar 17, 2001 at 12:23 UTC

    there is something wrong with your vars assignment... are you sure that there is a hash called %in ??

    did you enable warnings in your script ?? like #!/usr/bin/perl -w ??

    print out $in{'pSection'} alone to see if it is correctly assigned. because I think that the problem is with the var assignment, and not the concatenation.


    Chady | http://chady.net/
Re: inserting varibles into a string
by extremely (Priest) on Mar 18, 2001 at 01:09 UTC
    Your first example works for me. I'd recommend not putting the single quotes around hash key names like 'pNum' since the squiggly braces are nore than enough for perl.

    Did you cut'n'paste this code or retype it for us? The second line only fixes one of the two calls to the same variable yet you present that as a working line?

    Can you get us more complete code? something isn't right here.

    --
    $you = new YOU;
    honk() if $you->love(perl)