• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

really quick programming question!!! Perl and reg ex's

evident

Lifer
Hi all,

it's late and my brain isnt functioning right, if any of you guys can help me i would greatly appreciate it.

i am basically just trying to to a find and replace in perl, and then outputting the result to a file.

i have got $temp="foo";
i have the variable $_ = "Bunch of text";

i want to replace "text" w/ the string stored in $temp.

i've tried using a regular expression, s/text/$temp
but in my output file i get Bunch of $temp

but i would like to have Bunch of foo

how would i go about doing this?

 
Make sure you're putting double quotes ("") around the regex, rather than single quotes ('').

Disclaimer: I don't actually do Perl, but this might help anyway.
 
$text = "foo";
$_ = "Wrong text forum text";

$_ =~ s/text/$text/g;

print OUTFILE $_;

OUTFILE should have "Wrong foo forum foo". If you only want the first instance replaced, take out the trailing g in the regexp.

Oops fixed.
 
Back
Top