Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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
Can not link to "id" in shortcuts in Perl Monks Discussion
2 direct replies — Read more / Contribute
by Lady_Aleena
on May 31, 2017 at 22:30

    I just tried to create a link to part of my scratchpad where I placed an id=. I tried [id://637756#laundry|my pad]. It did not munge. I just got [id://637756#laundry|my pad]. I would really like to link to tags with ids. For example, if I give an id to a section of my home node, I can link to just that section. Pretty please?

    Update: It looks like I can not add ids to the html elements. They do not make it to display. 8(

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Finding what modules use and what uses the modules in Seekers of Perl Wisdom
6 direct replies — Read more / Contribute
by Lady_Aleena
on May 26, 2017 at 21:16

    As some of you know, I'm doing an audit of my code. Part of that audit is finding what modules my modules use and what modules I have written are used by other modules I have written. If I ever get things nice enough in some of my modules, I might one day put a few up on CPAN. However, I need to know what modules my modules use so I can include them in the install if the user does not already have. Like, if I use Lingua::EN::Inflect in a module (or group of modules), it would need to be installed if the user does not have it already. At least I think so.

    I came up with the following code to find the information but there might be a better way.

    Update: I put the updated code I used here: Re: Finding what modules use and what uses the modules. Your options looked interesting but did not differentiate things the way I wanted.

    #!/usr/bin/perl use strict; use warnings; use File::Find; my @files; sub wanted { my $file = $_ =~/.pm$/ ? $File::Find::name : undef; push @files, $file if $file; } my @directories = ('/home/me/Documents/'); find(\&wanted, @directories); my $module_directory = $directories[0].'www/files/lib/'; my $modules; for my $file (@files) { open my $fh, '<', $file or die "$file: $!"; my $file_convert = $file; $file_convert =~ s/$module_directory(.+)\.pm/$1/; $file_convert =~ s/\//::/g; while (<$fh>) { chomp; if ($_ =~ s/^use ((:|\w)+)(.+)/$1/) { push @{$modules->{$file_convert}{'uses'}}, $1; # what modules + the module uses push @{$modules->{$1}{'used by'}}, $file_convert; # what modules + use this module } } } my $in = shift; use Data::Dumper; print Dumper($modules->{$in});

    Here is example output.

    me@office:~$ perl Documents/scripts/find_module_use.pl 'RolePlaying::R +andom' $VAR1 = { 'used by' => [ 'RolePlaying::CharacterMutation', 'RolePlaying::Random::Range', 'RolePlaying::Random::Time', 'RolePlaying::Random::SpecialAttack', 'RolePlaying::Random::Title', 'RolePlaying::Random::WildPsionics', 'RolePlaying::Random::Descriptor', 'RolePlaying::Random::Spell', 'RolePlaying::Random::SavingThrow', 'RolePlaying::Random::Color', 'RolePlaying::Random::Monster', 'RolePlaying::Random::GemMetalJewelry', 'RolePlaying::Random::Thing', 'RolePlaying::Random::Weapon', 'RolePlaying::Random::Size', 'RolePlaying::Random::Food', 'RolePlaying::Random::Misc', 'RolePlaying::Random::Event', 'RolePlaying::Random::Water', 'RolePlaying::Random::Class', 'RolePlaying::Random::MagicItem', 'RolePlaying::Random::Color::VisiBone', 'RolePlaying::Random::Body::Function', 'RolePlaying::Random::Body::Modification' ], 'uses' => [ 'strict', 'warnings', 'Exporter', 'List::Util' ] };

    If you know of a better way that will give me deeper or more sophisticated results, I am interested.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Can figure out a way to get File::Grep's fgrep to chomp matches in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Lady_Aleena
on May 13, 2017 at 19:36

    Hello. I've been stuck for over an hour now. I can't figure out how to get File::Grep's fgrep to return chomped values in its matches. I've tried chomping $file, chomping $_ in the fgrep, and more. Am I using it wrong, not understand something in the module description, or just plain out of luck and have to munge the values of matches later?

    #!/usr/bin/perl use strict; use warnings; use File::Grep qw(fgrep); use Data::Dumper; my @line = fgrep { /^[2-6] .+$/ } *DATA; print Dumper(\@line); __DATA__ 2 foo 3 bar 4 baz 5 qux 6 quux 7 thingy 8 widget

    The output is

    $VAR1 = [ { 'filename' => *::DATA, 'count' => 5, 'matches' => { '1' => '2 foo ', '2' => '3 bar ', '3' => '4 baz ', '4' => '5 qux ', '5' => '6 quux ' } } ];

    I'm at the end of my abilities.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Confession of a hard headed Monk in Meditations
2 direct replies — Read more / Contribute
by Lady_Aleena
on May 05, 2017 at 23:43

    Over the last few days, I've been doing a project that is forcing me take a new harder look at everything I've written: code and markup. One of the items which came up in my audit was a little subroutine which takes a number (usually scalar(@list)) and returns how many columns the list would be in according to exponential calculations. The default behavior of this subroutine is to return a word number not an integer. When I looked at it again, a voice in the back of my head told me the subroutine should return the integer by default because integers are more useful. I also had the sinking feeling someone here probably pointed that out to me, and I ignored it. I wanted what I wanted, and no one was going to make me change my mind at the time. I had to change my own mind and pay the price for it later.

    So, this is my confession. I am a doofus. I am hard headed and obstinate when it comes to attaining my short term goals. I crawled into my shell to avoid any good advice about coding for the future.

    So here is my old sub...

    use Lingua::EN::Inflect qw(NUMWORDS); sub get_columns { my ($max_cols, $amount, $number) = @_; if ($amount <= $max_cols ** 2) { for my $num (1..$max_cols) { if ($amount >= $num ** 2 && $amount < ($num + 1) ** 2) { return $number && $number =~ /^[yt1]/ ? $num : NUMWORDS($num); } } } else { return $number && $number =~ /^[yt1]/ ? $max_cols : NUMWORDS($max_ +cols); } }

    And the new more useful sub...

    use Lingua::EN::Inflect qw(NUMWORDS); sub get_columns { my ($max_cols, $amount, $word) = @_; if ($amount <= $max_cols ** 2) { for my $num (1..$max_cols) { if ($amount >= $num ** 2 && $amount < ($num + 1) ** 2) { return $word && $word =~ /^[yt1]/ ? NUMWORDS($num) : $num; ############################################# Delete to + get rid of Lingua::EN::Inflect } } } else { return $word && $word =~ /^[yt1]/ ? $NUMWORDS($max_cols) : $max_co +ls; ################################################### Delete +to get rid of Lingua::EN::Inflect } }

    I feel bad for only now realizing returning a integer by default would be more useful than returning a number word. I think I spoke aloud when I called myself a doofus for returning a number word by default.

    I've been doing a lot of rethinks lately. Some of my "utility" scripts seem useless in a broader sense.

    The great advice I got from Monks long ago is finally settling into my head. I hope I am better with future advice, but that is to be seen.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Opening files to write in browser returns Permission denied in Seekers of Perl Wisdom
9 direct replies — Read more / Contribute
by Lady_Aleena
on May 02, 2017 at 18:14

    Hello. I just recently noticed when I try to open a file for writing in a script running in my browser, permission denied is returned. So, is there a way to programatically tell my script running in my browser it is okay to write to that file? Also, how do I do it?

    I've looked at open and nothing popped up at me say this is where permissions are granted. Even File::Slurp's write_file returned permission denied. I think this is weird because I can open files to be read in the browser without any issues with either open or File::Slurp's read_file.

    In the mean time, I have set both files' permissions to 666.

    Note: Please tell newbies to die to always include the $! at the end. If I had $! at the end of my die message, it would have cut at least 15 minutes of me traversing directories thinking the file did not exist. I felt like a doofus.

    Edit per hippo: My OS is Debian jessie.

    Update: Running the same script from my web host does not require me to set the permissions to 666. It writes to the file while it is 644.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
The Cookies account in Perl Monks Discussion
4 direct replies — Read more / Contribute
by Lady_Aleena
on Apr 26, 2017 at 04:47

    A little over four years ago, I created the Cookies account for fun. I was known for my chatterbox antics with cookies; so on April Fools 2013, I decided to have some fun. Two years ago I went in for surgery, which is scary. I was thinking something could happen, and Cookies would be left without someone to maintain the account.

    Some users still play with the buttons from time to time. I would not want the account to die just because I did. So, if anything happened to me, would there be someone who would be willing to take over this very silly account?

    P.S. I am always willing to add more flavors and options to the account. Just let me know.

    P.P.S. This thread can be for anything related to the Cookies account that might merit general discussion, too. 8)

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena, the Cookie Lady
Happy unbirthday redux! and other birthday stuff in Cool Uses for Perl
1 direct reply — Read more / Contribute
by Lady_Aleena
on Apr 15, 2017 at 01:34

    Hello everyone! About five and a half years ago, I posted Happy unbirthday!. When I saw my fifteenth PerlMonks anniversary, I decided to write something new. However, I began to notice the new code I was writing had similar aspects to the old code I wrote for Unbirthdays, specifically the date verification subroutines I was was writing. So, I opened up Unbirthdays and took a second look. So here is the updated Unbirthdays and the new Birthday scripts.

    Date::Verify

    Date::Verify verifies in input and returns the appropriate value.

    • four_digit_year verifies the user input a four digit year. Usage: four_digit_year($year)
    • month_name verifies the mount input is correct (such as inputting 13 as a month or the too short Ju). It returns a fully spelled out month name. Usage: month_name($month)
    • month_number verifies the same as month_name, but it returns a month number instead. Usage: month_number($month)
    • day_number verifies the day is a number and that the day exists within the month of the year. It returns the day number. Usage: day_number($year, $month, $day)

    I am thinking on localizing this to the various countries available on Date::Calc.

    unbirthdays.pl

    I have made several changes to unbirthdays.

    • First, I got rid of the Q&A. That became annoying to me while testing the changes I made to the script. To that end, I moved the input to the command line as @ARGV.
    • Second, the Q&A was written to recurse until the input was in the correct form, however, the script now dies if the input is not in the correct form.
    • Third, I fixed several things from the former unbirthdays thread.

    Usage is: unbirthdays.pl name month day year. However, if unbirthdays.pl help is used, a helpful message appears.

    birthday.pl

    I was writing birthday.pl when I realized I was writing similar code as was in unbirthdays.pl. This script will tell the user their tropical zodiace sign, their birth stone and flowers (flowers for the US and UK are listed), and birth day stone (based on day of the week the user was born).

    This is a silly little script, but it helped me fix the previous one.

    Usage is: birthday.pl name month day year. However, if birthday.pl help is used, a helpful message appears.

    In closing

    I know these scripts probably still need work. I just hope you find them fun, or at least interesting.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
My local libs are not being used by my browser in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Lady_Aleena
on Sep 28, 2016 at 19:50

    Hello all. I am having a problem with my browser not recognizing my local libs. I set them up because I was told installing modules with sudo cpan and putting them in the main libs was not great. So I set up my local libs and installed all kinds of modules into them, got apache set up so I could view my website in my browser, but the browser does not use my local libs.

    Here is the result of perl -e 'print "$_\n" for sort @INC' on the command line:

    . /etc/perl /home/me/Documents/fantasy/files/lib /home/me/perl5/lib/perl5 /home/me/perl5/lib/perl5/5.20.0 /home/me/perl5/lib/perl5/5.20.2 /home/me/perl5/lib/perl5/5.20.2/x86_64-linux-gnu-thread-multi /home/me/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/local/lib/site_perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/share/perl/5.20 /usr/share/perl5

    Here is the list of libs my browser is looking in:

    files/lib /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl

    I ran echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >>~/.bashrc at the command line, and it added the following lines to my .bashrc file:

    PATH="/home/me/perl5/bin${PATH:+:${PATH}}"; export PATH; PERL5LIB="/home/me/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export P +ERL5LIB; PERL_LOCAL_LIB_ROOT="/home/me/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCA +L_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT; PERL_MB_OPT="--install_base \"/home/me/perl5\""; export PERL_MB_OPT; PERL_MM_OPT="INSTALL_BASE=/home/me/perl5"; export PERL_MM_OPT; eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"

    I already have several PATH statements above these lines and a PERL5LIB line, so I do not know if there is a conflict. Here are the lines:

    # My changes to things # export LC_ALL=C export LC_COLLATE=C export LESS=-SXi export PERL5LIB="$HOME/Documents/fantasy/files/lib" PATH="$PATH:$HOME/bin" PATH="$PATH:$HOME/Documents/fantasy" PATH="$PATH:$HOME/Documents/scripts" export PATH setterm --linewrap off

    So can anyone tell me what I am missing here?

    Thank you!

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Getting numeric month for comparisons in Cool Uses for Perl
4 direct replies — Read more / Contribute
by Lady_Aleena
on Mar 05, 2016 at 07:47

    I wrote this little script to get numeric months for comparisons. The input can be in initial uppercase, all uppercase, and all lowercase. I added a few other languages for fun.

    #!/usr/bin/perl use strict; use warnings; my @month_numbers = (1..12); my %month_names = ( 'English' => [qw(January February March April May June July Aug +ust Spetember October November December)], 'English abbr' => [qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Now De +c)], 'Dutch' => [qw(januari februari maart april mei juni juli aug +ustus september oktober november december)], 'French' => [qw(janvier février mars avril mai juin juillet ao +űt septembre octobre novembre décembre)], 'German' => [qw(Januar Februar März April Mai Juni Juli August + September Oktober November Dezember)], 'Greek' => [qw(Ianuários Fevruários Mártios Aprílios Máios Iú +nios Iúlios Avghustos Septémvrios Októvrios Noémvrios Thekémvrios)], 'Italian' => [qw(gennaio febbraio marzo aprile maggio giugno lu +glio agosto settembre ottobre novembre dicembre)], 'Spanish' => [qw(enero febrero marzo abril mayo junio julio ago +sto septiembre octubre noviembre diciembre)], ); my %months; for my $language (keys %month_names) { @months{@{$month_names{$language}}} = @month_numbers; @months{map(uc $_, @{$month_names{$language}})} = @month_numbers; @months{map(lc $_, @{$month_names{$language}})} = @month_numbers; } sub get_month_number { my $month = shift; return $months{$month}; }

    So, if you want the month number for July, you use it like the following.

    print get_month_number('July');

    The above will return 7.

    Now you can put dates in the right order. I'll be modularizing this shortly. 8)

    Updates

    Code simplified from morgon's (no @month_numbers array) and poj's (case insensitive input) suggestions.

    my %months; for my $language (keys %month_names) { my $number = 0; $months{lc $_} = ++$number for @{$month_names{$language}}; } sub get_month_number { my $month = lc shift; return $months{$month}; }

    Added aprile to Italian list of months from AnomalousMonk.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
RFC: Playing with glob in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Lady_Aleena
on Sep 15, 2015 at 15:25

    Several weeks ago I was playing around with glob's ability to create lists from stringified lists. (The forth paragraph in the doc.) I at first wanted to see if I could feed it arrays directly, but I was shown by jeffa the lists had to be comma separated strings. After playing around with it for a few minutes, I thought about finding a way use arrays, so wrote the following.

    Note: I do not like the name of the subroutine, so I am open to suggestions.

    sub glob_array { my (%opt) = @_; my $joiner = $opt{'joiner'} ? $opt{'joiner'} eq ' ' ? "' '" : $opt{ +'joiner'} : ''; my $space = $opt{'space holder'} ? $opt{'space holder'} : '_'; # The arrays have to be strinified into comma separated lists. Thank + you to jeffa for showing me. my $arrays = [map { $_ = '{'.join( ',', @{$_} ).'}'; $_ =~ s/ /$spac +e/g; $_; } @{$opt{'arrays'}}]; my $string = join( $joiner, @$arrays ); my @raw_array = glob "$string"; my @array = map { $_ =~ s/$space/ /g; $_; } @raw_array; return \@array; }
    • The joiner is the character you wish to use to join the values of the arrays together. (If the joiner is a space, it has to be quoted, hence the complicated line of code for it.)
    • The space holder converts the spaces in the values into the character of your choice. Spaces in the array values will muck up your output. (Sorry I can't explain that better.)
    • The arrays are the list of array (refs) you want to use to make the list.

    Here are some sample arrays and how they would look once glob has done its work.

    my @colors = qw(red green blue); my @directions = qw(north south east west); my @numbers = (1..3); my $array = glob_array( 'arrays' => [\@colors, \@directions, \@numbers +], 'joiner' => ' ', 'space holder' => '__' );

    Output

    $VAR1 = [ 'red north 1', 'red north 2', 'red north 3', 'red south 1', 'red south 2', 'red south 3', 'red east 1', 'red east 2', 'red east 3', 'red west 1', 'red west 2', 'red west 3', 'green north 1', 'green north 2', 'green north 3', 'green south 1', 'green south 2', 'green south 3', 'green east 1', 'green east 2', 'green east 3', 'green west 1', 'green west 2', 'green west 3', 'blue north 1', 'blue north 2', 'blue north 3', 'blue south 1', 'blue south 2', 'blue south 3', 'blue east 1', 'blue east 2', 'blue east 3', 'blue west 1', 'blue west 2', 'blue west 3' ];

    I have yet to figure out how to make this more interesting by including a pattern or a single joiner. From the above output, instead of plain green west 2 having green sector west tower 2nd floor or something akin to it. I could pre-munge the lists, but adding the ability to use a pattern would be nice too.

    So, I would like a new name for the subroutine and maybe some pointers on how to add in a pattern to this. Also, maybe a few good reasons to use this I may not be seeing other than making a list to use for random selection.

    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 examining the Monastery: (4)
As of 2024-04-25 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found