in reply to Simple query regarding unpack/splice

@datapoint = splice(@values, 0, $x);

So you take $x items from from @values, and assign it to @datapoint. How many values will @datapoint have at the end? Right, exactly $x. Which is 1, in your script.

Update: BTW this is a bad idea: while (read(FILE, $buf, $recsize) == $recsize) {

The last chunk of the file might be shorter than $recsize, in which case read returns a smaller number. The body of the loop is then skipped. If you want to read all records from your file, just say

while (read(FILE, $buf, $recsize)){ ... }

Replies are listed 'Best First'.
Re^2: Simple query regarding unpack/splice
by pc88mxer (Vicar) on May 08, 2008 at 18:13 UTC
    moritz wrote:
    Update: BTW this is a bad idea: while (read(FILE, $buf, $recsize) == $recsize) {
    However, if you do get a short read, do you really want to perform the unpack?

    You can always detect a short read by checking the length of $buf at the end of the loop:

    while (...) { } if (length($buf) > 0 && length($buf) < $recsize) { # last read was short }
    When reading from a disk file (that no one else is writing to), the only place you'll get a short read is at the end of the file. This isn't true for a pipe or a socket where there are more circumstances that will give you a short read before you've reached eof.
Re^2: Simple query regarding unpack/splice
by sf_ashley (Sexton) on May 08, 2008 at 16:31 UTC
    Indeed, it was evident that it was not iterating over @datapoint, so replacing @datapoint with $datapoint[$i] or push @datapoint, yielded a working script. My sincere thanks for your suggestions regarding this matter moritz.