why not multiple statement modifiers?

I

ioneabu

Just curious, would it be possible for a future version of Perl to
support this sort of statement?

print for @a if $a;

or

print for @$_ if /^a/ while(<A>);

I imagine that a module could be written to do it:

multiples 'print for @a if $a'

where the multiples function would construct a function to execute the
statement properly. The problem is that it already looks ugly and the
implementation would probably be very difficult.

Is there a logic problem with allowing more than one statement
modifier?

Thanks!

wana
 
B

Brian McCauley

Just curious, would it be possible for a future version of Perl to
support this sort of statement?

print for @a if $a;

No.

It has been decided and it ain't gonna change. Very many people
(including myself) have said they want it but Larry Wall has put his
foot down on this.

Some people 'round 'ere (notably Uri) here claim that there are real
technical reasons to be found in the p5p mailing list archives. I've
looked and I can't find them.

All I can find are:

[1] Because you can't, so there!
[2] Because you could abuse it to produce unreadable code
[3] Because using for without an explicit loop variable is bad
[4] For well known reasons I won't repeat

You'll note that [1] and [4] are no sort of explaintion. [2] applies
to pretty much everyting in Perl. [3] is an argument against the
"for" statement modifier per-se, not an argument against being able to
chain statement modifiers. Let's not rake over this again.

The above is taken form a previous thread:

http://groups-beta.google.com/group/comp.lang.perl.misc/msg/c87ec3bf248e75e3

KILL THIS THREAD NOW!

Do not contribute to this thread unless you have something _new_ to say.
 
I

ioneabu

Brian said:
No.

It has been decided and it ain't gonna change. Very many people
(including myself) have said they want it but Larry Wall has put his
foot down on this.

Some people 'round 'ere (notably Uri) here claim that there are real
technical reasons to be found in the p5p mailing list archives. I've
looked and I can't find them.

Thanks! Sorry I didn't find the earlier post before asking. I
personally think it might lead to a more natural flow of certain
statements.

How often have people had to change:

dosomething() if $true;

to

if ($true)
{
dosomething() for @list;
}

or something similar that could have been done in a single statement if
multiple modifiers were allowed. I know it has happened to me a few
times. Like the Switch module, it might be interesting if it could be
implemented as a module just to show it can be done and might benefit
some people.

wana
 
B

Brian McCauley

How often have people had to change:

dosomething() if $true;

to

if ($true)
{
dosomething() for @list;
}

I'd say that if I consider hours spent actually cutting Perl code (as
opposed to total elapsed time) it would be every 2 to 10 hours.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top