in reply to What's the deal with apostrophes?

JavaFan's already answered your core question quite thoroughly, but I'd like to offer a little side advice on the true travesty1 in your demo code:
$fileline =~ s/$line.shtml"-->/$line.shtml"-->\n<SCRIPT language="Java +Script" SRC="http:\/\/mygreatwebsite.net\/cgi-bin\/gcountdir\/gcount. +pl?0=$line"> <\/SCRIPT>/
Although / is the default regex delimiter in Perl, you can use different punctuation in that role to avoid "leaning toothpick syndrome":
$fileline =~ s#$line.shtml"-->#$line.shtml"-->\n<SCRIPT language="Java +Script" SRC="http://mygreatwebsite.net/cgi-bin/gcountdir/gcount.pl?0= +$line"> </SCRIPT>#
or even, if you want to get fancy:
$fileline =~ s[$line.shtml"-->] [$line.shtml"-->\n<SCRIPT language="JavaScript" SRC="htt +p://mygreatwebsite.net/cgi-bin/gcountdir/gcount.pl?0=$line"> </SCRIPT +>]

Edit: 1Just to clarify, I referred to the regex in question as a "travesty" solely to echo the OP's description of the code it came from as "the below travesty". I would not normally consider it nearly bad enough to qualify as such.

Replies are listed 'Best First'.
Re^2: What's the deal with apostrophes?
by tallCoolOne (Initiate) on Jun 09, 2009 at 17:56 UTC
    esper, javafan,

    Thanks to both of you - these are both some of the "rough edges" in my coding knowledge. I really appreciate the input. I will add these approaches to my scripts, and I am sure that they will work as I had hoped that they would originally.
    *bows before the monks*
    This one is grateful for the wisdom you have shared with me.

      I still see a problem with your code: You are not counting "pages requested", but "pages requested with a browser that supports and allows Javascript". The real page request counts are in the access log of your web server. If you don't have access to that, you could deliver all pages through a perl script that counts the request.

      Oh, and by the way: You are using file locks when you update the counter file, right? And you check that the file name passed by the browser is one of the files you want to update, right?

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        ok, hmmm... Some new points to ponder. I guess I kind of assumed that javascript was pretty ubiquitous. I do have access to "real" server access logs provided by my host. But where's the fun in that, when I can write scripts to do things?
        Ummm... file locks? I am not updating the counter file myself, the perl program in the cgi-bin directory does that. It is just a simple increment script that increments the number in the file supplied to it by the calling command. I have made sure that there is a count file for every page, with the same name as the content page, but with no extension (it seems the perl code wants it this way), and that the javascript call in the webpage has the name of the count file for that page. So it all lines up nicely.
        Now I am trying to figure out how to add LWP to my cygwin installation so that I can request the count files, and put the numbers into a report that shows each page that is visited. To be sure, I can validate this against the server logs if I want, but again, where's the fun in that?
        It's great to have come this far after so long, but now I want to do all the cool stuff that the big people do with real websites, but I can still only barely crawl.
        Can you explain the file locking thing a little more for me please? If need be, I can supply the count program code, to check it to see if it locks files.
        Thanks for your help.
      Esper, Is there a particular command or system variable to re-set to change from the default search delimiter / to the examples you have given # ?
      It seems a little odd to me to just change characters for something like that and expect perl to "know" that's what they are there for. Does it really work that way?
      Again, you have my gratitude for your enlightening information.
      Mark
        It seems a little odd to me to just change characters for something like that and expect perl to "know" that's what they are there for. Does it really work that way?

        Yes, it does really work that way... more or less.

        The one catch is that, when you use alternate delimiters, you have to explicitly use either "m" or "s" at the beginning of the regex. The "m" and "s" are the actual operators which (in the right context) trigger a regex operation, so when perl sees those followed by punctuation, it recognizes that the punctuation used will be the delimiter for that regex without needing to expicitly set or reset anything.

        So, for example, all of these variations are equivalent:

        #!/usr/bin/perl use strict; use warnings; my $text = 'This is a text string.'; print $text =~ m/is a/, " - m//\n"; # Default delimiter, so the "m" can be omitted print $text =~ /is a/, " - //\n"; # Custom delimiters, so the "m" is mandatory print $text =~ m#is a#, " - m##\n"; print $text =~ m!is a!, " - m!!\n"; print $text =~ m^is a^, " - m^^\n"; # Open/close punctuation is used in pairs print $text =~ m[is a], " - m[]\n"; print $text =~ m(is a), " - m()\n"; print $text =~ m<is a>, " - m<>\n";
        The print on each regex displays the number of matches found along with the delimiters used:
        1 - m// 1 - // 1 - m## 1 - m!! 1 - m^^ 1 - m[] 1 - m() 1 - m<>