Data-Rlist
view release on metacpan or search on metacpan
lib/Data/Rlist.pm view on Meta::CPAN
$V = $data->{$K};
$K = __quote7($K) unless is_number($K);
$R.= $pref.chr(9).$K;
if (defined $V) {
$R.= ' => ';
if (ref $V) {
compile_Perl1($V);
} else {
$V = __quote7($V) unless is_number($V);
$R.= $V;
}
} $R.= ",\n";
} $R.= $pref.'}';
} else {
$R.= '{}'
}
} elsif ($Datatype == 82) {
compile_Perl1($$data)
} elsif ($Datatype == 83) {
$R.= is_number($data) ? $$data : __quote7($$data);
} else {
$R.= '"?'.reftype($data).'?"'
}
$Depth--;
} elsif (defined $data) { # number or string
$R.= is_number($data) ? $data : __quote7($data);
} else { # undef
$R.= DEFAULT_VALUE;
}
}
=head2 Auxiliary Functions
The utility functions in this section are generally useful when handling stringified data.
Internally F<L</quote7>>, F<L</escape7>>, F<L</is_integer>> etc. apply precompiled regexes and
precomputed ASCII tables. F<L</split_quoted>> and F<L</parse_quoted>> simplify
L</Text::ParseWords>. F<L</round>> and F<L</equal>> are working solutions for floating-point
numbers. F<L</deep_compare>> is a smart function to "diff" two Perl variables. All these
functions are very fast and mature.
=over
=item F<is_integer(SCALAR-REF)>
Returns true when a scalar looks like a positive or negative integer constant. The function
applies the compiled regex F<$Data::Rlist::REInteger>.
=item F<is_number(SCALAR-REF)>
Test for strings that look like numbers. F<is_number> can be used to test whether a scalar looks
like a integer/float constant (numeric literal). The function applies the compiled regex
F<$Data::Rlist::REFloat>. Note that it doesn't match
- leading or trailing whitespace,
- lexical conventions such as the C<"0b"> (binary), C<"0"> (octal), C<"0x"> (hex) prefix to denote
a number-base other than decimal, and
- Perls' legible numbers, e.g. F<3.14_15_92>,
- the IEEE 754 notations of Infinite and NaN.
See also
$ perldoc -q "whether a scalar is a number"
=item F<is_symbol(SCALAR-REF)>
Test for symbolic names. F<is_symbol> can be used to test whether a scalar looks like a symbolic
name. Such strings need not to be quoted. Rlist defines symbolic names as a superset of C
identifier names:
[a-zA-Z_0-9] # C/C++ character set for identifiers
[a-zA-Z_0-9\-/\~:\.@] # Rlist character set for symbolic names
[a-zA-Z_][a-zA-Z_0-9]* # match C/C++ identifier
[a-zA-Z_\-/\~:@][a-zA-Z_0-9\-/\~:\.@]* # match Rlist symbolic name
For example, names such as F<std::foo>, F<msg.warnings>, F<--verbose>, F<calculation-info> need not
be quoted.
=item F<is_value(SCALAR-REF)>
Returns true when a scalar is an integer, a number, a symbolic name or some quoted string.
=item F<is_random_text(SCALAR-REF)>
The opposite of F<L</is_value>>. Such scalars will be turned into quoted strings by F<L</compile>>
and F<L</compile_fast>>.
=cut
sub is_integer(\$) { ${$_[0]} =~ $REInteger ? 1 : 0 }
sub is_number(\$) { ${$_[0]} =~ $REFloat ? 1 : 0 }
sub is_symbol(\$) { ${$_[0]} =~ $RESymbol ? 1 : 0 }
sub is_value(\$) { ${$_[0]} =~ $REValue ? 1 : 0 }
sub is_random_text(\$) { ${$_[0]} =~ $REValue ? 0 : 1 }
=item F<quote7(TEXT)>
=item F<escape7(TEXT)>
Converts TEXT into 7-bit-ASCII. All characters not in the set of the 95 printable ASCII characters
are escaped. The following ASCII codes will be converted to escaped octal numbers, i.e. 3 digits
prefixed by a slash:
0x00 to 0x1F
0x80 to 0xFF
" ' \
The difference between the two functions is that F<quote7> additionally places TEXT into
double-quotes. For example, F<quote7(qq'"FrE<uuml>her Mittag\n"')> returns C<"\"Fr\374her
Mittag\n\"">, while F<escape7> returns C<\"Fr\374her Mittag\n\">
=item F<maybe_quote7(TEXT)>
Return F<quote7(TEXT)> if F<L</is_random_text>(TEXT)>; otherwise (TEXT defines a symbolic name or
number) return TEXT.
=item F<maybe_unquote7(TEXT)>
lib/Data/Rlist.pm view on Meta::CPAN
$ perl -e 'print *42{GLOB}'
GLOB(0x100110b8)
$ perl -e '*x = 42; print $::{42}, *x'
*main::42*main::42
$ perl -v
This is perl, v5.8.8 built for cygwin-thread-multi-64int
(with 8 registered patches, see perl -V for more detail)
Of course these behaviors are not reliable, and may disappear in future versions of F<perl>. In
German you say "Schmutzeffekt" (dirt effect) for certain mechanical effects that occur
non-intendedly, because machines and electrical circuits are not perfect, and so is software.
However, "Schmutzeffekts" are neither bugs nor features; these are phenomenons.
B<LEXICAL VARIABLES>
Lexical variables (F<my> variables) are not stored in stashes, and do not require typeglobs. These
variables are stored in a special array, the F<scratchpad>, assigned to each block, subroutine, and
thread. These are really private variables, and they cannot be F<local>ized. Each lexical variable
occupies a slot in the scratchpad; hence is addressed by an integer index, not a symbol. F<my>
variables are like F<auto> variables in C. They're also faster than F<local>s, because they can be
allocated at compile time, not runtime. Therefore you cannot declare F<*x> lexically:
$ perl -e 'my(*x)'
Can't declare ref-to-glob cast in "my" at -e line 1, near ");"
Seel also the Perl man-pages L<perlguts>, L<perlref>, L<perldsc> and L<perllol>.
=head3 C++
In C++ we use a F<flex>/F<bison> scanner/parser combination to read Rlist language productions.
The C++ parser generates an F<Abstract Syntax Tree> (AST) of F<double>, F<std::string>,
F<std::vector> and F<std::map> values. Since each value is put into the AST, as separate object,
we use a free store management that allows the allocation of huge amounts of tiny objects.
We also use reference-counted smart-pointers, which allocate themselves on our fast free store. So
RAM will not be fragmented, and the allocation of RAM is significantly faster than with the default
process heap. Like with Perl, Rlist files can have hundreds of megabytes of data (!), and are
processable in constant time, with constant memory requirements. For example, a 300 MB Rlist-file
can be read from a C++ process which will not peak over 400-500 MB of process RAM.
=head1 BUGS
There are no known bugs, this package is stable. Deficiencies and TODOs:
=over
=item *
The C<"deparse"> functionality for the C<"code_refs"> L<compile option|/Compile Options> has not
yet been implemented.
=item *
The C<"threads"> L<compile option|/Compile Options> has not yet been implemented.
=item *
IEEE 754 notations of Infinite and NaN not yet implemented.
=item *
F<L</compile_Perl>> is experimental.
=back
=head1 COPYRIGHT/LICENSE
Copyright 1998-2008 Andreas Spindler
Maintained at CPAN (F<L<http://search.cpan.org/dist/Data-Rlist/>>) and the author's site
(F<L<http://www.visualco.de>>). Please send mail to F<rlist@visualco.de>.
This library is free software; you can redistribute it and/or modify it under the same terms as
Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have
available.
Contact the author for the C++ library at F<rlist@visualco.de>.
Thank you for your attention.
=cut
1;
### Local Variables:
### buffer-file-coding-system: iso-latin-1
### fill-column: 99
### End:
( run in 0.653 second using v1.01-cache-2.11-cpan-39bf76dae61 )