Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Friday, April 25, 2014

unpack

You skip characters in the input with x, eg

unpack("A1x2A8", "1..Hartnell")

This is badly explained in the documentation, which is all written in terms of pack and so explains 'x' as meaning 'insert a null byte'.

Case is significant in pack codes, and particularly in this one: 'X' means 'back up a byte in the input'.

Thursday, April 10, 2014

Perl chain

I knew it was possible to 'chain' one Perl script from another with do, but I could never see how to give the second script arguments.

But of course it turns out to be easy: you just explicitly set @ARGV before you 'do'. The second script is eval'd in the same global scope that the 'do' is in, so it gets the @ARGV that you set.

Btw in this situation, $0 does not change inside the 'do' - it's still the name of the first script.

Should point out that 'chain' isn't quite the right word - control of course returns to the first script after the 'do' is complete. 'Chain' implies that script 1 finishes when script 2 begins.

Followers

Blog Archive