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

I have a variable $folder,I am trying to convert the value in it into uppercase with '' quotes around it,meaning for example if $folder=data,I want to print 'DATA'.Trying the below ,but it always prints "$FOLDER",how to dechipther the value in it and convert it to uppercase with ' ' wrapped around it

my $up= uc('"$folder"'); print "\n$up"; --->always prints "$FOLDER"

Replies are listed 'Best First'.
Re: Converting to uppercase and wrapping ''
by wind (Priest) on May 02, 2011 at 04:57 UTC

    Do you want single quotes or double quotes around it?

    Either way, use qq as your string qualifier and just use your preferred quotes within:

    my $up = uc qq{'$folder'};

      I tried above ,in the below code for me if $mk matches 'DATA' it should ignore all the subsequent statements,why is it printing "IN"?Please advise

      $folder= "data"; my $up=uc qq{'$folder'}; print "\n$up"; my $mk= 'DATA'; next if $mk =~ /uc qq{'$folder'}/i; print "\nIN"; --->prints,ideally if above line matches it should not p +rint this line

        Why do you want to put quotes around $folder? Are you really just wanted to test if $folder and $mk are equal except for case?

        If so just do the following:

        next if uc $mk eq uc $folder;
Re: Converting to uppercase and wrapping ''
by anonymized user 468275 (Curate) on May 02, 2011 at 12:08 UTC
    single quotes suppress the evaluation of the contained expression, whereas you want the double quotes, so you need to separate them from the variable expression to allow evaluation, e.g:
    my $up = '"' . uc($folder) . '"';

    One world, one people

Re: Converting to uppercase and wrapping ''
by MoFiddy (Sexton) on May 02, 2011 at 13:52 UTC
    This seems to work.
    my $folder = "data"; my $up = '\'' . uc($folder) . '\''; print $up . "\n";
      my $folder = "data"; print qq{'\U$folder\E'\n}; printf "'%s'\n", uc $folder; __END__ 'DATA' 'DATA'