regex

L

lucas

I have this perl oneliner that I'm using to recognize certain file
extentions in a url. This works, but I was wondering if any of you know of
a better way to write this.

echo "http://fu.bar/test.jpg" | perl -ne 'print if((/\.jpg\n$/i)|
(/\.bmp\n$/i)||(/\.png\n$/i));'

Regards,
 
J

Jürgen Exner

lucas said:
I have this perl oneliner that I'm using to recognize certain file
extentions in a url. This works, but I was wondering if any of you
know of a better way to write this.

Just use File::Basename, (undef, undef,$suffix) =
fileparse($fullname,@suffixlist), put the desired extensions as keys in a
hash, then check for exists() of $suffix in the hash.

jue
 
J

John Bokma

lucas said:
I have this perl oneliner that I'm using to recognize certain file
extentions in a url. This works, but I was wondering if any of you
know of a better way to write this.

echo "http://fu.bar/test.jpg" | perl -ne 'print if((/\.jpg\n$/i)|
(/\.bmp\n$/i)||(/\.png\n$/i));'

print if /\.(jpg|bmp|png)$/i

you might want to replace jpg with jpe?g
 
A

Arved Sandstrom

Abigail said:
lucas ([email protected]) wrote on MMMMDCCCLXXVI September MCMXCIII
in <URL:^^ I have this perl oneliner that I'm using to recognize certain file
^^ extentions in a url. This works, but I was wondering if any of you
know of
^^ a better way to write this.
^^
^^ echo "http://fu.bar/test.jpg" | perl -ne 'print if((/\.jpg\n$/i)|
^^ (/\.bmp\n$/i)||(/\.png\n$/i));'

Yeah.

echo "http://fu.bar/test.jpg"

is a lot simpler.

I'm gathering - this is just me, mind you - that his actual input is not
manually typing in echo "http://fu.bar/test.jpg".
Or did you want to ask how to grep? In that case, I'd use 'grep', not
perl.

That works on Windows, does it?

Get over being so elitist.

AHS
 
A

Arved Sandstrom

DJ Stunks said:
wait a minute, you believe that using grep is pretentious? hahaha

someone better tell Dennis Ritchie.

Assuming that the reader is *not* using the most common OS on the planet is
pretentious. Abigail's entire post was useless - she gave no information.
She informed everyone that she is sarcastic (in the case of the first
answer), and that she prefers UNIX/Linux (in the case of the second). At
least I assume she prefers UNIX/Linux. As it happens so do I, but I am a
professional software developer and don't assume everyone uses a flavour of
*nix.

There's a good example of Abigail's type of post in "Internet for Dummies".
It describes someone posting on a NG asking for help, and someone else posts
a reply saying that they don't have an answer...

_Using_ grep is not pretentious. Assuming that the poster is working on UNIX
or Linux is.

I respect what I've seen of Abigail's contributions, but somehow I think I'd
not like having her on any team that I was part of.

AHS
 
U

Uri Guttman

AS> I respect what I've seen of Abigail's contributions, but somehow I
AS> think I'd not like having her on any team that I was part of.

your loss. what abigail posts here and what kind of team member he is
are very different things. and abigail is a he.

uri
 
P

Paul Lalli

Arved said:
_Using_ grep is not pretentious. Assuming that the poster is working on UNIX
or Linux is.

And assuming that any particular Windows user is too incompetant to
download cygwin is insulting.

Paul Lalli
 
J

John W. Kennedy

Abigail said:
Both 'echo' and pipes are very
Unixy things,

Maybe, but they were available all the way back in MS-DOS 2.0 (although
the pipes were emulated with disk files and serial execution of processes).
 
A

Arved Sandstrom

Abigail said:
Arved Sandstrom ([email protected]) wrote on MMMMDCCCLXXVII
September MCMXCIII in <URL:|| || > lucas ([email protected]) wrote on MMMMDCCCLXXVI September
MCMXCIII
|| > in <URL:|| > ^^ I have this perl oneliner that I'm using to recognize certain
file
|| > ^^ extentions in a url. This works, but I was wondering if any of
you
|| > know of
|| > ^^ a better way to write this.
|| > ^^
|| > ^^ echo "http://fu.bar/test.jpg" | perl -ne 'print if((/\.jpg\n$/i)|
|| > ^^ (/\.bmp\n$/i)||(/\.png\n$/i));'
|| >
|| > Yeah.
|| >
|| > echo "http://fu.bar/test.jpg"
|| >
|| > is a lot simpler.
||
|| I'm gathering - this is just me, mind you - that his actual input is
not
|| manually typing in echo "http://fu.bar/test.jpg".
||
|| > Or did you want to ask how to grep? In that case, I'd use 'grep', not
|| > perl.
||
|| That works on Windows, does it?


Well, last time I looked, Windows didn't come with perl either.
'grep' works on Windows, yes.

But that's not the point. The user was using 'echo', pipes, and single
quotes to delimit the Perl program. Both 'echo' and pipes are very
Unixy things, and Windows people are always complaining that single
quotes around a Perl one liner doesn't work on their shells.

|| Get over being so elitist.

I don't think assuming the user is using Unix and not Windows is elitist,
given how the user wrote his code.

Good point, one which I missed. I had a bad day that day - I recall it
clearly - and I shouldn't have even checked newsgroups. My apologies.

Arved Sandstrom
 
A

Arved Sandstrom

Paul Lalli said:
And assuming that any particular Windows user is too incompetant to
download cygwin is insulting.

My apologies were made to her...him. The name throws me; I've been using
Perl since '93 or so, and I never knew, until Uri informed me just now on
this NG. I usually assume that people use real names, unless they are
obviously made up. Oh well, live and learn.

Like I said in my apology, I'd had a bad day when I wrote that (nothing to
do with work), and I was inclined to be looking for bones to pick. Mea
culpa. I can also totally not notice things in a command line that mark out
an OS, because in the course of a given working day I'm using Linux and
Windows at the same time, and I tend to mentally filter that stuff out. Now,
of course, it stands out clearly.

In any case, the apology was made, and I meant it.

I'm still not a big fan of how "Abigail" answers many questions, and I
certainly stand by my assertion that I'd not want him/her as a member of any
programming team that I'm on, except at a high consulting rate for a 2-3
hour session to shake up some programmers. That opinion is based on years of
seeing what "Abigail" posts. But it has nothing to do with my sincere
apology on this subthread.

Arved Sandstrom
 
D

Dr.Ruud

Arved Sandstrom schreef:
I'm still not a big fan of how "Abigail" answers many questions, and I
certainly stand by my assertion that I'd not want him/her as a member
of any programming team that I'm on, except at a high consulting rate
for a 2-3 hour session to shake up some programmers. That opinion is
based on years of seeing what "Abigail" posts.

LOL, I only know Abigail as a friendly person, who helped me plenty in
this group when I started using Perl.
I'll leave it to others to comment on inside-out objects and
Regexp::Common and his educational presentations and so on.
:)
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top