How do you remove a metacharacter from a file name. I have a filename of cos.NEW&OLD.0826.12345 but the perl script only recognizes cos.NEW. The NEW&OLD is a EDI Trading Partner ID. I want to remove the ampersand and replace it with an underline so that the code does not generate a false alert. I tried $script=~s/(\W)/_/g; but is that to replace what is in the contents of the file because I am still getting the error message.

08/26/2009_16:16:36 14802 ***ERROR: cannot upload data file /usr/edi/cos.NEW&OLD.0826.14802 into Database 08/26/2009_16:16:36 14802 *** ALERT 521

Snippet of code below

$script=$ARGV[3]; # Value of this $ARGV is NEW&OLD : : $otis_db="$base_dir/otis_db/cos.$script.$cdate.$pid"; : : : : chomp($end_date=`date +%m/%d/%Y_%T`); $end_date=~s/_/ /g; $values="(\'$file_name\',\'$send_from_dir\',\'$serv_ref\',TO_D +ATE\(\'$end_date\',\'MM\/DD\/YYYY HH24:MI:SS\'))\;"; : I placed this line right before the echo statement. Was getting an er +ror could not upload " cos.NEW&OLD.082609.12345" because it could not + be found. But it did create the file "cos.NEW". The & and anything + after is ignored. $script=~s/(\W)/_/g; : `echo "INSERT into COSBRIDGE\n\tvalues$values\n" >> $otis_db`;

In reply to Removing a Metacharacter from a filename by sputnik

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.