Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Lady_Aleena

by Lady_Aleena (Priest)
on Apr 25, 2002 at 08:28 UTC ( [id://161890]=user: print w/replies, xml ) Need Help??

What I like about PerlMonks is the only expectation of me they have is I improve myself. To that end, PerlMonks go out of their way to give me the resources to do so. Also, I will more than likely be remembered most for the cookies I give out. :)

Over the years I have been here, most made me feel welcome here, but a few have made it plain my presence is very unwelcome. I hope to not push away those who have been friendly to me so far. I also hope that those who actively dislike me will soften their views after reading this, if they read it.

"I thought that once I get syntax OK, I would be out of the woods. That only makes the woods thicker when there is a problem." - by me

703rd Saint on 19 May 2017

Socialize with me

Goal

My programming goal is to completely rewrite my entire web site using Perl. This task is daunting as I have so many different ways I have to manipulate the data. I have gotten most of it figured out, though there are areas with which I am not quite happy.

The past

Coming from the world of markup languages into the world of programming languages was extremely daunting for me and still is upon occasion. Not knowing the right questions to ask, the correct terminology, or even what to put into searches made me feel very, very anxious. I am interested in what can be done in Perl. Until I get a grip on those areas where I am weak, would you please be extremely patient with me?

Annoyance caused me to state when my currant project was finished, you would never hear from me again. My feelings got hurt and my project was at a complete standstill when my temper got the best of me (which it does quite often when my feelings are hurt).

I had to see perl in a new light to get my project into motion again. When I wrote my first working module, I really got things going.

Coding history

A little less than a decade ago, I got 10 megabytes of complimentary web space from my internet service provider along with several e-mail addresses. Wanting to put my mark on the net, I created my first web page in Microsoft Word. Everything was going fine. My site got bigger and bigger, and Word even gave me frames. It was when I wanted to put some code on my site from somewhere else when the need to know how to write HTML caught up with me. No matter what I did in Word, the block would not go where I wanted it. I got the message, learn how to write a web page. Before that moment I did not care about the markup, I just wanted my pages to look pretty.

At first I found a site here and there which told me what all those things meant in between the < and >. With just the basics, I started to rewrite my site. I kept the frames and still did a lot wrong. I had depreciated tags everywhere. The amount of <font> tags was enough to make some throw their hands up in the air in exasperation. Not only did I have a lot of depreciated tags, I had tags unclosed. I just plain did not get it.

It took some very patient people talking me through my hysterics when something on my site did not work to finally get my site looking better and most areas working right. Then I ran out of space. I had filled my 10 megabytes rather quickly. Hysterics ensued. That is when someone casually mentioned CSS. When I saw what one line of CSS could do to cut my page size down, I nearly cried (or did I actually feel a tear?). Within weeks the size of my site was down by more than 75%. After that my whole coding philosophy became small is beautiful.

Let's pause for a moment. At the time the only browser on my computer was Internet Explorer. I was still a very lazy writer, so some of my HTML was browser specific. I was not writing for the masses, just those who were using IE. Then along came Firefox becoming the cause for a fresh bought of hysterics. I still have a few cross browser issues, but they are not critical.

The main issue causing my headaches was my frames looked bad in Firefox. So, I had to find another way of making my pages look and act the same without frames. Then I was introduced to <divs>s and in CSS scrolling. The problem with getting rid of the frames was I would have to put the same stuff on all of the pages, making them bigger. I did not want that. Then I was introduced to Server Side Includes. It was a miracle to me. I could put all kinds of stuff into one file and have it read by another. So slowly and up until six years ago, I had been altering all of my pages to have SSI.

I was talking to several people here on PerlMonks. When I told them that I was using SSI to add markup to my pages, I was told Perl could do the same thing. I was wondering, would Perl be smaller than SSI; and the answer is a resounding YES!

The present

I still have a lot of hurdles to overcome before I get anywhere near good at Perl. I have been told that I have come a long way from when I started here; yet with the amount that I have left to learn, it seems that I am still at the beginning. I am getting better at reading the perldocs and finding modules that may work for me. I have also developed a few peeves which may or may not stick with me as I learn more.

Have a cookie for making it this far into my node! I am impressed with your resilience! I tend to babble when given the chance. Have another if you intend to continue reading. :)

Web frameworks

Lately some have been suggesting strongly that I use one of the more popular perl web frameworks like Mojolicious or Dancer2. They seem to be good suggestions. However, I went and looked at their tutorials and got lost on the very first bit of code they both showed and did not understand what they were doing.

Mojolicious Dancer2
#!/usr/bin/env perl use Mojolicious::Lite; get '/' => sub { my $c = shift; $c->render(text => 'Hello World!'); }; app->start;
#!/usr/bin/env perl use Dancer2; get '/' => sub { return 'Hello World!'; }; start;

Neither started off with HTML as I expected web frameworks to do. I expected the first line to be print "Content-Type: text/html; charset=utf-8 \n\n"; or <!DOCTYPE html>. If I am to convert my code over to Mojolicious or Dancer2 code, I need to see HTML at the top. My code produces HTML, I do not know what their code is doing, but it is not HTML as I expected. Also, neither state whether or not they support HTML5, which I happily use.

I have not gotten my head around some of the most basic modules normally used by perl programmers. The two more commons ones that I do not use because I have not figured them out are File::Find and Text::CSV. So, do you really think that someone who does not know how to use File::Find and Text::CSV is ready for Mojolicious or Dancer2? I am still using hand rolled code to get a list of files that should be done with File::Find and making hashes with hand rolled code instead of Text::CSV. (My make_hash subroutine is disliked by most.)

So, when you need a list of files, you type furiously for a minute in a wanted subroutine for File::Find, get the list of files you want, and have them processed all while I am still listing the files to see if my first conditional is working. When you have a separated values file you want to make a hash out of, you type a minute using Text::CSV and have a hash that you have processed while I am rereading the module POD again.

It may seem to flatter me that some of you believe that I am ready for the bigger concepts, but it is a reminder of just how little I know. I have a lot that is hand rolled where I should have used more popular (common) modules, but those modules are over my head still.

Recently, I looked at Text::CSV again and still could not write working code with it. I am also cargo culting code to get File::Find work in one place.

I will not ask for help to convert my site to either of those frameworks because you have families, jobs, and lives outside of PerlMonks. Converting my code to either of those frameworks would take a deep dive into my code and that would take days or even weeks. You have your own work to do that is more important than my little website. Just know that both frameworks, from the start, overwhelm me with concepts I have never seen before. I am not ready for them and do not know if I will ever be ready for them.

It takes me, sometimes, up to a dozen runs of a list to get a grep or map written correctly. I cargo cult when I use File::Find. I have not figured out Text::CSV. I do not know when or how to write object oriented code.

Objects

I have read and searched and read again about them, but they still do not make sense to me. I would need to see them in action with some code that I have already written to maybe get a grip on them. There are no promises on that score; ikegami, GrandFather, and others have tried to show me without it sinking in how they work. Because of my frustration with the topic, I am beginning to dislike almost everything to do with objects, even eschewing object oriented modules. I would rather write my own function then wrestle with an object to make it behave.

Update 1: I am giving them another try again. I hope this time that how to write them sinks in.

Update 2: They have confounded me again! I do not get it!

Update 3: I gave it yet another try, nothing. I still do not understand what is so wonderful about objects. So after Why won't a hash in a hash work as a hash reference to create an object?, RFC on how I'm doing when it comes to writing objects?, and How do I go from procedural to object oriented programming?; I give up. If one day my code morphs into objects on their own, I won't know it. To me objects are just a pain the a** especially since everyone tells me to separate my data out of them. Well, I can not do that. My data stays where it is with the subroutines that use it.

Over-complication

I have been told that I have a knack for this. There are times when reinventing the wheel is a good thing. For example, I was going to use DateTime to get the current week of the year when all I had to do was int($day_of_year / 7). Sure DateTime has something like that, but why go through all the trouble of setting it up, when something else much simpler is already around?

So called templates

I am sorry, but I can't see how any of these so called template modules really create a template that will fill in everything that I need them to fill in. HTML::Template appears to do only very basic stuff, but since I use so many conditionals and list iterations and loops, it won't work. Template Toolkit doesn't even look like perl, so I will stay as far away from that mess as possible. I don't need to get all mixed up right now. Printing the titles of my pages based on a slew of conditions seems beyond their capabilities, so how could I get them to print my site's menu and the right list of style sheets?

/*SQL*/ databases

Almost everyone I talk to here and elsewhere gets on my case about using a text based database system, with the directory structure being a part of it, over a SQL related database. I have tried to explain that I do not have access to either MySQL or SQLite on the server where my main site is, Xecu.net. When they tell me to move to somewhere that has either, I also try to explain that moving would mean a lot of trakking through the net trying to find everywhere I have a link to my site and changing the link. This is a lot of work.

I made attempts to check to see whether or not MySQL or SQLite was available to me on Xecu.net by trying to create a database at the command line. The results follow.

MySQL test...

/users/fantasy>mysql db_name ERROR 2002 (HY000): Can't connect to local MySQL server through socket + '/tmp/mysql.sock' (2)

SQLite test...

/users/fantasy>sqlite3 test.db sqlite3: Command not found.

The above tells me that they are not available, so I had to find an alternative, which I did in separated values files. I would have to have a database and the access and editing s‎crip‎ts for that database to test, but since I can't make a /*SQL*/ database, I can't play with the concept either.

The last problem with /*SQL*/ databases is that they are binary, meaning I would not be able to edit them in my text editor. If I can't get a decent front end up for my text based databases, I would be horribly disadvantaged with a binary one. I would have to keep all the text around somewhere to edit in my text editor just to stuff that text into the binary database. So, I will use what I have available to make databases.

I would like this to be the last time I have to defend my use of separated values. I try to stay away from the database topic as much as possible these days whenever it comes up.

Version control

There are two schools of thought for this one. A few seem to feel that I will crash and burn without it; while others say that since I am working alone, I don't need it. I have looked around and haven't found anything to my liking. There is the whole concept of storing all of the changes to my files that really is not appealing to me. There is also the lack of automation, where the changes are stored whenever I save in my favorite text editor. I spoke to a few of its developers who seemed interested but nothing came of it. Maybe once its integrated into my text editor and automatic, I will give version control a whirl.

Take a break

Wow! You read it all! The rest is just tools I use to write perl. Have a plate of cookies!

Toolbox

Coding Toolbox

  • What I have:
    • Unlimited web space
    • Markup
      • HTML
      • CSS
      • SSI
    • S‎crip‎ting
      • perl
        • 5.28.1 (local)
        • 5.16.3 (web host with #!/usr/bin/perl shebang [preferred shebang])
        • 5.30.0 (web host with #!usr/local/cpanel/3rdparty/bin/perl shebang)
      • javas‎crip‎t
    • Programs
      • geany
      • Filezilla
      • Firefox
  • What I don't have or understand:
    • PHP
    • ASP
    • MySQL
    • SQLite

Quote

"A man's knowledge is like an expanding sphere, the surface corresponding the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all." - L. Sprague de Camp

Geek Code

-----BEGIN GEEK CODE BLOCK----- Version: 3.1 G! d- s+:+ a+ C++ UL>++++>$ P++>$ W++>$ N !o !K w M-- PS+ PE Y+ t+(---) 5++ X+ R+++ tv+(--) b++ D- G e h- r++ x+ ------END GEEK CODE BLOCK------

Last edited and updated: 2020-05-26


Posts by Lady_Aleena
Coming up with good examples in POD in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 25, 2020 at 15:02

    I have been writing POD for some of my modules, and one of the harder aspects of writing POD is coming up with good examples in the synopsis. I came up with, what I think is, a good example for numerical use; but I am stuck on coming up with a good example for the alpha use of the following sub.

    The sub splits the values of the list into two parts, sorting by the first part, then sorting by the second part.

    Please note, I do not know why I wrote this, since I am not using it anywhere in my code. I even searched my history here to see if I brought it up before and can not find anything, which is strange because most of what I write ends up here at some point.

    I just can not come up with a list where this might be needed on alphabetical strings.

    Comments on the code are always welcome.

    Edit: I have a feeling I added the usage for alphabetical strings for completeness, nothing more. I have tried coming up with lists of alphabetical strings that would change if this is used and have not found any. I am now thinking that I should just put a note in saying that the alphabetical usage is redundant.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Unparent tangents? in Perl Monks Discussion
4 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 15, 2020 at 11:02

    Hello everyone. Is it possible to unparent tangents in threads? In the conversation of Expression form of map or grep, I answered a question as to why I cared about the number of lines. I replied here, and that created a tangent. Is it possible to unparent my reply and its replies into a new thread, maybe titled "I do not like scrolling" or something? It would be to keep the focus on the map/grep topic and let the new topic be its own thread.

    In my mind, tangents could confuse some newer users.

    I know this may be a bad thought or too much of a bother, but I would like to know. Please?

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Expression form of map or grep in Meditations
7 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 10, 2020 at 15:47

    As you might know, I have been using Perl::Critic on my code over the last several days. After I finished checking my code on the gentle setting, I kicked it up a notch and used stern. Well, Perl::Critic set on stern gave me screens full of problems, and the biggest one is I use the expression form of map and grep. I looked around the web to find out why.

    Here is my opinion that could be very wrong.

    All of the examples I found of the expression form of map and grep would lead to inevitable problems, and I can see why the writers of those examples would jump on using the block form for both. However, the one thing all of the examples had in common is the disuse of parentheses. I feel that if the expression form of a map or grep is used with parentheses, it is contained within them.

    The map below would lead to problems, since there is nothing containing the expression or on which list(s) the map is being applied.

    my @colors = qw(red yellow green cyan blue magenta); my @grey_scale = qw(white grey black); my @list = map "$_ beads", @colors, @grey_scale;

    However, I do not think this needs a block form to contain the map and list if parentheses are used.

    my @list = map( "$_ beads", @colors ), @grey_scale;

    Now the map is contained within parentheses, and @grey_scale does not get beads mapped to it. However, if one must use the block form, parentheses would still be needed to contain the mapped items.

    my @list = ( map { "$_ beads" } @colors ), @grey_scale;

    I think the expression form with parentheses is easier on the eyes, but it is just my opinion. I can understand using the block form if the map were more complex, however, I think I would write a separate subroutine instead of loading the block with more than two or three modifications and use the expression form.

    Converting from expression to block form is also problematic as it is not always as simple as the above would suggest, especially with grep. I have also found the expression form of grep to be easier to use, in one case (I can not remember the specifics) I could not get the block form of grep to work.

    If I use sort with map and/or grep on the same list, I will wrestle the block forms until I get the results I want, because in that case, it is easier on my eyes than trying to mix expression forms with the block of sort.

    I know I can ignore Perl::Critic's results on this and other issues, however, I do want code that is more acceptable by the community. So, I am trying to decide if I want to start wrestling with Perl on this or not. (I ran Perl::Critic on all of my modules, and it found 330 lines where I used the expression forms of map and grep, so this is fairly big to me.)

    I hope I am not too wrong about this.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Perl::Critic says don't modify $_ in list functions and other things in Seekers of Perl Wisdom
9 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 08, 2020 at 21:29

    Hello all. I have been playing around with Per::Critic on the command line and found to my dismay that some of my modules do not pass gentle. I realize that I can ignore the recommendations of Perl critic, but I would love for my modules to pass "gentle" before I begin ignoring things.

    The most common issue is that I modify $_ in list functions. The following is a convenient and short one liner to put the lines of files into a list. I thought doing it this way was nice and slim.

    my @list = map { chomp($_); $_ } <$fh>; my @uc_list = map { chomp $_; [uc $_] } <$lc_fh>; # used only onc +e my @split_list = map { chomp $_; [ split(/\|/, $_) ] } <$piped_fh>; +# used only once

    In one subroutine, I have this three times.

    Also, my idify subroutine is just modifying $_.

    And my Fancy::Map modifies $_ too.

    If this is something ignored usually, I will ignore it, but I would like to know how to make it better. Should I just assign $_ to a variable and then use the variable?

    Another thing that I am confused by is why the expression form of eval is discouraged?

    The rest of the gentle issues are me being lazy with conditionals. While writing I was thinking my $var = "foo" if 'some condition', but Perl critic does not like it, but it is fixed easily.

    NOTE: Please see my update. Most are fixed, but the eval problem remains.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Where to put data that goes with a module? in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 02, 2020 at 00:21

    I have been documenting my Random modules in a readme for GitHub when I came across some that have external data. Two of them have text files that I open, chomp, and make into an array; nothing special. However, the data for those two are in my general data directory. If I people want to use these modules (and if I ever get them properly written), I will need to put the data closer to them. Now, I just don't know where to put them. (The other modules with external data need hashes made, and that is a bigger problem.)

    You might be wondering why I did not put the data directly into the module. It is because two of the lists are over 100 items long and the other two are over 10 with longer strings.

    I am also looking to move these Random modules away from using any of my Util modules. My Util modules are messes and for my personal use. (So many PODs to update with their dependencies, hopefully without using any of those Util modules one day.)

    I know it may be a matter of taste, but where you would put data files relative to the module that uses them?

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Collapsing smaller scripts into a larger one, request for comment in Seekers of Perl Wisdom
6 direct replies — Read more / Contribute
by Lady_Aleena
on May 29, 2020 at 13:35

    I have been trying to decide for weeks whether or not I want to collapse most of my individual page-scripts (scripts that act like web pages) into their indexes and use a touch of CGI:Minimal to switch the text on a click. Below are the page-scripts for my Collections where you can see how similar they are above the __DATA__.

    Link to all of the Collections; links to the modules: Base::Page (page and story), Util::StoryMagic, Util::StoryMagic::Collection.

    index.pl
    Fiction.pl
    Movies.pl
    Music_and_comedy.pl
    Programs.pl
    Tie-ins.pl

    With the above being so similar, I can collapse them into one umbrella script that is below.

    (file_directory and file_list are in Util::Data in the above and in the sub below.)

    The above script works as expected, but I would not be posting here if there were not a problem. The problem is my site's menu is built by recursing through the directory structure of my site and uses the files and directories it finds to make the menu. If I were to collapse the 155 page-scripts into the 25 index scripts, I would lose the links to the topics those separate page-scripts now have. I did something very close to this a while ago, and I have not liked that the directory does not have entries for each topic. That directory may not get any traffic because it appears that there is nothing much there.

    Side note, I did not realize I had so many page-scripts.

    I use my base_menu sub (below) to make the menu for my site and would like to know how you would populate the directories that have only one file in them. With base_menu, all I have to do is add a page-script and refresh, and the menu is updated. Without those page-scripts, the menu will be almost empty.

    (base_menu is in Util::Menu, name_sort and article_sort are in Util::Sort, textify is in Util::Convert.)

    So, why did I post this? I would like to know if this way appears better? I also need ideas on how to collapse these page-scripts into their indexes without losing the automatic addition to the menu that I have now. There are a few scripts that do not use story, and those are the hardest to figure out how to add to the menu since they will not have a text file to go with it.

    Thank you for reading this latest bit of my craziness.

    There is an update below.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

    Version control is a non-issue, I do not use it.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Adding details with summary html tags in Perl Monks Discussion
4 direct replies — Read more / Contribute
by Lady_Aleena
on May 22, 2020 at 14:23

    I was wondering if <details> with <summary> could be added as acceptable html here in PerlMonks. Those tags could be used when code or data examples are more than 10 or so lines. <readmore> is great for keeping long batches of code or data from the main list of posts, however, long batches of code might do well if kept in a <details> tag where the code or data can be hidden to keep page lengths from being over long upon initial load. So what do you all think?

    My OS is Debian 10 (Buster); my perl version is 5.28.1.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
How do I get an exclusion with grep? in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Lady_Aleena
on Apr 26, 2020 at 23:17

    I am trying to exclude certain items with grep, however, my exclusion is not working.

    My OS is Debian 10 (Buster); my perl version is 5.28.1.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Get code ready for a loop (and a little RFC) in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Lady_Aleena
on Mar 13, 2020 at 02:03

    Hello everyone!

    The code posted works as I expected, and I am pleased with it generally The following scripts are for generating SVGs with SVG.

    What I am working towards is looping lines 47 through 154 in the first script to put between lines 80 and 82 in the second script, which is a lot of lines in a loop. I know that long loop blocks may be fine, but I am just wondering if there is anything in the code that I could make more concise to make the loop shorter (on the page). So, is there anything that I made too long that can be made shorter?

    Also, if you have any "How come?" or "Why?" questions about how I wrote the code in general, please ask.

    After I get the code from script 1 all nice and loopy and into script 2, I will begin working on the rectangles for the people in the family tree. Then I will make that loopy.

    I've missed you guys! So thank you to everyone who stops by and read this.

    Update: (18 March 2020) The code above was put into a subroutne from the suggestions below and is now all nice and loopy. The code's output is what was expected.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Refactoring just to refactor? in Meditations
8 direct replies — Read more / Contribute
by Lady_Aleena
on Jun 27, 2019 at 20:25

    Hello everyone.

    I wrote the following subroutine recently using map and grep in the BLOCK LIST style. Line 4 had gotten long, so as you can see, I put the map, grep, and sort on separate lines. After doing that and seeing how good it looked, I began thinking about all the times I used map and grep in the EXPR, LIST format and that I may want to rewrite all of them.

    Most, if not all, other people I have chatted with over my years here use the BLOCK LIST format instead of the EXPR, LIST format. I stubbornly stuck with the EXPR, LIST format. Now I am not sure if I am thinking of refactoring to use the format is normally used or if this is refactoring just to refactor. So, I am on the fence on whether or not I should do it.

    What do you think?

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2024-04-19 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found