shmem has asked for the wisdom of the Perl Monks concerning the following question:
I have been reading kyle's Context tutorial. Now I just wonder - how much of context is compile-time, how much run-time? Has that been discussed yet?
I ask because
perl -le 'my $f = 1; ($f > 0 ? @a : $a ) = ("a", "b", "c")' Assignment to both a list and a scalar at -e line 1, at EOF Execution of -e aborted due to compilation errors.
could be resolved at run-time, which isn't, because it barfs at compile-time. This works, however:
perl -le 'my $f = -1; ($f > 0 ? @a : @b ) = ("a", "b", "c"); print "a: + @a\nb: @b"' a: b: a b c perl -le 'my $f = 1; ($f > 0 ? @a : @b ) = ("a", "b", "c"); print "a: +@a\nb: @b"' a: a b c b:
update: diagnostics tells me that
Execution of -e aborted due to compilation errors (#1)(F) If you assign to a conditional operator, the 2nd and 3rd arguments
must either both be scalars or both be lists. Otherwise Perl won't
know which context to supply to the right side.
which looks like establishing the context for the RHS is a compile-time thing. Is there such a thing as runtime context resolving, at all?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Context: compile-time vs. run-time
by ikegami (Patriarch) on Jan 25, 2009 at 16:50 UTC | |
Re: Context: compile-time vs. run-time
by ikegami (Patriarch) on Jan 25, 2009 at 22:32 UTC | |
Re: Context: compile-time vs. run-time
by Anonymous Monk on Jan 25, 2009 at 16:17 UTC | |
by shmem (Chancellor) on Jan 25, 2009 at 19:22 UTC | |
by bart (Canon) on Jan 25, 2009 at 22:02 UTC | |
by Anonymous Monk on Jan 26, 2009 at 00:59 UTC | |
Re: Context: compile-time vs. run-time
by Anonymous Monk on Oct 20, 2010 at 14:06 UTC |
Back to
Seekers of Perl Wisdom