in reply to use shift function in regex

You do not get a result because you never load $var with a value.

Try this:

perl -e "$var = shift; $var=~s/^($var)$/\u$1/;print $var;" hi
(use single quotes if you are not on Windows)

Note that the /e modifier only works on the substitution part of the regex, never on the pattern part. Adding /e, does not magically make shift get the argument out of the argument list.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: use shift function in regex
by ikegami (Patriarch) on Nov 24, 2009 at 07:46 UTC

    That should be

    perl -e "$var = shift; $var=~s/^(\Q$var\E)$/\u$1/s; print $var;" hi

    Text treated as a pattern doesn't (necessarily) match itself.

      Thanks ALL for explaining me the right way to perform the task :)