Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to remove last character of a line

by Polyglot (Chaplain)
on Mar 23, 2021 at 03:03 UTC ( [id://11130169]=note: print w/replies, xml ) Need Help??


in reply to How to remove last character of a line

Given:

$line = '.abc(abc),';

You can remove the final character by simply saying:

chop $line;

This will remove ANY character, even a newline (\n). But to have a little more precision as to which character you might wish to remove, you could use a substitution:

$line =~ s/.$//; #remove the last character before the newline $line =~ s/[A-Za-z]$//; #remove an alphabetic character before the ne +wline $line =~ s/;$//; #remove a semicolon at the end of the line $line =~ s/[ ]$//; #remove a single space at the end of the line $line =~ s/\s+$//; #remove one or more whitespace characters at the e +nd of the line

Blessings,

~Polyglot~

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found