in reply to Re^4: How to remove underscore at the end of the line?
in thread How to remove underscore at the end of the line?
Thank you for posting some code. It's not a great code example because it contains code that is not part of the problem, doesn't compile, and doesn't demonstrate how it's being used with some sample data. But it's enough to test your assertion.
The portion of what you posted that is relevant to your assertion that the code snippet provided in this thread doesn't work is the first three lines of the subroutine ir().
# First three lines of your subroutine, ir() with the prototype remove +d because it's not useful: sub ir { my $prefix = shift @_; $prefix=~ s/_$//; print $prefix,"\n"; } # A loop to test those first three lines of your code to see if they w +ork: while(<DATA>) { chomp; ir($_); } # Sample input you provided: __DATA__ DCMS_DEMO_ DCMS_DEMO_new_block2_ DCMS_DEMO_new_block2_checklist_tmp_ DCMS_DEMO_new_block2_checklist_tmp_rev1_
....output....
DCMS_DEMO DCMS_DEMO_new_block2 DCMS_DEMO_new_block2_checklist_tmp DCMS_DEMO_new_block2_checklist_tmp_rev1
It works.
Dave
|
|---|