Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Whats the dif between \&date and &date in record def

Quote Reply
Whats the dif between \&date and &date in record def
I wanted to "require" my dbman and links record formats from one file. I would like to know if any one knows of a problem with doing this so I do not have to update different files as they both use the same database and fields.

My other question is that I would like to know what the difference in between the &date and \&date in the field descriptions of links and dbman. Smile


Date => [8, 'date', 15,15, 1, &get_date, ''],
_________

Date => [3, 'date', 15, 15, 1, \&get_date, ''],

Basically the question is, what does the "\" do for us in the latter.

TimRyan

Quote Reply
Re: Whats the dif between \&date and &date in record def In reply to
In Perl there are characters that have special meanings, & is one of them.

The \ is an escape character that removes the special Perl meaning from the & character. It tells the script to not substitute the & with it's special meaning, but leave it as part of &date.

Dan O.
Quote Reply
Re: Whats the dif between \&date and &date in record def In reply to
Thanks, That brings up another question. Why is \&date used in the links def and not in the dbman def? Will links def work just as will with &date as it will with \&date and/or will dbman work ok with the \&date put in it?

I want to have dbman and links share my same def file.

Thanks
TimRyan


------------------
Quote Reply
Re: Whats the dif between \&date and &date in record def In reply to
The \ may not even need to be used in that situation, but is just there as a safety precaution. I would say it's probably better to have it then not.

Try it and see if it causes any problems. Be sure to back up your data before though.

Dan O.
Quote Reply
Re: Whats the dif between \&date and &date in record def In reply to
Code:
Date => [8, 'date', 15,15, 1, &get_date, ''],
VS
Date => [3, 'date', 15, 15, 1, \&get_date, ''],

&get_date is a _call_ to the function, and creates a replacement for that with the value returned from that function.

\&get_date _INSIDE_ a string modifier " or qq would print out the string "&get_date"

the trick is, inside the set notation, it's not a string, or a literal, so I imagine that what is being done is a _REFERECE_ to the function in inserted.

In the first case, the function call would be evaluated, the time obtained, and that value inserted into the array. It would not change, nor be reevaluated during the course of the program -- since it had already been evaluated.

In the second version -- it's a REFERENCE to the function, so every time it's called or used, the function is re-evaluated.

I have no way to test this, but it looks like that is what would be happening. To insert &get_date into the array as a string, you'd have to put it between two ' - and then the 'Date' field would contain '&get_date' rather than a value or a reference to a value.

Does anyone know for _SURE_ (maybe post this in the CGI area).