Gossamer Forum
Home : Products : DBMan : Customization :

Perl syntax problem

Quote Reply
Perl syntax problem
Hi,

I'm not so familiar with perl, please tell me what's wrong here:

Code:
if($rec{'hometeam'} eq 'Israel') {
$rec{'hometeam'} =~ s/<.?B>//g;
}
else{
$rec{'awayteam'} =~ s/<.?B>//g;
}


I'm trying to disable bolding for a specific record. this code is in html_record just below my (%rec) = @_;. I also tried it with == and even using a global like $isr=Israel.

Can anyone tell me what's wrong here?

Last edited by:

alon_g: Jul 17, 2002, 5:28 AM
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
Are your bold tags <b> or <B> ?
Quote Reply
Re: [Paul] Perl syntax problem In reply to
I think tey're <B>, but anyway, when I wrote the same lines without the IF it disabled the b's succesfuly.
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
Is it hitting the if or else part?

The regex should work although this would be more appropriate:

Code:
=~ s|</?B>||ig;
Quote Reply
Re: [Paul] Perl syntax problem In reply to
I think it's hitting just the else all the time, allthough it in half of the games Israel IS the hometeam. So I guess there's something wrong with $rec{'hometeam'} eq 'Israel'.
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
Make sure $rec{hometeam} is defined (you can just print it or something)
Quote Reply
Re: [Paul] Perl syntax problem In reply to
It is defined, I copied it 1:1 from the long view...
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
Try changing the end of the regex from ig to sig ....if that doesn't work add in an "m" too.
Quote Reply
Re: [Paul] Perl syntax problem In reply to
I can't explain why, but this DOES works for me.

REPLACE:

if($rec{'hometeam'} eq 'Israel') {

WITH:

if ($in{'hometeam'} eq 'Israel') {

rec is used for printing, but in is used for the actual value...or something like that

Hope it works! - let me know if that did anything

Last edited by:

mabel: Jul 17, 2002, 3:18 PM
Quote Reply
Re: [mabel] Perl syntax problem In reply to
>>
rec is used for printing, but in is used for the actual value
<<

%rec is used for pulling (rec)ords from the database....%in is used for form (in)put.

Last edited by:

Paul: Jul 17, 2002, 3:13 PM
Quote Reply
Re: [Paul] Perl syntax problem In reply to
ok, thanks, but does that support or go against what I said before; which one would you want to use in this case?

because for me, i know rec doesn't work in this situation, but in does (I guess i could just be going crazy)
Quote Reply
Re: [mabel] Perl syntax problem In reply to
Quoted from post 1:

>>
this code is in html_record just below my (%rec) = @_;.
<<

So it would be %rec in this case.
Quote Reply
Re: [Paul] Perl syntax problem In reply to
Hey guys,

The sig(m) in the end didn't work and the $in didn't help either. The problem is not at the <B> removal syntax, because it does perform the ELSE term well and disable <B> in all awayteam fields.

Have any idea what's wrong with the If statement?

I should also point out that Israel is actually written in hebrew (I changed it to english for the display in the forum). I tried to convert the hebrew to this thing (like in the browser's address bar) - %E9%F9%F8%E0%EC But it didn't help either.

The code (with Israel in hebrew) looks like this right now:
if($rec{'hometeam'} eq 'ישראל') {
$rec{'hometeam'} =~ s|</?B>||ig;
}
else{
$rec{'awayteam'} =~ s|</?B>||ig;
}

Last edited by:

alon_g: Jul 17, 2002, 4:59 PM
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
Try:
Code:
if ($rec{hometeam} eq "\xE9\xFA\xF8\xE0\xEC") {
Quote Reply
Re: [Paul] Perl syntax problem In reply to
Nope.. Unimpressed
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
Sorry typo...change \xFA to \xF9
Quote Reply
Re: [Paul] Perl syntax problem In reply to
No, still nothing.. In other part of html.pl I have a similar IF that uses hebrew and it works perfectly. It uses a value that is sent from the form, but doesn't exist on the DB. it's on the html_record_form and looks like this:

if($rec{'view_records'} eq ' אישור ')

It works fine, so I really can't see where's the problem.. well, I'll let it go.. Unsure
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
I'm not really sure what the problem is...are you saying the if/else isn't working or that the regex isn't?

The code I gave above does work...I tested. The only way it wouldn't work is it $rec{hometeam} didn't contain a matching value and so it would go to the else {}
Quote Reply
Re: [Paul] Perl syntax problem In reply to
The regex works, because it does perform the ELSE part. The mistake must be in the value, but i'm 100% sure it's the right one. Maybe it's the hebrew that causes the problem.

Anyway - thank you for your time, I'll try it everyday 'till it'll work :-).
Quote Reply
Re: [alon_g] Perl syntax problem In reply to
Quote:
Maybe it's the hebrew that causes the problem.

Here's the code I'm testing with...it prints 1 for me....

Code:
my $foo = 'ישראל';

$foo eq "\xE9\xF9\xF8\xE0\xEC" and print 1;

....even....

Code:
$foo eq 'ישראל' and print 1;

...works.

Last edited by:

Paul: Jul 18, 2002, 12:05 PM
Quote Reply
Re: [Paul] Perl syntax problem In reply to
I can't explain it...

my $foo = 'ישראל';
$foo eq "\xE9\xF9\xF8\xE0\xEC" and print 1; -
-> works

-but-

$rec{'awayteam'} eq "\xE9\xF9\xF8\xE0\xEC" and print 1; --> doesn't work

Allthough it does find the result when I search for ישראל, meaning awayteam=ישראל.

It's too wired for me.