-
Notifications
You must be signed in to change notification settings - Fork 577
incompatibility of package-block and __DATA__ #22613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I do not see that warning when using |
I get
as expected. |
That is working as expected. The whole point of the |
@mauke that I know, I mentioned that in I also mentioned possible confusions and fact, that there is no alternative to attach |
I get that you might not like that aesthetically, but when is that a practical problem? |
@Leont bad wording, likely to confuse rest is only convenience - forcing inconsistent syntax across code base or, in case of |
On Fri, Sep 20, 2024 at 01:51:45AM -0700, Branislav Zahradník wrote:
When using package block syntax and `__DATA__` in single file, `__DATA__` doesn't belong to package
Example:
```perl
use strict;
use warnings;
package Foo;
print while <DATA>;
__DATA__
hello
world
```
Output
```
Name "Foo::DATA" used only once: possible typo at example.pl line 7.
readline() on unopened filehandle DATA at example.pl line 7.
That example doesn't produce the output shown. I'm guessing the example
was supposed to include a package block,
package Foo {
print while <DATA>;
}
which *does* produce the output you show.
Proposal:
a) support `__DATA__` inside package block (ie, it will be treated as `}` as well
Absolutely not. __DATA__ is currently straightforward and predictable. Why
on earth would you want to start including special-cased tricksy parsing?
Then you end up with a whole can of worms. What about nested packages,
possibly intermixed with other blocks?
b) treat insignificant content following `}` as content still belonging to the latest package block
Again, no, for the same reasons.
I can't see that this is a problem which needs fixing. The point of a
block-scoped package declaration is that at some point in the file, you
want to revert to the previous package. If you want the new package to be
in scope to the end of the file, including the __DATA__ token, then just
leave the block off.
…--
Wesley Crusher gets beaten up by his classmates for being a smarmy git,
and consequently has a go at making some friends of his own age for a
change.
-- Things That Never Happen in "Star Trek" #18
|
In addition, I'd like to note I feel |
@shlomif |
I wholeheartedly disagree. I use Main reason is that scripts with Here-docs are file for a single-use short piece of data, but when dealing with a list or longer data structures or text pieces to apply tests to (like: does this parse), here-docs only blur the code My € 2.00 |
Everything here is working as expected, and I don't think there's anything worth changing. If you need a block of data inside a scope, you can use a heredoc. |
@haarg I will repair your sentence: "Everything here is working as implemented", because this issue is about to change "as expected". |
No, I chose my words intentionally. Based on how these features work, doing something other that how they work right now would be very strange. |
Yeah I don’t see the issue here. The package is not in scope outside the block so the |
@ap issue is consistency of language. Currently you can have either Look at that from point of view of newbie in language used to |
There is no way to fix that (inasmuch as it even needs “fixing”). |
@ap as they say "never say never" - I put two proposal into issue Possible implementation of proposals: a) support DATA inside package block
current
new
b) treat insignificant content following } as content still belonging to the latest package blockI don't have exact implementation but idea:
|
Indeed, here's how one can tell Perl which package the
Output:
I think the above showed an example having both a
I don't know of other languages that have an equivalent of the |
removed as still out of point of issue - issue is not about how it works now, but how it should work better
re other language with re newbie (explained):
|
“Never” still applies. You didn’t put the features together, you proposed two possible ways to screw up the design of either one of them with some sort of craziness… just like I said. The whole point of And “let’s break the basic concept of how scopes work just for this one obscure super-special case” is not a serious proposal. Your list of languages is nice and handy here, go ahead and show me a construct in any of them where a scope consumes things that come after the end of the scope. You have a problem with the language because of a self-imposed stylistic preference. The solution is not to change the language but to fix your stylistic preference. |
Not a useful example. Ruby only has a single global
This is even more primitive. It just causes a constant |
doesn't what you say applies for combination of |
There's as many |
I admit I'm not native speaker but as this pair of sentences really so badly formulated ? |
Yes, if you write your multiple Perl code files in such a way that their So don’t do that. |
Since you can't stick a package Foo {
sub lines { <DATA> }
}
Foo::__DATA__
first line, index 0
second line, index 1 |
That is interesting idea as well. there is also possibility of new handle, eq |
On Mon, Apr 7, 2025 at 10:57 AM guest20 ***@***.***> wrote:
Since you can't stick a __DATA__ inside curlies, how about a namespaced
__DATA__ tokens?
package Foo {
sub lines { <DATA> }
}
Foo::__DATA__first line, index 0second line, index 1
—
Reply to this email directly, view it on GitHub
<#22613 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABMARDFI7CL5QZR4YW2JEXL2YKG6BAVCNFSM6AAAAABORSND42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBTGYZTINZUGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
[image: guest20]*guest20* left a comment (Perl/perl5#22613)
<#22613 (comment)>
Since you can't stick a __DATA__ inside curlies, how about a namespaced
__DATA__ tokens?
package Foo {
sub lines { <DATA> }
}
Foo::__DATA__first line, index 0second line, index 1
As noted earlier in the thread, this can already be done by prefixing the
line with `package Foo;`
…-Dan
|
Neither of these things are going to change, even if it means these two features don't usefully interact with each other. Something involving a lexical file handle would have to work significantly differently from |
@Grinnz that's a way better syntax for it than my suggestion ;) |
When using package block syntax and
__DATA__
in single file,__DATA__
doesn't belong to packagebut to the
main
.__DATA__
documentation states:Technically it is correct,
__DATA__
token is not specified inside package block (ie, package block prevents usage of__DATA__
)But with code like in example that may be misleading.
It may also harm adoption of syntax.
Example:
Output
All Perls v5.12 .. v5.40 are affected.
Proposal:
a) support
__DATA__
inside package block (ie, it will be treated as}
as wellb) treat insignificant content following
}
as content still belonging to the latest package blockThe text was updated successfully, but these errors were encountered: