Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 scrutinizing the Monastery: (10)
As of 2015-07-08 05:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls