finddata has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: How to remove underscore at the end of the line?
by afoken (Chancellor) on Mar 17, 2017 at 07:47 UTC
Re: How to remove underscore at the end of the line?
by Anonymous Monk on Mar 17, 2017 at 04:39 UTC
    s/_$//
      Also, the "code you tried" does NOT produce the "output you obtained," so I'm not sure what you're actually doing.
      But it is not displaying the expected output as per you mentioned.

        Then you must be using it wrong. Show us how you used the solution posted.

        I am confident that s/_$// works for the sample data you posted. Show us your code.


        Dave

        Just to drive davido's point home:

        c:\@Work\Perl\monks>perl -wMstrict -le "for my $s (qw( DCMS_DEMO_ DCMS_DEMO_new_block2_ DCMS_DEMO_new_block2_checklist_tmp_ DCMS_DEMO_new_block2_checklist_tmp_rev1_ )) { my $subject = $s; print qq{'$subject'}; $subject =~ s/_(?=[^_]*$)//; print qq{'$subject' \n}; } " 'DCMS_DEMO_' 'DCMS_DEMO' 'DCMS_DEMO_new_block2_' 'DCMS_DEMO_new_block2' 'DCMS_DEMO_new_block2_checklist_tmp_' 'DCMS_DEMO_new_block2_checklist_tmp' 'DCMS_DEMO_new_block2_checklist_tmp_rev1_' 'DCMS_DEMO_new_block2_checklist_tmp_rev1'
        That's with your original regex, and I get the same output with  s/_$// also.


        Give a man a fish:  <%-{-{-{-<