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

R

robic0

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)()
 
M

Matt Garrish

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
 
M

Matt Garrish

Matt Garrish said:
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
 
R

robic0

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
 
R

robic0

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);
}
 
A

Anno Siegel

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
 
A

A. Sinan Unur

(e-mail address removed)-berlin.de (Anno Siegel) wrote in @mamenchi.zrz.TU-Berlin.DE:
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
 
R

robic0

(e-mail address removed)-berlin.de (Anno Siegel) wrote in @mamenchi.zrz.TU-Berlin.DE:


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
 
R

robic0

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.....
 
R

robic0

(e-mail address removed)-berlin.de (Anno Siegel) wrote in @mamenchi.zrz.TU-Berlin.DE:


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........
 
T

Tad McClellan

robic0 said:
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?
 
A

A. Sinan Unur

....

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
 
R

robic0

(e-mail address removed)-berlin.de (Anno Siegel) wrote in
@mamenchi.zrz.TU-Berlin.DE:
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


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.
 
R

robic0

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top