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

Hi all , I am having problem with this setting a variable. I have the follwing $pass = blue , I need to change it to 5blue5 , I have tried the follwing but no luck. I am new to perl so please excuse me.
$pass = "5$pass5"; $pass = qq(5"$pass"5); $pass = "\5$pass\5";
can somone advice please. thanks

Replies are listed 'Best First'.
Re: declaring variable
by holli (Abbot) on Feb 14, 2005 at 17:18 UTC
    $pass = "5${pass}5"; #or $pass = 5.$pass.5; #or $pass = join ("", 5,$pass,5);


    holli, /regexed monk/
Re: declaring variable
by osunderdog (Deacon) on Feb 14, 2005 at 17:16 UTC

    Catenation would work:

    $pass = '5'.$pass.'5';

    Or sprintf

    $pass = sprintf('5%s5', $pass);

    "Look, Shiny Things!" is not a better business strategy than compatibility and reuse.

Re: declaring variable
by cowboy (Friar) on Feb 14, 2005 at 17:19 UTC
    $pass = "5$pass5";
    This is actually doing the equivalent of:
    $pass = "5" . $pass5;
    Try using:
    $pass = sprintf("5%s5", $pass); or $pass = "5" . $pass . "5";
      thanks all
Re: declaring variable
by sh1tn (Priest) on Feb 14, 2005 at 17:49 UTC
    $pass = 'blue'; $pass =~ s|^|5|o && $pass =~ s|$|5|o;

    (for "write-only"? variants)
      or,
      $pass = 'blue'; $pass =~ s/^(.+)$/5${1}5/;


      holli, /regexed monk/
        or

        $pass = 'blue'; $pass = '5'.(' ' x length($pass)).'5' | ' '.$pass.' '