c:\temp\colors.ps1
):
When executed with something like
It prints
c:\temp\colors.ps1
):
When executed with something like
It prints
Here's a simple module to demonstrate that
And here's a script that uses SomeModule
:
This script can call exp_one
and exp_two
from SomeModule
because these two functions are listed in @EXPORT
. Functions listed in @EXPORT
are by default exported into the user's namespace.
ok_one
, on the other hand, cannot be called directly as it is not listed in @EXPORT
. It can, however, be called so SomeModule::ok_one()
.
Here's another script:
Now, I specify the identifiers I want to have imported into my namespace (qw(ok_one ok_two)
). Accordingly, I can call these.
I cannot call exp_one (which I could call in the first script), because as soon as I begin specifying identifiers to be exported I need to specify all of them.
Of course, it will soon be tiresome to always indicate which functions I want to have imported. Therefore, I can define tags with the %EXPORT_TAGS
hash that groups multiple identifiers under a tag. For example, the tag all imports all functions. In my case, I just used the combined values of @EXPORT
and @EXPORT_OK
. This is demonstrated with the third script:
Lastly, I can import some functions, too:
Ususally, the cause for this error is that someone is granted access to a table via a role rather than directly. So, the user can select from that_table
but as soon as he uses the statement in a compiled PL/SQL source, it won't work anymore, erroring out with this ORA-00942
.
I can demonstrate this easily: First, a fresh user is created and given a few privileges:
select_catalog_role
so he can do
This procedure won't compile for the reasons outlined in the beginning of this post:
So, what to do? For such reasons, I have created the IPC PL/SQL package. The package's function exec_plsql_in_other_session
uses dbms_job
to create another session that can make full use of the granted privileges and also uses dbms_pipe
to return a value to the caller.
Of course, I need to grant the required privileges also:
After installing the packages, I can rewrite my function like so:
Now, I can use the function to report some memory figures
Under some special circumstances, it prints
Of course, this is impossible if PL/SQL were executing correctly. Either guid_ is null
or it has a value. Since the if statement executes the dbms_output
line, I should assume that guid_
is indeed null. Yet, a value for guid_
is printed.
This behaviour can be reproduced, at least on Oracle 11R2, with the following code:
I have also asked a question on stackoverflow.
K-NN can be used to classify sets of data when the algorithm is fed with some examples of classifications.
In order to demonstrate that, I have written a perl script. The script creates two csv files (known.csv
and
unknown
) and a third file: correct.txt
. The k-NN algorithm will use known.csv
to
train its understanding of a classification. Then, it tries to guess a classification for each record in unknown.csv
.
For comparing purposes, correct.txt
contains the classification for each record in unknown.csv
.
known.csv
known.csv
is a csv file in which each record consists of 11 numbers. The first number is the classifaction for the record. It is a integer between 1 and 4 inclusively. The remaining 10 numbers are floats between 0 and 1.
unknown.csv
unknown.csv
, each record consists of 10 floats between 0 and 1. They correspond to the remaining 10 numbers in
known.csv
. The classification for the records in unkown.csv
is missing in the file - it is the task of
the k-NN algorithm to determine this classification. However, for each record in unknown.csv
, the correct classification
is found in correct.txt
To make things a bit more complicated, two random values in the range [0,1] are added to the eight values resulting in 10 values. These two values can either be at the beginning, at the end or one at the beginning and the other at the end.
Number
object has the toFixed
method that allows display a number with a fixed amount of digits after the decimal point. Unfortunately, it doesn't round the number.