Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a line of data that uses pipes ( | ) as the delimiters, what do I use for an escape key? Thank you in advance!!!!!!!

Replies are listed 'Best First'.
Re: pipe as a delimiter
by japhy (Canon) on May 15, 2001 at 02:12 UTC
Re: pipe as a delimiter
by merlyn (Sage) on May 15, 2001 at 02:17 UTC
    The answers so far in this thread have all honed in on "escape key" meaning "how do I write a regex that matches this as a delimiter".

    One other meaning for "escape" that I would suggest is likely as valid is "how do I write the data so that it can also include a pipe character?"

    For that, we can't answer as quickly. We'll have to write both the parser and specify the data for that parser.

    Anyway, I just saw it amusing that everyone went for one end of the problem when it might be the other.

    -- Randal L. Schwartz, Perl hacker

Re: pipe as a delimiter
by Ovid (Cardinal) on May 15, 2001 at 02:12 UTC
    Well, the really depends upon what you want to do and why. If you're just splitting the data:
    my @data = split /\|/, $string;

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: pipe as a delimiter
by asiufy (Monk) on May 15, 2001 at 02:13 UTC
    Try split(/\|/, $line).
Re: pipe as a delimiter
by wardk (Deacon) on May 15, 2001 at 02:44 UTC

    well here's a possible solution for the output side... note the lack of an "escape", works with one too.

    #!/usr/bin/perl use strict; my $a="foo"; my $b="bar"; print join("|",$a,$b);
    produces..
    foo|bar
Re: pipe as a delimiter
by shotgunefx (Parson) on May 15, 2001 at 03:50 UTC
    Are you reading the data from another source or are you generating the data?