D
disco
I am using the readdir comand to read from a directory, but I have
presented the
contents of my directory below as <DATA> for this presentation so you
can run
my example. Surely I missing something simple. Can someone help?
I want to create a listing meeting the following criteria:
1) The line must start with a letter or number (e.g. no ".", etc.)
2) Only include letters and numbers up until a "." or "_" and disgard
the rest
3) My list can contain duplicates
expected result
===================
goofup
listing
bobby
junk
junk
junk34
bdfds
juice
master1
master2
memory
login
aray
test
----------------- script --------------------
while ( defined ($filename = <DATA>) )
{
if ($filename !~ /^\.|[#@]/) #Add to array if line does not begin
with "." or contain "#" or "@"
{
$filename =~ /(.*?)(\.|\_)(.*?)$/;
push @dirlist, $1;
}
}
foreach (@dirlist)
{
print $_ . "\n";
}
__DATA__
..
...
goofup.exe
listing.txt
bobby_switch_db60d
junk_none.log
junk_db4c5A
junk34_stwx_bine33A
bdfds_db4a4A
juice
master1
master2
memory_profile_db
login_profiles
aray_db76eA
test_master1
..profile
..cshrc
presented the
contents of my directory below as <DATA> for this presentation so you
can run
my example. Surely I missing something simple. Can someone help?
I want to create a listing meeting the following criteria:
1) The line must start with a letter or number (e.g. no ".", etc.)
2) Only include letters and numbers up until a "." or "_" and disgard
the rest
3) My list can contain duplicates
expected result
===================
goofup
listing
bobby
junk
junk
junk34
bdfds
juice
master1
master2
memory
login
aray
test
----------------- script --------------------
while ( defined ($filename = <DATA>) )
{
if ($filename !~ /^\.|[#@]/) #Add to array if line does not begin
with "." or contain "#" or "@"
{
$filename =~ /(.*?)(\.|\_)(.*?)$/;
push @dirlist, $1;
}
}
foreach (@dirlist)
{
print $_ . "\n";
}
__DATA__
..
...
goofup.exe
listing.txt
bobby_switch_db60d
junk_none.log
junk_db4c5A
junk34_stwx_bine33A
bdfds_db4a4A
juice
master1
master2
memory_profile_db
login_profiles
aray_db76eA
test_master1
..profile
..cshrc