Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split on a "?" character

Status
Not open for further replies.

TheObserver

Programmer
Mar 26, 2002
91
0
0
US
Hello. I've run into a small issue. I need to split a string with a "?" in it. However, I can't get the split to work - either it throws an error or it doesn't produce the proper result.

I've tried
split("?", $mystr)
split("\?", $mystr)
split('?', $mystr)
split('\?', $mystr)
split(/\?/, $mystr)

and nothing has worked thusfar. Does anybody have any tips or a solution?

Thanks for your time.
 
I don't know what to tell you, this worked for me:

my $test = "first?second";
my @foo = split(/\?/, $test);
print $foo[0] . "---" . $foo[1];

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Code:
my $str = 'zero?one?two?three';

my @arr = split /\?/, $str;

print "$_\n" for @arr;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top