Sunday 29 December 2013

Splice function in Perl

While using arrays in a Perl program, sometimes you might require only a part or a chunk of the array instead of the whole.

Splice is a function which is used to carve an array and cut a portion out of it.

Consider the following illustration.

Eg:

@arr = ('10', '90', '30', '70', '40', '60');

Now as you may be aware, each value in the array is identified by it's index. The first element of the array is denoted by index 0. The second element is denoted by index 1 and so on...

Let's use the splice function to cut the array:

$portion = splice(@arr, 2, 4);

If you observe above, we have basically specified the range of elements from 2nd to 4th index within the array.

In this case the element on 2nd index from left is 30 (since foremost element's 10's index is 0) and the element on 4th index is 40)

The above command will result into values ('30', '70', '40') getting stored in the @portion array, which is a chunk of the original @arr array.

In general, splice syntax can be remembered as splice (<array-name>, <beginning-index>, <ending-index>)

Chop vs Chomp in Perl

In Perl, the basic difference between the keywords 'chop' and 'chomp' is as follows:

Chop is used to literally chop the last character of a string. It simply deletes the last character.

Eg:

chop garlic;

The output will be garli with 'c' getting chopped off :)

On the other hand, Chomp is used to delete the endline character "\n";

Eg:

$var = "garlic\n";

chomp $var;

The resultant value of $var will be the same string garlic, but with only the newline character getting deleted.

Saturday 28 December 2013

Show file extensions in Mac OSX

People new to Mac OSX often ask how do I see a file's extension, since by default the extensions are hidden. In order to view the extensions, do the following:


  • Open any finder window or just click anywhere on the desktop.
  • From the topmost Finder menu, click Preferences.
  • Click the Advanced tab in the Finder Preferences.
  • Tick mark the "Show all filename extensions" 


Check if a directory exists in Unix

In Unix, you can check if a certain directory exists or not using -d

Eg:

if [-d $directory_name]
then
       execute_some_commands
fi

In the variable $directory_name you specify the name of the directory. If the directory exists, then the if loop executes and the commands would be executed. 

Friday 27 December 2013

Blog Renaming

Hello folks this is Ironclad Writer and if you're reading this post, you're not alone :) { a funny take on  Terminator Salvation... just kiddin }

Ok so as I said previously in my post on Blog rebranding, I am considering renaming my blog in the next couple of days.

I would like the name to be more catchy, something unique. Something which attracts more eyeballs and drives users to explore the whole blog, looking for interesting material. I basically intend to write posts on a range of multi variety topics. I want the users to be satisfied while browsing, to enjoy reading the posts which piques their interest and curiosity. Hence am looking for a unique blog name which matches the wavelength.

There are a few blog names in my mind currently and which are still available. I would appreciate if users reading this could suggest me a few good names. If you think of some good name, do leave your comments and suggestions.

Over and out. Thank you.


Move Task - Ant

Move task in Ant is used to move a file or a directory or a set of files to a new directory.


  • Move task can also be used rename a single file (analogous to mv command in unix)
Eg:

<move file="test.txt" tofile="test_updated.txt" />


  • You can use to move a file to a specific directory as follows:
Eg:

<move file="test.txt" todir="/usr/var/move_here/" />


  • Move a set of files to a certain directory

Eg:

<move todir="/usr/var/mover_here/">
    <fileset dir="/my/src/dir_to_be_moved">
         <include name = **/*.jar >
         <exclude name = **/ant.jar">
     </fileset>
</move>  

A detailed official guide of the Move task and its parameters can be found here.



Rename build properties in Ant

It is possible to rename the build.properties file to something more specific to your environment. For instance, you can have separate build.properties file for DEV, QA, UAT or Production environment, if you want to.

You could rename it to lets say build-dev.properties or build-test.properties

Accordingly, rename the property tag in build.xml where you define the properties file.

Eg:

<property file="${user.home}/build-test.properties"/>

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker