cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
Good day, monastic ones. When I run the following code
the output ismy $string = "foo / bar & etc"; my @parts = split(/ (\&|\/) /,$string); print join("\n",@parts);
foo
/
bar
&
etc
I don't understand why I'm getting the slash and ampersand. I thought whatever is specified as the split string is considered delimiter and is not supposed to be included in the resulting list. So for example if I run
(those are tabs between the words; don't know if they come thru as such on this post) then the resulting output ismy $string = "foo bar etc"; my @parts = split(/\t/,$string); print join("\n",@parts);
foo
bar
etc
with no tab chars output. What accounts for the difference between the two cases?
Many TIA....
Steve
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Why do I get regexp chars in split?
by duff (Parson) on Oct 11, 2006 at 16:37 UTC | |
Re: Why do I get regexp chars in split?
by idsfa (Vicar) on Oct 11, 2006 at 16:40 UTC | |
Re: Why do I get regexp chars in split?
by cdarke (Prior) on Oct 11, 2006 at 16:40 UTC | |
Re: Why do I get regexp chars in split?
by davido (Cardinal) on Oct 12, 2006 at 02:19 UTC |
Back to
Seekers of Perl Wisdom