Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
The function returns a formated string with 3 components joined with no token together. The components are 'packed' in to a string
OK so... "StartBE" is 7 characters long, this gets postfixed with spaces by $msgCode = $msgCode.(" " x ($maxMsgCodeLength-length($msgCode))); We'll say the max length is 10 here to make it easier. "StartBE " is now our string. Can be written more clearly as From pack on perldoc: a = A string with arbitrary binary data, will be null padded. i = A signed integer value. The three arguments ( $msgCode, $port, $ip ) get 'packed' into ( a10, i and a* ) respectively. 10 Number of characters in first arugment * However many items are left If you're familar with printf then it's simlar (but more powerfull then that )
You could use 'A' instead of 'a' in the pack statement. This will pad with spaces hence if you set A20 and only give a string length 10 then 10 spaces are added to the end rendering the line previous to pack useless. You'd probably want to make the function more generic...
J, In reply to Re: Please Explain this Function
by binf-jw
|
|