This is my perl 5.16 code
while(<>) {
chomp;
@data = split /a/, $_;
print(join("b",@data),"\n");
}
If I input a file with this in it:
paaaa
paaaaq
I get
p
pbbbbq
But I was expecting
pbbbb
pbbbbq
Why am I wrong to expect the latter behavior?
It is documented that trailing empties are removed unless you specify a third, non-zero argument.
If
LIMITis omitted (or, equivalently, zero), then it is usually treated as if it were instead negative but with the exception that trailing empty fields are stripped (empty leading fields are always preserved)
You want
split /a/, $_, -1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With