in reply to Initialize variable in BEGIN

I would declare it only once, like this:

#!/usr/bin/env -S perl -n use strict; use warnings; # USAGE: perl np.pl <np.dat our $total; BEGIN{ $total = 0; } $total += $_; END{ print $total }

This seems less verbose while retaining the clarity but it is all subjective, of course.


🦛

Replies are listed 'Best First'.
Re^2: Initialize variable in BEGIN
by ikegami (Patriarch) on Apr 30, 2025 at 16:43 UTC

    [Deleted incorrect comment.]