Обсуждение: inserting data that contains / or \

Поиск
Список
Период
Сортировка

inserting data that contains / or \

От
"Patrick Hatcher"
Дата:
Sorry up front.  I know this has probably been answered 10k times.
I need to insert data into a field that will look as such:  MC HANCOCK GOLD
5PPS S/4

my perl is getting better, but not quite there yet:  I have the following
regex:
$fields[$i] =~ s/\// /g;  which now puts a space in place of the /, but I
would like to the keep the text  as is.  I believe I need to replace the
single foward slash with 2 forward slashes.  But I'm lost as to how to do
it
Should it be this:  $fields[$i] =~ s/\//\///g;?

TIA

Patrick Hatcher
Macys.Com





Re: inserting data that contains / or \

От
Doug Silver
Дата:
On Thursday 03 October 2002 10:02 am, Patrick Hatcher wrote:
> Sorry up front.  I know this has probably been answered 10k times.
> I need to insert data into a field that will look as such:  MC HANCOCK GOLD
> 5PPS S/4
>
> my perl is getting better, but not quite there yet:  I have the following
> regex:
> $fields[$i] =~ s/\// /g;  which now puts a space in place of the /, but I
> would like to the keep the text  as is.  I believe I need to replace the
> single foward slash with 2 forward slashes.  But I'm lost as to how to do
> it
> Should it be this:  $fields[$i] =~ s/\//\///g;?
>
> TIA
>
> Patrick Hatcher
> Macys.Com
>

Try this -- note the use of "#" instead of the normal "/" as the regex
separator, very key when dealing with urls and other things that have the
forward slashes in them.

$fields[$i] =~s#/{1}#//#g;
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Doug Silver
Network Manager
Urchin Software Corp.    http://www.urchin.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Re: inserting data that contains / or \

От
Garrett Bladow
Дата:
Or if you are using the perl DBI you could skip the regex and do
something like this:
    $sql = "INSERT INTO foo_table(bar_field) VALUES(?)";
        connect_to_db();
        $sth = $dbh->prepare($sql);
        $foo = "MC HANCOCK GOLD 5PPS S/4";
        $sth->execute($foo);
        $dbh->commit();

---- This is what you wrote me ----

:On Thursday 03 October 2002 10:02 am, Patrick Hatcher wrote:
:> Sorry up front.  I know this has probably been answered 10k times.
:> I need to insert data into a field that will look as such:  MC HANCOCK GOLD
:> 5PPS S/4
:>
:> my perl is getting better, but not quite there yet:  I have the following
:> regex:
:> $fields[$i] =~ s/\// /g;  which now puts a space in place of the /, but I
:> would like to the keep the text  as is.  I believe I need to replace the
:> single foward slash with 2 forward slashes.  But I'm lost as to how to do
:> it
:> Should it be this:  $fields[$i] =~ s/\//\///g;?
:>
:> TIA
:>
:> Patrick Hatcher
:> Macys.Com
:>
:
:Try this -- note the use of "#" instead of the normal "/" as the regex
:separator, very key when dealing with urls and other things that have the
:forward slashes in them.
:
:$fields[$i] =~s#/{1}#//#g;
:--
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Doug Silver
:Network Manager
:Urchin Software Corp.    http://www.urchin.com
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:
:
:---------------------------(end of broadcast)---------------------------
:TIP 2: you can get off all lists at once with the unregister command
:    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
: