in reply to Re^4: Perl : Split/Regex
in thread Perl : Split/Regex

Interesting! I'd checked using a numeric constant for the conditional and that works as I expected:

use strict; use warnings; my @streams; my @spaces; push ((0 ? @streams : @spaces), 0); push ((1 ? @streams : @spaces), 1); print "$]\n"; print "Streams: '@streams'\n"; print "Spaces: '@spaces'\n";

Prints:

5.016003 Streams: '1' Spaces: '0'

but anything other than a numeric constant fails as you describe. That'll teach me to test one thing then post another!

Perl is the programming world's equivalent of English

Replies are listed 'Best First'.
Re^6: Perl : Split/Regex
by AnomalousMonk (Archbishop) on Sep 04, 2014 at 02:22 UTC

    Huh?!? (closes mouth, wipes away drool, ponders...)   Oh, yeah: constant folding (if that's the right term).

    c:\@Work\Perl>perl -wMstrict -le "print $]; ;; my (@streams, @spaces); push ((0 ? @streams : @spaces), 'ZIT'); print qq{(@streams) (@spaces)}; push ((1 ? @streams : @spaces), 'ZOT'); print qq{(@streams) (@spaces)}; " 5.014004 () (ZIT) (ZOT) (ZIT) c:\@Work\Perl>perl -wMstrict -MO=Deparse,-p -le "print $]; ;; my (@streams, @spaces); push ((0 ? @streams : @spaces), 'ZIT'); print qq{(@streams) (@spaces)}; push ((1 ? @streams : @spaces), 'ZOT'); print qq{(@streams) (@spaces)}; " BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; print($]); my(@streams, @spaces); push(@spaces, 'ZIT'); print("(@streams) (@spaces)"); push(@streams, 'ZOT'); print("(@streams) (@spaces)"); -e syntax OK