
clued
stranger
Aug 17, 2001, 12:10 PM
Post #1 of 4
(2812 views)
|
|
variable in regex
|
Can't Post
|
|
I'm totally at a loss, In the code below, I am getting input from a form. This input contains the string <insert>. I then open a directory with several text files. The text files contain 0ne line of text each. I then put the place the contents of each text file into the variable $line. I want this to do a simple thing. Insert the value of $line into the right place in $input, and print the results. The code below prints the value of $input, but leaves the value of $line blank. If I put "print "$line";" above "print "$input";" the value of $line is printed, so I know that $line has a value. question is...why won't the regex do the substitution? I can change the regex to $input =~ s/<insert>/sometext/; and it faithfully substitutes sometext for <insert>. I know you can use a variable in a regex, and I'm totally stumped. I know it's probably something simple, just a little out of my experience. my $input = $form{'input'}; opendir THEDIR, "$config{'path'}" or &error("packs directory could not be opened."); my @allfiles = readdir THEDIR; closedir THEDIR; my $file; foreach $file (@allfiles) { open THEFILE, "$config{'path'}$file"; my ($line) = <THEFILE>; close THEFILE; chomp ($line); $input =~ s/<insert>/$line/; print "$input"; } } Thanks for any help Bob
|