Re: Escaping a plus sign



So would this be the correct solution:

while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) =
$sth->fetchrow_array) {
$comment = "";

# added to escape the plus sign
$MGMTCMNT = ~ s/\+/\\+/g;
$MGMTNM = ~ s/\+/\\+/g;

if ($MGMTCMNT =~ /$MGMTNM/) {
$len = length($MGMTNM);
$start = index($MGMTCMNT, "$MGMTNM (");
$start += $len + 2;
$end = index($MGMTCMNT, ")", $start) - $start;
$comment = substr($MGMTCMNT, $start, $end);
}
if ($UPDATE1 > $artisttime || $UPDATE2 > $artisttime ) {
print (ARTMGRFILE "$PKEY\t$manager_id\t$comment\n");
}
}

On Tuesday 30 May 2006 14:23, Anthony Ettinger wrote:
should probably escape the + sign with \+

$field =~ s/\+/\\+/g;

On 5/30/06, Paul Nowosielski <paul@xxxxxxxxxxxxxxxxxxx> wrote:
Dear All,

I have a perl script that runs nightly. It create a data feed. The script
will die if the is a + sign in the fields its parsing.

Here is the snippet:

while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) =
$sth->fetchrow_array) {
$comment = "";
if ($MGMTCMNT =~ /$MGMTNM/) {
$len = length($MGMTNM);
$start = index($MGMTCMNT, "$MGMTNM (");
$start += $len + 2;
$end = index($MGMTCMNT, ")", $start) - $start;
$comment = substr($MGMTCMNT, $start, $end);
}
if ($UPDATE1 > $artisttime || $UPDATE2 > $artisttime ) {
print (ARTMGRFILE "$PKEY\t$manager_id\t$comment\n");
}
}

Here is the error message:

Quantifier follows nothing in regex; marked by <-- HERE in m/+ <-- HERE 1
Public Relations/ at /srv/www/htdocs/admin/utilities/aeg/manart.pl line
102.

In this error the problem file had the text "+1 Public Relations";

Is there a way to escape this character so in the future it won't kill
the script?

Thank you,
--
Paul Nowosielski



--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>

--
Paul Nowosielski
Webmaster
office: 303.440.0666 ext 219
cel: 303.827.4257

.



Relevant Pages

  • Visitorbook LE Multiple Vulnerabilities
    ... Vendor URL: http://www.freescripts.com/ ... which fails to escape various control characters in user ... If $mailuser is set to 1 then the script can be used as a ... DNS server to poison the script with a malicious reverse DNS response. ...
    (Bugtraq)
  • Re: sed replace with html code and variables
    ... I'm trying to write a bash script that will do a replace among ... that I am running this command on... ... Even more so, in the RHS of a substitution, you don't need to escape ... double quotes in the RHS. ...
    (comp.unix.shell)
  • Re: Disabling shell expansion
    ... >> The read script does indeed work, however thats not the enviroment I'm ... Basically I"m looking for a way to send these two lines as an argument to a shell command, without having to escape each ... character (because in OTHER error messages windows already escapes certain characters, so I'd end up escaping the ...
    (comp.unix.shell)
  • Re: script
    ... On 5/22/06, Daniel Hedlund wrote: ... > The issue is that it doesnot cd to the directory after running the ... this could be your problem; you'll need to escape the ... Now the script looks like ...
    (Fedora)
  • Re: Escaping a plus sign
    ... Paul Nowosielski wrote: ... # added to escape the plus sign ... Two entire lines instead of four additional characters ... You've just changed those strings, permanently, for the rest of the ...
    (perl.beginners)