Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   regex (http://www.velocityreviews.com/forums/t901324-regex.html)

lucas 01-06-2007 09:36 PM

regex
 
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,
--
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------

Jürgen Exner 01-06-2007 09:46 PM

Re: regex
 
lucas wrote:
> 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



John Bokma 01-06-2007 10:05 PM

Re: regex
 
lucas <lstouder@teksavvy.com> wrote:

> 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


--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/

lucas 01-06-2007 10:36 PM

Re: regex
 
Great! Thanks a lot guys!
--
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------

Tad McClellan 01-07-2007 04:48 AM

Re: regex
 
lucas <lstouder@teksavvy.com> wrote:

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



None of those dollar signs do anything, and so are not needed.


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Arved Sandstrom 01-07-2007 10:29 PM

Re: regex
 
"Abigail" <abigail@abigail.be> wrote in message
news:slrneq1jr9.fg.abigail@alexandra.abigail.be...
> lucas (lstouder@teksavvy.com) wrote on MMMMDCCCLXXVI September MCMXCIII
> in <URL:news:28e3e$45a01650$cef8bf30$16302@TEKSAVVY.C OM-Free>:
> ^^ 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



DJ Stunks 01-07-2007 11:09 PM

Re: regex
 

Arved Sandstrom wrote:
> "Abigail" <abigail@abigail.be> wrote in message
> > I'd use 'grep', not perl.

>
> Get over being so elitist.


wait a minute, you believe that using grep is pretentious? hahaha

someone better tell Dennis Ritchie.

-jp


Arved Sandstrom 01-08-2007 12:34 AM

Re: regex
 
"DJ Stunks" <DJStunks@gmail.com> wrote in message
news:1168211351.870692.115260@s34g2000cwa.googlegr oups.com...
>
> Arved Sandstrom wrote:
>> "Abigail" <abigail@abigail.be> wrote in message
>> > I'd use 'grep', not perl.

>>
>> Get over being so elitist.

>
> 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



Uri Guttman 01-08-2007 02:25 AM

Re: regex
 
>>>>> "AS" == Arved Sandstrom <asandstrom@accesswave.ca> writes:

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

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

Paul Lalli 01-08-2007 03:34 AM

Re: regex
 
Arved Sandstrom wrote:

> _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



All times are GMT. The time now is 06:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.