Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re^2: a farewell to chop

by tommyw (Hermit)
on Sep 11, 2002 at 15:56 UTC ( [id://196984]=note: print w/replies, xml ) Need Help??


in reply to Re^2: a farewell to chop
in thread a farewell to chop

Which, fortunately, is why we've got the marvellous \X sequence: s/\X$// will do what you want.

--
Tommy
Too stupid to live.
Too stubborn to die.

Replies are listed 'Best First'.
Re^4: a farewell to chop
by particle (Vicar) on Sep 11, 2002 at 18:29 UTC
    \X fixes the utf8 problem, but there's still a problem with this regex...

    #!/usr/bin/perl -w use strict; use utf8; my($a,$b,$c); $a=$b=$c="123\n456\n"; print chop $a; # prints "\n" print $b =~ s/\X$//; # prints "1" print $a; # prints "123\n456" print $b; # prints "123\n45\n" ## OOPS!!!
    i believe s/\X\z// will do what you want, although it still won't return the character removed. instead, use substr EXPR,OFFSET,LEN,REPLACEMENT (i.e. substr $_,-1,1,'').

    ~Particle *accelerates*

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found