OK Im a little confused now - I see where and why he is getting his error above and that $_ is undefined. In my example below - I see the first print statement which I beleive to be equivelant to the ops print statement. But Im confused about my second print statement - where and how is $_ getting set? Is split setting it?

from perldoc -f split:
If EXPR is omitted, splits the $_ string. If PATTERN is also omitted, + splits on whitespace (after skipping any leading whitespace). Anyth +ing matching PATTERN is taken to be a delimiter separating the fields +. (Note that the delimiter may be longer than one character.)
EXPR is not omitted, PATTERN is not omitted - where is $_ coming from? Is there some documentation someone can point out that explains this behavior?
#!/usr/bin/perl use warnings; use strict; print "$_\n" for split ( "Hello World" ); print "$_\n" for split /\s+/, "Hello World";

UPDATE
OK I see in perlvar that for is setting it and split is not my culprit.
Here are the places where Perl will assume $_ even if you don't use it +: __snip__ - The default iterator variable in a foreach loop if no other variable + is supplied.
But why is for not setting it in the first print statement?

UPDATE #2
from the following looks like $_ is an empty hash?
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; print "\n\n"; print "\$_ = $_\n"; print "\n\n"; for ( 1 .. 10 ) { print "\$_ = $_\n" } print "\n\n"; print $_ for {}; print "\n\n"; print Dumper $_ for {}; print "\n\n"; my $count = 0; for ( sort keys %{ $_ } ) { print $count++, ":$_{$_} $_\n" };

Now Im really confused.
Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson

In reply to Re: Split ( ) is Giving Me a Splitting Headache by tcf03
in thread Split ( ) is Giving Me a Splitting Headache by HughBris

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.