regex question matching dates
regex question matching dates
am 29.05.2008 06:02:34 von Richard Lee
given then ARGV[0] is 2008052803, why woulnd't below regex match them??
} elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {
@array = qx#ls -tr $directory/$ARGV[0]*#;
#2008052803
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: regex question matching dates
am 29.05.2008 06:39:58 von krahnj
Richard Lee wrote:
> given then ARGV[0] is 2008052803, why woulnd't below regex match them??
2008052803 is a ten digit number.
> } elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {
Your pattern matches eight digits with a \b word boundary at each end so
it will never match a ten digit number. Also the character class [1-31]
could be more simply written as [1-3] (repeated characters are ignored.)
> @array = qx#ls -tr $directory/$ARGV[0]*#;
Why not do that directly in perl:
@array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M ],
glob "$directory/$ARGV[0]*";
> #2008052803
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: regex question matching dates
am 29.05.2008 06:47:47 von krahnj
John W. Krahn wrote:
> Richard Lee wrote:
>>
>> @array = qx#ls -tr $directory/$ARGV[0]*#;
>
> Why not do that directly in perl:
>
> @array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M ],
> glob "$directory/$ARGV[0]*";
Sorry, that should be:
@array = map $_->[0], sort { $b->[1] <=> $a->[1] } map [ $_, -M ],
glob "$directory/$ARGV[0]*";
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: regex question matching dates
am 29.05.2008 06:50:02 von Richard Lee
John W. Krahn wrote:
> Richard Lee wrote:
>> given then ARGV[0] is 2008052803, why woulnd't below regex match them??
>
> 2008052803 is a ten digit number.
>
>
>> } elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {
>
> Your pattern matches eight digits with a \b word boundary at each end
> so it will never match a ten digit number. Also the character class
> [1-31] could be more simply written as [1-3] (repeated characters are
> ignored.)
>
>
>> @array = qx#ls -tr $directory/$ARGV[0]*#;
>
> Why not do that directly in perl:
>
> @array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M
> ], glob "$directory/$ARGV[0]*";
>
>
>> #2008052803
>
>
> John
hey thanks!
this works fine now
} elsif ( $ARGV[0] =~
m/\b2008(0[1-9]|1[12])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9] |2[0-3])\b/ ) {
@array = qx#ls -tr $directory/$ARGV[0]*#;
#2008052803
} else {
I will try that direct perl solution as well!!
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: regex question matching dates
am 29.05.2008 07:27:17 von krahnj
Richard Lee wrote:
> John W. Krahn wrote:
>> Richard Lee wrote:
>>> given then ARGV[0] is 2008052803, why woulnd't below regex match them??
>>
>> 2008052803 is a ten digit number.
>>
>>
>>> } elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {
>>
>> Your pattern matches eight digits with a \b word boundary at each end
>> so it will never match a ten digit number. Also the character class
>> [1-31] could be more simply written as [1-3] (repeated characters are
>> ignored.)
>>
>>
>>> @array = qx#ls -tr $directory/$ARGV[0]*#;
>>
>> Why not do that directly in perl:
>>
>> @array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M
>> ], glob "$directory/$ARGV[0]*";
>
> hey thanks!
>
> this works fine now
>
> } elsif ( $ARGV[0] =~
> m/\b2008(0[1-9]|1[12])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9] |2[0-3])\b/ ) {
^^^^^
So you don't want to test for October?
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: regex question matching dates
am 29.05.2008 17:13:08 von Richard Lee
John W. Krahn wrote:
>>
>>
>> } elsif ( $ARGV[0] =~
>> m/\b2008(0[1-9]|1[12])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9] |2[0-3])\b/
>> ) {
> ^^^^^
> So you don't want to test for October?
>
>
>
> John
fixed now. thanks!!
} elsif ( $ARGV[0] =~
m/\b2008(0[1-9]|1[012])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9 ]|2[0-3])\b/ ) {
@array = qx#ls -tr $directory/$ARGV[0]*#;
$hour = substr($ARGV[0], 8 , 2);
$date_1 = substr($ARGV[0], 4 , 4);
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/