glob question

J

justme

hi

while using the glob function to check for wildcards eg,

while ( glob *.txt )
{
#do something with txt files...
}
how can i specify globbing those not *.txt?

is it something like this
while ( ! glob *.txt )
{

}

when i use this method , there is no output, even though there are
other files in the directory ...
thanks
 
J

Josef Moellers

justme said:
hi

while using the glob function to check for wildcards eg,

while ( glob *.txt )
{
#do something with txt files...
}
how can i specify globbing those not *.txt?

is it something like this
while ( ! glob *.txt )
{

}

while ( glob "*" )
{
next if /\.txt$/;
# Do something with non-txt
}

But tpmtowtdi,

Josef
 
T

Ted Zlatanov

while ( glob "*" )
{
next if /\.txt$/;
# Do something with non-txt
}

But tpmtowtdi,

The OP didn't say he wanted * without *.txt, so your example is
incomplete. You need opendir() and readdir() to really get all the
files in the directory, including the hidden ones.

Ted
 
A

axel

The OP didn't say he wanted * without *.txt, so your example is
incomplete. You need opendir() and readdir() to really get all the
files in the directory, including the hidden ones.

Why?

#/usr/bin/perl -w

$\ = "\n";

# Print what a glob gives us
print join " ", glob ".* *";

# Print what using readdir gives us
opendir DIR, ".";
my @inlist = readdir DIR;
closedir DIR;
print join " ", @inlist;


Results:

.. .. .r1.pl.swp .z.pl.swp 11-02-2050 aless_rob_udo.jpg apache_conf
bdb-conf DIRNAME DIRNAMEF m_i openldap-conf php_conf q1.c qa1 qa2.tar
qq.pl r1 r1.pl x x1.pl z.pl
.. .. .r1.pl.swp .z.pl.swp 11-02-2050 aless_rob_udo.jpg apache_conf
bdb-conf DIRNAME DIRNAMEF m_i openldap-conf php_conf q1.c qa1 qa2.tar
qq.pl r1 r1.pl x x1.pl z.pl

Axel
 

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
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top