Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: substr and strings on the outside

by George_Sherston (Vicar)
on Aug 19, 2001 at 20:29 UTC ( [id://106036]=note: print w/replies, xml ) Need Help??


in reply to substr and strings on the outside

I'm not sure this does what you want in all cases, but it might be a step forward:
my $f = " "; substr($f, length $f, length $f, "12345");
Or do you want the new string to go in at exactly position 5, even if the old string is shorter than that? Then:
my $f = " "; my $l = length $f; substr($f, $l, $l, " " x ($l<5 ? 5-$l : 0) . "12345");
Having said that, this all may betray my failure to understand the question, since one could get the same result with
$f . " " x ($l<5 ? 5-$l : 0) . "12345".

§ George Sherston

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found