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

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: $!";

Replies are listed 'Best First'.
Re^7: Epoch time conversion script
by Anonymous Monk on Apr 05, 2012 at 07:05 UTC

    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>){'

        Well, perl is not executing that program

        If you're not going to type  perl program you need to set the shebang correctly, for ex  #!/usr/bin/perl --

        More on this in perlrun, Behind the GUI lives the Shell (enable javascript for images)