in reply to Re^2: search and replace with a variable
in thread search and replace with a variable

Well, that makes it pretty clear: your problem is in the code you didn't show us; the part by which you obtain and generate the scalars! (possibly need to chomp?)

check Ln42


Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
  1. code
  2. verbatim error and/or warning messages
  3. a coherent explanation of what "doesn't work actually means.
  • Comment on Re^3: search and replace with a variable

Replies are listed 'Best First'.
Re^4: search and replace with a variable
by tronmason (Initiate) on Apr 09, 2014 at 15:49 UTC
    Here's the entire code. Those values are being read in via CGI. I tried chomp already. See below:
    #!/usr/bin/perl use strict; use CGI; use Getopt::Long; use FindBin qw($Bin $Script); my ($BASE,$NAME)=($Bin,$Script) ; my ( $fqdn, $address ); my ( @results, $result, $response ); my $sestimeout = 3600; open(FILE, "<ADDACS.csv") || die "File not found"; my @lines = <FILE>; close(FILE); my $q = CGI->new; my $fqdn = $q->param('fqdn'); chomp $fqdn; my $address = $q->param('address'); chomp $address; my @newlines; foreach(@lines) { $_ =~ s/RECORDNAME/$fqdn1/; $_ =~ s/RECORDIP/$address/; push(@newlines,$_); } open(FILE, ">ADDACS1.csv") || die "File not found"; #print "Content-type: text/plain\n\n"; print FILE @newlines; close(FILE); print "Content-type: text/plain\n\n"; print "$address / $fqdn";

      "Here's the entire code."

      Really? See Re^2: search and replace with a variable. Your "entire code" won't compile because you added use strict; to it before posting, which catches the fact that you misspelled $fqdn on line 27. If it were spelled correctly, the substitution would work as expected. But do read Re^2: search and replace with a variable, because without proper file locking your next bug is only a few web hits away.


      Dave

      Have you checked to see whether $q->param('fqdn') and $q->param('address') are successful in getting the strings you want?
        Yes. They both read in just fine. The last lines of the code confirms this with a print out.