Others have mentioned that if you want to split using '?' as a delimiter, you need to escape it first, though I'm not convinced that's really your problem here given that ASCII character 215 is not actually a ?.
The problem I suspect you're encountering is that the variables $1, $2, $3, etc. have special meanings in Perl -- they refer to portions captured within the parentheses of a pattern match. Try this instead:
($one, $two, $three) = split quotemeta($delimiter);
where $delimiter is ASCII 215 or whatever you're intending to use. The quotemeta will escape any characters that might have special meanings when used in a regular expression. (To be more precise, it escapes any non-"word" character.)
Also note that split used in this fashion is implicitly operating on the contents of the $_ variable. If you're not familiar with the use of $_, you can sometimes make your life easier by explicitly indicating what variable you want to split:
($one, $two, $three) = split quotemeta($delimiter), $stuff_to_split;
Good luck! | [reply] [d/l] [select] |
The expressions you use in split (unlike join) are regex's. '?' is a special character (zero or one) in a regex. You will need to escape '?' with a '\' (Ex. "\?").
You should use -w or use warnings because what you did would have shown up as the warning
Quantifier follows nothing before HERE mark in regex m/? << HERE
grep
|
Unix - where you can throw the manual on the keyboard and get a command |
| [reply] [d/l] [select] |
split splits on a pattern, even if you use double or single quotes. try:
($1, $2, $3) = split /\?/;
tstock | [reply] [d/l] |
Kudos to seattlejohn. So, is "#215" a decimal ascii value?
or octal? (probably not hex, since that would only need two
digits, the first of which would be a letter in this case).
If you know the octal or hex value of the delimiter character,
the easiest expression for split (IMO) is: @arry = split /\0215/; # or /\x8d/ if 215 is the octal value
@arry = split /\0327/; # or /\xd7/ if 215 is the decimal value
| [reply] [d/l] |
| [reply] [d/l] |
That did it. Thanks mate.
| [reply] |
my $str = 'foo' . chr(215) . 'bar' . chr(215) . 'baz';
print $str, "\n";
my ($a,$b,$c) = split chr(215), $str;
print "As simple as $a $b $c";
__DATA__
foo×bar×baz
As simple as foo bar baz
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] [d/l] |