Timelocal input, post good Date filters (from - to)

Discussion in 'Perl Misc' started by robic0@yahoo.com, Oct 26, 2005.

  1. Guest

    I get some weird concat warnings on print if enabled so its commented.
    Post any you have (or make some up).
    Here's mine ..

    use strict;
    #use warnings;

    my @dates = ('2/30/5-7/2005', '2/5', '-3/29.2000', '4-12/05',
    '-12/01-1/03', '10/2002,8/31/2005', '1/2-asdvf');

    for (@dates) {
    my $date = $_;
    print '-'x40,"\n$date\n";
    $date =~ /.*/;
    $date =~
    /^(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([,-]*)(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)$/;
    print "date = ($1)($2)($3)($4)($5)($6)($7)\n";
    }

    __DATA__

    ----------------------------------------
    2/30/5-7/2005
    date = (2)(30)(5)(-)(7)(2005)()
    ----------------------------------------
    2/5
    date = (2)(5)()()()()()
    ----------------------------------------
    -3/29.2000
    date = ()()()()()()()
    ----------------------------------------
    4-12/05
    date = (4)()()(-)(12)(05)()
    ----------------------------------------
    -12/01-1/03
    date = ()()()()()()()
    ----------------------------------------
    10/2002,8/31/2005
    date = (10)(2002)()(,)(8)(31)(2005)
    ----------------------------------------
    1/2-asdvf
    date = ()()()()()()()
    , Oct 26, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > Post any you have (or make some up).


    I don't have to make anything up. I just

    use Date::Manip;
    , Oct 26, 2005
    #2
    1. Advertising

  3. Matt Garrish Guest

    <> wrote in message
    news:...
    >I get some weird concat warnings on print if enabled so its commented.


    They aren't weird errors. You don't check if your match succeeds, so you
    wind up using numbered variables that aren't intialized.

    > Post any you have (or make some up).
    > Here's mine ..
    >
    > use strict;
    > #use warnings;


    Always a bad idea...

    >
    > my @dates = ('2/30/5-7/2005', '2/5', '-3/29.2000', '4-12/05',
    > '-12/01-1/03', '10/2002,8/31/2005', '1/2-asdvf');
    >
    > for (@dates) {
    > my $date = $_;


    Why?

    foreach my $date (@dates)

    > print '-'x40,"\n$date\n";
    > $date =~ /.*/;
    > $date =~
    > /^(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([,-]*)(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)
    > ([0-9]+)?(?:\/*)$/;
    > print "date = ($1)($2)($3)($4)($5)($6)($7)\n";


    This is you problem. If you look at your output you'll notice that you're
    getting an equal number of unintiliazed warnings as empty value within
    parentheses. This is not a coincidence. Most people will, at a minimum, test
    if their regular expression even succeeded:

    if ($date =~ /longregex/) {
    # do something
    }

    else {
    print "Invalid date\n";
    }

    > }
    >
    > __DATA__
    >


    The above is misleading. __DATA__ signifies that the data that follows is
    used by your program (e.g., somewhere in your code is "while (my $line =
    <__DATA__>)"). What follows, however, is your output.

    Matt
    Matt Garrish, Oct 27, 2005
    #3
  4. Matt Garrish Guest

    "Matt Garrish" <> wrote in message
    news:Io38f.7243$...
    >
    > <> wrote in message
    > news:...
    >>I get some weird concat warnings on print if enabled so its commented.

    >
    > They aren't weird errors. You don't check if your match succeeds, so you
    > wind up using numbered variables that aren't intialized.
    >


    That's a little misleading, on second look (since you manufactured your
    dates to work). You don't require content in all your captures, so you wind
    up with the unintialized warnings. It's still bad practice not to check, and
    feed data that doesn't match your pattern and you will get the messages for
    the above reason.

    Matt
    Matt Garrish, Oct 27, 2005
    #4
  5. Guest

    On Thu, 27 Oct 2005 08:06:05 -0400, "Matt Garrish"
    <> wrote:

    >
    ><> wrote in message
    >news:...
    >>I get some weird concat warnings on print if enabled so its commented.

    >
    >They aren't weird errors. You don't check if your match succeeds, so you
    >wind up using numbered variables that aren't intialized.
    >
    >> Post any you have (or make some up).
    >> Here's mine ..
    >>
    >> use strict;
    >> #use warnings;

    >
    >Always a bad idea...
    >
    >>
    >> my @dates = ('2/30/5-7/2005', '2/5', '-3/29.2000', '4-12/05',
    >> '-12/01-1/03', '10/2002,8/31/2005', '1/2-asdvf');
    >>
    >> for (@dates) {
    >> my $date = $_;

    >
    >Why?
    >
    >foreach my $date (@dates)
    >
    >> print '-'x40,"\n$date\n";
    >> $date =~ /.*/;
    >> $date =~
    >> /^(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([,-]*)(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)
    >> ([0-9]+)?(?:\/*)$/;
    >> print "date = ($1)($2)($3)($4)($5)($6)($7)\n";

    >
    >This is you problem. If you look at your output you'll notice that you're
    >getting an equal number of unintiliazed warnings as empty value within
    >parentheses. This is not a coincidence. Most people will, at a minimum, test
    >if their regular expression even succeeded:
    >
    >if ($date =~ /longregex/) {
    > # do something
    >}
    >
    >else {
    > print "Invalid date\n";
    >}
    >
    >> }
    >>
    >> __DATA__
    >>

    >
    >The above is misleading. __DATA__ signifies that the data that follows is
    >used by your program (e.g., somewhere in your code is "while (my $line =
    ><__DATA__>)"). What follows, however, is your output.
    >
    >Matt
    >

    About the __DATA__ thing, I thought it was a flag to ignore below as
    comments, but thats where I put the output. Whats the right way
    to do it?
    Thx
    , Oct 28, 2005
    #5
  6. Guest

    On Thu, 27 Oct 2005 08:15:57 -0400, "Matt Garrish"
    <> wrote:

    >
    >"Matt Garrish" <> wrote in message
    >news:Io38f.7243$...
    >>
    >> <> wrote in message
    >> news:...
    >>>I get some weird concat warnings on print if enabled so its commented.

    >>
    >> They aren't weird errors. You don't check if your match succeeds, so you
    >> wind up using numbered variables that aren't intialized.
    >>

    >
    >That's a little misleading, on second look (since you manufactured your
    >dates to work). You don't require content in all your captures, so you wind
    >up with the unintialized warnings. It's still bad practice not to check, and
    >feed data that doesn't match your pattern and you will get the messages for
    >the above reason.
    >
    >Matt
    >

    Hey Matt,
    I don't know what you mean by manufactured dates. Maybe this will
    help:

    elsif ($_ =~ /^([~\/-]+date$)/ || $_ =~
    /^([~\/-]+date:)/) {
    if ($1 =~ /~/) {
    $hCmdp{'Date'}->[0] = '~'; next;
    }
    $hCmdp{'Date'}->[0] = undef;
    $hVars{'Date'} = '';
    $hVars{'date_1'} = -1;
    $hVars{'date_2'} = -1;
    my $date_err = 0;

    if ($_ =~ /^[\/-]+date:(.+)$/) #($_
    =~ /^[\/-]+date:([0-9\/,\*-]+)/)
    {
    my $date = $1;
    #print "date = \"$date\"\n";
    $hCmdp{'Date'}->[0] = $date;
    $hVars{'Date'} = $date;
    if ($date =~ /\*/) {
    $hCmdp{'Date'}->[0] = '*';
    $hVars{'Date'} = '*';
    } else {
    my @times = ();

    # Date format:
    # -##/##/## = all up to this
    date
    # ##/##/##- = all from this
    date forward
    # ##/##/##,##/##/## =
    between these two dates

    $date =~ /.*/;
    $date =~
    /^(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([,-]*)(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)([0-9]+)?(?:\/*)$/;
    #print "date =
    ($1)($2)($3)($4)($5)($6)($7)\n";

    if (length($1) == 0 &&
    length($5) == 0) {
    # error, invalid date
    format ...
    push (@ArgErrs, ['E',
    $LOGINFO, $ERRLOG, '9016', (0,0,0,0), "$date", '', 1,0,1]);
    $SHOWUSAGE = 1;
    $date_err = 1;
    } else {
    my ($mo,$day,$yr,$cnt)
    = (0,0,0,0);
    if (length($1) > 0)
    {
    $cnt++ if
    (length($3));
    $cnt++ if
    (length($2));
    $cnt++ if
    (length($1));
    if ($cnt ==
    3) { $mo=$1; $day=$2; $yr=$3; }
    elsif ($cnt ==
    2) { $mo=$1; $day=1; $yr=$2; }
    elsif ($cnt ==
    1) { $mo=1; $day=1; $yr=$1; }
    if ($day < 1
    || $day > 31 || $mo < 1 || $mo > 12) {
    #
    error, date parameter out of range ... use default
    push
    (@ArgErrs, ['E', $LOGINFO, $ERRLOG, '9014', (0,0,0,0), "$mo/$day/$yr",
    '', 1,0,1]);

    $SHOWUSAGE = 1; $date_err = 1;
    }
    else {
    # here
    all is ok ...
    #use
    Time::Local 'timelocal';
    #my
    $time = timelocal($sec,$min,$hour,$mday,$mon-1,$year);
    my
    $time = 0;
    eval
    {$time = timelocal(0,0,0,$day,$mo-1,$yr);};
    if
    ($@) {

    #print "$@\n";

    push (@ArgErrs, ['E', $LOGINFO, $ERRLOG, '9015', (0,0,0,0),
    "\[$mo/$day/$yr\] $@", '', 1,0,1]);

    $SHOWUSAGE = 1; $date_err = 1;
    } else
    {

    push (@times, $time);

    if (length ($5) == 0) {

    push (@times, timelocal(0,0,0,1,0,2038)); # 2038, max int seconds
    with 32-bit

    #push (@times, 2**32 - 1);

    }
    }
    }
    }
    ($mo,$day,$yr,$cnt) =
    (0,0,0,0);
    if (length($5) > 0)
    {
    $cnt++ if
    (length($7));
    $cnt++ if
    (length($6));
    $cnt++ if
    (length($5));
    if ($cnt ==
    3) { $mo=$5; $day=$6; $yr=$7; }
    elsif ($cnt ==
    2) { $mo=$5; $day=1; $yr=$6; }
    elsif ($cnt ==
    1) { $mo=1; $day=1; $yr=$5; }
    if ($day < 1
    || $day > 31 || $mo < 1 || $mo > 12) {
    #
    error, date parameter out of range ... use default
    push
    (@ArgErrs, ['E', $LOGINFO, $ERRLOG, '9014', (0,0,0,0), "$mo/$day/$yr",
    '', 1,0,1]);

    $SHOWUSAGE = 1; $date_err = 1;
    }
    else {
    # here
    all is ok ...
    #use
    Time::Local 'timelocal';
    #my
    $time = timelocal($sec,$min,$hour,$mday,$mon-1,$year);
    my
    $time = 0;
    eval
    {$time = timelocal(0,0,0,$day,$mo-1,$yr);};
    if
    ($@) {

    #print "$@\n";

    push (@ArgErrs, ['E', $LOGINFO, $ERRLOG, '9015', (0,0,0,0),
    "\[$mo/$day/$yr\] $@", '', 1,0,1]);

    $SHOWUSAGE = 1; $date_err = 1;
    } else
    {

    push (@times, $time);

    if (length ($1) == 0) {

    push (@times, 86400); # 1,1,1970

    }
    }
    }
    }
    }
    $date =~ /.*/;
    if ($date_err) {
    $hCmdp{'Date'}->[0] =
    undef;
    $hVars{'Date'} = '';
    $hVars{'date_1'} = -1;
    $hVars{'date_2'} = -1;
    next;
    }
    ($hVars{'date_1'},
    $hVars{'date_2'}) = sort { $a <=> $b } @times if (@times == 2);
    }
    }
    else {
    $hCmdp{'Date'}->[0] = '*';
    $hVars{'Date'} = '*';
    }
    #print "date err = $date_err\ncmdp =
    $hCmdp{'Date'}->[0]\ndate1 = $hVars{'date_1'}\ndate2 =
    $hVars{'date_2'}\n";
    #<STDIN>; exit (0);
    }
    , Oct 28, 2005
    #6
  7. Guest

    On 26 Oct 2005 01:01:14 -0700, wrote:

    > wrote:
    >> Post any you have (or make some up).

    >
    >I don't have to make anything up. I just
    >
    >use Date::Manip;

    And what does that do?
    , Oct 28, 2005
    #7
  8. Anno Siegel Guest

    <> wrote in comp.lang.perl.misc:
    > On 26 Oct 2005 01:01:14 -0700, wrote:
    >
    > > wrote:
    > >> Post any you have (or make some up).

    > >
    > >I don't have to make anything up. I just
    > >
    > >use Date::Manip;

    > And what does that do?


    Bell's ringing. Back to the docs.

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Oct 28, 2005
    #8
  9. Anno Siegel Guest

    <> wrote in comp.lang.perl.misc:

    > About the __DATA__ thing, I thought it was a flag to ignore below as
    > comments, but thats where I put the output. Whats the right way
    > to do it?


    Bell's ringing. Off to the docs!

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Oct 28, 2005
    #9
  10. -berlin.de (Anno Siegel) wrote in news:djsvbj$ess$3
    @mamenchi.zrz.TU-Berlin.DE:

    > <> wrote in comp.lang.perl.misc:
    >
    >> About the __DATA__ thing, I thought it was a flag to ignore below as
    >> comments, but thats where I put the output. Whats the right way
    >> to do it?

    >
    > Bell's ringing. Off to the docs!


    Indeed.

    The OP can start by reading the posting guidelines:

    Also provide example input data for your program. If you
    need to show file input, use the __DATA__ token (perldata.pod)
    to provide the file contents inside of your Perl program.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 28, 2005
    #10
  11. Guest

    On Fri, 28 Oct 2005 10:56:47 GMT, "A. Sinan Unur"
    <> wrote:

    >-berlin.de (Anno Siegel) wrote in news:djsvbj$ess$3
    >@mamenchi.zrz.TU-Berlin.DE:
    >
    >> <> wrote in comp.lang.perl.misc:
    >>
    >>> About the __DATA__ thing, I thought it was a flag to ignore below as
    >>> comments, but thats where I put the output. Whats the right way
    >>> to do it?

    >>
    >> Bell's ringing. Off to the docs!

    >
    >Indeed.
    >
    >The OP can start by reading the posting guidelines:
    >
    > Also provide example input data for your program. If you
    > need to show file input, use the __DATA__ token (perldata.pod)
    > to provide the file contents inside of your Perl program.
    >
    >Sinan


    The trouble is your abbrv's aren't in the posting guidelines.
    I don't know what OP is. I don't think that you know the context
    of guidelines. You may want to suggest improvements to the OP
    code if its relavent to their topic, but not to the extent of
    exlusivity and divergence from the OP intent from which they
    started the thread. Otherwise, English composition teachers
    might have a voice in this group.

    If instead, perhaps you would like to contribute more than
    an English teacher to the OP intent your suggestion's would
    attract more attention that not.

    I know there's brilliant regulars who post follow-ups in
    this group. One would read the guidelines and conclude
    the narrowness precludes abstract and creative largest
    thinking. Unless you are content, and wish to restrict
    you skill to 1 line programs, you might want to open
    your mind and imagine the world of programing as being
    abstract, creative and most of all inclusive.

    You should temper your "anal retentive, close to psycotic"
    madness, with something that shows others, yes indeed you
    are human!

    I'm starting to think this is a perpetual Perl intro class
    with brilliant masters trolling for a quick "gotcha" fix
    to ease their need for revenge when they were butt-fucked
    by a family uncle in their youth. This is metaphorical of
    course, it could have been their father's, brother's or
    neighbor. Its a psycho-sexual dysfunction exibited by
    some, copied by others.

    Good day gentlemen.

    PS. bells ringing, it will again I'm sure
    , Oct 29, 2005
    #11
  12. Guest

    On Thu, 27 Oct 2005 08:15:57 -0400, "Matt Garrish"
    <> wrote:

    >
    >"Matt Garrish" <> wrote in message
    >news:Io38f.7243$...
    >>
    >> <> wrote in message
    >> news:...
    >>>I get some weird concat warnings on print if enabled so its commented.

    >>
    >> They aren't weird errors. You don't check if your match succeeds, so you
    >> wind up using numbered variables that aren't intialized.
    >>

    >
    >That's a little misleading, on second look (since you manufactured your
    >dates to work). You don't require content in all your captures, so you wind
    >up with the unintialized warnings. It's still bad practice not to check, and
    >feed data that doesn't match your pattern and you will get the messages for
    >the above reason.
    >
    >Matt
    >

    Well, I gave up a code block. To the extreme, it relaxes content
    in the filter to gather the max info in one shot. As you can see,
    the filter lets in multiple options as designed. A quick gather and
    processing is done after. Given all that this block does I think its
    an economical hybrid that can't be done in a single regexp.
    Unfortunately, I don't have the time luxury of 1-liners.
    I would think this might replace much more code necessary if the
    kind of content your thinking of had to be imposed.
    But you had know way of knowing.
    peace.....
    , Oct 30, 2005
    #12
  13. robic0 Guest

    On Fri, 28 Oct 2005 10:56:47 GMT, "A. Sinan Unur"
    <> wrote:

    >-berlin.de (Anno Siegel) wrote in news:djsvbj$ess$3
    >@mamenchi.zrz.TU-Berlin.DE:
    >
    >> <> wrote in comp.lang.perl.misc:
    >>
    >>> About the __DATA__ thing, I thought it was a flag to ignore below as
    >>> comments, but thats where I put the output. Whats the right way
    >>> to do it?

    >>
    >> Bell's ringing. Off to the docs!

    >
    >Indeed.
    >
    >The OP can start by reading the posting guidelines:
    >
    > Also provide example input data for your program. If you
    > need to show file input, use the __DATA__ token (perldata.pod)
    > to provide the file contents inside of your Perl program.
    >
    >Sinan


    Even though i'm the original poster, i think i can
    wiper ur ass in Perl day or nite. Day or nite jackoff.
    I own u Perl wise. All of u........
    robic0, Nov 13, 2005
    #13
  14. robic0 <> wrote:

    > i think i can
    > wiper ur ass in Perl day or nite. Day or nite jackoff.
    > I own u Perl wise. All of u........



    Why is it that you persist in asking questions of people that
    know less than you do?

    You can't possibly get an answer that's better than what you already
    know, so what would be the point in asking?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 13, 2005
    #14
  15. Tad McClellan <> wrote in
    news::

    > robic0 <> wrote:
    >
    >> i think i can wiper ur ass

    ....

    > Why is it that you persist in asking questions of people that
    > know less than you do?


    I am not sure, but I think he is saying he wants to wipe our behinds. I am
    sure Freud would have had something to say about that.

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Nov 13, 2005
    #15
  16. robic0 Guest

    -berlin.de (Anno Siegel) wrote in
    news:djsvbj$ess$3
    @mamenchi.zrz.TU-Berlin.DE:

    > <> wrote in comp.lang.perl.misc:
    >
    >> About the __DATA__ thing, I thought it was a flag to ignore below as
    >> comments, but thats where I put the output. Whats the right way
    >> to do it?

    >
    > Bell's ringing. Off to the docs!


    Indeed.

    The OP can start by reading the posting guidelines:

    Also provide example input data for your program. If you
    need to show file input, use the __DATA__ token (perldata.pod)
    to provide the file contents inside of your Perl program.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

    On Sun, 13 Nov 2005 08:56:18 -0600, Tad McClellan
    <> wrote:

    >robic0 <> wrote:
    >
    >> i think i can
    >> wiper ur ass in Perl day or nite. Day or nite jackoff.
    >> I own u Perl wise. All of u........

    >
    >
    >Why is it that you persist in asking questions of people that
    >know less than you do?
    >

    So the lesson is docs on __DATA__ is more important than you. Too
    important to trust your pea brain. I guess you got docs
    up your ass. Never did docs before, never will.
    But hey, if you have a date filter feel free to join the world dude.

    >You can't possibly get an answer that's better than what you already
    >know, so what would be the point in asking?
    robic0, Nov 16, 2005
    #16
  17. robic0 Guest

    On Sun, 13 Nov 2005 15:04:33 GMT, "A. Sinan Unur"
    <> wrote:

    >Tad McClellan <> wrote in
    >news::
    >
    >> robic0 <> wrote:
    >>
    >>i think i can wiper ur ass with Tads nose.....

    >...
    >
    >> Why is it that you persist in asking questions of people that
    >> know less than you do?

    >
    >I am not sure, but I think he is saying he wants to wipe our behinds. I am
    >sure Freud would have had something to say about that.
    >

    Hey go back to India where you got your first American job.
    >Sinan
    robic0, Nov 16, 2005
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dieter Vanderelst

    using the Filters DLL (image filters)

    Dieter Vanderelst, Feb 15, 2006, in forum: Python
    Replies:
    1
    Views:
    408
    Michele Petrazzo
    Feb 15, 2006
  2. yocoyote

    Bug in timelocal?

    yocoyote, Apr 6, 2005, in forum: Perl Misc
    Replies:
    14
    Views:
    151
    Joe Smith
    Apr 7, 2005
  3. J Moreno
    Replies:
    14
    Views:
    242
    J Moreno
    Mar 9, 2006
  4. Datamon
    Replies:
    1
    Views:
    91
  5. John
    Replies:
    2
    Views:
    104
Loading...

Share This Page