in reply to Question on SV internals
Below, $a starts out as a string with leading zeroes. Adding "0" to it (use in a numeric context), causes the "leading zeroes" to be eliminated, i.e. it is now a binary numeric value. The original string value of $a is now not accessible by any normal Perl operation (you won't know how many leading zeroes it had to begin with). If further math operations are done on $a, no further string to binary conversions are required. Perl math operations are very fast.
Leading zeroes in a numeric assignment like shown below for $b, causes the numeric value to be interpreted as an octal number.
Update: -- extraneous verbage that added nothing deleted.#!/usr/bin/perl -w use strict; my $a = '00000022'; my $b = 00000033; #leading zero means octal! print "$a $b\n"; #00000022 27 $a+=0; print "$a $b\n"; #22 27 #22 now numeric
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question on SV internals
by syphilis (Archbishop) on May 08, 2011 at 08:22 UTC | |
|
Re^2: Question on SV internals
by John M. Dlugosz (Monsignor) on May 09, 2011 at 21:52 UTC | |
by Tux (Canon) on May 09, 2011 at 22:05 UTC |