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

Hi I want to add the string that is stored in variable before the text without space. my current output wont come.
$artpage="ID2"; $boxtxt=~s/<\/boxed-text>/<p><inline-supplementary-material mimetype=\ +"video\" mime-subtype=\"avi\" xlink:href=\"$artpagevideo_clip_$videoi +d\.avi\">Download Video $videoid<\/inline-supplementary-material><\/p +><\/supplementary-material>/g;
But the variable taken as "$artpagevideo" instead of "$artpage" I need output like "ID2video_clip_Man.avi".

Replies are listed 'Best First'.
Re: How to add perl variable before any text in perl code
by toolic (Bishop) on Dec 10, 2014 at 15:04 UTC
    Use ${artpage} (see Scalar values):
    $boxtxt=~s/<\/boxed-text>/<p><inline-supplementary-material mimetype=\ +"video\" mime-subtype=\"avi\" xlink:href=\"${artpage}video_clip_$vide +oid\.avi\">Download Video $videoid<\/inline-supplementary-material><\ +/p><\/supplementary-material>/g;
Re: How to add perl variable before any text in perl code
by AnomalousMonk (Archbishop) on Dec 10, 2014 at 16:11 UTC

    And do, please, consider giving your eyes and sanity a huge break by thinking about using balanced delimiters — and maybe even some whitespace:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $xxx = 'YYY'; ;; my $boxtxt = 'aaa</boxed-text>bbb'; print qq{'$boxtxt'}; ;; $boxtxt =~ s{ </boxed-text> } {</new-stuff xxx${xxx}xxx>}xmsg; print qq{'$boxtxt'}; " 'aaa</boxed-text>bbb' 'aaa</new-stuff xxxYYYxxx>bbb'
    See perlre and perlretut, and  m// s/// qr// qq// etc. in perlop.

      Also, something to consider, a templating system to separate your perl code from the HTML, etc.

      ++ AnomalousMonk for concern for OP's eyes; addendum: OP needs to be kind to our eyes, too (AKA: make it easy for us to help)!



      check Ln42!