Here is an example of why using @arr[0] is just asking from trouble...
#!/usr/bin/perl -wT
use strict;
my @arr;
@arr[0] = localtime();
$arr[1] = localtime();
print "\$arr[0] = $arr[0]\n";
print "\$arr[1] = $arr[1]\n";
Any guesses about the output of this simple script? Select area below to find out.
=OUTPUT
Scalar value @arr[0] better written as $arr[0] at ./arrayslice.pl line
+ 6.
$arr[0] = 58
$arr[1] = Tue Oct 23 14:30:58 2001
5 points for anyone who expected $arr[0] to contain an integer. 20 points for anyone who knew it would contain the seconds value, *not* the number of elements in the list
returned by localtime().
(10 points for anyone who coded up an example because they weren't sure... woohoo)
|
-Blake
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|