On Wed Feb 01 12:30:58 2012, sprout wrote:
> On Wed Feb 01 09:05:37 2012, dcmertens.perl@gmail.com wrote:
> > On Wed, Feb 1, 2012 at 10:35 AM, Father Chrysostomos via RT <
> > perlbug-followup@perl.org> wrote:
> >
> > > On Wed Feb 01 05:52:42 2012, tom christiansen wrote:
> > > > I fear we need people who actually *think* in J/P/R for this sort of
> > > > question.
> > >
> > > Unfortunately I can’t be much help there, as there is no JavaScript
> > > section. :-)
> > >
> > > --
> > >
> > > Father Chrysostomos
> > >
> > >
> > > ---
> > > via perlbug: queue: perl5 status: open
> > > https://rt.perl.org:443/rt3/Ticket/Display.html?id=109408
> > >
> >
> > Any reason you haven't written one? :-D
>
> Well, when I learnt Perl I rarely got tripped up on anything. Maybe I’m
> just the wrong sort of person. I might be able to do it, but certainly
> not in time for Camel 4.
>
On the other hand, I’ve just thought of a few things, the first one
being a real problem that I’ve seen in Perl code.
I don’t know whether Tom would want to include this.
=item *
C<? :> has higher precedence than assignment. In JavaScript, one can
write:
condition ? do_something() : variable = 3
and the variable is only assigned if the condition is false. In Perl, you
need parentheses:
$condition ? do_something() : ($variable = 3);
Or just use C<if>.
=item *
Perl requires semicolons to separate statements.
=item *
Unlike C<for...in>, Perl's C<for> does not allow the left-hand side to
be an arbitrary expression. It must be a variable:
for my $variable (keys %hash) {
...
}
=item *
The C<+> unary operator doesn't do anything in Perl. It exists to avoid
syntactical ambiguities.
=item *
One cannot easily add arbitrary properties to an existing object. For a
publicly-accessible property, make a subclass, and maybe consider
C<AUTOLOAD>. To associate data with arbitrary objects, see
L<Hash::Util::FieldHash>.
=item *
An object's members cannot be made accessible as variables. The closest
Perl equivalent to C<with(object) { method() }> is C<for>, which can alias
C<$_> to the object:
for ($object) {
$_->method;
}
=item *
Variable declarations only affect code I<after> the declaration. You
cannot write C<$x = 1; my $x;> and expect the first assignment to affect
the same variable. It will instead assign to an C<$x> declared previously
in an outer scope, or to a global variable.
=item *
C<my> variables are scoped to the current block, not to the current
function. If you write C<{my $x;} $x;>, the second C<$x> does not refer to
the one declared inside the block.
=item *
The object on which a method is called is passed as one of the method's
arguments, not as a separate C<this> value.
--
Father Chrysostomos
---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=109408
Thread Previous
|
Thread Next