Pravesh Biyani wrote:
>
> hi
Hello,
> i have a prog which should create a file according to the date and name
> it "$date.log" and write something depending upon other things in it!
> Here is the code.. which refuses to work
>
> --------------------------------------------------------------
> #!/usr/bin/perl -w
>
> $prefix_file = ` date '+%x' ` ;
There is no need to run an external program to get the date as perl
provides localtime() and gmtime(). Also, as Paul points out, the %x
format uses slashes to separate the month, day and yesr fields which is
not a valid file name character. The easiest way to create a formated
date is to use the strftime function from the POSIX module.
use POSIX 'strftime';
my $prefix_file = strftime '%Y%m%d', localtime;
You will notice that I used the order year, month, day to make sorting
by date easier.
> $log = ".log" ;
>
> print " the date is $prefix_file" ;
>
> $probe_logfile = $prefix_file . $log ;
>
> $probefile = "<probe.log" ;
> $OUTFILE = ">>$probe_logfile";
The '<' and '>>' prefixes are part of the open function not the file
name.
> my ($line_number) = 0;
> my ($yes) = 1;
> my ($no) = 0;
> open(probefile) or die("ERROR: $! \n");
> open(OUTFILE) or die ("ERRROR :$! \n");
You should probably write these as:
my $probefile = 'probe.log';
my $outfile = "$prefix_file.log";
open PROBE, '<', $probefile or die "ERROR $probefile: $!";
open OUTFILE, '>>', $outfile or die "ERROR $outfile :$!";
> while(<probefile>) {
>
> my @row_elems =split ;
>
> for (my $x=0; $x<3 ; ++$x)
> {
> $rows[$x][$line_number] =$row_elems[$x] ;
If you changed the order to $rows[$line_number][$x] this would be
simpler.
> if($rows[1][$line_number] > 0.1)
> {
> print OUTFILE "$rows[0][$line_number] \t $yes \t";
> }
> else
> {
> print OUTFILE "$rows[0][$line_number] \t $no \t";
> }
>
> }
> }
my @rows;
while ( <PROBE> ) {
push @rows, [ (split)[0 .. 2] ];
print OUTFILE "$rows[-1][0] \t ", $rows[-1][1] > 0.1 ? $yes : $no, "
\t";
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]