in reply to problem in splitting on special character
my @arr = split /\Q$ele\E/, $var;
BTW, you have $ele when you should have $sep, unless you plan on splitting on the "~" character. You did say in your question that you wanted split on the "|" character?
In this case you probably don't need the \E since you are quoting the entire regex anyway.
#!/usr/bin/perl # vim: sw=4 use strict; use warnings; use Data::Dumper; my $var = "21|23|24~|34|45|56~"; my @arr = split("", $var); my $sep = $arr[2]; my $ele = $arr[8]; my @ar = split(/\Q$sep\E/, $var); print Dumper \@ar; bruce:1:~/tmp $ ./p.pl $VAR1 = [ '21', '23', '24~', '34', '45', '56~' ]; bruce:1:~/tmp $
|
|---|