Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Alexander's scratchpad

by Alexander (Sexton)
on Jun 02, 2004 at 02:34 UTC ( #359055=scratchpad: print w/ replies, xml ) Need Help??

Alexander's Scratchpad
A log of my experiences. Here for me, here for you.

Click here to go to my most recent notes
Click here to go to the current script that I am working on

Notes: Miscelaneous/As I go
Observations and what I have learned along the way

Notes

May 5, 2003: While installing modules in preparation to install Interchange, one module was denied permission to install to a certain directory on my webhost. bart directed me to
perlfaq8 which said to use the PREFIX option when generating Makefiles:

perl Makefile.PL PREFIX=/u/mydir/perl
May 7, 2003:
16:27 <irc> dpkg -i filename.deb 16:29 <alexander> that unpacks only, right? 16:30 <irc> alexander: dpkg's in-line help is pretty complete. The manpage and info page both include thorough information as well. 16:30 <irc> alexander: dpkg -i unpacks and installs 16:32 <irc> if you're looking to install a common application/package and you're not familiar with apt, aptitude, tasksel (more redhatish), or dselect, check those out. 16:37 <alexander> ok i will - finding the relevant docs is still seldom easy for me to do without asking - all my searches were fruitless, so thank you (i am going to try installing openssl is why I was wanting to know) 16:42 <irc> alexander: try and 'apt-get install openssl' before you mess with dpkg. 16:42 <irc> if apt is set to go to an internet source, it will probably get newer stuff 16:45 <alexander> oh, alright - i'll do that instead 16:47 <alexander> the debian site says "libc6" and "libssl" are possible dependancies (is the "6" in "libc6" a version number? would i just want to say 'apt-get install libc'?) 16:50 <irc> apt-get should try to get the dependencies that aren't already installed. 16:50 <irc> but yes, libc6 is libc - version6. 16:50 <irc> which is basically listed as /lib/libc-2.x.x.so or whatever. 16:51 <alexander> oh alright - that certainly simplifies things 16:51 <irc> check your /etc/apt/sources.list and see if it points to a CD-ROM source or an http/ftp source. 16:51 <alexander> alright... 16:53 <alexander> yes - it is set to ftp and http sources 16:53 <irc> alexander: if you have extra time to waste, do a 'apt-get update && apt-get dist-upgrade' to upgrade the whole box's complement of software. 16:54 <irc> join the debian horde 16:54 <alexander> oh.... how much "extra time" are you talking about? 16:55 <irc> it'll go out and download about 3MB of indicies and compare your versions to the current versions. 16:55 <irc> depends on your connection :) 16:55 <alexander> dsl fortunately 16:56 <irc> if I take a stock box on my DSL and upgrade, it would take prolly 40 minutes. 17:01 <alexander> thank you <irc> :-) 17:01 <irc> np, have fun
I discovered today that it is possible to be your very own certificate authority using OpenSSL whereby you can generate your own secure certificates to use with SSL for free! To pay Verisign or Thwate (now owned by Verisign) lots of money means paying for their name recognition alone. Their general public keys are already installed on browsers so a user will not get a popup message about do you trust 'so and so'. As long as users click yes, this is a great alternative! Now I only need to see if my webhost's sysadmin will install such a certificate. There is also certSSL.org which will apparently create a certificate for you for free.

Ya gotta love open source! =-D

The default SSL on my webhost has been down since signing up. Today it occured to me to wonder if the apache mod-rewrite functions in the web-root's .htaccess file could be a cause. A quick talk with Milan (my webhost's sysadmin) and we discovered that it was indeed the problem. I suggested that Milan change the unix symbolic links for the SSL root to the same level in the filesystem hierarchy:
From /usr/alexander/web-root To /usr/alexander/ssl-root
That made the fix! YIPEE!

I will need to figure out what kind of architecture to use in the SSL root now, but I finally have it functioning!

I finally cracked the spine of Learning Perl. I read the intro and preface last night, and started chapter 1 earlier this evening. I got as far as the example of a shell script and that was it... onto the computer I went to explore this new tidbit of the kind of info I so sorely lack. As soon as I finish updating to this scratchpad, its time to open a shell session to my webhost and toy about some.

It's gonna take me FOREVER to finish reading this book! But I would rather explore in just this fashion to seize each tidbit and imprint each new discovery upon my synapses than to let something fade just so I can finish the book faster. Sheesh, if I do not absorb as much as possible, there's no point taking the time to read the book!

May 26, 2003:
<Enlil> it will work if $var looks something like this $var = ["A", 1] +<code> or <code>@array = (1,2);$var = \@array;<code> Try this: <code> + perl -le '$var = ["a","b",3]; print $var" <Enlil> it should print something like:ARRAY(0x224eb4) <Enlil> which is an array reference... so if you did this: perl -le '$ +var ="A","b",3; ($var1,$var2,$var3) = @{$var}; print "$var1, $var3,$v +ar2";' all should be good with the world...
He suggested I read these for more info:
perlreftut, References quick reference (on perlmonks), References (on perlmonks), Hash Keys (strings or numbers?) (on perlmonks), (perldata, and perldsc) - in that order
<Enlil> alexander another problem you have is your are sending more th +an just a hash as a parameter for SetCookie(%hash) which is also scre +wing you up...that is the odd number of elements warning you are gett +ing..


May 30, 2003:

Boy did I learn alot at 2am in the CB. (Ofcourse now that its morning, I'm regretting the hours of sleep I missed.) *yawn*
#$ENV{'CUSTOMENV'} = 'value';delete $ENV{CUSTOMENV}; -or- $ENV{PATH} = + undef; #<Alexander> what about unsetting them? #<theorbtwo> same as any other hash: delete $ENV{CUSTOMENV} #<Enlil> ummm... $ENV{PATH} = undef; or delete $ENV{PATH}; should work #<Alexander> oh fantastic! ...are there any pros/cons to one or the ot +her method of unsetting them? #<Enlil> undef makes it undefined... delete removes completely from th +e hash.. so it no longer even exists... i would use delete.. #<Alexander> huh? "autovivify" -?!? #Enlil notes that Alexander should look up exists, defined, and delete #<theorbtwo> Also, look up ENV in perlvar. #<Enlil> perldoc++++ #<Alexander> how do i do 1.00 + 1.00 = 2.00 instead of 1.00 + 1.00 = 2 + and 1.00 + 1.50 = 2.50 instead of 1.00 + 1.50 = 2.5 --? #<castaway> you just format the output with sprintf, alexander #<castaway> (cos 2.50 == 2.5 ) #<Enlil> my $var = sprintf("%.2f",1.00 + 1.004); print $var; #perl -le 'my $var = sprintf("%.2f",1.00 + 1.004); print $var;' perl -le 'printf("%.2f",1.00+1.032);' printf is like sprintf, except that it prints the formatted string, ra +ther then returning it. (You could say that the other way around, which is more historicly acc +urate, and makes the names make sense.) Printf also ignores $\, as you've noticed; -l is of no help. happen to know why? I don't know. I suspect because it simply uses printf directly from C +. nods. If there was, or is, a rationale for why it <em>should</em> be that w +ay, I haven't heard it. i have seen the light and now understand the niftiness of the printf +now. wow, perl -e 'printf("%.2f", 1 .00+1.032 .00+74);' equals 85.03! there is no shame spending an afternoon looking at [http://www.perldo +c.com/perl5.8.0/pod/perlfunc.html|perlfunc] for new never used functi +ons... like [http://www.perldoc.com/perl5.8.0/pod/func/ucfirst.html|u +cfirst] is good when needed too:) Enlil says autovivify... try this:use strict;use warnings;use Data::Du +mper;my %hash;if($hash{this}{that}){print "nope";}print Dumper \%hash +; :) i just meant be careful how you check for existence and whatnot: +) <Alexander> castaway, was "unique for each environment.." for me? (and + if so, is that a "yes, each user will safely get the data unique to +them and them alone"?) <castaway> yes it was.. and yes they should <castaway> (each login creates a new environment..) <tye> Alexander, requests from different users will still hit web serv +er processes at random so ENV variables will jump between users rando +mly. castaway didnt know Alexander was talking about web server stuff.


Observations

I have learned things a bit backwards, so I'll try to make these notes take a more directed approach.

It starts with Unix. Become familiar with using a unix shell/command line interface (CLI). Those commands and concepts used in Unix apply directly to Perl.
  • Concepts like Pipes for example
  • The use of Regular Expressions (RegEx) to parse and filter data
  • The typical system tree schema used by the file system
    • Like Perl is often at /usr/bin/perl or /usr/local/bin/perl
  • Learning to use "switches"
    • Especially -w to enable warnings in Perl
          #!/usr/bin/perl -w
Perl is supposted to have certain similarities to C and C++. At least a small level of familiarity with those should help with Perl.

Debugging
Learn how to get at the potential cause of problems. Turn guesswork into a process of elimination.















 


#!/usr/bin/perl -w # bourne.pl "monkified" v1.0 # bart lines 5 & 29, and theorbtwo for ! delimiters line 36 use strict; ############ ## note: six assumptions are made here... ## 1) $USER legal characters are alphanumeric, "_", or "-" ## 2) $USER is between 3 and 16 characters in length ## 3) your default shell is a bourne-like shell (like bash) ## 4) you know enough bourne shell to not get in trouble ## 5) your $HOME directory is /home/$USER ## 6) you accept that you are using this at your own risk my @cmds = split /\n/, <<'--CMDs--'; ############ ## edit whoami pwd id echo \$PATH=$PATH echo \$PERL5LIB=$PERL5LIB perl -V ############ ## no edit --CMDs-- my $i=4; my $size=@cmds; my $me=`whoami`; my $dir=`pwd`; $me=~s/\n//; $dir=~s/\n//; $dir=~s!\/home\/[\w-]{3,16}\/!\/!; my $prompt="$me\@~$dir>"; print "Content-type: text/plain\n\n"; while ($i <= $size - 4) { my $cmd=$cmds[$i]; print $prompt,"$cmd\n",`$ +cmd`,"\n"; $i++; }



sub UpdateCart { #print "Content-type:text/plain\n\n"; my (@itemquantities, $itemnum, $itemqty, $baseprice, $upsizeamt); if (&GetCookies('itemprice')) { + # if item price, get values my $rawvalue = pop(@Cookie); ($itemnum, $itemqty, $baseprice, $upsizeamt) = split(/;/, $raw +value); @itemquantities = split(/\|/, $itemqty); } else { die "Missing Cookie: itemprice! It is required to use the cart +."; } my $number = $query->param("number"); my $i = "0"; my $count = "0"; while ($count <= $number) { my $update = $query->param($count); $itemquantities[$i] = $update; $i++; $count++; } #if ($number eq "0") { # $itemqty = $itemquantities[0]; # my $new_itemprice = "$itemnum;$itemqty;$baseprice;$upsizeamt" +; # &SetCookies("itemprice",$new_itemprice); #} else { $itemqty = $itemquantities[0]; $i = "0"; $count = "1"; while ($count <= $number) { $i++; my $temp = "$itemqty\|$itemquantities[$i]"; $itemqty = $temp; $count++; } my $new_itemprice = "$itemnum;$itemqty;$baseprice;$upsizeamt"; # print "New Itemprice: $new_itemprice\n"; &SetCookies("itemprice",$new_itemprice); #} ################################################################## +############ ################################################################## +############ &GetCookies('total'); my $rawvalue = pop(@Cookie); + # get raw totals my ($itemt, $subt, $grandt, $ouncest, $shippingt) = split(/;/, + $rawvalue); # get totals from raw totals &GetCookies('itemprice'); $rawvalue = pop(@Cookie); ($itemnum, $itemqty, $baseprice, $upsizeamt) = split(/;/, $raw +value); my @itemnumbers = split(/\|/, $itemnum); @itemquantities = split(/\|/, $itemqty); my @baseprices = split(/\|/, $baseprice); my @upsizeamounts = split(/\|/, $upsizeamt); &GetCookies('details'); $rawvalue = pop(@Cookie); my ($isize, $icolor, $istyle, $iounces) = split(/;/, $rawvalue +); my @itemsizes = split(/\|/, $isize); my @itemcolors = split(/\|/, $icolor); my @itemstyles = split(/\|/, $istyle); my @itemounces = split(/\|/, $iounces); &GetCookies('itemtitle'); my $ititle = pop(@Cookie); my @itemtitles = split(/;/, $ititle); ############################################################## +############## ############################################################## +############## $i = "0"; my @remove = $query->param("remove"); my %remove; @remove{@remove} = (1)x@remove; @itemnumbers = @itemnumbers[ grep !$remove{$_}, 0..$#itemnumbers ] +; @itemquantities = @itemquantities[ grep !$remove{$_}, 0..$#itemqua +ntities ]; @baseprices = @baseprices[ grep !$remove{$_}, 0..$#baseprices ]; @upsizeamounts = @upsizeamounts[ grep !$remove{$_}, 0..$#upsizeamo +unts ]; @itemsizes = @itemsizes[ grep !$remove{$_}, 0..$#itemsizes ]; @itemcolors = @itemcolors[ grep !$remove{$_}, 0..$#itemcolors ]; @itemstyles = @itemstyles[ grep !$remove{$_}, 0..$#itemstyles ]; @itemounces = @itemounces[ grep !$remove{$_}, 0..$#itemounces ]; @itemtitles = @itemtitles[ grep !$remove{$_}, 0..$#itemtitles ]; if (@remove) { # foreach my $item (@remove) { # print "Splice: $item\n"; # $item -= $i; # $i++; # splice(@itemnumbers, $item, 1); # splice(@itemquantities, $item, 1); # splice(@baseprices, $item, 1); # splice(@upsizeamounts, $item, 1); # splice(@itemsizes, $item, 1); # splice(@itemcolors, $item, 1); # splice(@itemstyles, $item, 1); # splice(@itemounces, $item, 1); # splice(@itemtitles, $item, 1); # } $ouncest = "0"; foreach my $item (@itemounces) { # print "Itemounces: $item\n"; my $temp = ($ouncest + $item); $ouncest = $temp; } &ShippingChart($ouncest); $shippingt = shift(@NewShipping); $itemt = "0"; foreach my $item (@itemquantities) { # print "Itemquantities: $item\n"; my $temp = ($itemt + $item); $itemt = $temp; } my $count = "1"; $subt = "0"; $i = "0"; while ($count <= $number) { my $temp = sprintf("%.2f",$baseprices[$i] + $upsizeamounts +[$i]); my $itemprice = sprintf("%.2f",$temp * $itemquantities[$i] +); $temp = sprintf("%.2f",$subt + $itemprice); $subt = $temp; # print "Subtotal$i: $subt\n"; $i++; $count++; } $grandt = sprintf("%.2f",$subt + $shippingt); my $new_total = "$itemt;$subt;$grandt;$ouncest;$shippingt;"; &SetCookies("total",$new_total); #$count = "1"; $itemnum = $itemnumbers[0]; $itemqty = $itemquantities[0]; $baseprice = $baseprices[0]; $upsizeamt = $upsizeamounts[0]; # print "(0) Itemnumber: $itemnum, Itemquantity: $itemqty, Base +price: $baseprice, Upsizeamount: $upsizeamt\n"; if ($itemnumbers[1] and $itemquantities[1] and $baseprices[1] +and $upsizeamounts[1]) { $i = "1"; # while ($count <= $number) { for (1..$#itemnumbers) { my $temp = "$itemnum\|$itemnumbers[$i]"; $itemnum = $temp; $temp = "$itemqty\|$itemquantities[$i]"; $itemqty = $temp; $temp = "$baseprice\|$baseprices[$i]"; $baseprice = $temp; $temp = "$upsizeamt\|$upsizeamounts[$i]"; $upsizeamt = $temp; # print "($i) Itemnumber: $itemnum, Itemquantity: $item +qty, Baseprice: $baseprice, Upsizeamount: $upsizeamt\n"; $i++; # $count++; } } my $new_itemprice = "$itemnum;$itemqty;$baseprice;$upsizeamt"; &SetCookies("itemprice",$new_itemprice); #$count = "1"; $isize = $itemsizes[0]; $icolor = $itemcolors[0]; $istyle = $itemstyles[0]; $iounces = $itemounces[0]; # print "(0) Itemsize: $isize, Itemcolor: $icolor, Itemstyle: $ +istyle, Itemounces: $iounces\n"; if ($itemsizes[1] and $itemcolors[1] and $itemstyles[1] and $i +temounces[1]) { $i = "1"; for (1..$#itemsizes) { # while ($count <= $number) { my $temp = "$isize\|$itemsizes[$i]"; $isize = $temp; $temp = "$icolor\|$itemcolors[$i]"; $icolor = $temp; $temp = "$istyle\|$itemstyles[$i]"; $istyle = $temp; $temp = "$iounces\|$itemounces[$i]"; $iounces = $temp; # print "($i) Itemsize: $isize, Itemcolor: $icolor, Ite +mstyle: $istyle, Itemounces: $iounces\n"; $i++; # $count++; } } my $new_details = "$isize;$icolor;$istyle;$iounces"; &SetCookies("details",$new_details); #$count = "1"; $ititle = $itemtitles[0]; # print "(0) Itemtitle: $ititle\n"; my $new_itemtitle; if ($itemtitles[1]) { $i = "1"; for (1..$#itemtitles) { # while ($count <= $number) { my $temp = "$ititle;$itemtitles[$i]"; $ititle = $temp; # print "($i) Itemtitle: $ititle\n"; $i++; # $count++; } $new_itemtitle = $ititle; } &SetCookies("itemtitle",$new_itemtitle); } my $location = "/cart/action?is=view"; print $query->redirect(-uri=> $location), "\n\n"; exit 0; }



May 4, 2006
Alexander    2006-05-04 07:33:13 GMT
ok, complete "out of left field" question here: whats the etymology (word origin) of using word variable substitutions such as "foo", "bar", "quux", etc in programming/scripting examples?
Corion    2006-05-04 07:35:13 GMT
Acme::Metasyntactic ;-)) No, not really - "foobar" is an expression dating back to at least WWII, and "quux" is a magic word (I think) from Advent or one of the other early Infocom adventures
Alexander    2006-05-04 07:39:15 GMT
see Corion, its actually kindof scary that you could even just pull that out of your proverbial hat lol... yet its exactly why I come here
Corion    2006-05-04 07:40:16 GMT
Corion has lots of hats with various contents. Choosing the right hat to pull things out of is the art!
teabag    2006-05-04 07:40:34 GMT
teabag checks Corion's hat andd finds a spare rabbit
chargrill    2006-05-04 07:40:55 GMT
origins of foo
Alexander    2006-05-04 07:43:34 GMT
well given that response, i am VERY glad I choose "hat" and not pulled from a certain part of anatomy lower down ;p
teabag    2006-05-04 07:44:51 GMT
teabag wonders if that's a parrot in Alexanders pocket....;)
Alexander    2006-05-04 07:45:20 GMT
thanks chargrill
Alexander    2006-05-04 07:46:25 GMT
polly went looking for a craker and settled for sausage? =8X
Alexander    2006-05-04 07:47:03 GMT
<-- crosses legs
chargrill    2006-05-04 07:47:37 GMT
alexander: np. granted that link has enough other links to give you the history of the other metasyntactic variables you're asking after. though i couldn't find any reference to advent, corion.
Alexander    2006-05-04 07:50:16 GMT
shoot - what happened to crazyinsomniac's last 35 CB messages?? (and site)
virtualsue    2006-05-04 07:50:29 GMT
good old advent
Corion    2006-05-04 07:50:47 GMT
ESR claims MIT origin for quux as well. I think MIT was also home to lots of later Infocom people. But I don't find any reference to any magic word. Maybe I'm confusing it with xyzzy
Corion    2006-05-04 07:50:59 GMT
cb60, cbhistory
Alexander    2006-05-04 07:51:17 GMT
...and is there a substitute script for CB history?
virtualsue    2006-05-04 07:51:21 GMT
long since superseded by http://nbpfaus.net/~pfau/cbhistory.cgi?site=PM
chargrill    2006-05-04 07:51:37 GMT
little rock, ar. i littered while driving through AR once because it pissed me off so much. i just wanted to get to TX, damnit.
virtualsue    2006-05-04 07:51:57 GMT
the magic words in adventure were xyzzy, plugh and possibly another
Alexander    2006-05-04 07:52:15 GMT
ok thanks - i've obviously been out of the loop for quite some time
chargrill    2006-05-04 07:52:33 GMT
http://nbpfaus.net/~pfau/cbhistory.cgi?site=PM <-- my favorite cbhistory link
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-12-21 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls