Reputation: 87
the problem is that it return like split on undefined value
B
e
c
k
y
.
split string perl code
sub start_thread {
my @args = @_;
print('Thread started: ', @args, "\n");
open(my $myhandle,'<',@args) or die "unable to open file"; # typical open call
my @aftersplit;
for (;;) {
while (<$myhandle>) {
chomp;
@aftersplit = split('|',$_);
#print $_."\n";
foreach my $val (@aftersplit){
print $val."\n";
}
}
sleep 1;
seek FH, 0, 1; # this clears the eof flag on FH
}
}
it split the string in $_ and save in array aftersplit
Upvotes: 1
Views: 673
Reputation: 70732
You need to escape your delimiter, since it's a special character.
For certain special characters you need to precede your character with a literal \
my @aftersplit = split '\|', $_;
You can also use quotemeta.
my $separator = quotemeta('|');
my @aftersplit = split /$separator/, $_;
Or implement the escape sequence \Q
my @aftersplit = split /\Q|/, $_;
Upvotes: 2
Reputation: 11713
You need to escape special character |
with \
@aftersplit = split('\|',$_);
Upvotes: 3
Reputation: 50647
You have to escape |
as it is special char in regex,
my @aftersplit = split(/\|/, $_);
Upvotes: 3