Some variables in SQL-Ledger code

by Armaghan Saqib, Thursday, December 15, 2022, 00:25 (495 days ago)

There are two variables which you will see every where in SQL-Ledger code. These are:


This section is explanation of both these variables.


by Armaghan Saqib, Thursday, December 15, 2022, 00:27 (495 days ago) @ Armaghan Saqib
edited by Armaghan Saqib, Thursday, December 15, 2022, 00:46

When you add new users in sql-ledger using (or through HR--Employees--Add Employee), it is added to the 'users/members' text file. This 'members' file is a text file which stores information in key/value pairs with username as the section name.

Here is one such section:

company=UK DEMO
dboptions=set DateStyle to 'POSTGRES, US'
[email protected]

When this user logs in into sql-ledger, a conf file named after this user is created in the users folder in Perl syntax (actually, a hash variable named %myconfig) and then included in the perl code. For example in this example '[email protected]' will be created and executed whenever you will login or access any sql-ledger function.

Within the sql-ledger Perl code, you can access user configuration from this user hash variable using standard syntax. So $myconfig{dbname} will return the current database name and $myconfig{company} will return the company name.

This Perl hash is also passed from executable scripts to modules (in SL folder) as a reference as part of parameters list. So in modules you access this using hash reference syntax. This means that now $myconfig->{dbname} will return the current database name.


1. Open users/members and see what is in it.
2. Open any conf file in users/ folder and see how user information is stored there.


by Armaghan Saqib, Thursday, December 15, 2022, 00:45 (495 days ago) @ Armaghan Saqib
edited by Armaghan Saqib, Friday, December 23, 2022, 11:45

$form is a hash reference which contains the data sent by user through GET or POST http requests (whenever Save, Delete, Post buttons on forms are pressed). So, for example, if you had the following field in your form:

<input type=text name=firstname size=10 value="Armaghan Saqib">

You can access it with $form->{firstname} in your Perl code once that form is submitted.

It is also used as a global variable to store data temporarily read from database as needed. This makes it convenient to pass data around different 'subs' or modules.

$form is created in SL/'s 'sub new' and also converted into an object with 'bless' statement in the 'sub new'. This means that the functions and procedures in the SL/ can be used as properties and methods on the $form hash.

For example, you can format a number into the user specified number format with following code:

my $formatted_number = $form->($myconfig, 19290, 2);

And $formatted_number will contain "19,290.00".


Please open SL/ and go through all the subs to see what it has to offer.

RSS Feed of thread