in reply to declare and init a scalar
There is only one situation when I consciously assign the null string to a scalar:
{ my $vec; vec( $vec, 0, 1 ) = 1; };; Use of uninitialized value $vec in vec at (eval 9) line 1, <STDIN> lin +e 1. Use of uninitialized value $vec in scalar assignment at (eval 9) line +1, <STDIN> line 1. { my $vec = ''; vec( $vec, 0, 1 ) = 1; };;
A somewhat analogous situation arises with substr:
{ my $s; substr( $s, 0, 1, 'fred' ); };; Use of uninitialized value $s in substr at (eval 13) line 1, <STDIN> l +ine 5. { my $s = ''; substr( $s, 0, 1, 'fred' ); };;
But that is less useful because it only silences the warning if there is an overlap between the range being overwritten and that that already exists:
{ my $s = ''; substr( $s, 1, 1, 'fred' ); print $s; };; substr outside of string at (eval 16) line 1, <STDIN> line 8. { my $s = ' '; substr( $s, 1, 1, 'fred' ); print $s; };; fred
But beyond those few special cases, it's pretty much pointless typing.
(I also think that using q{} instead of '' is a waste of effort; and a mild form of obfuscation. PBP strikes again.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: declare and init a scalar
by johngg (Canon) on Jan 22, 2015 at 22:35 UTC | |
by BrowserUk (Patriarch) on Jan 22, 2015 at 22:58 UTC | |
by Anonymous Monk on Jan 23, 2015 at 02:00 UTC | |
by soonix (Chancellor) on Jan 23, 2015 at 11:44 UTC | |
by BrowserUk (Patriarch) on Jan 23, 2015 at 12:49 UTC | |
by soonix (Chancellor) on Jan 23, 2015 at 13:53 UTC | |
|
Re^2: declare and init a scalar
by Not_a_Number (Prior) on Jan 22, 2015 at 21:39 UTC | |
by BrowserUk (Patriarch) on Jan 22, 2015 at 21:52 UTC |