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

I am trying to decode the value in "$data" using the following code,but it doesnt while printing,it just prints $data as is?how do I dechipher $data?

$data_brf=$data_dir.'\\$data\.brf'; print "$data_brf";

Replies are listed 'Best First'.
Re: Deciphering $data
by GrandFather (Saint) on Apr 01, 2012 at 06:49 UTC

    I'm not sure I understand your question, but I suspect the answer is that you need to use double quotes (") to interpolate the contents of $data into the string you are building. I'd do it like:

    my $data_brf = "$data_dir\\$data\.brf";
    True laziness is hard work

      Basically I want to append "$data.brf" to "$data_dir" and then print it,so am I am trying to interpolate $data,if I use the way you suggested..I am not able to append...

      $data_brf=$data_dir.'\\$data\.brf'; print "$data_brf";

        I suggest you copy and paste the code I gave earlier. It is not what you implied I suggested. Consider:

        use strict; use warnings; my $data_dir = 'c:\\Wibble'; my $data = 'Plonk'; my $data_brf = "$data_dir\\$data\.brf"; print "$data_brf\n";

        Prints:

        c:\Wibble\Plonk.brf

        If that is not what you want you better show us the contents of $data_dir and $data, and show us what you expect to see printed.

        True laziness is hard work
Re: Deciphering $data
by Anonymous Monk on Apr 01, 2012 at 06:49 UTC

    I am trying to decode the value in "$data"

    What you're trying to do is interpolate $data, or append it to $data_brf

    Since single quotes do not interpolate, you get a literal $data instead of the contents of $data (interpolation)

    As perlintro tells us, double quotes interpolate, so use double quotes

     $data_brf = "$data_dir\\$data\.brf";

     $data_brf = qq{$data_dir\\$data\.brf};

     $data_brf = qq[$data_dir\\$data\.brf];

     $data_brf = qq<$data_dir\\$data\.brf>;

     $data_brf = qq($data_dir\\$data\.brf);

     $data_brf = qq'$data_dir\\$data\.brf';

      My goal is I want to append "$data.brf" to "$data_dir" and then print it,so am I am trying to interpolate $data,if I use the way you suggested..I am not able to append...

      $data_brf=$data_dir.'\\$data\.brf'; print "$data_brf";

        I suggested you use double-quotes, I showed you six different ways, simply copy and paste one of them