4

Create a time variable in perl

 3 years ago
source link: https://www.codesd.com/item/create-a-time-variable-in-perl.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Create a time variable in perl

advertisements

I want to create a variable that will store hardcoded hours and minutes value. Rest stuff like min, day, date, year should be current date and time. How can I do this? I tried timelocal, localtime and many others, but they didn't work.


Unless I'm missing something, you indeed use localtime, as in perldoc: http://perldoc.perl.org/functions/localtime.html

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

Then, if you want to stick to using the broken-down components, you could overwrite whichever variables you want to "fix":

$hour = $my_hardcoded_hour;
$min  = $my_hardcoded_minute;

If instead you need to translate this back to "seconds since the epoch" (Jan 1, 1970, 12:00AM GMT) format, you need the Time::Local package:

http://perldoc.perl.org/Time/Local.html

use Time::Local;

$epoch_current_time_with_fixed_hour_min =
    timelocal($sec, $my_hardcoded_minutes, $my_hardcoded_hour, $mday, $mon, $year);

Tags perl

Related Articles

SAS: create a time ID variable with a program (instead of using the point-and-click system)

SAS offers a point-and-click system to create a time ID variable from a certain starting date using a particular frequency (e.g. weeks, quarters, years). Since I need to do this proces repeatedly, I like to use a code as it makes things much easier.

PHP Create a new variable for each time a link in an iframe changes

I have a basic html form page where a user enters a word and it submits to a php page with an iframe in it and it searches the term in wikipedia see below: <?php $userEntered = $_POST["userEntered"]; echo '<html xmlns="http://www.w3.o

Creating a file name using variables in Perl

I am trying to write out to a file, where the file name is created from a variable(the name + the user id + the date and time + file extension). I have read various things on Stackoverflow which I have based my code off. my $windowsfile = "winUserfil

Is there a new variable created each time in a loop?

In the following example: for(int i=0; i<10; i++) { int k; } Is it true that the loop body (that is, the statement "int k") will repeatedly be executed 10 times? If this is the case, does that mean each time there will be a new variable k cre

Create a date variable from the time (with SAS 9.3)

Using SAS 9.3 I have files with two variables (Time and pulse), one file for each person. I have the information which date they started measuring for each person. Now I want create a date variable whom change date at midnight (of course), how? Examp

How do I create a new variable for a list each time a new key is entered?

I am trying to write a code which asks different users about their dream vacation destinations. It's a dictionary where the key is the poll taker's name and the value is a list called 'dream_vacations'. I want to create a new variable when a new key

Archive :: Zip Can not create a Zip object in Perl

I'm a newbie in Perl language programming. I cut & paste a short example from CPan official website (https://metacpan.org/pod/Net::FTP::RetrHandle), which lists the member names in a Zip file without downloading the whole thing. Please note that I ch

Is it a good practice to export variables in Perl?

I'm finding it very convenient to pass configuration and other data that is read or calculated once but then used many times throughout a program by using Perl's use mechanism. I'm doing this by exporting a hash into the caller's namespace. For examp

Creating a time series from a netcdf file for specific coordinates

I am currently trying to create a time series of precipitation data from the CRU global land precipitation data. The file I am working has 60 time slices, from 2011-2015. My code so far is: b<-brick('/Volumes/LDRIVE2/Masters/Dissertation/Global Surfa

Creating with time series from a dataset with missing values

I need to create a time series from a data frame. The problem is variables is not well-ordered. Data frame is like below Cases Date 15 1/2009 30 3/2010 45 12/2013 I have 60 observations like that. As you can see, data was collected randomly, which is

How to create a multi-variable & ldquo; Ts & rdquo; Object in R?

I have have a dataframe of two different time series. I am able to create ts object separately with the following command: Data Frame: Year Grocery_Stores Liquor 1 Feb-11 1953.8 216.8 2 Mar-11 2108.1 240.5 3 Apr-11 2062.3 244.4 4 May-11 2034.8 232.1

Create a new variable defined only for a subset of data using `dplyr`

Consider this example data: set.seed(1234567) mydf <- data.frame(var1 = runif(10), var2 = c(runif(5), rep(NA, 5))) And this EXAMPLE vectorized function that, unfortunately, triggers an error whenever one of the arguments is NA myfn <- function(x, y)

Scope of variables in perl

In the following code upto what scope the anonymous array referred by $ref is available. mod1.pm: package mod1; sub do_something{ ..... my $array_ref = ["elemnt1","elmnt2"] ; return $array_ref ; } 1; file.pl use mod1; my $ref = mod1::d

Is there a way to create your own @@ variable in SQL Server?

In SQL server, there are times when I have a variable which may change, that many stored procedures all use and just think it would be cool if I could store it as an '@@variable' (like @@servername). Is it possible to create your own '@@variable'? An

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK