regex

Discussion in 'Perl Misc' started by lucas, Jan 6, 2007.

  1. lucas

    lucas Guest

    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;
    -------------------------
     
    lucas, Jan 6, 2007
    #1
    1. Advertising

  2. 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
     
    Jürgen Exner, Jan 6, 2007
    #2
    1. Advertising

  3. lucas

    John Bokma Guest

    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.
    >
    > 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/
     
    John Bokma, Jan 6, 2007
    #3
  4. lucas

    lucas Guest

    Great! Thanks a lot guys!
    --
    lucas
    -------------------------
    Perl Coder since 2001
    shift || die;
    -------------------------
     
    lucas, Jan 6, 2007
    #4
  5. lucas <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 7, 2007
    #5
  6. "Abigail" <> wrote in message
    news:...
    > lucas () wrote on MMMMDCCCLXXVI September MCMXCIII
    > in <URL:news:28e3e$45a01650$cef8bf30$-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
     
    Arved Sandstrom, Jan 7, 2007
    #6
  7. lucas

    DJ Stunks Guest

    Arved Sandstrom wrote:
    > "Abigail" <> 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
     
    DJ Stunks, Jan 7, 2007
    #7
  8. "DJ Stunks" <> wrote in message
    news:...
    >
    > Arved Sandstrom wrote:
    >> "Abigail" <> 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
     
    Arved Sandstrom, Jan 8, 2007
    #8
  9. lucas

    Uri Guttman Guest

    >>>>> "AS" == Arved Sandstrom <> 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 ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Jan 8, 2007
    #9
  10. lucas

    Paul Lalli Guest

    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
     
    Paul Lalli, Jan 8, 2007
    #10
  11. Abigail wrote:
    > 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).

    --
    John W. Kennedy
    "The blind rulers of Logres
    Nourished the land on a fallacy of rational virtue."
    -- Charles Williams. "Taliessin through Logres: Prelude"
     
    John W. Kennedy, Jan 8, 2007
    #11
  12. "Abigail" <> wrote in message
    news:...
    > Arved Sandstrom () wrote on MMMMDCCCLXXVII
    > September MCMXCIII in <URL:news:vveoh.116055$rv4.12127@edtnps90>:
    > || "Abigail" <> wrote in message
    > || news:...
    > || > lucas () wrote on MMMMDCCCLXXVI September
    > MCMXCIII
    > || > in <URL:news:28e3e$45a01650$cef8bf30$-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?
    >
    >
    > 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
     
    Arved Sandstrom, Jan 11, 2007
    #12
  13. "Paul Lalli" <> wrote in message
    news:...
    > 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.


    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
     
    Arved Sandstrom, Jan 11, 2007
    #13
  14. lucas

    Dr.Ruud Guest

    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.
    :)

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Jan 11, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    712
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,634
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    600
  4. Xah Lee
    Replies:
    1
    Views:
    944
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    770
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page