First off thanks for the assistance

See inline comments:

>>> John W.Krahn <[EMAIL PROTECTED]> 11/20/2007 4:31:01 PM >>>
On Tuesday 20 November 2007 14:00, Gerald Wheeler wrote:
> Running Perl 5.6.1 on Solaris 9 SPARC
> No (access to) modules available other than what comes with the
basic
> perl installation.
>
> I have a file: ifiln.csv as such:
> Julian Day of the year, value
> 1,4144.34
> 2,4144.38
> 3,4144.38

[ SNIP ]

So far, so good.


> 366,4147.56 (Leap Year)

Is the text ' (Leap Year)' actually part of the file data?  Is there 
some place in the world where 366 days is *not* a leap year?

>>>>> You'd be supprised.. actually I often get accused of not clearly
stating the issues

> ....OR....
> This may be (as shown below) between the current date and the last
> day of the year or with missing data 331,
> 332,
> 333,
> ...
> 365,
> 366, (Leap Year)
> ----------------------------------
> I would like to create a new file: ofiln based on the data in
> ifiln...  Days without values (missing data or future date) would be
> set as null. If this is run on November 2, 2007 then all days
between
> November 3, 2007 and December 31, 2007 would have a date and a "null
> value" for parameter value.

That seems easy enough.

>>>>> That's what I like to read

> Passed in as commandline arguments
> arg1 (ex: 201)
> arg2 (ex: 11)
> startdate (2007) - January 1, 2007
> The data would be incremented as per column one value of ifiln.

What exactly do arg1 and arg2 represent?  Which data would be 
incremented?

arg1, arg2 (arguments 1, 2) are simply the first two values passed in
from the commandline: 201 and 11 (these are constants and are not
incremented. Just need to be inserted into each line of output.)

> The output file should look something like this:
>         insert some text1, 366, insert some text2 201, insert some
> text3 11, 4144.62, some text4, 2007/11/20, some text5

Where did the date 2007/11/20 come from?

>>>>> Actually as the output file is populated the date should be
inserted based on the year value (2007) input via the commandline entry:
2007
Thus: The ouput file will contain 
...some text and values... 2007/01/01.... some text
...some text and values... 2007/01/02.... some text
...some text and values... 2007/01/03.... some text
...some text and values... 2007/01/04.... some text
...some text and values... 2007/01/05.... some text
...
...some text and values... 2007/02/01.... some text
...some text and values... 2007/02/02.... some text
...
thru the end of the calendar year (versus fiscal year, water year,
whatever year)
records with a date in the future (today is November 21, 2007 so all
records (one/day) through December 31 will have null/blank data values
but will still have a calendar date entry as such:
...some text and values... 2007/12/30.... some text
...some text and values... 2007/12/31.... some text

> below is what I have... can someone assist...  Thanks
>
> *** I do NOT know how to increment (and format as "2007/01/01") date
> so that it crosses over for each new month and know when it is a
leap
> year. Also, Is they a better way to write this??
>
> *------------------------
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $ifiln = 'abc.csv';
> my $ofiln = 'xyz.txt';
>
> # get start year (yyyy) from command line
> my($rsvr, $rdt, $dyr) = @ARGV;

What exactly do $rsvr and $rdt represent?
>>>>>  a simple numeric value between 1 and 100

> print "Year input argument: $ARGV[0] - $ARGV[1] - $ARGV[2]\n";
> print "Year input: $dyr, $rsvr, $rdt\n";
>
> my(@data_line, @rsvrs);       # start out empty

@data_line should be declared inside the loop.


> my $line = "default text";    # start with some default text

$line should be declared inside the loop.


> my $cntr = 0;         # line cntr

$cntr is not needed.


> open RDATA, $ifiln or die "can not open file: $ifiln: $!\n";
>
> while($line = <RDATA>)

You should declare $line here:

while ( my $line = <RDATA> )


> {
> @data_line = split(/,/,$line);

You should declare @data_line here:

    my @data_line = split( /,/, $line );


> $rsvrs[$cntr]{jday} = $data_line[0];
> $rsvrs[$cntr]{rval} = $data_line[1];
> $cntr++;

You don't need $cntr, just use push():

    push @rsvrs, { jday => $data_line[ 0 ], rval => $data_line[ 1 ] };


> }
>
> close(RDATA);
>
> $cntr = 0;

Again, $cntr is not needed.


> open(ORDATA, ">$ofiln");

You should *always* verify that the file opened correctly:

open ORDATA, '>', $ofiln or die "Cannot open '$ofiln' $!";


> foreach(@rsvrs)
> {
>       print ORDATA "insert some text1,";
>       print ORDATA $rsvrs[$cntr]{jday};

You are looping over each element of @rsvrs so in every iteration the 
value of $_ is a reference to a hash and you can just dereference it:

        print ORDATA $_->{ jday };


>       print ORDATA "insert some text2 $rsvr,";
>       print ORDATA "insert some text3 $rdt,";
>       print ORDATA chomp($rsvrs[$cntr]{rval});

chomp() returns the number of $/ values that were removed from its 
argument(s) so that is not what you want to do here.  You should 
probably have chomped the data when you input it.

As above, you can dereference the hash directly:

        print ORDATA $_->{ rval };


>       print ORDATA "some text4";
>       print ORDATA "Calendar Date 2007/11/20 format - How? ($dyr)";

Calendar Date from where?


>       print ORDATA "some text5\n";
>     $cntr++;
> }
>
> close(ORDATA);

>>>>>  Thanks
>>>>>  Does it show that I was once a FORTRAN 77 programmer.. card
punch days and all!

John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 
http://learn.perl.org/ 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to