Monday, January 22, 2007

PHP : Handling multiple select menu

Thought of putting a code to illustrate handling multiple select menus with php.

Note the square brackets and the multiple="multiple" part in the form.

HTML form
---------

<form action="some_action_file.php" method="post">
<select name="select_name[]" multiple="multiple">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>
<input type="submit" value="Submit" />
</form>
PHP part
----------
<?php ## some_action_file.php foreach ($_POST['select_name'] as $select_name){ echo "$select_name<br />"; ## prints all the selected values; one per line } ?>

Monday, January 15, 2007

Perl : Removing last newline in while

Here's a way to check if we are at the last iteration and removing the newline if true, while iterating through lines.

while(<>){
chomp if eof; ### eof returns 1 if next read on filehandle returns end of file
print;
}


Friday, January 05, 2007

Perl : Locating a perl module file

How do you find out exactly where a perl module file is ? Following example searches Template.pm in the paths where perl modules are installed.

find `perl -e '$,="\n";print @INC'` -name Template.pm

Note

The perl command is in back-ticks. This is an example of command execution within a command.

Thursday, January 04, 2007

Networking : Switches versus Hubs

A few days back, I replaced hub with a switch in my small LAN at home. Although it's just a plug and play sort of switch, I had to do some configuration changes so that computers could ping each other. I spent a lot of time solving connectivity problems :-) Learnt a lot about how switches work in the process.

I can think of following differences between a hub and a switch.

1. Hub requires no knowledge of how it works. It's easy to install. The same is not true with switches. Even if the manual s
ays "plug and play switch", it's better to know how switches work.

2. You may have to configure your NICs (network cards) so that the switch communicates. To configure network cards, you need
 to learn what to configure.

3. Switches offer you a learning opportunity :-). In the process of making your network work for you, you'll learn people me
an by words like duplex auto-negotiation and speed.

4. If you are required to troubleshoot, you learn still more. In that case, you'll learn commands like ethtool, ifconfig, tr
aceroute, ifup, ifdown etc.

5. Conlusion is, Switches are better than hubs not only because of the reasons you read on the net, but they also teach you
networking.