Hi, I have the following function:
sub getSubjects($) { my $ref_sRecord = $_[0]; my @aSubNos = $$ref_sRecord =~ m/<subno>(.+?)<\/subno>/sig; .... }
If the contents of $$ref_sRecord contains :
.... <level>1</level> <subject> <subno>2.1.c</subno> <subtxt>Subject 1</subtxt> <subno>2.2</subno> <subtxt>Subject 2</subtxt> </subject> ....
This array aSubNos should contain 2.1.c and 2.2 (in this case).   This works fine for the majority of data but on occasion it fails and doesn't match anything. For some reason, replacing
my @aSubNos = $$ref_sRecord =~ m/<subno>(.+?)<\/subno>/sig;
with
my $sString = $$ref_sRecord; my @aSubNos = $sString =~ m/<subno>(.+?)<\/subno>/sig;
makes it work consistently across all of my data.   The perl script is running on Perl v5.8.4 (sun4-solaris).   The question is, why? This doesn't make any sense to me.

janitored by ybiC: formatting tweaks for legibility


In reply to Weirdness with matching into an array by gcthompson

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.