Gossamer Forum
Home : General : Perl Programming :

please explain and or

Quote Reply
please explain and or
i don't understand the following if statements. db_sort{column} is the field type so i know it's checking to see if the field is supposed to be a date. then &date_to_unix checks to see if it's a valid date. so i'm guessing if the $in value is supposed to be a date and is a valid date, then it skips the return and does the push, right? idon't understand the words 'and' and 'or'. if you can explain one statement, it will probably make them all clear!

Code:
foreach $column (@db_cols) {
if ($in{$column} =~ /^\>(.+)$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($1) or return "Invalid date format: '$1'");
push (@search_gt_fields, $i); $in{"$column-gt"} = $1; $i++; next; }
if ($in{$column} =~ /^\<(.+)$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($1) or return "Invalid date format: '$1'");
push (@search_lt_fields, $i); $in{"$column-lt"} = $1; $i++; next; }
if ($in{$column} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{$column}) or return "Invalid date format: '$in{$column}'");
push(@search_fields, $i); $i++; next; }
if ($in{"$column-gt"} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{"$column-gt"}) or return "Invalid date format: '$in{$column}'");
push(@search_gt_fields, $i); }
if ($in{"$column-lt"} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{"$column-lt"}) or return "Invalid date format: '$in{$column}'");
push(@search_lt_fields, $i); }
$i++;
}
Quote Reply
Re: [delicia] please explain and or In reply to
Hi,

It's a bit easier if you "read" it like this:

Code:
if ($in{"$column-lt"} !~ /^\s*$/) {
($db_sort{$column} eq 'date') and (&date_to_unix($in{"$column-lt"}) or return "Invalid date format: '$in{$column}'");
push(@search_lt_fields, $i);
}

Ok, so lets break it down

Code:
($db_sort{$column} eq 'date')

That is just checking to see if the column name matches "date" AND then:

Code:
(&date_to_unix($in{"$column-lt"})

I'm assuming that function returned either "1"or "0", depending on the result of its calculations

Code:
or return "Invalid date format: '$in{$column}'"

That is just saying "match both the first condition, and the 2nd one, OR return an error message"

Hopefully that helps a little :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] please explain and or In reply to
why use "and" instead of && ???
Quote Reply
Re: [delicia] please explain and or In reply to
In this case, I think its just preferential. Here is a post explaining it:

http://www.perlmonks.org/?node_id=570885

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] please explain and or In reply to
thank you. seems like a combination of math and grammar!