http://www.perlmonks.org?node_id=1206611

Broggy69 has asked for the wisdom of the Perl Monks concerning the following question:

I am not understanding regex and getting confused with it. I am new and read a whole bunch of stuff on it but I am no closer to answering what should be simple.

My Perl program exports data from an MS-Access file. But that file has some characters that need to be removed. I am not sure where these characters are coming from as they are not in the original file used to create the MS-Access table, nor in the MS-Access table. One thing to note that whether I create the file from Visual Basic .net or Perl the special character are there. I am just learning perl. I know how I can replace a character in Visual Basic .net without regex, but I can't seem to replace characters in perl with or with perl. Below is my code and in the file Plants.txt I want to replace a special character with a space.

use Win32::ODBC; use DBI; use Win32; use Config; use warnings; use Text::CSV; $HOSTNAME = `hostname`; my $name = Win32::LoginName; my @Files = ("schema.ini", "Log.log", "Plants.txt"); my @list; open(my $filelog, '>', 'log.log'); print $filelog "Computer Name: $HOSTNAME"; print $filelog "Username $name\n"; print $filelog "$Config{archname}\n\n"; if (-e $Files[0]) { unlink $Files[0]; print $filelog "Deleted file: $Files[0]\n"; } if (-e $Files[1]) { unlink $Files[1]; print $filelog "Deleted file: $Files[0]\n"; } if (-e $Files[2]) { unlink $Files[2]; print $filelog "Deleted file: $Files[0]\n"; } my $filename = 'C:/GBowl/strawberry32/Scripts/ccname.txt'; my $db_file = 'C:/GBowl/strawberry32/Scripts/Hello.accdb'; print $filelog "Will try to connect to ms-access database\n"; my $dbh = DBI->connect( 'dbi:ADO:Provider=Microsoft.ACE.OLEDB.12.0;Data Source='.$db_file, ) or die $DBI::errstr; print $filelog "Connected to ms-access database\n"; #prepare and execute SQL statement $Export = $dbh->prepare( 'SELECT Company_Code, Name INTO [Text;HDR=No;DATABASE=C:\GBowl\str +awberry32\Scripts].[Plants.txt] FROM Plants ORDER BY Company_Code'); $Export->execute || die "Could not execute SQL statement ... maybe invalid?"; print $filelog "New $Files[2] file created\n"; print "$Files[0]\n"; print "$Files[1]\n"; print "$Files[2]\n"; ### Section to get plant ID's ### my $file = "$Files[2]"; open(my $csv, '>>', $file) or die "Could not open '$file' $!"; if (open(my $fh1, '<:encoding(iso-8859-1)', $Files[2])) { while (my $row = <$fh1>) { chomp $row; print "$row\n"; } } else { warn "Could not open file '$filename' $!"; } open(my $PlantFile, '>', 'Plants.txt'); #Here is where I need code to replace character &#65533; with nothing close $PlantFile; close $filelog;