A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android

Image
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...

perl learning : read xml to hash table


#get node tag of a nodestring like <%TAG% ... >
#in param: the nodestring
#return value: the tag : %TAG%
sub GetNodeTag
{
my ($NodeString) = @_;
$NodeString =~ m/</s*//(/w+)/s*>/ or $NodeString =~ m/</s*(/w+).*?>/;
return $1;
}

#get the attributes of a node that description by a string like
#in param1: the nodestring
#in param2: a array to store the names and values of the attributes
#in the array: name1, value1, name2, value2, name3, value3,...
sub GetAtribList
{
my ($nodestring, $atribarray) = @_;
@$atribarray = $nodestring =~ m/(/w+)/s*=/s*/"(/w*?)/"/g;
}

#push the attributes of a node into a hash that reprent the node
#in param1: the nodestring
#in param2: the hash that will reprent the node
sub pushattributes
{
my ($nodestring, $hash) = @_;
my @tsarray = ();
GetAtribList($nodestring, /@tsarray);
if (@tsarray)
 {
for (my $j = 0; $j < @tsarray;)
{
my $key = @tsarray[$j];
my $value = @tsarray[$j+1];
$$hash{$key} = $value; $j += 2;
}
}
}

#push a couple of key and value to a hash
#in param1: the key
#in param2: the value
#in param3: the hash
sub pushhash
{
my ($key, $value, $hash) = @_;
if ($hash =~ /^HASH/)
{
if (exists $$hash{$key})
{
$ekvalue = $$hash{$key};
if ($ekvalue =~ /^ARRAY/)
{
my @array=@{$ekvalue};
my $index = @array;
$$hash{$key}[$index] = $value;
}
else
{
my @tparray = ();
push (@tparray, $ekvalue);
push (@tparray, $value);
$$hash{$key}=[@tparray];
}
}
else
{
$$hash{$key} = $value;
}
}
}

#generate a xml dom hash by a nodearray that contained the nodestring of the xml file
#in param1: the nodearray that contained all the nodestring in the xml file <...>
#in param2: the begin pos to generate the xml dom hash in the nodearray
#in param3: the end pos to generate the xml dom hash in the nodearray
#in param4: the hash
sub GenerateXMLDom
{
my ($nodearray, $begin, $length, $root)=@_;
for (my $i=$begin; $i<$begin + $length; )
{
$temp = $$nodearray[$i];
my ($nodetag) = GetNodeTag($temp);
if ($temp =~ m////s*>/) #single node
{
my %tshash1 = ();
pushattributes($temp, /%tshash1);
pushhash($nodetag, /%tshash1, $root); $i++; next;
}
elsif ($temp =~ m/</s*///) #end of complex node
{
$i++;
next;
}
else #complex node
{
my %tshash2 = ();
pushattributes($temp, /%tshash2);
my $headnum = 1;
my $endnum = 0;
my $start = $i;
while ($endnum != $headnum && $i < $begin + $length-1)
{
$i++;
my $nextnode = $$nodearray[$i];
if ($nextnode =~ m////s*>/) #single node
{
$headnum++;
$endnum++;
}
elsif ($nextnode =~ m/</s*///) #end of complex node
{
$endnum++;
}
else
{
$headnum++;
}
}

$i++;
my $len = $i - $start;
GenerateXMLDom(/@nodearray, $start+1, $len-2, /%tshash2);
pushhash($nodetag, /%tshash2, $root); next;
}
}
}

#my xml simple, to read a xml file into a hash
#in param: the xml file to read
#return value: the hash that contained the xml dom content
sub MyXMLSimple
{
my ($xmlfile) = @_;
open (INFILE, "$xmlfile") or die "can't open $xmlfile for reading $!";
while ($line=)
{
chomp $line;
$filecontent.=$line;
}
close INFILE;
#delete xml comment $filecontent =~ s///g;
#cut file context by <...>
@nodearray = $filecontent =~ m/<.*?>/g;
$length = @nodearray;
%rootnode = (); #the root node of the xml file
#construct the xml dom struct
GenerateXMLDom(/@nodearray, 0, $length, /%rootnode);
return %rootnode;
}

#test code
(%xmldoc) = MyXMLSimple("test.xml");

❤️ Support This Blog


If this post helped you, you can support my writing with a small donation. Thank you for reading.


Comments

Popular Posts

Fix “A problem occurred starting process 'command node'” in Android Studio for React Native

Fix up watchman issue with Ghost

Using Mutual TLS (mTLS) in Next.js (Server-Side Only)