'ello Monks!
I'm still quite the noob, as will soon be evident. In being tasked with modifying an ancient parser I soon noticed that it was using local $/=undef. Which I gathered is generally frowned upon. This is a stripped down version of the original file:

local $/=undef; open (NOTFOUND, "<transact.QDX"); open (NOTOUT, ">NotOut.txt"); my $lenOfFile = (stat(NOTFOUND)) [7]; while ($position <= $lenOfFile - 64) { sysread NOTFOUND, $record,64; chomp($record = $record); $opcode = unpack ("H*", substr($record, 0,1)); $subcode = unpack ("H*", substr($record, 1,1)); $position +=64; sysseek NOTFOUND, $position, 0; if ($opcode eq "60" and $subcode eq "01" ){ $plu = unpack("H*", substr($record,2,7)); syswrite NOTOUT, $plu . "\t" . $ymd . "\r" . "\n"; } }

In my situation there isn't a performance issue to worry about, I just wanted to do things 'right' from the get-go.

while ($position <= $lenOfFile - 64) { sysread NOTFOUND, my $record,64; push(@records, chomp($record)); $position += 64; sysseek NOTFOUND, $position, 0; } foreach my $currentrecord (@records) { $opcode = unpack ("H*", substr($currentrecord,0,1)); $subcode = unpack ("H*", substr($currentrecord, 1,1)); syswrite DEBUG, $opcode . "\t" . $subcode . "\n"; if ($opcode eq "60" and $subcode eq "01" ) { $plu = unpack("H*", substr($currentrecord,2,7)); syswrite NOTOUT, $plu . "\t" . $ymd . "\n"; }

In using my method I get blank output. The debug file I created shows that the opcode is always 30, and the subcode is just a box in notepad(i'm only using windows because i'm forced to at work, promise!). Funny thing is, there is no opcode 30 in the QDX file being read.

My fragile perl reality is crumbling around me. The two blocks of code seem like they should be accomplishing nearly the same thing. Perhaps my understanding of "local $/=undef" isn't well grounded? Is it a peculiarity with QDX files? What is going on?


In reply to Avoid using local $/=undef? by irDanR

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.