Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to remove last character of a line

by Polyglot (Friar)
on Mar 23, 2021 at 03:03 UTC ( #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? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-09-17 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?