Neo

This user hasn't shared any biographical information


Posts by Neo

How to configure apache virtual host in Microsoft Windows for safer development

Typically for web development, one likes to simulate the web environment by using actual domain name as is instead of using some local IP address. It is very useful in case if you want to host WordPress and would like to copy your version of database as is from development server to the the actual hosting server. The applications like WordPress store domain names in the database while storing your posts as part of permalinks etc.

Another use for having real simulated environment is to ensure your ad slots like Google AdSense, DoubleClick etc appear without any issues. Otherwise the ads More >

How to iterate or loop through all elements of an array in a perl script

Here you can see multiple ways of implementing array iterator.

Example1:

This example reads each element of the array to a variable “$item” in a loop.

@myarray = ('One', 'Two', 'Three');
foreach $item (@myarray) {
  print $item;
}

Example2:

This example avoids intermediate variable “$item” shown in the above script. However if you have nested loops, this method is not suitable. Each element is available in a special variable “$_” inside the loop.

@myarray = ('One', 'Two', 'Three');
foreach (@myarray) {
  print $_;
}

Example3:

This example is similar to “for” loop style of a C programmer .

@myarray = ('One', 'Two', 'Three');
for($i=0; $i <= $#myarray; More >

How to pass and read function or subroutine arguments in a perl script

All the arguments passed to a perl subroutine are packed in an array “@_”. The following script shows you how to access function arguments in a subroutine.

[nick@techpulp ~]# cat funargs.pl
#!/usr/bin/perl

sub myfun
{
  my $i = 0;
  $nargs = $#_+1;
  print "Number of arguments: $nargs\n";
  foreach $arg (@_) {
    $i++;
    print "Arg $i: $arg\n";
  }
}

myfun("One", "Two");
[nick@techpulp ~]#

Let us run the above script.

[nick@techpulp ~]# ./funargs.pl
Number of arguments: 2
Arg 1: One
Arg 2: Two
[nick@techpulp ~]#

If the subroutine is expected to take fixed number of arguments, you can simplify the script as following.

[nick@techpulp ~]# More >

How to read input line by line in a perl script

The following perl script reads one line at a time from the standard input which can be from normal console or a redirected file using pipes.

[nick@techpulp ~]# cat readline.pl
#!/usr/bin/perl

$line = 0;
while (<>) {
  $line++;
  print "Line $line: " . $_;
}
[nick@techpulp ~]# chmod +x readline.pl
[nick@techpulp ~]#

In the above script, The “<>” reads a line from standard input file of the script and “$_” contains the last read data.

For input, let us consider following file (input.txt) which contains four lines.

[nick@techpulp ~]# cat input.txt
first line
second line
third line
fourth line
[nick@techpulp ~]#

Now let More >

How to reset WordPress adminstrator’s password using phpMyAdmin

Its is recommended that this method of setting password is used only as last resort. Because there is a standard way of resetting password using “Lost your password?” option by which you get a mail containing newly generated random password.

WordPress saves MD5 hash of plain passwords. For thos who don’t know what is MD5, it is a digest algorithm (cryptography) that generates fixed length digest for a variable length input. So you will not see plain passwords in WordPress database. This feature ensures even the administrator user unable to know the passwords of subscribed users.

Follow the instruction given below to More >

How to set various colors for A links using CSS

The CSS supports following for <A> tag.

Name Description a:link Style is applied to all non-visited links a:visited Style is applied to all visited links a:hover Style is applied when mouse moves over a link a:active Style is applied to active links. A link becomes active when it is clicked

It is always recommended to specify the styles for a link in the same order as specified in the above table.

An example style specification:

<style type="text/css">
a:link {
  color: #ff0000;
  background-color: #00ffff;
  text-decoration: none
}

a:visited {
  color: #00ff00;
  background-color: #ff00ff;
  text-decoration: none
}

a:active {
  color: #0000ff;
  background-color: #ffff00;
  text-decoration: none More >

How to scroll backwards on text-mode console or graphical terminal to see history of my previous activity

If you are using text-mode console, you can use key combination “Shift+PageUp” to scroll up by one page. Similarly use key combination “Shift+PageDown” to scoll down by a page in console history. You need to use regular “Page Up” and “Page Down” keys and the keys on numeric keypad do not work.

Generally, the same key combinations work in graphical terminal programs like xterm, GNOME Terminal and Konsole etc. The KDE desktop based terminal program konsole adds more flexibility by supporting “Shift+Up” and “Shift+Down” key combinations to scroll down and up by a line in history. This is more convinient in More >