R
RedGalaxy UK
Help!!
I'm rather new to Perl; trying it out as it has advantages over PHP in
the things I want to do.
In PHP there is a simple function, addslashes(), which changes ' for
\', " for "\, \ for \\ and so on (basically adding a backslash to
escape it).
Trying to do the same in Perl and can't find any way to do the \ = \\
change? Found this little sub:
sub addslashes {
my $string = shift;
$string=~s/'/\\'/g;
$string=~s/"/\\"/g;
return $string;
}
If I pass it something like:
This is just a 'dummy test' and it works.
It will give me:
This is just a \'dummy test\' and it works.
However, parts of my data will include backslashes in the data itself,
and if I try passing something like:
C:\Windows\System\
It will print:
C: indows ystem
Anybody know how I could do this, or even if there is a function within
Perl I just don't know about? I'm using ActiveState's ActivePerl 5.8.7
for Windows.
Thanks.
Paul
I'm rather new to Perl; trying it out as it has advantages over PHP in
the things I want to do.
In PHP there is a simple function, addslashes(), which changes ' for
\', " for "\, \ for \\ and so on (basically adding a backslash to
escape it).
Trying to do the same in Perl and can't find any way to do the \ = \\
change? Found this little sub:
sub addslashes {
my $string = shift;
$string=~s/'/\\'/g;
$string=~s/"/\\"/g;
return $string;
}
If I pass it something like:
This is just a 'dummy test' and it works.
It will give me:
This is just a \'dummy test\' and it works.
However, parts of my data will include backslashes in the data itself,
and if I try passing something like:
C:\Windows\System\
It will print:
C: indows ystem
Anybody know how I could do this, or even if there is a function within
Perl I just don't know about? I'm using ActiveState's ActivePerl 5.8.7
for Windows.
Thanks.
Paul