Can I modify scalars contained in the array ref returned by DBI

A

Aaron Anodide

Hi,

I'm fairly new to PERL. The following code fetches a row from DBI as
an array ref. It then sends a reference to an element of that array
to a sub which modifies it in place. This effectively (i think)
modifies the original string which was returned by DBI.

My question is: Is this OK? Are the scalars in the array returned
from DBI special in any way, such that I might corrupt memory by doing
this?

Thanks in advance,
Aaron Anodide

sub CleanXMLString
{
my $s_ref = shift;
$$s_ref =~ s/\&/\&amp\;/g;
$$s_ref =~ s/\</\&lt\;/g;
$$s_ref =~ s/\>/\&gt\;/g;
}

my $sql = "SELECT x,y FROM TT WHERE ID=1";

$sth = $dbh->prepare($sql);

$sth->execute();

$row_ref = $aref = $sth->fetchrow_arrayref;

CleanXMLString( \$row_ref->[0] );
CleanXMLString( \$row_ref->[1] );
 
G

gnari

Aaron Anodide said:
Hi,

I'm fairly new to PERL. The following code fetches a row from DBI as
an array ref. It then sends a reference to an element of that array
to a sub which modifies it in place. This effectively (i think)
modifies the original string which was returned by DBI.

My question is: Is this OK? Are the scalars in the array returned
from DBI special in any way, such that I might corrupt memory by doing
this?

yes, in the case of DBI, it is OK.

gnari
 
E

Eric Amick

sub CleanXMLString
{
my $s_ref = shift;
$$s_ref =~ s/\&/\&amp\;/g;
$$s_ref =~ s/\</\&lt\;/g;
$$s_ref =~ s/\>/\&gt\;/g;
}

The backslashes really aren't necessary.
 
A

Aaron Anodide

John Bokma said:
Also the > doesn't need to be escaped in many cases.
<something> a > b </something> is valid.

That's interesting, I didn't know it. I wonder if it's worth the
effort to analyze the context of the >'s though...

Regards,
Aaron
 
J

John Bokma

(e-mail address removed) (Aaron Anodide) wrote in
That's interesting, I didn't know it. I wonder if it's worth the
effort to analyze the context of the >'s though...

I import (Perl) code into XML, and only escape the < and &. There probably
is a module which has a nice escape function for this. (And I guess it
escapes the > too).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top