I have recently overcome a major hurdle assembling a website of purely the hobby sort, by using a series of perl programs to put together my simple html pages, and links to those pages and so forth. The end result was very pleasing to my eye, and as I had completed assembling all of my original reference documents (text files), and assembling them into nice, uniform html pages, I sought out and found a web hosting service to my liking and bought space.
Once I had "moved in", I found that they offered a nice, easy perl page counter which was once of my little missing details that I had promised myself that I would get around to. This involved writing a small perl program that would create a text file containing "0" in it to initialize the count for a particular page, where the name of the counter file corresponds to the file being counted. I am sure that you are all familiar with this general approach.
Well, it was easy enough to create the "counter files" with the names of all the pages on the site (why count some pages, when perl will let you count them all?). I then wrote a quick and dirty perl program to go through all of my previously created html pages, and add the single line needed to call the counter program, which also had to contain the name of the page itself.
Now to the part where it got sticky for me. The pages are named for what they are, or the title of the material being discussed on the page, and in many cases (43 out of 423 total pages), the title of the page contains an apostrophe - ' , as in:

Joe's_Page.shtml
Mark's_Page.shtml
Moe's_Reasons_For_Putting_A_Site_Together.shtml
Really_'Cool'_Reasons_For_This_Site_To_Exist.shtml

Well, it turns out that those apostrophes (single quotes) are a problem, and cause syntax errors in the perl program for the pages that contain the single quotes in the titles, but the pages without work fine. And I didn't have any trouble with the first little kludge to create "counter files" which had the same single quotes in the names. Here's the first program:
#!/user/bin/perl @textFile = `cat Brain1.txt`; foreach $line (@textFile) { chop $line; open(COUNTERFILE, ">./$line"); print COUNTERFILE "0"; close(COUNTERFILE, $line); }

Brain1.txt is just a list of all the files to make counter files for, one file name to a line(filenames only, no extensions). This worked great, and made 423 files each containing "0" in it, and named exactly as I wanted. I had to get a little more kludgy to insert the call for the perl program into the actual files as the below travesty reveals:
#!/user/bin/perl @textFile = `cat Brain1.txt`; foreach $line (@textFile) { chop $line; $pagefile = $line.".shtml"; @ModPageFile = `cat $pagefile`; foreach $fileline (@ModPageFile) { $fileline =~ s/$line.shtml"-->/$line.shtml"-->\n<SCRIPT langua +ge="JavaScript" SRC="http:\/\/mygreatwebsite.net\/cgi-bin\/gcountdir\ +/gcount.pl?0=$line"> <\/SCRIPT>/ } open(NEWPAGEFILE, ">./$pagefile"); print NEWPAGEFILE @ModPageFile; close(NEWPAGEFILE); } exit; <br>
Can anyone tell me how to get around this apostrophe problem? It's rather annoying, and I figure in cases like this, perl is smarter than I am, and can be told how to deal with it. I thought of various ways of renaming the files to get the single quotes out of the names, and processing them that way, and then changing them back, but it all gets ugly rather fast. I'd really appreciate a lesson on how-to handle file names as strings, and not worry about certain characters.
Because my next big idea is to create a perl script that will will reach out into deep internet space and open each of those counter files and pick out the number contained inside from my laptop down here on earth, and make up a pretty little list of which pages get read, and which don't. I am hoping to not have to deal with the apostrophe problem when I get to that point.
It's all about using perl to help me stroke my tiny ego and show me that my site gets read by people.
Thanks, Monks

In reply to What's the deal with apostrophes? by tallCoolOne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.