Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I hope this doesn't come out wrong but...
Where are people getting this "$_ only happens in a regular while loop stuff? I would like to see a reference. I routinely use one liners like print while (<>). I think this might be confussion with the $_ magic assignment only happens in a while loop when using the <> operator. Can anyone correct me on this? BTW I <e>really</e> liked demerphq's
my @words = map { split " ",$_ } <DATA>;
solution. Ugh, Zog say map gooood.

I also subscribe to the unsubstantiated opinion that a statement like

my @ary = split (" ", $_) while (<DATA>);
is exactly like
while (<DATA>) { my @ary = split (" ", $_); }
which would kinda explain this behavior.

again, I would love to be corrected on this and shown the errors of my ways.

I'm a sinner! Ira punnishes his wicked flesh bad, bad flesh. After running some code samples I have no answers but only questions.

So clearly the my declaration of array is *not* local to some implicit scope because use strict doesn't complain when you access it later in the file. And so I used the Dump procedure from Devel::Peek and the plot thickened...

use strict; use warnings; use Devel::Peek; my @array = split (" ", $_) while (<DATA>); print Dump(\@array); __DATA__ ksg gae agdg ekau eg Gke geo g ep ge
Gave me...
SV = RV(0x1a97584) at 0x1a7f0bc REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x1a72ffc SV = PVAV(0x1a7dd3c) at 0x1a72ffc REFCNT = 2 FLAGS = (PADBUSY,PADMY) IV = 0 NV = 0 ARRAY = 0x1a7012c FILL = -1 MAX = 4 ARYLEN = 0x0 FLAGS = (REAL)
Note that MAX is 4? When I do this on an empty, never accessed array MAX is -1. So I think that somewhere along the way @array got 4 elements assigned to it. But that's also weird because there should have been 5.

Any hubris I had is now confussion. All is lost... all is lost...


In reply to Re: Re: Re: Getting data out of __DATA__ and __END__ by IraTarball
in thread Getting data out of __DATA__ and __END__ by George_Sherston

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (1)
    As of 2019-08-21 05:55 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found