Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Help comparing two fields
I have a csv file  that I want to compare the value in field 22 to a
varialbe

if the value of field 22 is greater than the variable  I want to skip
to the next line.  if it is not => I want to print the line.

while ($line = <tempxxxI> ) {
$line =~ s/'//g;
$csv = Text::CSV->new();
$csv->parse($line) && $csv->fields();
@fields = $csv->fields();
next if $fields[21] => $Date7;
print OUT $line;
}

Problem I am having is  dates are in the mm/dd/yyyy format 09/25/2006.
How do you compare values like this?

Thanks


Report this thread to moderator Post Follow-up to this message
Old Post
mmittiga17@gmail.com
09-25-06 11:57 PM


Re: Help comparing two fields
mmittig...@gmail.com wrote:
> I have a csv file  that I want to compare the value in field 22 to a
> varialbe
>
> if the value of field 22 is greater than the variable  I want to skip
> to the next line.  if it is not => I want to print the line.
>
> while ($line = <tempxxxI> ) {
>       $line =~ s/'//g;
>       $csv = Text::CSV->new();
>       $csv->parse($line) && $csv->fields();
>       @fields = $csv->fields();
>             next if $fields[21] => $Date7;

Please post *real* code.

>             print OUT $line;
>     }
>
> Problem I am having is  dates are in the mm/dd/yyyy format 09/25/2006.
> How do you compare values like this?

Please check the built-in Perl FAQ *before* posting:
perldoc -q compare
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
How can I compare two dates and find the difference?

Paul Lalli

>
> Thanks


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Lalli
09-25-06 11:57 PM


Re: Help comparing two fields
perldoc was of know help.  it does not explain or show how to compare
fields that contain "/".

Paul Lalli wrote:
> mmittig...@gmail.com wrote: 
>
> Please post *real* code.
> 
>
> Please check the built-in Perl FAQ *before* posting:
> perldoc -q compare
> Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
>      How can I compare two dates and find the difference?
>
> Paul Lalli
> 


Report this thread to moderator Post Follow-up to this message
Old Post
mmittiga17@gmail.com
09-25-06 11:57 PM


Re: Help comparing two fields
[PLEASE DO NOT TOP-POST!!]

mmittig...@gmail.com wrote:
> Paul Lalli wrote: 

> perldoc was of know help.  it does not explain or show how to compare
> fields that contain "/".
>

The hell it wasn't. Did you *read* it, or did you just scan it for the
exact answer to your question?  It tells you exactly how to compare
dates.  You cannot compare just the string values.  You have to parse
them out to find the month, date, and year.  Then you have to use those
values to find an epoch-time representation of that date.

Paul Lalli


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Lalli
09-25-06 11:57 PM


Re: Help comparing two fields
mmittig...@gmail.com wrote:

[please don't toppost]

> perldoc was of [no] help.  it does not explain or show how to compare
> fields that contain "/".

Did you actually READ it?  Maybe it doesn't hold your hand and describe
the exact format you're using, but you ought to be able to get a clue
about how to proceed for ANY given date format:
 

Hmmmm... I'd check that out if I were you...

--
David Filmer (http://DavidFilmer.com)


Report this thread to moderator Post Follow-up to this message
Old Post
usenet@DavidFilmer.com
09-25-06 11:57 PM


Re: Help comparing two fields
As they say - in perl there is more than one way to do something.
If all you need to do is to compare the dates and find which is greater
without worrying about how many days are actually between them - then
here is a trick - just turn the mm/dd/yyyy date into a number made up
of yyyymmdd: This shows how it works

#!/usr/bin/perl
use strict;

my $entry;
my $prevday="0";
my @dates =("09/25/2006","10/01/2006","07/09/2006","09/27/2001");

foreach $entry(@dates){
my @day =split(/\//,$entry);
my $yyyymmdd ="$day[2]$day[0]$day[1]";
if ($prevday < $yyyymmdd ) {
print   "new date $yyyymmdd is later than previous day $prevday
\n";
}
$prevday = $yyyymmdd;
}


Report this thread to moderator Post Follow-up to this message
Old Post
bdz
09-26-06 11:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:15 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.