[non-META] How to be an expert

Paul Lussier p.lussier at comcast.net
Tue Jun 13 13:36:01 EDT 2006


"Ken D'Ambrosio" <ken at proximatech.net> writes:

> Speaking about being ignorant, I *think* I understand what the following
> line does... but, if so, then I don't understand why.  Anyone care to give
> me their interpretation?  [From /usr/share/perl5/Bugzilla/CGI.pm]
>
>     $self->charset(Param('utf8') ? 'UTF-8' : '');

Take it apart from the inside out:

     
  The statement:
       Param('utf8') ? 'UTF-8' : ''

  is your basic ternary operation akin to an if-else:

     if foo is true  then  return this  else return that
       Param('utf8')   ?     'UTF-8'     :       ''

  Param() is a function, and it's getting passed the string 'utf8'

  Param() will some value which, in this context will be evaluated as
  true or false.  If it's true, the ternary statement evaluates to the
  string 'UTF-8', otherwise it evaluates to the empty string ''

  The result of the ternary operation is then passed to the method
  $self->charset().

  $self->charset() is an example of perl's idea of an OO interface.
  charset is probably a 'setter method', which is a fancy way of
  saying, "a function/sub which sets some parameter". There's likely a
  'getter' method somewhere named something like get_charset() which
  could be called as $self->get_charset() and would return the current
  value for the character set to be used.

HTH,

-- 
Seeya,
Paul



More information about the gnhlug-discuss mailing list