Need help with grep function

P

perlUSER

Hello;
I am trying to select files based on the pattern and can't get the
script to work on one of the pattern. Code snippet:

my @list = glob('*');
@list = grep {m[^EOM_[A-Z][a-z]{2}_\d{4}]} @list;
foreach my $list (@list){
print $list."\n";
}
The above code return all files matching the pattern. Ex: EOM_Jan_2006,
EOM_Feb_2006.

my @list = glob('*');
@list = grep {! m[^\d{2}_d{2}_d{2}]} @list;
foreach my $list (@list){
print $list."\n";
}
I am expecting to see files like these 06_04_01, 06_04_02 thru
06_04_28.

Please help me with this issue.

Thanks in advance.
 
P

Paul Lalli

perlUSER said:
my @list = glob('*');
@list = grep {! m[^\d{2}_d{2}_d{2}]} @list;
foreach my $list (@list){
print $list."\n";
}
I am expecting to see files like these 06_04_01, 06_04_02 thru
06_04_28.

Then why are you writing code to specifically return all files that do
*not* match that pattern?

What do you think that ! is doing in the grep block?

Paul Lalli
 
I

it_says_BALLS_on_your forehead

Paul said:
perlUSER said:
my @list = glob('*');
@list = grep {! m[^\d{2}_d{2}_d{2}]} @list;
foreach my $list (@list){
print $list."\n";
}
I am expecting to see files like these 06_04_01, 06_04_02 thru
06_04_28.

Then why are you writing code to specifically return all files that do
*not* match that pattern?

What do you think that ! is doing in the grep block?

marking it as "High Importance".
 
P

perlUSER

Paul said:
perlUSER said:
my @list = glob('*');
@list = grep {! m[^\d{2}_d{2}_d{2}]} @list;
foreach my $list (@list){
print $list."\n";
}
I am expecting to see files like these 06_04_01, 06_04_02 thru
06_04_28.

Then why are you writing code to specifically return all files that do
*not* match that pattern?

What do you think that ! is doing in the grep block?

Paul Lalli

Paul,
Thanks for your response. Actually I was testing various scenarious and
forgot to remove the '!' from my code before I posted it here.
To remove any confusion, I copied the hole script here:

#!/usr/bin/perl -w

my @list = glob('*');
@list = grep {m[^\d{2}_d{2}_d{2}]} @list;

foreach my $list (@list){
print $list."\n";
}

This script didn't return any even though I have files matching that
pattern.

And here is my directory listing where my test.pl is:
$ ls
02_02_02

Any suggestions what I am doing wrong?

Thanks in advance.
 
I

Ingo Menger

perlUSER said:
Paul said:
perlUSER said:
my @list = glob('*');
@list = grep {! m[^\d{2}_d{2}_d{2}]} @list;
foreach my $list (@list){
print $list."\n";
}
I am expecting to see files like these 06_04_01, 06_04_02 thru
06_04_28.

Then why are you writing code to specifically return all files that do
*not* match that pattern?

What do you think that ! is doing in the grep block?

Paul Lalli

Paul,
Thanks for your response. Actually I was testing various scenarious and
forgot to remove the '!' from my code before I posted it here.
To remove any confusion, I copied the hole script here:

#!/usr/bin/perl -w

my @list = glob('*');
@list = grep {m[^\d{2}_d{2}_d{2}]} @list;

foreach my $list (@list){
print $list."\n";
}

This script didn't return any even though I have files matching that
pattern.

And here is my directory listing where my test.pl is:
$ ls
02_02_02

Any suggestions what I am doing wrong?

Yes. Please, do the following:
- run command the following shell command: touch 42_dd_dd
- repeat your script.
 
J

jck11

perlUSER said:
Paul said:
perlUSER said:
my @list = glob('*');
@list = grep {! m[^\d{2}_d{2}_d{2}]} @list;
foreach my $list (@list){
print $list."\n";
}
I am expecting to see files like these 06_04_01, 06_04_02 thru
06_04_28.

Then why are you writing code to specifically return all files that do
*not* match that pattern?

What do you think that ! is doing in the grep block?

Paul Lalli

Paul,
Thanks for your response. Actually I was testing various scenarious and
forgot to remove the '!' from my code before I posted it here.
To remove any confusion, I copied the hole script here:

#!/usr/bin/perl -w

my @list = glob('*');
@list = grep {m[^\d{2}_d{2}_d{2}]} @list;

@list = grep {m[^\d{2}_\d{2}_\d{2}]} @list;
 
P

perlUSER

Yes. Please, do the following:
- run command the following shell command: touch 42_dd_dd
- repeat your script.

You are funny. Your solution will work with out a question. Thanks for
the comment.
 
T

Tintin

perlUSER said:
You are funny. Your solution will work with out a question. Thanks for
the comment.

Did you try what Ingo suggested? It was meant as a gentle nudge to help you
detect your problem.
 
P

perlUSER

Tintin said:
Did you try what Ingo suggested? It was meant as a gentle nudge to help you
detect your problem.

Tintin,
I din't try what Ingo suggested, as soon as I saw his post, I figured
out what the problem is, thats why I said he is funny. Instead of
giving the solution he told me what to do in order to make my script.

Thanks.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top