I have some code which was generated from SCL to PERL. It produced the following line.
substr($DATE, 2, 5) = $YEAR . $MONTH;
My first thought was that this would do nothing. I was wrong it didn't do what was expected but it did do something. When put into this context
$YEAR = "2005"; $MONTH = "06"; $DATE = "20050608"; substr($DATE, 2, 5) = $YEAR . $MONTH; print $DATE; #output 202005068
I'm not asking how to fix it I just wont to know how its doing whats its doing now?

UPDATE
It wasn't so much what it was trying to do as how it was doing it. The orginal SCL code from the mainframe did the same and was wrong as well. Thanks to all for explaining what is happenning.

The joke is the SCL code was passing the resulting $DATE to a utility to get the days since 1900. It was failing, however the code was last run in 2002 and the ops. here think it failed then as well. Historic conversions don't you just love um.....


In reply to What is substring working on here. by Scarborough

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.