Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Perl Question - Split using |

Re: Perl Question - Split using |

From: <Jared.Still_at_radisys.com>
Date: Fri, 05 Jul 2002 09:05:12 -0800
Message-ID: <F001.00490654.20020705090512@fatcity.com>


Well, I guess this is why Andy's name is first on the book. ;)

Jared

Andy Duncan <andy_j_duncan_at_yahoo.com>
Sent by: root_at_fatcity.com
07/05/2002 08:38 AM
Please respond to ORACLE-L  

        To:     Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>
        cc: 
        Subject:        Re: Perl Question - Split using |


Hi Celine,

> After seeing the e-mails about "Perl for Oracle-DBAs",
> I presume, my question wouldn't be completely
> inappropriate for this list.
> So if you Oracle Gurus, can help me with this Perl
> problem, I would greatly appreciate it.
> I have a problem with "split" when my delimiter is "|".
> I know that if I escape the pipe, split should work,
> that is only when it is a literal like split(/\|/, "abc|def|123)
>
> But when my delimiter is to be dynamically read from a
> file, I have it in a variable. Then this escaping
> stuff doesn't work......
> eg:
> my $HeaderAttributes = "abc|defgh|123";
> print "$HeaderAttributes\n";
> my $Delimiter = "\|";
> (@Fields) = split(/$Delimiter/, $HeaderAttributes);
> print "Delimiter = $Delimiter.... Field[0] =
> $Fields[0]\n";
>
> prints
> a
> instead of
> abc.
>
> Does somebody have a solution to this.

You might want to try and use the quotemeta function, to create a regex variable, which backslashes all alphanumerics within string variables, eg:

my $HeaderAttributes = "abc|defgh|123";
print "$HeaderAttributes\n";
my $Delimiter = "|";
my $regex = quotemeta($Delimiter);
(@Fields) = split(/$regex/, $HeaderAttributes); print "Delimiter = $Delimiter.... Field[0] = $Fields[0]\n";

At this end, this produced:

abc|defgh|123
Delimiter = |.... Field[0] = abc

In a reckless bid towards on-topic status, I can only say that there's much
more of this kind of thing in Appendix C of "Perl for Oracle DBAs", 'The Essential Guide to Regular Expressions'! :-)

HTH! :) Rgds,
AndyD



Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Andy Duncan
  INET: andy_j_duncan_at_yahoo.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: 
  INET: Jared.Still_at_radisys.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Fri Jul 05 2002 - 12:05:12 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US