Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Byte strings- a question I cannot figure out involving pack/unpack

Status
Not open for further replies.

LinuxNoobPhilip

Technical User
Jan 22, 2008
11
US
Hi, I am trying to take a number format it as a 32 bit(4 byte) unsigned integer, then append it to a string.

the string I want is the follow "#0001", where the integer was 12. does this make sense? so this is what I thought I should do it

$string = "#";
$int = pack('L',1)
$string.= unpack('L',$int)

Ouput: "#1
 
What I want to do is take a number (say from a for loop 1,2,...) make it 4 bytes long(in representation) and append it to a string like this.

$theString.=the4ByteNumber; # "xxxxxx0001" for example
 
Code:
my $str='#';
my $result='';
foreach my $i (1..15) {
	$result=$str.sprintf("%04u",$i);
	print "$result\n";}
Does this makes sense to you?

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Sweet Thank you very much man!

That is exactly what I was trtying to do!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top