Feedback and Hints, January 2003.
If you have a question regarding any of the articles in this journal, or some comments please send them in. If there are any general questions about Unix or Database Administration, I will attempt to answer them.
Feedback:
Hints for this month:
Text file of user agent strings.
Date: Sat, 11 Jan 2003 03:43:25 +1100 Hi, I think your lists of http_user_agent strings is very useful. Only thing is, is that I am having difficulty importing them into a lookup table from HTML format. Is there any way I can download an ASCII delimited text file, with the 2 columns of data? David Perry USA (?) This is something that I had intended to do. But I did not get around to doing it. I have added two text files browser_list and robots_list. These files are tab-delimited ASCII and are created when the other lists are updated.
Calling the fm script from another CGI script.
Date: Sun, Dec 29, 2002 Gerry, Thank you very much for writing fm.pl, and its accompanying article 'Formatting Text with Perl.' It's just what I need and is the best formatter I've found. Question: How to pass it a string instead of it taking its input from a file? Brian Hauk Vancouver, BC Canada Date: Mon, Jan 12, 2003 Brian, I have been away on holiday for the past three weeks, which I spent at a little coastal town called Mallacoota (on the border between NSW and VIC). It was an excellant break and I never even looked at computer. So that is why I did not answer your e-mail. Can you tell me if your question relates to using the script in Unix or Windows? Gerry Patterson Date: Mon, Jan 13, 2003 Hi Gerry, Thanks for your reply. Glad to hear you had an excellent break, but I'm surprised you survived without a computer. Regarding fm.pl, I'm now using another less sophisticated formatting script found on the web, but am curious to see how to modify yours to accept a string variable. What I found is the following: ++++++++++++++++++++++++++++++++++++++++++ #!/usr/bin/perl -w # wrapit.pl - works! require 5.0.0; # require Perl version 5.0 and above use strict; use warnings; use diagnostics; use Text::Wrap; print createArticleBody(); sub createArticleBody # create { my $new_body; my @wrapped_body; $Text::Wrap::columns = 72; my @article_body = <<HERE_TARGET; We at UPSERJ (an anti poverty anti racist group here in Suburban NYC) need a wee bit of CGI or Perl scripting for UPSERJ.org. We have an anti-police brutality project going on over at http://upserj.org. We want the site to be able to take in a police brutality incident report. HERE_TARGET # wrap lines and convert to string @wrapped_body = Text::Wrap::wrap('', '', @article_body); $new_body = join '', @wrapped_body; return $new_body; } ++++++++++++++++++++++++++++++++++++++++++ Regards, Brian G'day Brian. It's not really a holiday if I take a computer ... It was good to read some books and relax in the shade. Anyway, I checked your site. I must confess I am not familiar with Zeus 3.4. If this is a Unix operating system, you could use the script as is, by invoking it as a command. I actually designed it for use on the fly within vi (In fact that is how I am writing this e-mail right now). This is why it accepts input from stdin as well as the command line. So you could use the existing script inside your CGI script using code like: my $length; my $tmpstr; # set these variables somewhere ... blah blah blah # assume that the script fm resides in /usr/local/bin/fm chomp( $cgitmp = `mktemp /tmp/cgi/XXXXXX`); die "Cannot create temp file: $cgitmp" unless (-f $cgitmp); open (TMPTXT,">$cgitmp") || die "Cannot open $cgitmp\n"; print TMPTXT "$tmpstr\n"; close TMPTXT || die "Cannot close $cgitmp\n"; my @t = `/usr/local/bin/fm -r$length $cgitmp`; # the hash @t now contains the formatted text # if want it as a scalar rather than a list then # invoke capture the output as a scalar ... However, you might be concerned about a possible security hole (using the shell to read back a string). Still if you are using the latest copy of perl and/or you have already checked $tmpstr for shell meta characters, I don't think this would be an issue. And if you feel strongly enough about it, you could modify the fm script to write to a another temp file (rather than stdout) and return the name of the file Although this means modifying the code ... and if you start doing that you might want to turn it into a module. Hope this is helpful ... Cheers, Gerry Patterson Hi Gerry, Thanks for your reply. I forgot to mention that the OS is Windows. Sorry about that. What I'd like to do is to pass a string to fm.pl and have it return the parsed string or an array. I don't know how difficult this is to do. Brian Brian, You can still do it. But it is more difficult. As far as I know the general method outlined below will work in Windows 2000 or NT. I can't guarantee that it will work with Windows 95/98 (which are very poor operating systems in my experience). But if you do have windows 2000 or NT, you need to overcome the following difficulties: First of all you do not have a system mktemp function. Fortunately there is one available in the perl library. You will have to read about it in your documentation. An example of this is as follows: use File::Temp qw/ tempfile tempdir /; ($fh,$filename) = tempfile( $template, DIR => $dir ); NOTE: As with the unix function, the Xs in $template are replaced by random digits. This method opens the file and returns a file handle, so you don't need to open it. Also, according to the documention, Windows will automatically delete the file when it is closed, IF tempfile() is invoked in SCALAR mode. -- READ the documentation! Also it may be difficult to persuade Windows to just execute perl programs. You may need to add .PL to your PATHEXT environment variable. This needs to be done at the system level. You may also want to use the ftype and assoc commands to assign your processor. e.g. Sometimes this has to be done at the command line as well as the GUI, as follows: FTYPE Perl=C:\Perl\bin\Perl.exe "%1" %* ASSOC .pl=Perl This should be done by the user who owns the sessions that will be running the programs. Regards, Gerry Patterson
Activate text links with w3m.
Here is a hint that might be useful to new users of w3m (like me). I discovered a useful feature in w3m recently. If I press ':' while viewing a (plain ASCII) text file, any text element that looks like a link is turned into one. You can then navigate to these links and activate them as you would in a HTML file. It is in the documentation, of course. So I could have discovered this little feature by RTFM. But who has time to RTFM?