in reply to Re^7: Ignore a range of numbers ina List
in thread Ignore a range of numbers ina List

Hi AnomalousMonk,

I'm actually running these tests on 5.14.4, and the syntax you've shown is exactly what I was after to shorten the loop:

for my $num (@$aref) { $flag = 1 if $num == 6; push $flag ? \@temp : \@result, $num; do {@temp = (); $flag = 0;} if $num == 7; } } push @result, @temp; print Dumper \@result;
This is working fine on the few data samples that I used.

I just did not think about using array refs instead of arrays to get the ternary operator to work in this context. Thank you, AnomalousMonk, for showing it, I've just learned something.

That said, the fact that I did not find the right syntax to do it with the ternary operator prompted me to use an array ref in another fashion (instead of a $flag) which is quite concise and, IMHO, relatively elegant.

Replies are listed 'Best First'.
Re^9: Ignore a range of numbers ina List
by AnomalousMonk (Archbishop) on Jun 26, 2017 at 22:18 UTC
    ... I've just learned something.

    Unfortunately, you've just learned something that is obsolete. I should have made it clear that this feature, added with Perl version 5.14, was removed with version 5.24. I've added an update to this effect to the previous node. Sorry for any inconvenience.


    Give a man a fish:  <%-{-{-{-<

      Well, you know, at $work, I'm stuck with version 5.10 on our aging AIX servers (but we are moving soon to a RHEL Linux) and even with version 5.8 on our VMS servers. That's one of the reasons I am not too keen to upgrade above 5.14 at home (on Cygwin), I wouldn't be able to use new functionalities when back at work anyway. In a way, I don't have trouble with obsolete features, it is more with modern features that I have issues. I can't even use "say" on my VMS server (unless I implement it myself, which I did in at least a couple of occasions).

      To tell the full truth, I also now have a quite nice bash under Windows at home (which got installed, I believe, together with Git or Github, not sure which one), including a fairly modern Perl 5.24 (it was even the most modern version at the time). So I can try many of the modern features such as Postfix Dereference Syntax, although it has, IMHO, an ugly syntax which I'll probably never be able to memorize, so I'll have to look up the documentation anytime I would want to use it.