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

guys:

i'm having trouble using a pipe delimiter in parse_line.
can anyone help out?
thanks

use strict; use warnings; use Text::ParseWords; s1 ("just|another|perl|hacker"); s2 ("just|another|perl|hacker"); sub s1 { my $text = shift; my @words = split /\|/, $text; foreach my $word ( @words ) { print "[$word]"; } print "\n"; } sub s2 { my $text = shift; my @words = parse_line("|", 0, $text); foreach my $word ( @words ) { print "[$word]"; } print "\n"; }

Replies are listed 'Best First'.
(jeffa) Re: Text::ParseWords and pipe delimiter
by jeffa (Bishop) on Jul 29, 2002 at 17:46 UTC
    You need to do two things: escape the pipe and use single quotes:
    my @words = parse_line('\|', 0, $text);

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      thanks alot!
      you would laugh if you saw all the stuff i was trying to push into that function