[24384] in Perl-Users-Digest
Perl-Users Digest, Issue: 6572 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 16 18:05:38 2004
Date: Sun, 16 May 2004 15:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 16 May 2004 Volume: 10 Number: 6572
Today's topics:
ANNOUNCE: GMP module version 2.00 <user42@zip.com.au>
ANNOUNCE: QuikWiki 1.4 (Robert Kiesling)
Re: help w/ opening a file <noreply@gunnar.cc>
Re: IF problem?! <jurgenex@hotmail.com>
Re: IF problem?! <tadmc@augustmail.com>
Re: IF problem?! <ittyspam@yahoo.com>
Re: IF problem?! <werbs@cox.net>
It works and thanks. Re: what's wrong with my CPAN modu (yjin6666@hotmail.com)
Passing params from cli/sh <takesmore--nospam--thanthat@hotmale.com>
perl 5.8.3 problem (laszlo)
Porter algorithm in spanish (Daniel Kawer)
print all combinations <jidanni@jidanni.org>
simple problem w/ opening files <werbs@cox.net>
Re: simple problem w/ opening files (Malcolm Dew-Jones)
Re: simple problem w/ opening files <usenet@morrow.me.uk>
Re: simple problem w/ opening files <uri@stemsystems.com>
Re: Sort an array + more <tadmc@augustmail.com>
Re: Sort an array + more <spamtrap@dot-app.org>
Re: Sort an array + more <krzys-iek@-----wp.pl>
Re: Sort an array + more <tadmc@augustmail.com>
Re: Sort an array + more <krzys-iek@-----wp.pl>
Re: Sort an array + more <usenet@morrow.me.uk>
Re: Sort an array + more <krzys-iek@-----wp.pl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 14 May 2004 22:42:04 GMT
From: Kevin Ryde <user42@zip.com.au>
Subject: ANNOUNCE: GMP module version 2.00
Message-Id: <HxtBpu.1yHG@zorch.sf-bay.org>
The GMP aribitrary precision arithmetic library includes a "GMP"
module, providing a perl interface to the library. GMP version 4.1.3
contains a new version 2.00 of this interface.
This version adds support for scalar magic on inputs, tightens up
conversion of inputs with combinations of IV, NV and PV values, and
addresses problems with substrings in perl 5.8.2 and initializers in
MINGW.
It should be noted the GMP module is not the same as Math::BigInt, but
is instead designed as a friendly low-overhead native interface to the
library. Operator overloading, optional big constants, and access to
the full set of library operations is provided.
The GMP distribution is available from
ftp://ftp.gnu.org/gnu/gmp/gmp-4.1.3.tar.gz
or
ftp://ftp.gnu.org/gnu/gmp/gmp-4.1.3.tar.bz2
A great many sites around the world mirror ftp.gnu.org, please use one
near you. See http://www.gnu.org/order/ftp.html for a full list.
The GMP home page is http://swox.com/gmp, send bug reports and
comments to bug-gmp@gnu.org.
------------------------------
Date: Sat, 15 May 2004 01:37:15 GMT
From: rkies@cpan.org (Robert Kiesling)
Subject: ANNOUNCE: QuikWiki 1.4
Message-Id: <HxtBpJ.1yGq@zorch.sf-bay.org>
QuikWiki, as its name implies, is a lightweight Perl/CGI Wiki that
provides basic Wiki browsing and editing functionality and also
includes:
- WikiWiki compatible text markup.
- RCS integration to save page revisions.
- JPEG and PNG image viewing within pages or separately.
- Dynamic page header and footer templates.
- Perl scripting within pages.
- Self documentation, including indexed words.
- Unlimited page size.
- Cross-platform browser compatibility.
- Operation in server's system document subdirectory, or user's
~/public_html directory.
- Text-mode installation wizard.
QuikWiki is written for Apache and mod_perl, but it makes use of
generic HTTP functions and should be easily adaptable to other
server
The README file, included below, provides information about
installation and configuration.
Obtaining QuikWiki
------------------
You can download version 1.4 at the following archives:
ftp://ftp.cpan.org/pub/CPAN/authors/id/R/RK/RKIES/.
http://prdownloads.sourceforge.net/quikwiki/quikwiki-1.4.tar.gz?download
Project Page
------------
http://sourceforge.net/projects/quikwiki/.
QuikWiki is licensed under the same terms as Perl
Installing QuikWiki
-------------------
QuikWiki is a small Wiki that provides, in addition to editing,
saving, and browsing Wiki pages with a Web browser, inline JPEG and
GIF image display, version control for edited pages, and embedded Perl
page templates.
Requirements
Perl, version 5.6.0 or later. Also pod2html, if you want to view the
view the manual on-line. Pod2html is part of the Perl source code
distribution. If you don't have pod2html, consult your system
administrator.
Apache with mod_perl. QuikWiki is untested with other HTTP servers.
The program tries to adhere to generic HTTP and CGI protocols.
QuikWiki should work with other Web servers that can run Perl CGI
scripts, although it's untested.
The section, "Apache Configuration Notes," provides information about
how to configure Apache to run Perl CGI scripts.
Optionally, Revision Control System, if you want QuikWiki to keep
track of revisions. Without RCS, QuikWiki makes backup copies of
edited pages by adding a, ".bak," extension.
Quick Install
If the quick install doesn't work for some reason, go to the,
"Manual Install," section.
1. Unpack the tar file.
tar zxvf quikwiki-<version>.tar.gz
If you're logged in without superuser privileges, you can
only install QuikWiki in the public HTML subdirectory of your
$HOME directory. The directory name depends on the Web server
configuration. The name should be something like, "public_html,"
or, "htdocs." Ask your Web administrator if you're not certain.
QuikWiki should also work in any server-accessible directory
that has, "Options +ExecCGI," enabled in httpd.conf.
If upgrading, make sure to back up the old QuikWiki directory.
2. Change to the source code directory and run the configuration
script. Configure asks if you want to create a RCS directory
for page revisions, and the user ID for the QuikWiki files and
directories. If you're installing quikwiki in <DocumentRoot>,
you'll need to have write permissions in that directory
(i.e., you're the administrator).
If you're installing QuikWiki in $HOME/public_html, configure asks
if you want to rename quikwiki.cgi to index.cgi, so you can avoid
typing the program name if the Web server configuration does not
permit executing symlinked programs in User directories.
# cd quickwiki-<version>
# perl configure
That's it! (Or, that should be it.) If you don't see the QuikWiki
HomePage, refer to the "Manual Installation" section below.
Browse to the HomePage by typing, in your Web browser,
http://<server_address>/quikwiki/quikwiki.cgi
Or, alternately,
http://<server_address>/quikwiki/
If you installed QuikWiki in your ~/public_html directory,
http://<server_address>/~<your_user_name>/quikwiki/quikwiki.cgi
Substituting the actual network address of the server for
<server_address>, and your actual user name for <your_user_name>.
If for some reason RCS doesn't provide a Revision number or Last
Modified date/time in the page footer, edit and then save the page to
create the RCS repository. If you have trouble saving the revision,
double-check the permissions of the page, the RCS subdirectory, and
the RCS archive.
To view QuikWiki's Perl Online Documentation, browse to:
http://<server_address>/quikwiki/quikwiki.cgi?doc
or click on the, "doc," link in the page header.
Manual Installation
1. Unpack the tar file and change to the QuikWiki source directory.
tar zxvf quikwiki-<version>.tar.gz
cd quikwiki-<version>
2. Determine in the location of the system's, "htdocs," directory,
the directory named by the "DocumentRoot" directive in the
server's httpd.conf file, or the name of the $HOME directory's
public HTML subdirectory. The server also needs to have, "Options
ExecCGI," enabled for that directory. Ask your Web administrator
if you're not certain.
2. Make quikwiki.cgi executable with the shell command:
chmod +x quikwiki.cgi
3. If installing in the system's <DocumentRoot> directory:
mkdir <DocumentRoot>/quikwiki
If installing in your public HTML directory:
mkdir $HOME/<public HTML directory>/quikwiki
3. (Optional) To use RCS to manage revisions, create a, "RCS,"
subdirectory.
mkdir <DocumentRoot>/quikwiki/RCS
or
mkdir $HOME/<public HTML directory>/quikwiki/RCS
4. Copy the QuikWiki files to the destination directory.
cp quikwiki.cgi HomePage WikiHeader WikiFooter <DocumentRoot>/quikwiki
cp eg/QuikReference <DocumentRoot>/quikwiki
or
cp quikwiki.cgi HomePage WikiHeader WikiFooter $HOME/<public_html>/quikwiki
cp eg/QuikReference $HOME/<public_html>/quikwiki
4. You can omit the script name if, "DirectoryIndex index.cgi," is
set in, "httpd.conf," or the directory's, ".htaccess," file.
You'll need to symlink quikwiki.cgi to index.cgi.
Change to the installation directory and run the shell command:
ln -s quikwiki.cgi index.cgi
The Web server must be configured to permit this. If the server
won't execute the script through a symlink, you can also rename
quikwiki.cgi to index.cgi. Again, ask your Web administrator.
5. Make sure that Apache can read and write the files. The
directories and files need to be owned by the same user as
the HTTPD server process, or the user that owns a $HOME<public HTML>
directory.
This example uses, "apache," but the owner should be the
user named in the, "User," http.conf directive if installing
system-wide.
cd ..
chown -R apache quikwiki
Or even better, make the files and directories group-writable.
If you have trouble saving page revisions, make certain that the
ownership and permissions of the quikwiki and RCS subdirectories,
the page itself, and the RCS archive, allow you to write to those
files and directories.
Apache Configuration Notes
There is copious documentation in the mod_perl and Apache source code
packages. It is easier to allow mod_perl's build to also configure
Apache; then, you can simply, "make install," the HTTP server.
The HTTPD daemon needs to be configured with modules that are either
loaded at run time (look at the, "Load Module," directive in
httpd.conf, or compiled into the server daemon. Running "httpd -l"
should provide output like this.
Compiled-in modules:
http_core.c
mod_env.c
mod_log_config.c
mod_mime.c
mod_negotiation.c
mod_status.c
mod_include.c
mod_autoindex.c
mod_dir.c
mod_cgi.c
mod_asis.c
mod_imap.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_access.c
mod_auth.c
mod_setenvif.c
mod_perl.c
suexec: disabled; invalid wrapper /usr/local/apache/bin/suexec
At least a few of the following httpd.conf directives are necessary
to run QuikWiki or any Perl CGI script.
# Perl script handler. This might be present but commented out in
# a default httpd.conf file. The actual path to the Perl binary
# should have been configured during compilation.
<IfModule mod_perl.c>
<Location /perl>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
</IfModule>
# This line should also be uncommented
AddHandler cgi-script .cgi
# Adding index.cgi allows you to omit the script's name in URLs.
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi
</IfModule>
# The UserDir directive needs to be set if installing
# in $HOME/public_html
<IfModule mod_userdir.c>
UserDir public_html
</IfModule>
# The "<Directory /usr/local/apache/htdocs> (use the
# actual value of DocumentRoot) section should contain the
# following options:
Options Indexes FollowSymLinks ExecCGI
# These are the default options for ~/public_html subdirectories in
# the default Apache configuration and should be uncommented in
# httpd.conf
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ExecCGI
<Limit GET POST OPTIONS PROPFIND>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
# As an alternative, options can be set in the quikwiki
# subdirectory only.
<Directory /usr/local/apache/htdocs/quikwiki>
Options +ExecCGI
# Allow access only by hosts on local network.
Order allow,deny
Allow from 192.168.0
</Directory>
# In a QuikWiki subdirectory, you can set options in a
# .htaccess file.
Options ExecCGI
# But this must still be allowed in httpd.conf:
AllowOverride Options
Licensing
Quikwiki is free software. You can modify and distribute QuikWiki
using the same licensing terms as Perl itself. Consult the file
"Artistic" for details.
Questions concerning QuikWiki (or Apache) configuration, bug
reports, and suggestions should be sent to the author,
rkies@cpan.org.
$Id: README,v 1.13 2004/02/23 19:51:08 kiesling Exp $
------------------------------
Date: Sun, 16 May 2004 22:21:23 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: help w/ opening a file
Message-Id: <2gq0pdF5guckU1@uni-berlin.de>
Mat W wrote:
> I need help opening files.
First of all you need help to understand that it's rude to post the
same question concurrently in multiple newsgroups. Please learn to
behave yourself on Usenet!
> Basically, I have a directory full of html pages. These pages are
> templates, with variables where i want them. For example, lets say
> i have a file called test.html in my pages directory, and it
> contains the following:
>
> <head><title>$mytitle</title></head>
You seem to be asking a FAQ.
perldoc -q "expand variables"
But you should also consider to make use of a templating system, where
special template variables are replaced instead of interpolated. Check
out CPAN for suitable modules.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 16 May 2004 13:08:39 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: IF problem?!
Message-Id: <rJJpc.78070$sK3.46608@nwrddc03.gnilink.net>
[Please follow established Usenet customs and don't post jeopardy style;
trying to re-arrange into chronological sequence]
tihana@kata.com wrote:
>>> My Perl program:
>>> ...
>>> if ($sup=="HTM") {
>>> print "$sup\n";
>>> }
>> change == to eq.
>> that's first.
>> second - what about "new line characters"?
> 1.) Is that mean that == is different than eq ?
Did you Read The Fine Manual? From "perldoc perlop":
Equality Operators
Binary "==" returns true if the left argument is numerically equal to
the right argument.
[...]
Binary "eq" returns true if the left argument is stringwise equal to the
right argument.
> That line work normaly "if ($dir == 0) {..."
Well, in this case you probably want to compare the numerical value, don't
you?
> 2.) What about "\n" is something wrong too?
Often people forget that a line is terminated by a newline when reading data
from a file.
jue
------------------------------
Date: Sun, 16 May 2004 08:06:03 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: IF problem?!
Message-Id: <slrncaeppr.192.tadmc@magna.augustmail.com>
<tihana@kata.com> <tihana@kata.com> wrote:
> 1.) Is that mean that == is different than eq ?
Perl's operators are documented in:
perldoc perlop
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 16 May 2004 09:19:00 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: IF problem?!
Message-Id: <20040516090202.T15402@dishwasher.cs.rpi.edu>
On Sun, 16 May 2004 tihana@kata.com wrote:
> 1.) Is that mean that == is different than eq ?
> That line work normaly "if ($dir == 0) {..."
Yes. == and eq are two different operators. == tests for numeric equality
(which is why it does what you expect for $dir == 0), while eq tests for
string equality.
perldoc perlop lists these operators as well as all the others that have
both numeric and string values, but for a few examples:
$x = 'abc';
$y = 'def':
print "$x == $y\n" if $x == $y;
print "$x eq $y\n" if $x eq $y;
$i = "3.0";
$j = "3";
print "$i == $j\n" if $i == $j;
print "$i eq $j\n" if $i eq $j;
$m = '3e2';
$n = '300';
print "$m == $n\n" if $m == $n;
print "$m eq $n\n" if $m eq $n;
---------------------------
OUTPUT:
$x == $y
$i == $j
$m == $n
Each of these pairs of values are numerically equivalent. The first pair
is because strings that do not start with 'numeric' values are evaluated
as 0 in numeric context. None of them are equivalent in string context.
Paul Lalli
> 2.) What about "\n" is something wrong too?
>
>
> > change == to eq.
> > that's first.
> > second - what about "new line characters"?
>
> >> My Perl program:
> >> ...
> >> if ($sup=="HTM") {
> >> print "$sup\n";
> >> }
> >> ...
>
>
>
>
------------------------------
Date: Sun, 16 May 2004 12:40:53 -0700
From: "Mat W" <werbs@cox.net>
Subject: Re: IF problem?!
Message-Id: <atPpc.164747$f_5.127527@lakeread01>
There are different operators for testing strings and numbers.
To test numbers:::
is equal to: ==
is not equal to: !=
and the others (you should know these): < <= > >=
For string comparisons, you have to use different operators, or the results
wont be what you want:
is equal to: eq
is not equal to: ne
(there are others that test for ascii order and stuff like that, but i
dont know em by heart)
<tihana@kata.com> wrote in message news:c87ip2$nk4$1@ls219.htnet.hr...
> How is possible that My printout prints all value of $sop, e.g.
> -----------------
> My printout:
> ERI
> SOF
> HTM
> SOF
> ------------------
> My Perl program:
> ...
> if ($sup=="HTM") {
> print "$sup\n";
> }
> ...
> ------------------
>
>
>
------------------------------
Date: 16 May 2004 14:57:39 -0700
From: yjin6666@hotmail.com (yjin6666@hotmail.com)
Subject: It works and thanks. Re: what's wrong with my CPAN module
Message-Id: <edd5194d.0405161357.24c0f74@posting.google.com>
Hi, Ben,
I deleted the Lockfile /root/.cpan/.lock file and it works. Thanks a lot.
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c83jkb$5p1$2@wisteria.csv.warwick.ac.uk>...
> Quoth yjin6666@hotmail.com (yjin6666@hotmail.com):
> > Hi,
> >
> > I use to able to install perl modules by CPAN (perl -MCPAN -e shell).
> > Yesterday when I was installing some perl modules, I also updated CPAN
> > as the system made the suggestion. Now I have a problem as the
> > following:
> >
> > [root@versaw03 jin]# perl -MCPAN -e shell
> > Undefined value assigned to typeglob at (eval 14) line 15, <RC> line
> > 11.
> > Warning [/etc/inputrc line 11]:
> > Invalid variable `mark-symlinked-directories'
> > CPAN.pm panic: Lockfile /root/.cpan/.lock
> > reports other host localhost.localdomain and other process 5008.
> > Cannot proceed.
> >
> > Could someone tell me how to solove this problem.
>
> Make sure you don't have any CPAN processes running and delete
> /root/.cpan/.lock.
>
> Ben
------------------------------
Date: Sun, 16 May 2004 21:46:26 GMT
From: idis <takesmore--nospam--thanthat@hotmale.com>
Subject: Passing params from cli/sh
Message-Id: <Xns94EBB4E785D0Dx@65.24.7.50>
Greetings,
This is literally my first day with perl. So i hope
that you can bear with yet another fng. If this is not quite
presented in the most efficient or coherent manner. It will
improve.
The object is to pass data/parameters to this scriptlet
from within a bash/sh/*sh script or from the cli. It is basically
an attempt for a generic and somewhat simple sed util.
here is a crude outline..
#!/usr/bin/perl
#
#
#
#
no idea what to do here. The book im using is
is painfully brief and has no examples of how
to handle any function with unknown variables
-i.old -p -e "s/\ $vfindstr/\ $vreplacestr/g" $vfilestr
I think that this line above is correct. Just not sure how
to connect the dots.
It appears as though parameters are stored in @_
that will allow something such as
local($vfindstr,$vreplacestr,$vfilestr) = @_;
This however is described in a context unlike
I've seen before.. Is there a simple way to
do this. To provide a find and replace string with
target file. Yet keeping it generic enough to
call this script.sub/function from various locations?
I assumed that it would be implemented such as
perl psed.pl "vfindstr","vreplacestr","vfilestr"
Any help would be appreciated. If this is the
millionth time this question was posed. My apologies.
~Init
------------------------------
Date: 16 May 2004 08:28:06 -0700
From: GlgAs@Netscape.net (laszlo)
Subject: perl 5.8.3 problem
Message-Id: <945e4584.0405160728.829b6d5@posting.google.com>
The following program worked fine with Activstate perl 5.8.0. The
slide can be moved by the cursor and shows the values between 0.0 and
3.0 in .1 increments
Now I upgraded to 5.8.3 and the slide sticks to the 0.0 or 0.1
positions, can not be moved further. The Tk programs are identical in
both case (v 8.024).
In the comp.lang.perl.Tk list somone complained similar problem in
Linux.
I suppose something is wrong with the rounding process used by the Tk
module.
#!/usr/bin/perl
use Tk;
$mw = MainWindow->new();
$parvalue = .11;
$mw->Scale(-from=>0,-to=>3,-variable=>\$parvalue,
-orient=>'horizontal',
-borderwidth=>0,
-sliderlength=>20,
-label=>"",
-highlightthickness=>0,
-troughcolor=>'white',
-resolution=>'.1',
-takefocus=>1
)->pack();
MainLoop();
Ps: if -resolution is not set the slider takes only 0, 1, 2, 3 values,
and scale works properly for integers).
Any help appreciated.
laszlo
------------------------------
Date: 16 May 2004 12:08:00 -0700
From: dkawer@ic-itcr.ac.cr (Daniel Kawer)
Subject: Porter algorithm in spanish
Message-Id: <4ec3c2e4.0405161108.6d3dcd18@posting.google.com>
Im working on the development of a spanish search engine and I want to
use the Porter Stemming Algorith. I havent been able to find a version
for spanish in PERL, only in C.
Does anyone knows the existance of a Perl implementation of the Porter
Algorithm for Spanish?
Help will be appreciated and documented,
Thanks in advance,
Daniel Kawer
Costa Rica Institute of Technology
------------------------------
Date: Sat, 15 May 2004 10:16:58 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: print all combinations
Message-Id: <871xlmxwmd.fsf@jidanni.org>
Let's say our country's radio callsigns look like the output of
for $a('B'){for $b(qw{V X}){for $c(1..8){for $d('A'..'Z'){print "$a$b$c$d\n"}}}}
It bothers me that even though I can describe those callsigns
with regexp /B[VX][1-8][A-Z]/, in printing them out one needs to write
for loops for each element. Isn't there some
sub combinations(){print all the combinations of all the elements of
the array (not permutations)} that I can write?
------------------------------
Date: Sun, 16 May 2004 12:27:37 -0700
From: "Mat W" <werbs@cox.net>
Subject: simple problem w/ opening files
Message-Id: <JgPpc.164739$f_5.1241@lakeread01>
I need help opening files. Basically, I have a directory full of html
pages. These pages are templates, with variables where i want them. For
example, lets say i have a file called test.html in my pages directory, and
it contains the following:
<head><title>$mytitle</title></head>
Now, in the script there are times when i need to print this file. What i
want to do is first set the variables, then open the file and print the html
contents.
For example:
$mytitle = "TEST";
open (FILEIN, "./pages/test.html");
@contents = <FILEIN>;
close (FILEIN);
print @contents.
The above code opens files the files and reads them fine, but the problem is
the printing.
Instead of interpolating the contents of the file, it prints EXACTLY whats
in the file.
so, given whats above, the output is literally:
<head><title>$mytitle</title></head>
instead of being
<head><title>TEST</title></head>
Is there any way to open a file so that, when the contents are printed, perl
interprets any special characters? More or less what im trying to say is,
that when the file contents are printed, its like they are in single quotes
instead of double quotes (ie. variables arent processed).
Please help me! This is the only thing stopping me from completing my
project.
P.S. my html pages contain more than a variable for the title. They contain
variables in certain places so i can have list boxes and other things that
reflect the contents of a database.
------------------------------
Date: 16 May 2004 13:31:45 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: simple problem w/ opening files
Message-Id: <40a7cfb1@news.victoria.tc.ca>
Mat W (werbs@cox.net) wrote:
: I need help opening files. Basically, I have a directory full of html
: pages. These pages are templates, with variables where i want them.
There are numerous template modules on cpan. You could try one of them,
that would be the easiest long term solution, and they support more
complex processing such as loops, etc, which you're bound to want at some
point.
There is also a faq entry, look for
"How can I expand variables in text strings?
There is also at least one other solution, using the eval <<XX format,
that is often mentioned in this newsgroup when ever the above faq is
mentioned. google this group on that faq entry to find details.
I could give examples but finding a template module you like would be my
first choice.
One key item - the various techniques are generally safe IFF you control
the template. They are NOT SAFE if a user controls what the temlate looks
like. In that case you have to be more careful.
--
(paying) telecommute programming projects wanted. Simply reply to this.
------------------------------
Date: Sun, 16 May 2004 20:43:42 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: simple problem w/ opening files
Message-Id: <c88jpu$fgs$1@wisteria.csv.warwick.ac.uk>
Quoth "Mat W" <werbs@cox.net>:
> I need help opening files.
This is not a problem with opening files. This is a problem with
interpolating variables into strings.
> Basically, I have a directory full of html
> pages. These pages are templates, with variables where i want them. For
> example, lets say i have a file called test.html in my pages directory, and
> it contains the following:
>
> <head><title>$mytitle</title></head>
There are (at least) three ways to achieve what you are trying to do.
1. Use a proper templating system, such as the Template Toolkit (search
for Template.pm on CPAN). This is long-term the most flexible solution.
2. Keep your strings to be interpolated in a hash, and interpolate them
like this:
use File::Slurp;
my %strings = (
mytitle => 'TEST',
);
my $html = read_file '/path/to/file/;
for ($html) {
s/ (?! \\ ) \$ (\w+) /$strings{$1}/gx;
s/ (?! \\ ) \$ \{ (\w+) \} /$strings{$1}/gx;
s/ \\ \$ /\$/gx;
}
print $html;
This will allow interpolations like "$mytitle" and "${mytitle}", and
will let you insert a literal $ with "\$".
3. Do what you actually asked, which involves using eval and is thus
DANGEROUS. This Is Not A Good Solution.
$html = eval <<EVAL;
<<__END__OF__EVAL__
$html
__END__OF__EVAL__
EVAL
$html =~ s/\n$//;
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk
------------------------------
Date: Sun, 16 May 2004 21:51:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: simple problem w/ opening files
Message-Id: <x78yfs2g7p.fsf@mail.sysarch.com>
>>>>> "MW" == Mat W <werbs@cox.net> writes:
MW> Now, in the script there are times when i need to print this
MW> file. What i want to do is first set the variables, then open the
MW> file and print the html contents.
this is not a problem with opening files, it is a problem with variable
interpolation and template expansion.
please choose better subject on your future posts. knowing how to
describe a problem is half the solution.
BTW, where did you ever get the idea that variables in text read from a
file would get interpolated? i am curious as if it is a source for your
perl knowledge, it should be marked as very wrong.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 16 May 2004 08:08:37 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Sort an array + more
Message-Id: <slrncaepul.192.tadmc@magna.augustmail.com>
krzys-iek <krzys-iek@-----wp.pl> wrote:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> napisal nam:
>> Have you
>> read
>> what "perldoc -f sort" says?
>
> I didn't know that command.
Have you seen the Posting Guidelines that are posted here frequently?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 16 May 2004 09:23:02 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Sort an array + more
Message-Id: <CJOdnWnaBPGl9jrdRVn-uw@adelphia.com>
krzys-iek wrote:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> napisal nam:
>
>
>> What specific problem do you have with the sort function? Have you
>> read
>> what "perldoc -f sort" says?
>
> Well, I am new to Perl and I read web tutorials. I didn't know that
> command.
Now is a great time to learn it then. ;-)
Perldoc is the perl documentation reader. It's similar to 'man', the unix
manual page reader, but it has some additional useful features as well. To
learn about it, open up a terminal window, and type "perldoc perldoc" -
without the quotes of course.
Also, as Tad suggested, reading the Posting Guidelines would be a great idea
too. They're posted here frequently.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sun, 16 May 2004 15:46:38 +0200
From: "krzys-iek" <krzys-iek@-----wp.pl>
Subject: Re: Sort an array + more
Message-Id: <c87rgs$5ak$1@nemesis.news.tpi.pl>
Ben Morrow <usenet@morrow.me.uk> napisal nam:
> as your using strict.
'my' is a name of varieble or ... ?
perldoc strict returns nothing, where can I read about it?
> Personally I would use a pattern match here, rather than two splits:
>
After few tests I had to add third split (case with only forename given
etc)...
my ($name, undef, $uid, $gid, $full_name) = split /:/;
my ($forename_a, $surname_a) = split (/[ ]/, $full_name, 2);
my ($forename) = split (/[,]/,$forename_a,2);
my ($surname) = split (/[,]/,$surname_a,2);
But I couldn't write a signle pattern match, andy idea?
I read about *.? meaning here
http://www.comp.leeds.ac.uk/Perl/matching.html#res
>
> push @users, {
> name => $name,
> uid => $uid,
> gid => $gid,
> forename => $forename,
> surname => $surname,
> };
> }
Is it a structure? I should learn about it and understand it.
perldoc -f ..... :)
>
> my $key = ('name', 'forename', 'surname')[ $ARGV[1] ];
>
We use agian "my" (because we use strict mode?)
I must read about it....
>> @users =
>> sort { $a->{$key} cmp $b->{$key} }
>> grep { $_->{gid} == $ARGV[0] }
>> @users;
> These will be from entries which have fields missing, I expect. If you
> are happy to have such entries display and sort as blanks then you can
> put
>
OK I see (I have blank fields).
> no warnings 'uninitialized';
It works ;)
My script (new ver.):
==========================
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'uninitialized';
system("clear");
$_=$ARGV[0];
( /--help/ ) && ( printf "\n\nHELP \n\n
---------------------------------------\n
---------------------------------------\n
---- sorry no help yet ----------------\n\n" ) && (exit);
# I do not how to use <<heading; here. It did not work. ??????????????????
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
( m/([^0-9]+)/ ) &&
(printf "\n Bad GID ($_)! \n Use --help !\n\n") &&
(exit);
$_=$ARGV[1];
( m/([^0-2])/ ) &&
(printf "\n Bad sorting rule ($_)! \n Use --help !\n\n") &&
(exit);
my $file = 'passwd';
open my $INFO, '<', $file or die "\n\n Can not open $file:\n $!\n\n";
my @users;
while (<$INFO>) {
my ($name, undef, $uid, $gid, $full_name) = split /:/;
my ($forename_a, $surname_a) = split (/[ ]/, $full_name, 2);
my ($forename) = split (/[,]/,$forename_a,2);
my ($surname) = split (/[,]/,$surname_a,2);
push @users, {
name => $name,
uid => $uid,
gid => $gid,
forename => $forename,
surname => $surname,
};
}
my $key = ('name', 'forename', 'surname')[ $ARGV[1] ];
@users =
sort { $a->{$key} cmp $b->{$key} }
grep { $_->{gid} == $ARGV[0] }
@users;
my $i;
print <<heading;
--------------------------------------------------
| # | login | forename | surname |
--------------------------------------------------
heading
printf "| %-3d | %10s | %11s | %15s |\n",
++$i, $_->{name}, $_->{forename}, $_->{surname}
for @users;
printf " --------------------------------------------------\n";
------------------------------
Date: Sun, 16 May 2004 09:14:11 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Sort an array + more
Message-Id: <slrncaetpj.1d8.tadmc@magna.augustmail.com>
krzys-iek <krzys-iek@-----wp.pl> wrote:
> Ben Morrow <usenet@morrow.me.uk> napisal nam:
>
>> as your using strict.
>
> 'my' is a name of varieble or ... ?
a function. You access the docs for functions with the "-f" switch:
perldoc -f my
> perldoc strict returns nothing,
Then you have a broken installation of perl...
> where can I read about it?
On your own computer (once you have fixed the installation).
or: www.perldoc.com
>> push @users, {
>> name => $name,
>> uid => $uid,
>> gid => $gid,
>> forename => $forename,
>> surname => $surname,
>> };
>> }
>
> Is it a structure?
Yes. The 2nd argument to push() above is a reference to an anonymous hash.
> I should learn about it and understand it.
> perldoc -f ..... :)
You are catching on. :-)
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
>> my $key = ('name', 'forename', 'surname')[ $ARGV[1] ];
>>
>
> We use agian "my" (because we use strict mode?)
Yes. strict requires that you declare all of your variables
before you use them.
> I must read about it....
See also:
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
> # I do not how to use <<heading; here. It did not work. ??????????????????
> # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The << is called a "here document" (here-doc).
Read about it in the "Quote and Quote-like Operators" section of:
perldoc perlop
> ( m/([^0-9]+)/ ) &&
That is more clearly written this way:
( m/(\D+)/ ) &&
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 16 May 2004 17:02:06 +0200
From: "krzys-iek" <krzys-iek@-----wp.pl>
Subject: Re: Sort an array + more
Message-Id: <c87vub$irm$1@nemesis.news.tpi.pl>
Tad McClellan <tadmc@augustmail.com> napisal nam:
> Then you have a broken installation of perl...
Me stupid, I have used perldoc -f strict :D
> You are catching on. :-)
Who? Me? ;]
>
> http://perl.plover.com/FAQs/Namespaces.html
406 :(
>
> The << is called a "here document" (here-doc).
>
> Read about it in the "Quote and Quote-like Operators" section of:
>
> perldoc perlop
That perldoc sux... but finaly I found it (2700 lines...)!
( /--help/ ) && (printf <<'HELP_SCREEN') && (exit);
But now $0 (script name, bash varieble?) does not work here :(
With printf "This is a $0 script"; I saw name of the script.
Any ideas?
HELP_SCREEN
>
> That is more clearly written this way:
>
> ( m/(\D+)/ ) &&
\D # Any non-digit. The same as [^0-9]
Thank you again :)!
With kindest regards. Krzysiek
------------------------------
Date: Sun, 16 May 2004 18:39:12 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Sort an array + more
Message-Id: <c88cgg$cme$1@wisteria.csv.warwick.ac.uk>
Quoth "krzys-iek" <krzys-iek@-----wp.pl>:
> > http://perl.plover.com/FAQs/Namespaces.html
>
> 406 :(
WorksForMe...
> > The << is called a "here document" (here-doc).
> >
> > Read about it in the "Quote and Quote-like Operators" section of:
> >
> > perldoc perlop
>
> That perldoc sux... but finaly I found it (2700 lines...)!
No, it's a very concise description of all the operators in Perl...
there are a lot of them and they do some quite complicated things.
> ( /--help/ ) && (printf <<'HELP_SCREEN') && (exit);
^^^^^^
Still using printf where you should use print. This will bite you one
day, when you try to print something with a % in.
> But now $0 (script name, bash varieble?) does not work here :(
> With printf "This is a $0 script"; I saw name of the script.
> Any ideas?
From perlop:
| If quoted, the type of quotes used determine the treatment of the
| text, just as in regular quoting. An unquoted identifier works like
| double quotes.
That is,
<<HERE
...
HERE
or
<<"HERE"
...
HERE
will interpolate, but
<<'HERE'
...
HERE
won't.
Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
------------------------------
Date: Sun, 16 May 2004 21:45:53 +0200
From: "krzys-iek" <krzys-iek@-----wp.pl>
Subject: Re: Sort an array + more
Message-Id: <c88gea$7el$1@atlantis.news.tpi.pl>
Ben Morrow <usenet@morrow.me.uk> napisal nam:
>
> <<'HERE'
> ...
> HERE
>
> won't.
>
True... thank you (perldoc is OK but its interface is not, perldoc.com is
better).
BTW
@users =
sort { uc($a->{$key}) cmp uc($b->{$key}) }
grep { $_->{gid} == $ARGV[0] }
@users;
I had to uc() because sorting was case sensitive. And tom was before Adam :)
I think we can EOT
Thanks to everyone!
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6572
***************************************