(I'm not all that versed on Object Oriented Programming so bear with
me...)<br/>
<br/>
i thought the whold reason for the use of &quot;my&quot; when declaring
variables was to limit their scope and keep from overlapping with other
delcarations of the same variable name.<br/>
<br/>
Hence, the parent scope ('my $d1 =
Class::Date-&gt;new(&quot;1971-01-01&quot;);') were protected from the
subroutine scope declaration of d1 and d2.<br/>
<br/>
Doesn't the &quot;our&quot; declaration do what you want?&nbsp; From the
&quot;man perlfunc&quot;:<br/>
<br/>
<dl><dt>our EXPR</dt><dt><a name="our"></a><a
name="our_EXPR_TYPE"></a></dt><dd>
<p>An <code>our</code> declares the listed variables to be valid globals
within the enclosing block, file, or <code>eval</code>. That is, it has
the same scoping rules as a &quot;my&quot; declaration, but does not
create a local variable. If more than one value is listed, the list must
be placed in parentheses. The <code>our</code> declaration has no semantic
effect unless &quot;use strict vars&quot; is in effect, in which case it
lets you use the declared global variable without qualifying it with a
package name. (But only within the lexical scope of the <code>our</code>
declaration. In this it differs from &quot;use vars&quot;, which is
package scoped.)</p>
</dd></dl><br/>
Here is what I came up with:<br/>
<pre><font size="2">#!/usr/bin/perl -w</font></pre>
<pre><font size="2">use Class::Date qw( date );</font></pre>
<pre><font size="2"><br/>
our $d1 = date &quot;1970-01-01&quot;;</font></pre>
<pre><font size="2">our $d2 = date &quot;2000-01-01&quot;;</font></pre>
<pre><font size="2"><br/>
print &quot;Before stuff: [$d1][$d2]\n&quot;;</font></pre>
<pre><font size="2">stuff($d1, $d2);</font></pre>
<pre><font size="2">print &quot;After stuff :
[$d1][$d2]\n&quot;;</font></pre>
<pre><font size="2"><br/>
sub stuff {</font></pre>
<pre><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; our ($d1,
$d2) = @_;</font></pre>
<pre><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($d2
&gt; $d1) {</font></pre>
<pre><font
size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$d1 = $d2;&nbsp;&nbsp; # &lt;---- I want to overwrite the existing $d1
here</font></pre>
<pre><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></pre>
<pre><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print
&quot;Inside stuff: [$d1][$d2]\n&quot;;</font></pre>
<pre><font size="2">}</font></pre>
<br/>
Dan<br/>
<br/>
On Mon, October 24, 2005 15:25, Kenneth Thompson wrote:<br/>
&gt; Well, it's clumsy but it works. Maybe it could be written into the
class<br/>
&gt; as another clone option?<br/>
&gt; <br/>
&gt; use Class::Date qw( date );<br/>
&gt; <br/>
&gt; my $d1 = Class::Date-&gt;new(&quot;1971-01-01&quot;);<br/>
&gt; my $d2 = Class::Date-&gt;new(&quot;2000-01-01&quot;);<br/>
&gt; <br/>
&gt; print &quot;[$d1][$d2]\n&quot;;<br/>
&gt; stuff($d1, $d2);<br/>
&gt; print &quot;[$d1][$d2]\n&quot;;<br/>
&gt; <br/>
&gt; sub stuff {<br/>
&gt;     my ($d1, $d2) = @_;<br/>
&gt;     if ($d2 &gt; $d1) {<br/>
&gt; #      $d1 = $d2;   # &lt;---- I want to overwrite the existing $d1
here<br/>
&gt;        foreach my $idx (0 .. 9) {<br/>
&gt;          $d1-&gt;[$idx] = $d2-&gt;[$idx];<br/>
&gt;        }<br/>
&gt;     }<br/>
&gt; }<br/>
&gt; <br/>
&gt; <br/>
&gt; -----Original Message-----<br/>
&gt;<br/>
From: omaha-pm-bounces@pm.org [mailto:omaha-pm-bounces@pm.org] On Behalf<br/>
&gt; Of Jay Hannah<br/>
&gt; Sent: Monday, October 24, 2005 2:22 PM<br/>
&gt; To: class-date@lists.dlux.hu<br/>
&gt; Cc: omaha-pm@pm.org<br/>
&gt; Subject: [Omaha.pm] Class::Date - change once set<br/>
&gt; <br/>
&gt; <br/>
&gt; Hola --<br/>
&gt; <br/>
&gt; Is there any way to change a Class::Date value once one has been
set?<br/>
&gt; Right now my demo script is failing:<br/>
&gt; <br/>
&gt; My script:<br/>
&gt; <br/>
&gt; ---<br/>
&gt; use Class::Date qw( date );<br/>
&gt; <br/>
&gt; my $d1 = date &quot;1970-01-01&quot;;<br/>
&gt; my $d2 = date &quot;2000-01-01&quot;;<br/>
&gt; <br/>
&gt; stuff($d1, $d2);<br/>
&gt; print &quot;[$d1][$d2]\n&quot;;<br/>
&gt; <br/>
&gt; sub stuff {<br/>
&gt;     my ($d1, $d2) = @_;<br/>
&gt;     if ($d2 &gt; $d1) {<br/>
&gt;        $d1 = $d2;   # &lt;---- I want to overwrite the existing $d1
here<br/>
&gt;     }<br/>
&gt;     print &quot;[$d1][$d2]\n&quot;;<br/>
&gt; }<br/>
&gt; ---<br/>
&gt; <br/>
&gt; When I run it:<br/>
&gt; <br/>
&gt; $ perl j.pl<br/>
&gt; [2000-01-01 00:00:00][2000-01-01 00:00:00]<br/>
&gt; [1970-01-01 00:00:00][2000-01-01 00:00:00]<br/>
&gt; <br/>
&gt; $d1 is getting a NEW object, not overwriting the original $d1, so
when<br/>
&gt; stuff() returns I have lost my change to $d1.<br/>
&gt; <br/>
&gt; Is there any way to change $d1 inside stuff()? I tried clone() and
set()<br/>
&gt; without any luck.<br/>
&gt; <br/>
&gt; Thanks!<br/>
&gt; <br/>
&gt; j<br/>
&gt; <br/>
&gt; <br/>
&gt; <br/>
&gt; _______________________________________________<br/>
&gt; Omaha-pm mailing list<br/>
&gt; Omaha-pm@pm.org<br/>
&gt; http://mail.pm.org/mailman/listinfo/omaha-pm<br/>
&gt; <br/>
&gt; _______________________________________________<br/>
&gt; Omaha-pm mailing list<br/>
&gt; Omaha-pm@pm.org<br/>
&gt; http://mail.pm.org/mailman/listinfo/omaha-pm<br/>
&gt; <br/>
<br/>
<br/>
- - - -<br/>
&quot;Wait for that wisest of all counselors, time.&quot; -- Pericles<br/>
&quot;I do not fear computer, I fear the lack of them.&quot; -- Isaac
Asimov<br/>
GPG fingerprint:6FFD DB94 7B96 0FD8 EADF  2EE0 B2B0 CC47 4FDE 9B68