Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Trim Two Characters On Line

by BillKSmith (Monsignor)
on Oct 23, 2020 at 03:34 UTC ( [id://11123069]=note: print w/replies, xml ) Need Help??


in reply to Trim Two Characters On Line

Here is exactly what you request.
substr( $line, -2, 2, '' ) if $line =~ /sum/;

You may want to remove the second and third last character, leaving a newline at the end.

substr( $line, -3, 2, '' ) if $line =~ /sum/;
Bill

Replies are listed 'Best First'.
Re^2: Trim Two Characters On Line
by jalopez453 (Acolyte) on Oct 23, 2020 at 16:24 UTC
    Thank you Bill. This was the perfect one liner for what I was looking for, but I ended up running into another problem, after running the process on all my files, come to find out, not all of them have the extra commas at the end as I expected. Would it be okay to send you a message and show you what I am trying to do.
      not all of them have the extra commas at the end

      Are you trying to read a CSV file? Better use Text::CSV (and its accelerator Text::CSV_XS), it can handle all of the evil edge cases that you didn't even think of.

      Would it be okay to send you a message and show you what I am trying to do.

      Perlmonks does not work that way. Post detail questions right here in this thread.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Not all please do... This is what I decide to do instead, but what is happening is it is wrapping the line after on the same line.
        while(<IN>) { my $line = $_; my $number = () = $line =~ /\,/gi; $line =~ substr( $line, -2, 2, '' ) if ($number > 79); print OUT "$line"; } close OUT; close IN; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found