Help on regex

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajiv07
    New Member
    • Jun 2007
    • 141

    #16
    Originally posted by KevinADC
    The way you are doing it is OK, but are you sure you need to check the year, month, and day?
    Thanks Kevin

    Now i have try some other method.I am using Time::Local module to find the record between the date range.Is it better way to sort this problem.

    [CODE=perl]#!/usr/bin/perl
    use Time::Local;

    my $cUser_Name="ra jiv101";
    my @file;

    my $cYear1=2008;

    my $cYear2=2008;

    my $cMon1=2;

    my $cMon2=2;

    $cMon1-=1;

    $cMon2-=1;

    my $cDay2=18;

    my $cDay1=18;

    my $s=0;
    my $m=0;
    my $h=0;

    while(<DATA>)
    {

    next if /^(\s)*$/;

    my $date=(split(/#/,$_,3))[1];

    local ($year,$mon,$da y)=split(/\-/,$date);

    $mon-=1;

    if((timelocal($ s,$m,$h,$day,$m on,$year) >= timelocal($s,$m ,$h,$cDay1,$cMo n1,$cYear1))&&( timelocal($s,$m ,$h,$day,$mon,$ year) <= timelocal($s,$m ,$h,$cDay2,$cMo n2,$cYear2)))
    {
    push(@file,$_) ;
    }

    }

    print @file;





    __END__
    rajiv101#2008-02-16#10:06:00#19: 49:33#127.0.0.1 #19:49:54#18:18 :00#1 27.0.0.1#CY#Y

    rajiv101#2008-02-17#10:06:00#19: 49:33#127.0.0.1 #19:49:54#18:18 :00#1 27.0.0.1#CY#Y

    rajiv101#2008-02-17#10:06:00#19: 49:33#127.0.0.1 #19:49:54#18:18 :00#1 27.0.0.1#CY#Y

    rajiv101#2008-02-18#10:06:00#19: 49:33#127.0.0.1 #19:49:54#18:18 :00#1 27.0.0.1#CY#Y

    rajiv101#2008-02-18#10:06:00#19: 49:33#127.0.0.1 #19:49:54#18:18 :00#1 27.0.0.1#CY#Y

    rajiv101#2008-02-19#10:06:00#19: 49:33#127.0.0.1 #19:49:54#18:18 :00#1 27.0.0.1#CY#Y[/CODE]

    Regards
    Rajiv

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #17
      It probably is better, but since I have no idea what you are doing with your script besides searching a range of dates it is hard to say if it is the best way to do it. Make sure to read the Time::Local documentation thoroughly as it looks like you might be making an error in calculating the month. The months are number: 0 to 11 instead of 1 to 12.

      Comment

      Working...