Skip to content
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

[doc] perlsyn doesn't have any "push my ..." examples #22214

Closed
jidanni opened this issue May 14, 2024 · 10 comments
Closed

[doc] perlsyn doesn't have any "push my ..." examples #22214

jidanni opened this issue May 14, 2024 · 10 comments

Comments

@jidanni
Copy link
Member

jidanni commented May 14, 2024

$ perl -wle 'push my @z, 1..3; print for @z;'
1
2
3

Works great. Needs an example on perlsyn.

@Grinnz
Copy link
Contributor

Grinnz commented May 14, 2024

my @x can be used in almost any place @x can be used. It doesn't really need examples everywhere.

@jidanni
Copy link
Member Author

jidanni commented May 14, 2024

my @x can be used in almost any place @x can be used. It doesn't really need examples everywhere.

I wish the documentation would say just what you said too then. But it's never mentioned that either.

Anyway I've never seen anybody use the useage that I've presented. How did I figure it out? By accident!

@guest20
Copy link

guest20 commented May 14, 2024

You likely don't see it a lot because push my @thing,... is very similar to my @thing =... , since you're pushing into an empty array.

@jidanni
Copy link
Member Author

jidanni commented May 14, 2024

Well that is very well and good that most people can immediately tell that they're all the same. But for us other people, they're totally two different animals. And never having seen exactly even one example of my style, I think it would be high time to throw a few on some Man pages. Thanks.

@guest20
Copy link

guest20 commented May 14, 2024

Sorry? Just to clarify... Are you saying you've not ever seen push my @thing in any code?

@Leont
Copy link
Contributor

Leont commented May 15, 2024

And never having seen exactly even one example of my style

It's fine to have a personal style, but the docs are not the place to evangelize it. Especially when it is a lot easier to get this wrong than the obvious my @thing =... and push @thing, ....

@rwp0
Copy link
Contributor

rwp0 commented May 16, 2024

It is somewhat reminiscent of:

for my $item ( @items ) {
  ...
}

or:

chomp my $line = readline();

I also like this style and use it a lot, ie. defining/declaring/scoping variables in-place (rather than in a separate statement earlier).

I find it to be a lovely Perlism esp. where other languages lack this "shortcut".

@Leont
Copy link
Contributor

Leont commented May 16, 2024

I also like this style and use it a lot, ie. defining/declaring/scoping variables in-place (rather than in a separate statement earlier).

No one argued against declaring variables in-place per se, and in fact we have plenty of examples of that in our docs.

@jidanni
Copy link
Member Author

jidanni commented May 17, 2024

Maybe somewhere in the docs have a

Stick to the documented usage

You might have discovered different ways to write Perl expressions.

But we purposely don't document them. Please use the documented reliable syntax.

@guest20
Copy link

guest20 commented May 17, 2024

@jidanni The motto of perl is "There's more than one way to do it".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants