Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Sorry but 'last line is blank' doesnt wash..

by rchiav (Deacon)
on Sep 10, 2001 at 21:53 UTC ( [id://111521]=note: print w/replies, xml ) Need Help??


in reply to Sorry but 'last line is blank' doesnt wash..
in thread Getting data out of __DATA__ and __END__

Well I'm definately not at the wizard/god level, but I think I might know what's really going on. It's up to others to call it a bug or not.

I threw this in a debugger to see what exactly happens where. With this code..

my @ary=split(" ",$_) while (<DATA>); print "@ary"; __DATA__ These are words These are more words
I set a breakpoint upon reaching the suspect line. When it hits the line, the my variable @ary is created. It's empty. This is done before the evaluation of the expression. Unfortunately the debugger I was using won't show the reiteration of that line. But needless to say, when I stepped off that line, @ary was still empty.

Next, I used

my @ary; @ary=split(" ",$_) while (<DATA>); print "@ary"; __DATA__ These are words These are more words
I set the breakpoint on the my declaration. As before, when I hit that line, @ary was created. When I left the line, it contained the last line of text, each word in an array element.

What that information, here's my opinion:

Each time the line in question is accessed, @ary is redeclared (blank). This even happens when the line is executed just for <DATA> to return false. So the last iteration redeclares @ary, there's no more DATA and the program moves on.

Is that a bug? I'll let someone else answer that :)

Rich

Replies are listed 'Best First'.
Monks, I think we have a winner!
by demerphq (Chancellor) on Sep 10, 2001 at 22:17 UTC
    ++rchiav!!!

    Thats sounds like a damn good analysis to me.

    Each time the line in question is accessed, @ary is redeclared (blank). This even happens when the line is executed just for <DATA> to return false. So the last iteration redeclares @ary, there's no more DATA and the program moves on.

    I really have to get the debugger frame of mind happening, I almost never use it, preferring copious print statements and the like, but as you have done here it can work wonders.

    You might not consider yourself to be god/wizard level but I think this ones worth a bunch of votes. Good play sir!

    Yves
    --
    You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

Re: Re: Sorry but 'last line is blank' doesnt wash..
by George_Sherston (Vicar) on Sep 10, 2001 at 23:19 UTC
    Very interesting. Now /me understands. In fact this is a question of how my works rather than how $_ while works (I confess I am a very recent convert to use strict, so this is key for me to get to grips with). I understand both better now, and I must say, at the risk of sounding like a broken record, how inspired I am by how this thread (and many others) worked. It's not just a matter of having the right answers presented clearly, but of reading them in the context of a live problem. These are lessons I shan't forget - I hope it was educational for others too. Muchas gracias to all who posted.

    § George Sherston

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://111521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found