Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Shorten initializers

by Anonymous Monk
on Jun 26, 2003 at 18:29 UTC ( [id://269355]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I make this shorter?
my $a = 0; my $b = 0; my $c = 0;
Can I do this?
my ($a,$b,$c) = 0;

Replies are listed 'Best First'.
Re: Shorten initializers
by thelenm (Vicar) on Jun 26, 2003 at 18:38 UTC

    You can't do it quite like that, but you could do either of these:

    my ($foo, $bar, $baz) = (0, 0, 0); my ($foo, $bar, $baz) = (0)x3;

    -- Mike

    --
    just,my${.02}

      Thanks to everyone!
Re: Shorten initializers
by Zaxo (Archbishop) on Jun 26, 2003 at 18:39 UTC

    What you have is correct syntax, but it only initializes $a. Try: my ($a,$b,$c) = (0) x 3; or my ($a,$b,$c) = (0, 0, 0); Please avoid $a and $b as variable names, that will interfere with sort.

    After Compline,
    Zaxo

Re: Shorten initializers
by fglock (Vicar) on Jun 26, 2003 at 18:38 UTC
    my ($a, $b, $c) = (0) x 3; print "$a - $b - $c";

    update:

    $_=0 for my($a,$b,$c);
Re: Shorten initializers
by antirice (Priest) on Jun 26, 2003 at 19:27 UTC

    In the spirit of TMTOWTDI:

    my $a = my $b = my $c = 0;

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

      Sorry, but I saw your post, and started humming...

      My-my-my-my (U can't touch this) music hits me so hard Makes me say,"oh my lord thank you for blessing me

      Mc Hammer Lyrics

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://269355]
Approved by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found