Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > problems regexp

Reply
Thread Tools

problems regexp

 
 
john.swilting
Guest
Posts: n/a
 
      01-25-2007
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
 
Reply With Quote
 
 
 
 
john.swilting
Guest
Posts: n/a
 
      01-25-2007
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
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      01-25-2007
On Jan 25, 11:45 am, "john.swilting" <john.swilt...@wanadoo.fr> 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

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      01-26-2007
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."
 
Reply With Quote
 
john.swilting
Guest
Posts: n/a
 
      01-27-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new RegExp().test() or just RegExp().test() Matěj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57