Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How can I access/change the first N letters of a string?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:20 UTC ( #598=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

There are many ways. If you just want to grab a copy, use substr():

    $first_byte = substr($a, 0, 1);

If you want to modify part of a string, the simplest way is often to use substr() as an lvalue:

    substr($a, 0, 3) = "Tom";

Although those with a pattern matching kind of thought process will likely prefer:

    $a =~ s/^.../Tom/;

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[karlgoethebier]: marioroy ;Men need a challenge
Lady_Aleena remembers winning dodgeball and wonders why parents who played it will not let their kids play it.
[marioroy]: Disciplus My wife and I went on vacation. At work, I was stuck polling SNMP from 20 million devices. It would hang at 80,000. On the mist boat, hear a voice to enable grace in the design that 10x and more performance awaits.
[Lady_Aleena]: Women need challenges too karlgoethebier. 8)
[marioroy]: s/hear/heard/
[karlgoethebier]: Discipulus: No. See https://en. wikipedia.org/ wiki/Tribe_( Native_American)
[karlgoethebier]: They took Unix from some aliens
[marioroy]: Perl is so powerful that it can poll 40 metrics from 20 million devices in 40 minutes using 4 nodes only.
[karlgoethebier]: http://www. uncoveror.com/ aliens.htm
[Lady_Aleena]: marioroy, I can't decide whether or not to move my RolePlaying:: Random:: modules to just Random::. I'm not as sophisticated as most here.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2017-05-29 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?