Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Perl memset equivalent?

by moritz (Cardinal)
on Jun 26, 2012 at 18:37 UTC ( #978483=note: print w/ replies, xml ) Need Help??


in reply to Perl memset equivalent?

You don't have direct memory access in Perl, so talking about an equivalent is a bit misleading.

If you want to set a range of array elements to zero, you can do that as

@array[0..4] = (0) x 5;

If you want to create a string of zero-bytes, you can write

my $s = "\0" x 5;

(Update: fixed off-by-one error noticed by martin++).


Comment on Re: Perl memset equivalent?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2014-10-02 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (56 votes), past polls