A
Arne Ruhnau
Cheers,
is there some simpler/more elegant solution to the following problem:
given a string 'a\|b|c', transform it into the list ('a|b', 'c')
Currently, i have a intermediate representation, but i doubt its
generality. What if $string contains (out of reasons I cannot predict)
'{[[VerticalBar]]}' right from the start?
I need a primitive pattern-language, and currently it contains, among others,
(..|..|..) : Disjunction
which I have to parse to a list of its elements (w/o the |'s).
Arne Ruhnau
Code follows:
use strict;
use warnings;
use Test::More tests => 1;
my $string = 'a\|b|c';
is_deeply(string2list($string), ['a|b', 'c']);
sub string2list {
my $string = shift;
$string =~ s/\\\|/{[[VerticalBar]]}/g;
my @elements = split /\|/, $string;
for(@elements) {
s/\{\[\[VerticalBar\]\]\}/|/g;
}
return \@elements;
}
is there some simpler/more elegant solution to the following problem:
given a string 'a\|b|c', transform it into the list ('a|b', 'c')
Currently, i have a intermediate representation, but i doubt its
generality. What if $string contains (out of reasons I cannot predict)
'{[[VerticalBar]]}' right from the start?
I need a primitive pattern-language, and currently it contains, among others,
(..|..|..) : Disjunction
which I have to parse to a list of its elements (w/o the |'s).
Arne Ruhnau
Code follows:
use strict;
use warnings;
use Test::More tests => 1;
my $string = 'a\|b|c';
is_deeply(string2list($string), ['a|b', 'c']);
sub string2list {
my $string = shift;
$string =~ s/\\\|/{[[VerticalBar]]}/g;
my @elements = split /\|/, $string;
for(@elements) {
s/\{\[\[VerticalBar\]\]\}/|/g;
}
return \@elements;
}