Very newbie... please help!

C

csimojoe

I have a customer that uploads images to the web server, and then a
perl script shows the images in a slideshow. The files are sometimes
uploaded as .jpg and other times in all caps as .JPG extensions.

The script works perfectly with the lowercase .jpg uploads, but won't
recognize the .JPG files. Customer wants the script to work with both.

Here are the segments of the script that deal with the extension:

#$ext
# Extension of the images(do not include the ".") Examples:
"gif","jpg",
etc.

$ext = 'jpg';

@names=grep(/\.$ext$/,readdir(DIR));

I've tried to add -i to the grep... no good.

Any help would be GREATLY appreciated. I'm obviously not good with
perl or scripts. Sorry.

-Joe
 
P

Paul Lalli

csimojoe@ nospam.gmail.com said:
Subject: Very newbie... please help!

Please put the subject of your post in the Subject of your post. Your
post is not about you being a "very newbie". Your post is about
matching case-insensitively.
I have a customer that uploads images to the web server, and then a
perl script shows the images in a slideshow. The files are sometimes
uploaded as .jpg and other times in all caps as .JPG extensions.

The script works perfectly with the lowercase .jpg uploads, but won't
recognize the .JPG files. Customer wants the script to work with both.

Here are the segments of the script that deal with the extension:

#$ext
# Extension of the images(do not include the ".") Examples:
"gif","jpg",
etc.

$ext = 'jpg';

@names=grep(/\.$ext$/,readdir(DIR));

I've tried to add -i to the grep... no good.

That's because -i is an argument to the Unix command `grep`, not to the
Perl function `grep`. They are not the same thing.

Add the /i modifier to the pattern match:

my @names = grep /\.$ext$/i, readdir DIR;

Paul Lalli
 

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
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top