undef is not a constant. If you say
$a = undef;
you are not doing what you intend.
undef works like an operator
undef $a;
and can be used with return
return undef;
and can be used in an assignment
$a = undef;
Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.
Quick
- ($a, $b....) = unpack("A2A7...", $packed)
- push( array, list )
Friday, January 21, 2011
Perl push/pop
NB that if you are using a Perl array as a stack, by pushing and popping with it, the top-of-stack item has the highest index, not index 0.
Wednesday, January 19, 2011
Perl character classes
\d \s \w and their inverses can be used in Perl regexp character classes.
Metacharacters in character classes are - ] \ ^ $
Metacharacters in character classes are - ] \ ^ $
Friday, January 14, 2011
Perl if
The postfix if (and unless, while, until) in Perl aren't operators but statement modifiers. So operator precedence is not a concern when they follow an expression.
Tuesday, January 11, 2011
Circuit analysis with diodes
(Non-PDF notes on http://www.ittc.ku.edu/~jstiles/312/handouts/The%20Ideal%20Diode%20Circuit%20Analysis%20Guide.pdf)
1. Guess the bias of each diode, ie assume forward or reverse bias (FB/RB)
2. 'Enforce' the assumptions by replacing
(a) FB diodes with a short circuit (0 ohm link) so that there is zero voltage drop across them
(b) RB diodes with an open circuit (break) so that there is zero current through them.
3. Determine the circuit values in the usual way, and use them to check the assumptions you made:
(a) A short circuit (FB) should have positive current flowing through it
(b) An open circuit (RB) should have negative voltage across its two ends.
NB to check for these conditions, not for the 'zero' conditions in point 2.
4. Any assumptions that aren't met should be reversed, and the process gone through again.
Then, because real diodes aren't ideal diodes and do have a voltage drop across them, adjust the analysis to take the drops into account.
1. Guess the bias of each diode, ie assume forward or reverse bias (FB/RB)
2. 'Enforce' the assumptions by replacing
(a) FB diodes with a short circuit (0 ohm link) so that there is zero voltage drop across them
(b) RB diodes with an open circuit (break) so that there is zero current through them.
3. Determine the circuit values in the usual way, and use them to check the assumptions you made:
(a) A short circuit (FB) should have positive current flowing through it
(b) An open circuit (RB) should have negative voltage across its two ends.
NB to check for these conditions, not for the 'zero' conditions in point 2.
4. Any assumptions that aren't met should be reversed, and the process gone through again.
Then, because real diodes aren't ideal diodes and do have a voltage drop across them, adjust the analysis to take the drops into account.
Friday, January 7, 2011
Win32 Perl
It appears to be SIGHUP that Perl gets when its console window is closed, and SIGINT when Ctrl-C is pressed.
This makes sense as 'SIGHUP is a signal sent to a process when its controlling terminal is closed' and 'SIGINT is the signal sent to a process by its controlling terminal when a user wishes to interrupt the process'.
This makes sense as 'SIGHUP is a signal sent to a process when its controlling terminal is closed' and 'SIGINT is the signal sent to a process by its controlling terminal when a user wishes to interrupt the process'.
Thursday, January 6, 2011
.NET timespan
NB that Timespans have a sign (because they are the result of subtracting one DateTime from another).
.NET time and date
If you parse a string that only contains a time into a DateTime, the result is that time on the current day. Eg '11:14' parsed on Jan 6 2011 => 20119601T1114.
If you parse a string that only contains a date into a DateTime, the result is midnight (0000) on that day. Eg '01/01/2011' => 20110101T0000. You also get this if you take the Date property of any DateTime.
The difference between two DateTimes (including one returned from .Date) obtained with '-' is a TimeSpan. Similarly, if you want to add to a datetime with '+', the addend must be a TimeSpan.
C# is extremely picky about these definitions, which is a pain, but at least the system is consistent once you understand it. You aren't guessing like with SQL.
If you parse a string that only contains a date into a DateTime, the result is midnight (0000) on that day. Eg '01/01/2011' => 20110101T0000. You also get this if you take the Date property of any DateTime.
The difference between two DateTimes (including one returned from .Date) obtained with '-' is a TimeSpan. Similarly, if you want to add to a datetime with '+', the addend must be a TimeSpan.
C# is extremely picky about these definitions, which is a pain, but at least the system is consistent once you understand it. You aren't guessing like with SQL.
C# case
switch (expression)
{
case constant-expression:
statement
jump-statement
[default:
statement
jump-statement]
}
jump-statement is either break, or goto case-label, where default is also an acceptable label. Eg 'goto case "x"'.
Fall-through from case to case is not allowed, except when you precede a case with any number of empty cases.
Subscribe to:
Comments (Atom)