in reply to Embedded variable assignments inside local declarations

Oddly enough, this would work fine, although I'd question it in a code review:
my $a = 1, my $b = 2, my $c = 3;
Why not just change those commas to semis and be done with it?

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Embedded variable assignments inside local declarations
by pg (Canon) on Jan 26, 2003 at 19:39 UTC
    $a = 1, $b = 2, $c = 3; works, and that's exactly why my $a = 1, my $b = 2, my $c = 3; would work.

    Although it looks odd, but from a Perl internal view, it is the same animal as the following (,which we see from day to day):

    foreach $line (@lines) { ... }
    works, that's why
    foreach my $line (@lines) { ... }
    Basically, Perl allows you to my variables on fly.

    One more example for the same animal:
    for (my $i = 1; $i < 10; $i ++) { print $i; }