Home > Archive > PERL Miscellaneous > December 2004 > Strange leading character
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Strange leading character
|
|
|
| Jack wrote:
> Jack wrote:
>
> Sorry
>
> I just found that the value of $mycustcode contains a leading space,
> thus sql failed to match the right record.
> This also explained why the first element has no such problem.
> Sorry for being so careless.
>
I tried to remove the leading space, but the regular expression failed
to remove it. It may be not a whitespace, what what is it?
Here is the html string being passed to the $in{'outlets'} perl code:
outlets=07-6-0057%2C&outlets=07-3-0051%2C&outlets=07-2-0036
What is %2C here?
The code I used to strip the white space is:
$str =~s/[ ]//g;
Thanks
Sam
[color=darkred]
| |
| Darin McBride 2004-12-29, 3:57 am |
| sam wrote:
> Jack wrote:
>
> I tried to remove the leading space, but the regular expression failed
> to remove it. It may be not a whitespace, what what is it?
> Here is the html string being passed to the $in{'outlets'} perl code:
> outlets=07-6-0057%2C&outlets=07-3-0051%2C&outlets=07-2-0036
> What is %2C here?
%2C == the comma character.
> The code I used to strip the white space is:
> $str =~s/[ ]//g;
Better:
$str =~ s/\s+//g;
You may also want to try passing the string through Data::Dumper to
make sure you know exactly what character it is (if it's non-printable,
Data::Dumper may translate it to printable for you).
Also, you really should stop putting values in your SQL. As much as
possible, that is.
$create_view_stmt = qq{create view $viewtab as
select c.custcode, c.custname, c.type, sum(t.netsales) as sales from
customer c, transaction t
where c.custcode = t.custcode
and date(t.date) >= ?
and date(t.date) <= ?
and c.type in (?,?)
and c.custcode = ?
group by c.custcode};
Then, when you go to execute this:
$res = $sth->execute($start_date,
$end_date,
qw(EXPORT LOCAL),
$mycustcode);
Then you don't need to worry about special character as much. (Stray
characters are a different problem no matter how you do things.)
I would prefer putting a placeholder in for the view name, too, but I
doubt many (if any?) database vendors support that. If any do, it's
unlikely MySQL does.
Then again, MySQL may not even support this much for a create statement
- I'm not too sure. Then I presume you're using the DBI 'quote'
function to hide special characters properly?
|
|
|
|
|