Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

accessing randon number from perl script

by abcdefg (Acolyte)
on May 24, 2012 at 18:36 UTC ( [id://972290] : perlquestion . print w/replies, xml ) Need Help??

abcdefg has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a script where I am appending three binary files together.The second file being a 32bytes of zeroes in binary format.Now I dont want to have this second file and i want to add these 32 bytes of zeroes in the script itself.I am not sure how to do that.

$cmd = "copy $vrl_1.bin/B + $32bytes.bin/B + $2.bin $3.bin"; system $cmd;

i am not sure how can i hardcode the 32bytes of zeroes in this script.

Replies are listed 'Best First'.
Re: accessing randon number from perl script
by TomDLux (Vicar) on May 24, 2012 at 19:10 UTC

    You aren't copying the files with Perl, you are copying the files fith a DOS command which is invoked from Perl.

    If your goal is to eliminate the file of zeroes, I would suggest a perl routine to open an input file, copy it line by line to a provided output filehandle, and then close the file. To insert the zeroes, you can simply write to the output filehandle .... except you may need to reopen it in binary mode. Maybe printing "\x00" .. the string containing a single byte with the value 00 ... will work, you can give it a try.

    P.S. What does this have to do with "accessing randon number from perl script"?

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re: accessing randon number from perl script
by roboticus (Chancellor) on May 24, 2012 at 18:47 UTC


    Perhaps something like this would do:

    open $TMP, '>', 'ZERO' or die $!; print $TMP, chr(0) for 0 .. 31; close $TMP; $cmd = "copy $vrl_1.bin/B + ZERO/B + $2.bin $3.bin"; system $cmd; $cmd = "del /y ZERO" system $cmd;

    ...extricating tongue from cheek.


    Give a man a fish, and his hands will stink for a day. Teach him to fish, and they will stink for life.

Re: accessing randon number from perl script
by ww (Archbishop) on May 24, 2012 at 22:42 UTC
    Another nit (but non-trivial): You are not "appending three binary files together": you are concatenating three files... and not even exactly that, if I understand your "I dont (sic) want to have this second file...." correctly.

    In any case, appending implies that a second (third, fourth....) entitity is appended (surprise!) to a first with the result (in the case of files) being the first file extended by the content of the second. IOW, the original first file is changed.

    Concatenating, OTOH, implies building a new file (entity) by combining the originals... without modifying those originals, at all.

    So why is this minor, pedantic, but non-trivial? Because precision of language and thought are critical assets for a programmer.