I am doing some clean up of data in a file. So, I read each line and check certain conditions and perform the appropriate operation in the file. One of the things I need to do is check for the occurrence of the character $ in the string. If found I need to delete the rest of the line including the $. Example, if the line is
abc$hello-goodbye
I need to get
abc
How do I do this in Perl with minimal code? Use regexp of some sort?
Quickest is by an easy regular expression:
$string =~ s/\$.*//;
where
$string = 'abc$hello-goodbye';
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