in reply to replacing text with a function
This works for me because I can then validate what is returned from the function by checking what is in $rep.
-----#!/usr/bin/perl -w use strict; my $file = "myfile"; open(FILE,$file); my $rep = &replace_text_1; foreach (<FILE>) { $_ =~ s/\<REPLACE_TEXT_1\>/$rep/ if $_ =~ m/\<REPLACE_TEXT_1\>/; print "$_"; } close(FILE); sub replace_text_1 { #some stuff #print "foobar"; #some other stuff return("foobar"); }
|
|---|