in reply to Re^2: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
in thread Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)

There is in the second method posted by james28909:

my $data = do { local $/ = undef; open (my $fh, "<", $input_file) or die "could not open $input_file +: $!"; binmode($fh); <$fh>; }; my $reversed_data = pack( "v*", unpack( "n*", $data ) );
But since it's not copied from one variable to another, it probably makes little difference indeed, I didn't think it through.

  • Comment on Re^3: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
  • Download Code

Replies are listed 'Best First'.
Re^4: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
by ikegami (Patriarch) on Apr 14, 2015 at 18:19 UTC
    That code does copy —note the assignment operator— but I think COW wouldn't help there either because I think the string would be stolen from the temp rather than copied.
      Whoa, why the downvotes? Rephrased in case it was confusing.

        No idea about the downvote, but with no comment to go with it, you might as well pretend it's not there. And yes, I do agree that this code probably falls out of COW's scope (that's what I meant by "not copied from one variable to another"), as I said I overlooked that part.