On Feb 22, 12:34 pm, John <chunj...@gmail.com> wrote:
> On Feb 22, 11:56 am, "comp.llang.perl.moderated" <c...@blv-
>
>
>
> sam-01.ca.boeing.com> wrote:
> > On Feb 22, 11:01 am, John <chunj...@gmail.com> wrote:
>
> > > There must be something that I have ignored in PERL.
>
> > > To split a string with delimiter "|", sometimes, I need to give "\",
> > > sometimes it works for "\\" only.
>
> > > Here are the details.
>
> > > The String is " 0000|Null".
>
> > > And the ways I have tried to do split are:
> > > 1. my @columns = split('\|', $String);
> > > 2. my ( $proj, $desc) = split('\|', $String);
> > > 3. my ( $proj, $desc) = split('\\|', $String);
>
> > > Case 1 and Case 3 are good. But Case 2 failed, both $proj and $desc
> > > receive an empty string .
>
> > > What was wrong with case 2 , I thought if Case 1 works, Case2 should
> > > be working also, Right ? I am using perl 5.6.1 on linux box.
>
> > case 2 works as is. Is it possible you meant:
> > split( "\|", $String ) ...?
>
> > In that case, double-quotish interpolation causes
> > your split regex to be just '|':
>
> > # perl -MO=Deparse,-p -e 'split "\|"," 0000|Null"'
> > split(/|/, ' 0000|Null', 0);
> > -e syntax OK
>
> > Then, you have the alternation meta character
> > alone with empty alternatives on either side
> > which'll match the 1st 2 characters encountered:
>
> > $proj=' ' $desc='0'
>
> > Is it possible you had 2 leading blanks in
> > string which "looked" like 2 empty strings for
> > $proj and $desc...
>
> > --
> > Charles DeRykus- Hide quoted text -
>
> > - Show quoted text -
>
> I do not have any leading blanks in this String.
>
Hm, the original post does however:
> "The String is " 0000|Null".
--
Charles DeRykus
|