An Array of Hashes

Perl March 3rd, 2009

# First lets define an array of hashes.

my @file_attachments = (
       {file => 'test1.zip',  price  => '10.00',  desc  => 'the 1st test'},
       {file => 'test2.zip',  price  => '12.00',  desc  => 'the 2nd test'},
       {file => 'test3.zip',  price  => '13.00',  desc  => 'the 3rd test'},
       {file => 'test4.zip',  price  => '14.00',  desc  => 'the 4th test'}
  );

or if

my @file_attachments = ([%file_info]);
       {file => 'test1.zip',  price  => '10.00',  desc  => 'the 1st test'},
       {file => 'test2.zip',  price  => '12.00',  desc  => 'the 2nd test'},
       {file => 'test3.zip',  price  => '13.00',  desc  => 'the 3rd test'},
       {file => 'test4.zip',  price  => '14.00',  desc  => 'the 4th test'}
  );

# Get the number of items (hashes) in the array.

my $file_no = scalar (@file_attachments);

# $file_no is now: 4 in this instance as there is 4 hashes in the array.

# Looping through the hash and printing out all the hash “file” elements.

for (my $i=0; $i < $file_no; $i++) {
	print '$file_attachments[$i]{'file'}  is:'. $file_attachments[$i]{'file'}."\n";
}

# Looping through the hash and printing out all the hash “price” elements.

for (my $i=0; $i < $file_no; $i++) {
	print '$file_attachments[$i]{'price'} is:'. $file_attachments[$i]{'price'}."\n";
}

# Looping through the hash and printing out all the hash “desc” elements.

for (my $i=0; $i < $file_no; $i++) {
	print '$file_attachments[$i]{'desc'} is:'. $file_attachments[$i]{'desc'}."\n";
}

#The loops will return this output:

$file_attachments[0]{’file’} is: test1.zip
$file_attachments[1]{’file’} is: test2.zip
$file_attachments[2]{’file’} is: test3.zip
$file_attachments[3]{’file’} is: test4.zip

$file_attachments[0]{’price’} is: 10.00
$file_attachments[1]{’price’} is: 12.00
$file_attachments[2]{’price’} is: 13.00
$file_attachments[3]{’price’} is: 14.00

$file_attachments[0]{’desc’} is: the 1st test
$file_attachments[1]{’desc’} is: the 2nd test
$file_attachments[2]{’desc’} is: the 3rd test
$file_attachments[3]{’desc’} is: the 4th test

credit: htmlfixit.com

Tags: ,

Scroll Windows to Top with JavaScript

JavaScript December 1st, 2008

The following JavaScript link in your page will cause the page to scroll to the top:

<a href=”javascript:scroll(0,0)”>Top</a>

The first number is the x position, the second is the y position. (Positions are in pixels.)  So, you can also change these numbers to scroll to a specific point on a page, too.

ขั้นตอนการติดตั้ง PEAR บน Windows

PHP November 5th, 2008

- start menu > run > พิมพ์ cmd แล้ว enter
- เข้า folder ที่ลง PHP ไว้ เช่น cd c:\php
- พิมพ์ go-pear แล้วกด enter ไปเรื่อยๆ ครับ
- พอเรียบร้อย พิมพ์ pear list ถ้าขึ้น package ขึ้นมาเป็นอันเรียบร้อยครับ

Tags: ,

Perl random ค่าใน Array

Perl July 16th, 2008

Perl random ค่าใน Array

$index = rand @array;
$element = $array[$index];

Tags:

วิธีเพิ่มไฟล์ Extension ให้กับ Dreamweaver

Template Toolkit July 13th, 2008

ให้เพิ่มสกุลที่ต้องการที่ไฟล์ MMDocumentTypes.xml

เช่น หากต้องการเพิ่มไฟล์ .tt โดยต้องการให้แสดงผมเหมือนกับ HTML
ที่บรรทัดบนๆ จะเขียนว่า documenttype id=”HTML” ให้เติม tt เข้าไปทั้ง winfileextension และ macfileextension
ออกมาจะเป็นประมาณนี้


<documenttype id="HTML" internaltype="HTML" winfileextension="html,htm,shtml,shtm,stm,tpl,lasso,xhtml,tt" macfileextension="html,htm,shtml,shtm,tpl,lasso,xhtml,ssi,tt" file="Default.html" writebyteordermark="false">

จากนั้น save และเปืดเข้า Dreamweaver ตามปกติ

เลือก New Document เป็น HTML จากนั้น save เป็น theme.tt
ถ้า save แล้วยังขึ้นส่วนของ Design View มาให้เป็นอันถูกต้อง ครับ

โน๊ต:
Path ของไฟล์ MMDocumentTypes.xml บน Windows Vista 64bit
C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS3\configuration\DocumentTypes

ถ้าหาไม่เจอลอง search ดูครับ

Tags: ,

Copyright © 2008 iBiz Network Co., Ltd. Powered by wordpress, Theme by ericulous