Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / man / man3 / Scalar::Util.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Scalar::Util 3"
132.TH Scalar::Util 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134Scalar::Util \- A selection of general\-utility scalar subroutines
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& use Scalar::Util qw(blessed dualvar isweak readonly refaddr reftype tainted
139\& weaken isvstring looks_like_number set_prototype);
140.Ve
141.SH "DESCRIPTION"
142.IX Header "DESCRIPTION"
143\&\f(CW\*(C`Scalar::Util\*(C'\fR contains a selection of subroutines that people have
144expressed would be nice to have in the perl core, but the usage would
145not really be high enough to warrant the use of a keyword, and the size
146so small such that being individual extensions would be wasteful.
147.PP
148By default \f(CW\*(C`Scalar::Util\*(C'\fR does not export any subroutines. The
149subroutines defined are
150.IP "blessed \s-1EXPR\s0" 4
151.IX Item "blessed EXPR"
152If \s-1EXPR\s0 evaluates to a blessed reference the name of the package
153that it is blessed into is returned. Otherwise \f(CW\*(C`undef\*(C'\fR is returned.
154.Sp
155.Vb 2
156\& $scalar = "foo";
157\& $class = blessed $scalar; # undef
158.Ve
159.Sp
160.Vb 2
161\& $ref = [];
162\& $class = blessed $ref; # undef
163.Ve
164.Sp
165.Vb 2
166\& $obj = bless [], "Foo";
167\& $class = blessed $obj; # "Foo"
168.Ve
169.IP "dualvar \s-1NUM\s0, \s-1STRING\s0" 4
170.IX Item "dualvar NUM, STRING"
171Returns a scalar that has the value \s-1NUM\s0 in a numeric context and the
172value \s-1STRING\s0 in a string context.
173.Sp
174.Vb 3
175\& $foo = dualvar 10, "Hello";
176\& $num = $foo + 2; # 12
177\& $str = $foo . " world"; # Hello world
178.Ve
179.IP "isvstring \s-1EXPR\s0" 4
180.IX Item "isvstring EXPR"
181If \s-1EXPR\s0 is a scalar which was coded as a vstring the result is true.
182.Sp
183.Vb 3
184\& $vs = v49.46.48;
185\& $fmt = isvstring($vs) ? "%vd" : "%s"; #true
186\& printf($fmt,$vs);
187.Ve
188.IP "isweak \s-1EXPR\s0" 4
189.IX Item "isweak EXPR"
190If \s-1EXPR\s0 is a scalar which is a weak reference the result is true.
191.Sp
192.Vb 4
193\& $ref = \e$foo;
194\& $weak = isweak($ref); # false
195\& weaken($ref);
196\& $weak = isweak($ref); # true
197.Ve
198.Sp
199\&\fB\s-1NOTE\s0\fR: Copying a weak reference creates a normal, strong, reference.
200.Sp
201.Vb 2
202\& $copy = $ref;
203\& $weak = isweak($ref); # false
204.Ve
205.IP "looks_like_number \s-1EXPR\s0" 4
206.IX Item "looks_like_number EXPR"
207Returns true if perl thinks \s-1EXPR\s0 is a number. See
208\&\*(L"looks_like_number\*(R" in perlapi.
209.IP "openhandle \s-1FH\s0" 4
210.IX Item "openhandle FH"
211Returns \s-1FH\s0 if \s-1FH\s0 may be used as a filehandle and is open, or \s-1FH\s0 is a tied
212handle. Otherwise \f(CW\*(C`undef\*(C'\fR is returned.
213.Sp
214.Vb 4
215\& $fh = openhandle(*STDIN); # \e*STDIN
216\& $fh = openhandle(\e*STDIN); # \e*STDIN
217\& $fh = openhandle(*NOTOPEN); # undef
218\& $fh = openhandle("scalar"); # undef
219.Ve
220.IP "readonly \s-1SCALAR\s0" 4
221.IX Item "readonly SCALAR"
222Returns true if \s-1SCALAR\s0 is readonly.
223.Sp
224.Vb 1
225\& sub foo { readonly($_[0]) }
226.Ve
227.Sp
228.Vb 2
229\& $readonly = foo($bar); # false
230\& $readonly = foo(0); # true
231.Ve
232.IP "refaddr \s-1EXPR\s0" 4
233.IX Item "refaddr EXPR"
234If \s-1EXPR\s0 evaluates to a reference the internal memory address of
235the referenced value is returned. Otherwise \f(CW\*(C`undef\*(C'\fR is returned.
236.Sp
237.Vb 3
238\& $addr = refaddr "string"; # undef
239\& $addr = refaddr \e$var; # eg 12345678
240\& $addr = refaddr []; # eg 23456784
241.Ve
242.Sp
243.Vb 2
244\& $obj = bless {}, "Foo";
245\& $addr = refaddr $obj; # eg 88123488
246.Ve
247.IP "reftype \s-1EXPR\s0" 4
248.IX Item "reftype EXPR"
249If \s-1EXPR\s0 evaluates to a reference the type of the variable referenced
250is returned. Otherwise \f(CW\*(C`undef\*(C'\fR is returned.
251.Sp
252.Vb 3
253\& $type = reftype "string"; # undef
254\& $type = reftype \e$var; # SCALAR
255\& $type = reftype []; # ARRAY
256.Ve
257.Sp
258.Vb 2
259\& $obj = bless {}, "Foo";
260\& $type = reftype $obj; # HASH
261.Ve
262.IP "set_prototype \s-1CODEREF\s0, \s-1PROTOTYPE\s0" 4
263.IX Item "set_prototype CODEREF, PROTOTYPE"
264Sets the prototype of the given function, or deletes it if \s-1PROTOTYPE\s0 is
265undef. Returns the \s-1CODEREF\s0.
266.Sp
267.Vb 1
268\& set_prototype \e&foo, '$$';
269.Ve
270.IP "tainted \s-1EXPR\s0" 4
271.IX Item "tainted EXPR"
272Return true if the result of \s-1EXPR\s0 is tainted
273.Sp
274.Vb 2
275\& $taint = tainted("constant"); # false
276\& $taint = tainted($ENV{PWD}); # true if running under -T
277.Ve
278.IP "weaken \s-1REF\s0" 4
279.IX Item "weaken REF"
280\&\s-1REF\s0 will be turned into a weak reference. This means that it will not
281hold a reference count on the object it references. Also when the reference
282count on that object reaches zero, \s-1REF\s0 will be set to undef.
283.Sp
284This is useful for keeping copies of references , but you don't want to
285prevent the object being DESTROY-ed at its usual time.
286.Sp
287.Vb 6
288\& {
289\& my $var;
290\& $ref = \e$var;
291\& weaken($ref); # Make $ref a weak reference
292\& }
293\& # $ref is now undef
294.Ve
295.Sp
296Note that if you take a copy of a scalar with a weakened reference,
297the copy will be a strong reference.
298.Sp
299.Vb 4
300\& my $var;
301\& my $foo = \e$var;
302\& weaken($foo); # Make $foo a weak reference
303\& my $bar = $foo; # $bar is now a strong reference
304.Ve
305.Sp
306This may be less obvious in other situations, such as \f(CW\*(C`grep()\*(C'\fR, for instance
307when grepping through a list of weakened references to objects that may have
308been destroyed already:
309.Sp
310.Vb 1
311\& @object = grep { defined } @object;
312.Ve
313.Sp
314This will indeed remove all references to destroyed objects, but the remaining
315references to objects will be strong, causing the remaining objects to never
316be destroyed because there is now always a strong reference to them in the
317\&\f(CW@object\fR array.
318.SH "KNOWN BUGS"
319.IX Header "KNOWN BUGS"
320There is a bug in perl5.6.0 with \s-1UV\s0's that are >= 1<<31. This will
321show up as tests 8 and 9 of dualvar.t failing
322.SH "COPYRIGHT"
323.IX Header "COPYRIGHT"
324Copyright (c) 1997\-2005 Graham Barr <gbarr@pobox.com>. All rights reserved.
325This program is free software; you can redistribute it and/or modify it
326under the same terms as Perl itself.
327.PP
328Except weaken and isweak which are
329.PP
330Copyright (c) 1999 Tuomas J. Lukka <lukka@iki.fi>. All rights reserved.
331This program is free software; you can redistribute it and/or modify it
332under the same terms as perl itself.
333.SH "BLATANT PLUG"
334.IX Header "BLATANT PLUG"
335The weaken and isweak subroutines in this module and the patch to the core Perl
336were written in connection with the APress book `Tuomas J. Lukka's Definitive
337Guide to Object-Oriented Programming in Perl', to avoid explaining why certain
338things would have to be done in cumbersome ways.