-
Notifications
You must be signed in to change notification settings - Fork 559
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
incompatibility of package-block and __DATA__ #22613
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. |
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: