problems regexp

Discussion in 'Perl Misc' started by john.swilting, Jan 25, 2007.

  1. I try to test a scalar which ends by a .gif
    With any OS

    try
    if($data{attachement} = ~m/$`\.gif/){
    MAIL($data{attachement});
    }else{
    AFFICHAGE_ERREUR_ATTACHEMENT($data{attachement});
    }

    It does not walk(work)
    please help me

    serge
     
    john.swilting, Jan 25, 2007
    #1
    1. Advertising

  2. john.swilting wrote:

    > I try to test a scalar which ends by a .gif
    > With any OS
    >
    > try
    > if($data{attachement} = ~m/$`\.gif/){
    > MAIL($data{attachement});
    > }else{
    > AFFICHAGE_ERREUR_ATTACHEMENT($data{attachement});
    > }
    >
    > It does not walk(work)
    > please help me
    >
    > serge

    iseek a scalar which ens in .gif
     
    john.swilting, Jan 25, 2007
    #2
    1. Advertising

  3. john.swilting

    Paul Lalli Guest

    On Jan 25, 11:45 am, "john.swilting" <> wrote:
    > I try to test a scalar which ends by a .gif


    You have to define what you mean by "test" a scalar.

    > With any OS
    >
    > try
    > if($data{attachement} = ~m/$`\.gif/){


    If you'd enabled strict and warnings, Perl would tell you you'd done a
    few things wrong here.

    First, the operator is =~. Those two characters, right next to each
    other. You can not put a space in betwene them. Second, the $`
    variable is used *after* a successful pattern match, not within it.
    Third, you are only testing if the scalar *contains* .gif, not if it
    ends in .gif - you have to anchor the pattern.

    if ($data{attachment} =~ m/\.gif$/) {

    > It does not walk(work)


    "work" is the correct English word here. "walk" makes no sense.

    Paul Lalli
     
    Paul Lalli, Jan 25, 2007
    #3
  4. john.swilting

    Dr.Ruud Guest

    john.swilting schreef:

    > if($data{attachement} = ~m/$`\.gif/){



    Or try substr:

    if ( substr($data{attachement}, -4) eq q/.gif/ ) {

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Jan 26, 2007
    #4
  5. Dr.Ruud wrote:

    > john.swilting schreef:
    >
    >> if($data{attachement} = ~m/$`\.gif/){

    >
    >
    > Or try substr:
    >
    > if ( substr($data{attachement}, -4) eq q/.gif/ ) {
    >


    succes
    very nice
    its ok
    i am beginners in perl
    I progress
     
    john.swilting, Jan 27, 2007
    #5
    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. Greg Hurrell
    Replies:
    4
    Views:
    177
    James Edward Gray II
    Feb 14, 2007
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    541
    Mikel Lindsaar
    Mar 31, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    402
    7stud --
    Aug 21, 2009
  4. Uldis  Bojars
    Replies:
    2
    Views:
    213
    Janwillem Borleffs
    Dec 17, 2006
  5. Matìj Cepl

    new RegExp().test() or just RegExp().test()

    Matìj Cepl, Nov 24, 2009, in forum: Javascript
    Replies:
    3
    Views:
    201
    Matěj Cepl
    Nov 24, 2009
Loading...

Share This Page