Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2070 of 2650
16K+ Views
You can use the POSIX function strftime() in Perl to format the date and time with the help of the following table. Please note that the specifiers marked with an asterisk (*) are locale-dependent.SpecifierReplaced byExample%aAbbreviated weekday name *Thu%AFull weekday name *Thursday%bAbbreviated month name *Aug%BFull month name *August%cDate and time representation *Thu Aug 23 14:55:02 2001%CA year divided by 100 and truncated to integer (00-99)20%dDay of the month, zero-padded (01-31)23%DShort MM/DD/YY date, equivalent to %m/%d/%y08/23/01%eDay of the month, space-padded ( 1-31)23%FShort YYYY-MM-DD date, equivalent to %Y-%m-%d2001-08-23%gWeek-based year, last two digits (00-99)01%GWeek-based year2001%hAbbreviated month name * (same as %b)Aug%HAn hour in 24h ... Read More
9K+ Views
You can use the time() function in Perl to get epoch time, i.e., the numbers of seconds that have elapsed since a given date, in Unix is January 1, 1970.Example Live Demo#!/usr/local/bin/perl $epoc = time(); print "Number of seconds since Jan 1, 1970 - $epoc";OutputWhen the above code is executed, it produces the following result −Number of seconds since Jan 1, 1970 - 1361022130You can convert a given number of seconds into date and time string as follows −Example Live Demo#!/usr/local/bin/perl $datestring = localtime(); print "Current date and time $datestring"; $epoc = time(); $epoc = $epoc - 24 * 60 * 60; ... Read More
428 Views
You can use localtime() function in Perl to get a list of 9-elements and later you can use the printf() function to format date and time based on your requirements as follows −Example Live Demo#!/usr/local/bin/perl ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); printf("Time Format - HH:MM:SS"); printf("%02d:%02d:%02d", $hour, $min, $sec);OutputWhen the above code is executed, it produces the following result −Time Format - HH:MM:SS 06:58:52
849 Views
The function gmtime() in Perl works just like localtime() function but the returned values are localized for the standard Greenwich time zone. When called in list context, $isdst, the last value returned by gmtime, is always 0. There is no Daylight Saving Time in GMT.You should make a note on the fact that localtime() will return the current local time on the machine that runs the script and gmtime() will return the universal Greenwich Mean Time, or GMT (or UTC).Try the following example to print the current date and time but on GMT scale −Example Live Demo#!/usr/local/bin/perl $datestring = gmtime(); print ... Read More
559 Views
Let's start with localtime() function in Perl, which returns values for the current date and time if given no arguments. Following is the 9-element list returned by the localtime function while using in list context −sec, # seconds of minutes from 0 to 61 min, # minutes of hour from 0 to 59 hour, # hours of day from 0 to 24 mday, # day of month from 1 to 31 mon, # month of year from 0 to 11 year, # year since 1900 wday, # days since sunday yday, # days since January 1st isdst # hours of ... Read More
225 Views
There are following miscellaneous operators supported by Perl language. Assume variable a holds 10 and variable b holds 20 then −Sr.No.Operator & Description1.Binary operator dot (.) concatenates two strings.Example− If $a = "abc", $b = "def" then $a.$b will give "abcdef"2xThe repetition operator x returns a string consisting of the left operand repeated the number of times specified by the right operand.Example− ('-' x 3) will give ---.3..The range operator .. returns a list of values counting (up by ones) from the left value to the right valueExample− (2..5) will give (2, 3, 4, 5)4++Auto Increment operator increases integer value ... Read More
343 Views
There are following logical operators supported by Perl language. Assume variable $a holds true and variable $b holds false then −Sr.No.Operator & Description1andCalled Logical AND operator. If both the operands are true then the condition becomes true.Example− ($a and $b) is false. 2&&C-style Logical AND Operator copies a bit to the result if it exists in both operandsExample− ($a && $b) is false.3orCalled Logical OR Operator. If any of the two operands are non zero then condition becomes true.Example− ($a or $b) is true.4||C-style Logical OR Operator copies a bit if it exists in either operand.p>Example− ($a || $b) is true.5notCalled ... Read More
406 Views
Bitwise operator works on bits and performs bit by bit operation. Assume if $a = 60; and $b = 13; Now in binary format they will be as follows −$a = 0011 1100 $b = 0000 1101 ----------------- $a&$b = 0000 1100 $a|$b = 0011 1101 $a^$b = 0011 0001 ~$a = 1100 0011There are following Bitwise operators supported by Perl language, assume if $a = 60; and $b = 13Sr.No.Operator & Description1&Binary AND Operator copies a bit to the result if it exists in both operands.Example− ($a & $b) will give 12 which is 0000 11002|Binary OR Operator copies ... Read More
274 Views
Assume variable $a holds 10 and variable $b holds 20, then below are the assignment operators available in Perl and their usage −Sr.No.Operator & Description1=Simple assignment operator, Assigns values from right side operands to left side operandExample−$c = $a + $b will assigned value of $a + $b into $c2+=Add AND assignment operator, It adds right operand to the left operand and assign the result to left operandExample−$c += $a is equivalent to $c = $c + $a.3-=Subtract AND assignment operator, It subtracts right operand from the left operand and assigns the result to left operandExample−$c -= $a is equivalent ... Read More