Tweet

How do I initialize multiple variables in one statement?

How do I initialize multiple variables without having to manually specify each one?

The problem

    $a = 0;
    $b = 0;
    $c = 0;
    $d = 0;

The solution

    #!/usr/bin/perl
    use strict;
    use warnings;

    my ($a, $b, $c, $d);
    $a = $b = $c = $d = 0;
[Top]