hi Chris,
Thanks for the responses.
Q1: Your suggestion would work without the date module for now :-)
Q2: The input file is a flat file (.txt) parsed by "~" with 40 columns. Columns 2-40 has numbers (all integers, +ve and -ve numbers). Column 0 has items in alphanumeric and column 1 has labels in text. I would like to find the minimum value for numbers in columns 2-40 and write out an output in the form of a flat file with 2 columns (col. 0 = item, col. 1 =min value).


Please see the code I wrote. I does NOT work. Thanks for your input and help,
=====================
$i=0;
open INV_RPT, "$_inventory_rpt" or die "Can't open file handler";
open (INV_RPT_MIN, ">$_inventory_rpt_min");
{
chop($Ctmp1);
@Ctmp2=split(/~/,$Ctmp1);
$items{$Ctmp2[0]}=$Ctmp2[0];
}


foreach $item (keys %items)
{
while($Ctmp1 = <INV_RPT>)
{
chop($Ctmp1);
@Ctmp2=split(/~/,$Ctmp1);
$START_MIN{$ctmp2[0]}=$ctmp2[2];
for $i (0..40) { if(defined($Ctmp2[$i])) { $Ctmp2[$i] =~ s/\s*//; } else { $Ctmp2[$i] = ""; } }
if($START_MIN{$ctmp2[0]} < $Ctmp2[$i])
{
$END_MIN{$Ctmp2[0]}=$Ctmp2[$i];
print INV_RPT_MIN "$item~$END_MIN{$Ctmp2[0]}\n";
}
}
}
close(INV_RPT);
close(INV_RPT_MIN);
===============


sample input file content:
==========
col0~col1~col2.......
AI6CQ7~Finishing Onhand~ 48.0~ 42.0~ 134.0~ 124.0~ 120.0~ 120.0~ 120.0~ 110.0~ 108.0~ 102.0~ 96.0~ 94.0~ 94.0~ 94.0~ 90.0~ 88.0~ 88.0~ 60.0~ 60.0~ 60.0~ 60.0~ 60.0~ - 48.0~ -34.0~ 24.0~ 18.0~ 18.0~ 18.0~ 14.0~ 98.0~ 88.0~ 88.0~ 88.0~ 88.0~ -88.0~ 82.0~ 78.0~ 68.0~ 62.0~ 58.0~ 58.0~ 58.0~ 56.0~ 50.0~ 44.0~ 42.0~ 40.0~ 140.0~ 140.0~ 96.0~ 96.0~ 96.0~ 96.0~ 96.0~ -96.0~ -96.0~ 56.0~ 56.0~ 56.0~ 56.0~ 56.0~ 56.0~ 56.0~ 56.0~ 56.0~ 56.0~ 56.0~
============


I appreciate your help.

From: Chris Devers <[EMAIL PROTECTED]>
Reply-To: Perl Beginners List <[EMAIL PROTECTED]>
To: "M. Ilyas Hassan" <[EMAIL PROTECTED]>
CC: Perl Beginners List <[EMAIL PROTECTED]>
Subject: Re: questions
Date: Mon, 25 Oct 2004 19:28:38 -0400 (EDT)

On Mon, 25 Oct 2004, M. Ilyas Hassan wrote:

> #1 - Is there a way to add "days" to a date?

The modules that the other two respondants pointed you to are the right
way to do this, but it's good to know that the way to do this by hand --
which you won't want to do, but it's good to see why not -- is to only
deal with times represented as seconds.

So, for example, 90 days works out to 7776000 seconds (60 secs/min * 60
mins/hour * 24 hours/day * 90 days).

So you look up the Unix timestamp for the starting date. For this, let's
use the time as I type this, 1098746228:

    $ perl -le 'print scalar localtime 1098746228'
    Mon Oct 25 19:17:08 2004
    $

You add 90 days worth of seconds to that to get the future date:

    $ perl -le 'print 1098746228 + 7776000'
    1106522228
    $

And then you convert that back to a more conventional format:

    $ perl -le 'print scalar localtime( 1098746228 + 7776000 )'
    Sun Jan 23 18:17:08 2005
    $

Or, putting it all together:

$ perl -le '$now = 1098746228; $ninety_days = 7776000; $then = $now + $ninety_days; print scalar localtime $then'
Sun Jan 23 18:17:08 2005
$


This isn't *that* bad, but the math gets annoying to manage manually.
Using a module like Date::Calc saves a lot of effort & reduces errors.

Look up the documentation for Date::Calc for usage detals.

> #2 - How could I find the minimum value from table with say 80columns.

How is this table represented? Is it in a database? Is it in a flat file
of some kind? Do you already have it in memory in some kind of data
structure?

The approach to this problem depends a lot on what tools you have to
work with.

For this, you need to describe where this data is coming from, how you
are thinking of representing it in variables, and (most important) you
need to show us what code you've written to solve the problem.

The date problem was a gimme, but this is a larger task with many ways
it could be solved. You have to show us where you're starting from
before  you can expect people to fill in the blanks for you.

> Please email your feedback to [EMAIL PROTECTED] I will truly
> appreciate any help that you could offer.

This seems to be a typo -- all discussion should stay on the list where
it can be of use to everyone that is trying to learn this stuff. If you
have not already done so, please subscribe to the list so that we can
have the conversation on the list.


-- Chris Devers


-----------------------------------------------------------------
Muhammed I. Hassan
1030 Baytowne Drive, #24
Champaign, IL 61822
217-353-0075 (Home)
630-267-2494 (Mobile)



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




Reply via email to