Error in "RT Essentials" book

On page 88, it describes how to modify the autoreply template to give the
user a password if they don’t already have one. In the modified template
listed, the first part of the new code starts off as:

if ( $Transaction->CreatorObj->id != $RT::Nobody->id

but on page 89, where they discuss that new code, they replaced the 'if’
with ‘unless’.

Which is it?

-ste

It is an error but the two statements in the book are equivalent:

pg 88

if ($Transaction->CreatorObj->id != $RT::Nobody->id){}

pg 89

unless ($Transaction->CreatorObj->id == $RT::Nobody->id){}

Different ways to check for the same negative; “if this is not true” vs.
“unless this is true”.

Joby Walker
ITI SSG, University of Washington

Shaun T. Erickson wrote:

It is an error but the two statements in the book are equivalent:

pg 88

if ($Transaction->CreatorObj->id != $RT::Nobody->id){}

pg 89

unless ($Transaction->CreatorObj->id == $RT::Nobody->id){}

“unless(…)” in perl is equiv to “if(not(…))” and “not($val1 ==
$val2)” is equal to
"($val1 != $val2)".

You can also use next equivalent that doesn’t require loading of the
new User object:
unless ($Transaction->Creator == $RT::Nobody->id){}

General rule is next:
if object’s field is id of the record in other table(fields like
Creator, LastUpdateBy, Ticket, Transaction, GroupId, MemberId…) then
in most cases class(in the example RT::Transaction) has method named
FieldObj that creates new referenced object and load data by id.
Pseudo code for CreatorObj method looks like:

my $obj = new RT::User;
$obj->Load( $self->Creator );
return $obj;

Book has errata page on the Oreily site, please fill info about error there.

Different ways to check for the same negative; “if this is not true” vs.
“unless this is true”.

Joby Walker
ITI SSG, University of Washington

Shaun T. Erickson wrote:

On page 88, it describes how to modify the autoreply template to give
the user a password if they don’t already have one. In the modified
template listed, the first part of the new code starts off as:

if ( $Transaction->CreatorObj->id != $RT::Nobody->id

but on page 89, where they discuss that new code, they replaced the 'if’
with ‘unless’.

Which is it?


-ste



http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Be sure to check out the RT Wiki at http://wiki.bestpractical.com

Buy your copy of our new book, RT Essentials, today!

Download a free sample chapter from http://rtbook.bestpractical.com


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Be sure to check out the RT Wiki at http://wiki.bestpractical.com

Buy your copy of our new book, RT Essentials, today!

Download a free sample chapter from http://rtbook.bestpractical.com

Best regards, Ruslan.

It is an error but the two statements in the book are equivalent:

pg 88

if ($Transaction->CreatorObj->id != $RT::Nobody->id){}

pg 89

unless ($Transaction->CreatorObj->id == $RT::Nobody->id){}

Different ways to check for the same negative; “if this is not true” vs.
“unless this is true”.

I see. I also hadn’t noticed that the comparison operators had been changed
as well.

New question: On page 88, right after that if statement, in the next line,
that starts off “my $user”, shouldn’t that first ‘RT’ in the line have a
dollar sign in front of it, or is my lack of perl knowledge showing through
too much? :slight_smile:

TIA

-ste

No that is correct because you aren’t accessing a variable it is a
accessing the constructor (new) of an object (RT::User).

You might want to get O’Reilly’s “Programming Perl” (a.k.a The Camel) –
It helps.

Joby Walker
ITI SSG, University of Washington

Shaun T. Erickson wrote: