Perl has a built in function to retrieve the system date and time. The localtime function returns an array of nine (9) values but it is rare that you are interested in all nine values. There is a simple way to just retrive the values of interest by treating them as they are, an array.
First we set up the scalar variables we need to receive the values from the localtime function. In this case we are collecting minutes, hour, day of month, month, year, and if the Daylight Saving Time bit is set. We put them in parentheses to treat them as input into, or in this case output from, an array my ($min, $hour, $mday, $mon, $year, $isdst).
Next we query the system for the time and evaluate it as local time. (localtime(time())). Since we only some of the values we only reference those values from the array [1,2,3,4,5,8]. In order to make the two sides equal, we must eclose the entire expression in parentheses ((localtime(time()))[1,2,3,4,5,8]). It may be possible to write this expression in shorthand but this is the most explicet representation.
It may be possible to drop the time() function making the local time function look like ((localtime())[1,2,3,4,5,8]) or even ((localtime)[1,2,3,4,5,8]).
my @DST = ("No", "Yes");
#get system time but just the minutes, hour, day, month, year, and Daylight Saving Time bit.
my ($min, $hour, $mday, $mon, $year, $isdst)=((localtime(time()))[1,2,3,4,5,8]);
print "It is now: $mon/$mday/$year $hour:$min DST: $DST[$isdst]\n";
It is now: 11/6/2013 13:21 DST: No
Sometimes you may want read configuration data from a file. This is fine but you cannot always control the format data is entered. It is, therefore, a good idea to provide your end user a little wiggle room. Let us assume that we have a configuration file with a key = value format. On the left side of the equal sign we have a key such as home directory. On the right side we have the value to be stored with with the key such as /home/geen. A simple way to read
In the following example I have an input file that has a key/vale pair with a separator of and equal sign (=). If you note closely, the spaces are inconsistant. Sometimes there is a space before and/or after the equal sign. To account for this we just use a regular expression to note that there may be zero or more white spaces around the equal sign. We do this with the \s* regular expression notation.
userid = geen
#Sample split statement in perl
whie ( my $record,<$INFILE> )