Ask a Question related to PERL Miscellaneous, Design and Development.
-
Doron Stein #1
opening a file whose letter case is unknown
Say we have a file named "ABC" , yet A B and C can be upper or lower
case each ( 8 combinations ).
how can one neatly open this file without preprocessing a directory
content ?
i would have wanted something like
open(FILE, "ABC / ignore_case " )
Thanks in advance
Doron.
Doron Stein Guest
-
#40068 [NEW]: Warning: Unknown: failed to open stream: No such file or directory in Unknown..
From: triphius at tripslair dot com Operating system: FreeBSD 6.1 PHP version: 5.2.0 PHP Bug Type: Scripting Engine problem... -
No Pcase? how do I capitolize the first letter of aword, with the rest of the word lower case?
I know I can go one way or another, Ucase(var) all upppercase, or Lcase(var) all lowercase, but how can I get a Propercase? I've seen this in VB,... -
#25195 [Fbk->Csd]: Failed opening phpinfo.php ... in Unknown on line 0
ID: 25195 User updated by: mhawkins at ukeu dot com Reported By: mhawkins at ukeu dot com -Status: Feedback... -
#12995 [Csd->Opn]: "Failed opening ... in Unknown on line 0
ID: 12995 User updated by: se at brainbits dot net Reported By: se at brainbits dot net -Status: Closed +Status: ... -
Changing case of the first letter of words in string
I want to make the case of the first letter of all the words in a selected string to upper case. The code s/\b(\w+)/\u$1\E/g; enables me to do... -
Sam Holden #2
Re: opening a file whose letter case is unknown
On Wed, 17 Sep 2003 12:49:19 +0300, Doron Stein <dostein@cisco.com> wrote:
my $file = glob('[Aa][Bb][Cc]');> Say we have a file named "ABC" , yet A B and C can be upper or lower
> case each ( 8 combinations ).
>
> how can one neatly open this file without preprocessing a directory
> content ?
>
> i would have wanted something like
>
>
> open(FILE, "ABC / ignore_case " )
die "No file matching [Aa][Bb][Cc]" unless defined $file;
open(FILE, $file) or die "Unable to open $file: $!";
Of course that will just read all the filenames in the directory and find
the matches, and is probably inefficient since it will keep searching
after finding a match...
--
Sam Holden
Sam Holden Guest
-
Kasp #3
Re: opening a file whose letter case is unknown
"Doron Stein" <dostein@cisco.com> wrote in message
news:1063792099.938089@sj-nntpcache-5...On an OS like Windows, all filenames (upper case or lower case) are treated> how can one neatly open this file without preprocessing a directory
> content ?
>
> i would have wanted something like
> open(FILE, "ABC / ignore_case " )
alike.
So,
open(FILE, 'ABC.txt');
is same as
open(FILE, 'abc.txt');
I don't know how you can achieve the same for Unix-like systems.
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.
Kasp Guest
-
Doron Stein #4
Re: opening a file whose letter case is unknown
Thanks sam fro the idea ,
and say the file name is a variable , how can i imitate the '[Aa][Bb][Cc]'
Doron.
Sam Holden wrote:> On Wed, 17 Sep 2003 12:49:19 +0300, Doron Stein <dostein@cisco.com> wrote:
>>>> Say we have a file named "ABC" , yet A B and C can be upper or lower
>>case each ( 8 combinations ).
>>
>>how can one neatly open this file without preprocessing a directory
>>content ?
>>
>>i would have wanted something like
>>
>>
>>open(FILE, "ABC / ignore_case " )
>
> my $file = glob('[Aa][Bb][Cc]');
> die "No file matching [Aa][Bb][Cc]" unless defined $file;
> open(FILE, $file) or die "Unable to open $file: $!";
>
> Of course that will just read all the filenames in the directory and find
> the matches, and is probably inefficient since it will keep searching
> after finding a match...
>Doron Stein Guest
-
Anno Siegel #5
Re: opening a file whose letter case is unknown
Doron Stein <dostein@cisco.com> wrote in comp.lang.perl.misc:
Please don't top-post, it's rude.> Thanks sam fro the idea ,
>
> and say the file name is a variable , how can i imitate the '[Aa][Bb][Cc]'
>
> Doron.
(my $pat = $name) =~ s/([[:alpha:]])/[\u$1\l$1]/g;
[TOFU snipped]> Sam Holden wrote:> > On Wed, 17 Sep 2003 12:49:19 +0300, Doron Stein <dostein@cisco.com> wrote:
Anno
Anno Siegel Guest
-
Dominik Seelow #6
Re: opening a file whose letter case is unknown
> Say we have a file named "ABC" , yet A B and C can be upper or lower
Hello Doron,> case each ( 8 combinations ).
>
> how can one neatly open this file without preprocessing a directory
> content ?
>
> i would have wanted something like
>
>
> open(FILE, "ABC / ignore_case " )
>
> Thanks in advance
>
> Doron.
>
as you will have to care for the directory's content anyway, I suggest
to use grep and readdir:
opendir (DIR,'.') || die ($!);
my $filename='voId.txt';
open (FILE, ((grep /$filename/i,readdir DIR)[0])) || die ($!);
This will open the first file found.
HTH,
Dominik
Dominik Seelow Guest
-
Abigail #7
Re: opening a file whose letter case is unknown
Doron Stein (dostein@cisco.com) wrote on MMMDCLXIX September MCMXCIII in
<URL:news:1063792099.938089@sj-nntpcache-5>:
@@ Say we have a file named "ABC" , yet A B and C can be upper or lower
@@ case each ( 8 combinations ).
@@
@@ how can one neatly open this file without preprocessing a directory
@@ content ?
What if the directory contains all of "Abc", "aBc" and "abC", which
one do you want to open?
Note that in general, what you want isn't possible. Most file-systems
don't store the file names in an order that depends on the file name.
(And there's not general API for filesystems that do). Even opening
a file means that potentially all of the directory content will be
processed.
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(1 01,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
Abigail Guest
-
Randal L. Schwartz #8
Don't use glob() in a scalar context (was Re: opening a file whose letter case is unknown)
>>>>> "Sam" == Sam Holden <sholden@flexal.cs.usyd.edu.au> writes:
Sam> my $file = glob('[Aa][Bb][Cc]');
Don't use glob in a scalar context, as it maintains state. Consider
the output (on a Unix system) of:
for (1..10) {
my $passwd = glob '/etc/passw[d]';
if ($passwd) {
print "found it at $passwd\n";
} else {
print "not found!\n";
}
}
Every other time, it will print "not found", because it didn't find
*another* one.
You want
my ($file) = glob('[Aa][Bb][Cc]');
to get the first one (if any) discarding all others.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal L. Schwartz Guest



Reply With Quote

