Marco wrote:PeterH wrote:And another "by the way": nobody else uses this? It seems to have a lot of power

I used it just the other day for the first time. It is powerful indeed, I just need to get familiar with. I can see it basically allows you to create arrays, but in a "weird" way to my mind.
Anyway, here's my code: it creates a list of variables containing the dates DST begins and ends in Europe since 1999. Each variable contains, in its name, the year. I'm pretty sure this is not possible without the deference operator (even eval is useless)
Code: Select all
$annum = 1999;
while ($annum <= now("yyyy")) {
$begin = "$dst_b_"."$annum";
*$begin = "$annum-03-".(31 - ((floor((5 * $annum) / 4) + 4) % 7)); //when European DST begins, in ISO 8601 - https://en.wikipedia.org/wiki/European_Summer_Time#Exact_timing_for_the_next_several_years
$end = "$dst_e_"."$annum";
*$end = "$annum-10-".(31 - ((floor((5 * $annum) / 4) + 1) % 7)); //when European DST ends, in ISO 8601 - https://en.wikipedia.org/wiki/European_Summer_Time#Exact_timing_for_the_next_several_years
$annum++;
};
Hi Marco,
did you do this at will? If, by chance, you used a variable $dst_b_ before execution of
$begin = "$dst_b_"."$annum";
it will fail miserably. So you should change it to
$begin = '$dst_b_'."$annum";
Here it will be treated as a string - may it be defined or not.
And thats the reason for my additional request: if scripting would be expanded this way you could simply write
$begin = "dst_b_$annum";
When and how to use it - I'm just looking
Idea: I have 2 (or n) sets of variables, all ending on 1 or 2
I need a Subroutine to work on one or the other set.
Solution: a global var is set to 1 or 2 to define the set, all variables of both sets are global.
The subroutine constructs the names of all current variables dependent from the global number - and so can address just the wanted set.
In the moment I have 2 routines - one with names for set1, the other for set2.
I could have used one set for comunication with the subroutine, and fill it before each call. But I felt this was just too much code for every single call...