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;

In reply to Replacing a character in a file by Broggy69

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.