CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [dprogrammer] if then else with Date help needed: Edit Log



Kenosis
User

Mar 22, 2013, 10:42 PM


Views: 531
Re: [dprogrammer] if then else with Date help needed

To get the day of the month, you can use the following:


Code
( localtime(time) )[3]


localtime(time) returns a list, detailed here. The third item of the list is the day. Using Perl's ternary operator, consider the following:


Code
#!/usr/bin/env perl 

use strict;
use warnings;

my $con =
( localtime(time) )[3] == 1
? 'D:\\MyFiles\con_1.conf'
: 'D:\\MyFiles\con_2.conf';

print $con;


Output:


Code
D:\MyFiles\con_2.conf


However, it will return:


Code
D:\\MyFiles\con_1.conf


when it's the first day of the month, i.e., when:


Code
( localtime(time) )[3] == 1


is true.

Hope this helps!


(This post was edited by Kenosis on Mar 23, 2013, 9:05 AM)


Edit Log:
Post edited by Kenosis (User) on Mar 23, 2013, 9:05 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives