Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^5: Epoch time conversion script

by lidden (Curate)
on Mar 28, 2012 at 10:36 UTC ( #962142=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Epoch time conversion script
in thread Epoch time conversion script

Something like this should do what you want.

open my $in, '<', 'infile.txt' or die "Bummer: $!"; open my $out, '>', 'outfile.txt' or die "What: $!"; while(my $line = <$in>){ if(my ($epoch) = $line =~ /^#\+(\d+)\s*$/){ my $human_readable = `date -d \@$epoch`; # or: # my $human_readable = scalar localtime $epoch; print $out $human_readable; } else{ print $out $line; } }


Comment on Re^5: Epoch time conversion script
Download Code
Re^6: Epoch time conversion script
by hedkandi (Initiate) on Apr 05, 2012 at 06:53 UTC

    Hi lidden I used the while loop you provided and I'm getting this error

    [root@H99A115 03]# ./convert ./convert: line 4: syntax error near unexpected token `{' ./convert: line 4: `while(my $line = $in){'

    I removed the <> tags from <$in> and still the same error this is my input and output file:

    open my $in, '<', 'q22adm_history' or die "Bummer: $!"; open my $out, '>', 'q22adm' or die "What: $!";

      Well, the while loop lidden provided has no syntax errors, so show your code

      I removed the <> tags from <$in>

      that had nothing to do with the error, that was reading the file, that is readline

        Hi anonymous monk Thank you for pointing that out. Here's the result again

        # more perl_epoch open my $in, '<', 'jabadm_history' or die "Bummer: $!"; open my $out, '>', 'jabadm.txt' or die "What: $!"; while(my $line = <$in>){ if(my ($epoch) = $line =~ /^#\+(\d+)\s*$/){ my $human_readable = `date -d \@$epoch`; # or: # my $human_readable = scalar localtime $epoch; print $out $human_readable; } else{ print $out $line; } } # ls -lrt jabadm_history -rw-r--r-- 1 jabadm sapsys 1518 Mar 27 13:31 jabadm_history # ./perl_epoch ./perl_epoch: line 1: open: command not found ./perl_epoch: line 2: open: command not found ./perl_epoch: line 4: syntax error near unexpected token `)' ./perl_epoch: line 4: `while(my $line = <$in>){'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://962142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2015-07-06 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls