[18048] in Perl-Users-Digest
Perl-Users Digest, Issue: 208 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 4 00:05:34 2001
Date: Sat, 3 Feb 2001 21:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981263107-v10-i208@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 3 Feb 2001 Volume: 10 Number: 208
Today's topics:
Re: * Perl vs. Java in high-traffic Website * (Chris Fedde)
added? <victor@fontes.net>
Re: Anonymous FTP? <godzilla@stomp.stomp.tokyo>
Re: Anonymous FTP? <Ilu@erde.ghb.fh-furtwangen.de>
Re: Anonymous FTP? <tony_curtis32@yahoo.com>
Re: Anonymous FTP? <carvdawg@patriot.net>
Re: Apologies to Joyce Kilmer, a hack for your enjoymen <jdf@pobox.com>
Re: Apologies to Joyce Kilmer, a hack for your enjoymen <jdf@pobox.com>
Re: Apologies to Joyce Kilmer, a hack for your enjoymen <jdf@pobox.com>
Re: Can't read entire file into string. <jdf@pobox.com>
Re: CSV and XML (Eric Bohlman)
Re: CSV and XML <godzilla@stomp.stomp.tokyo>
deleting some folders... <c.gersch@team.isneurope.com>
Re: deleting some folders... <bwalton@rochester.rr.com>
Re: input parameters <derek@dpat.fsnet.co.uk>
Re: JAPH <sumus@aut.dk>
Re: JAPH <godzilla@stomp.stomp.tokyo>
Re: matching integer's and end of a string problem <jdf@pobox.com>
Problem opening for writing, going nuts, please help! misterfive@my-deja.com
Re: search index/stop words/performance <snowhare@long-lake.nihongo.org>
Re: Substituting variables in a text file <thoren@southern-division.com>
Re: Substituting variables in a text file <sumus@aut.dk>
System call correct? <johngros.NOSPAM@bigpond.net.au>
Re: System call correct? <bwalton@rochester.rr.com>
Re: System call correct? <johngros.NOSPAM@bigpond.net.au>
Re: Using Date::Manip to compute Fat Tuesday <sumus@aut.dk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 04 Feb 2001 02:22:13 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: * Perl vs. Java in high-traffic Website *
Message-Id: <p13f6.40$M8.171346944@news.frii.net>
[cc and posted]
In article <Xns903D779016001cuthereretohdplanetc@195.186.1.107>,
Reto Hersiczky <cut_here.retoh@dplanet.ch> wrote:
>
>! Need *your* opinion !
>
>"Some guys explain to a customer: Websites from <that> kind of traffic
> meet the edge of running dynamic pages with Perl. They sugguest to
> make future developments in pure Java."
>
>Technical Conditions:
>
>- Apache Webserver
>- Sun Solaris
>- Postgres database, ~ 15 Tables, < 50000 rows
>- Web traffic approximately 25000 page views per hour
>
>I assume the reason for their advise lies in the fact it is easyer
>to protect the intellectual property with Servlets rather than
>deploying a script where the customer becomes the ability to read code.
>
Do you really have a problem or is this some consultant spreading
fear uncertainty and doubt? That statement in quotes above? At best it
is misleading. At worst it is a lie.
It is my opinion that simply changing from Perl to Java, all other
things left the same, will make no significant change in the
performance of the system. Measuring and tuning the existing system
regardless of implementation language will be far more efficient
in terms of time and capital than re-writing the existing system
in a new language.
Often the best way to gain a performance improvement is simply to
upgrade to faster hardware. If your hardware is more that 12
months old it may well be time to move the application to a new
box. That will definitely be cheeper than hiring a developer to
re-write your app in Java. And at a much higher speedup factor
than simply re-writing it.
chris
--
This space intentionally left blank
------------------------------
Date: Sun, 4 Feb 2001 02:50:55 -0300
From: "Victor Fontes" <victor@fontes.net>
Subject: added?
Message-Id: <3a7ce112$1@news.terra.com.br>
Hello...
How can I make a script that can make it:
At a web page the user put a number betwen 01 and 99.
The script should return which numbers where added to form the result, and
it these numbers can only be 01, 02, 04, 08, 16, 32 or 64.
eg 1: user's input:19 -> script's result:01, 02 e 16.
eg 2: users' input:31 -> script's result:01, 02, 04, 08, 16.
Thanks for your help.
Victor
victor@fontes.net
------------------------------
Date: Sat, 03 Feb 2001 15:27:59 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Anonymous FTP?
Message-Id: <3A7C93FF.420BF4BA@stomp.stomp.tokyo>
"Jörg Vetter" wrote:
> I have to write a perl script which connects to a
> host and find out if the ftp server is anonymous.
> I already know that there´s running a ftp server
> on this host.
My presumption is you are asking how to
ascertain if a server allows an anonymous
logon via ftp.
You could discover your answer in less than
thirty seconds by starting your favorite
ftp program and, direct it to connect with
this server in question. Another alternative
is to use an ftp URL in your browser. For
a very definitive answer of certainty,
simply email this server and ask.
Any one of those options along with other
options, would be a lot easier and less
time consuming than writing a ftp script
simply to find out if anonymous logon
is allowed.
Godzilla!
------------------------------
Date: Sun, 04 Feb 2001 00:49:30 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <Ilu@erde.ghb.fh-furtwangen.de>
Subject: Re: Anonymous FTP?
Message-Id: <3A7C990A.1F31F2DA@erde.ghb.fh-furtwangen.de>
> Any one of those options along with other
> options, would be a lot easier and less
> time consuming than writing a ftp script
> simply to find out if anonymous logon
> is allowed.
> =
> Godzilla!
There are hundred oft ftps in my list, I
don=B4t have the time to do this manual.
Oliver S=F6der
------------------------------
Date: 03 Feb 2001 18:06:15 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Anonymous FTP?
Message-Id: <87d7cz1fd4.fsf@limey.hpcc.uh.edu>
>> On Sun, 04 Feb 2001 00:49:30 +0100,
>> Oliver Söder <Ilu@erde.ghb.fh-furtwangen.de> said:
>> Any one of those options along with other options,
>> would be a lot easier and less time consuming than
>> writing a ftp script simply to find out if anonymous
>> logon is allowed. =
>> Godzilla!
> There are hundred oft ftps in my list, I don=B4t have
> the time to do this manual.
Yes, well, there's a surprise.
Take a look at
perldoc Net::FTP
and see if you can access the ftp server with
$ftp->login('anonymous', 'me@my.address');
I'll assume this access checking is ethical :-)
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Sat, 03 Feb 2001 19:39:09 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Anonymous FTP?
Message-Id: <3A7CA4AD.DE2B6B50@patriot.net>
So, uh...what's your question?
"Jörg Vetter" wrote:
> I have to write a perl script which connects to a host and find out if the
> ftp server is anonymous. I already know that there´s running a ftp server
> on this host.
>
> Thanks in advance
>
> Oliver Söder
------------------------------
Date: 03 Feb 2001 19:38:44 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Apologies to Joyce Kilmer, a hack for your enjoyment
Message-Id: <lmrnjn8r.fsf@pobox.com>
clintp@geeksalad.org (Clinton A. Pierce) writes:
> "If you rush a Miracle Man,
> you get rotten Miracles." --Miracle Max, The Princess Bride
I tell this to my clients.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 03 Feb 2001 19:40:05 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Apologies to Joyce Kilmer, a hack for your enjoyment
Message-Id: <hf2bjn6i.fsf@pobox.com>
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
> rpolzer@web.de (Rudolf Polzer) writes:
>
> > Does not work.
>
> Are you using 5.6? It works fine for me on linux w/5.6,
> but not w/5.005_03.
Well, to be pedantic, maybe you should
require 5.6;
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 03 Feb 2001 19:40:25 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Apologies to Joyce Kilmer, a hack for your enjoyment
Message-Id: <d7czjn5y.fsf@pobox.com>
rpolzer@web.de (Rudolf Polzer) writes:
> Does not work. Perl complains about this. Is it really _your_ hack or did
> you copy it from a book?
Nasty, nasty!
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 03 Feb 2001 19:33:13 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Can't read entire file into string.
Message-Id: <pugzjnhy.fsf@pobox.com>
Mario <m_ario@my-deja.com> writes:
> It's not an error,it behaves in this way (reading a line at once).
> You read the entire file by accessing all the lines sequencially.
This is misleading. The correct (efficient, commonly used, idiomatic)
way to do it is described in perlfaq3.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 4 Feb 2001 00:09:37 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: CSV and XML
Message-Id: <95i6k1$b7j$1@bob.news.rcn.net>
MAW <maw@markaw.com> wrote:
> I'm hoping somebody can help me oujt or point me in the right direction. I
> have a java class which can convert any CSV file into an XML file, in the
> following format:
> CSV File contents
> "item1","item2","item 3","this is the fourth item"
> Result in:
> <COL_1>item1</COL_1>
> <COL_2>item2</COL_2>
> <COL_3>item 3</COL_3>
> <COL_4>this is the fourth item</COL_4>
> The reason I have this, is I have a web server running Java Servlets that
> receives a CSV file and then needs to convert it to XML. Well, now I have to
> convert everything over to Perl so I need a script/module that can convert
You'll have to do some programming on your own, but look into the
following modules:
DBD::RAM
DBD::CSV
DBIx::XML_RDB
Text::CSV_XS
XML::Writer
XML::Generator
------------------------------
Date: Sat, 03 Feb 2001 19:27:07 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: CSV and XML
Message-Id: <3A7CCC0B.1E3613C6@stomp.stomp.tokyo>
MAW wrote:
> Hi There,
Where? Oh! There is where!
> I'm hoping somebody can help me oujt or point me in the right direction. I
> have a java class which can convert any CSV file into an XML file, in the
> following format:
> CSV File contents
> "item1","item2","item 3","this is the fourth item"
> Result in:
> <COL_1>item1</COL_1>
> <COL_2>item2</COL_2>
> <COL_3>item 3</COL_3>
> <COL_4>this is the fourth item</COL_4>
Staying strictly within your stated parameters, a simple
while loop could handle this, just dandy.
However, if you are parsing for other aspects of XML,
you would be wise to research and learn about a good
number of modules available at CPAN for this very job.
http://www.perl.com/CPAN-local/README.html
This is an excellent site. However, practice patience;
it is exceptionally difficult to navigate CPAN.
Returning to your parameters, you have stated a comma
separated quote enclosed variable file. For my test
script below to work, each variable in each line of
your CS-quoted-V file, must be enclosed within quotes.
My intent is to display how you could handle this if
your needs are basic, not too complex. If so, you
will discover writing your own routines to be more
efficient and quicker than a module, for basic
low to moderate complexiety tasks.
You have not commented on your numbering scheme so
I am making a presumption you want linear numbering.
This is accomplished by a counter, $count , in my script.
Normally you could use the default counter for a while loop,
$. but this will not work quite right due to splitting
your lines into variables. If you were to replace $count
with $. in my script, you will note the number five and
multiples of five, will be skipped over, with four
variables being created for each line. Play with this
counter if your needs are different. It can be reset
after each input line, initialized with a different value,
whatever. Just takes some simple coding.
This test script is relatively efficient, fairly quick,
in its reliance on substring rather than a regex. This
does save on processing time and memory usage complimenting
the use of an easy-does-it while loop.
Other than staying strictly within your stated parameters,
this type of looping could be expanded to handle quite
a variety of parsing, up to a point where complexiety
becomes too great of an issue. A module might be a better
choice for highly complex circumstances.
Godzilla!
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
open (CSV, "test.txt");
$count = 1;
while (<CSV>)
{
chomp ($_);
@Array_Temp = split (/,/, $_);
foreach $element (@Array_Temp)
{
$element = substr ($element, 1, length ($element) - 2);
$element = "<COL_$count>$element</COL_$count>\n";
print $element;
$count++;
}
}
close (CSV);
exit;
CONTENTS OF TEST.TXT:
_____________________
"item 1","item 2","item 3","item 4"
"item 1","item 2","item 3","item 4"
"item 1","item 2","item 3","item 4"
PRINTED RESULTS:
________________
<COL_1>item 1</COL_1>
<COL_2>item 2</COL_2>
<COL_3>item 3</COL_3>
<COL_4>item 4</COL_4>
<COL_5>item 1</COL_5>
<COL_6>item 2</COL_6>
<COL_7>item 3</COL_7>
<COL_8>item 4</COL_8>
<COL_9>item 1</COL_9>
<COL_10>item 2</COL_10>
<COL_11>item 3</COL_11>
<COL_12>item 4</COL_12>
------------------------------
Date: Sun, 4 Feb 2001 04:02:52 +0100
From: "Christian Gersch" <c.gersch@team.isneurope.com>
Subject: deleting some folders...
Message-Id: <95igov$rer$04$1@news.t-online.com>
Hi there!
I have got a 'session' directory in that are subfolders with random numbers
included. Every subfolder does include two files.
Now I want to delete every subfolder including it two files in it if the
subfolder would be older than 5 minutes (by a perl script operated by cron).
Well, this is the first part of my code:
======
$dir= "/home/httpd/session" || '.';
opendir DIR, $dir or die "Can't open directory $dir: $!\n";
@files=grep !/^\./, readdir(DIR);
======
...and how could I go on?
======
$now = time();
$seconds = 60*5;
foreach (@files) { if ( ($now - (stat($_))[9]) > $seconds ) { unlink($_)
} }
======
....doen't work correctly. :-(
Thank you very much!
-Chris
--
Christian Gersch, chris@team.isneurope.com
:: www.neukunden.myisn.de - Geld für Ihre Startseite ::
------------------------------
Date: Sun, 04 Feb 2001 03:55:10 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: deleting some folders...
Message-Id: <3A7CD345.3971430D@rochester.rr.com>
Christian Gersch wrote:
...
> I have got a 'session' directory in that are subfolders with random numbers
> included. Every subfolder does include two files.
>
> Now I want to delete every subfolder including it two files in it if the
> subfolder would be older than 5 minutes (by a perl script operated by cron).
>
> Well, this is the first part of my code:
> ======
> $dir= "/home/httpd/session" || '.';
------------------------------^^^^^^
What is that supposed to do? The first part of the || is always true,
so the second piece will never be evaluated.
>
> opendir DIR, $dir or die "Can't open directory $dir: $!\n";
>
> @files=grep !/^\./, readdir(DIR);
> ======
>
> ...and how could I go on?
>
> ======
> $now = time();
> $seconds = 60*5;
> foreach (@files) { if ( ($now - (stat($_))[9]) > $seconds ) { unlink($_)
> } }
> ======
>
> ....doen't work correctly. :-(
Please describe in much much greater detail. "doesn't work correctly"
leaves a lot of possibilities open. Looks like it would work to me, if
unlink() were capable of removing a directory which is not empty. But
it won't even remove a directory unless you are superuser and Perl was
started with -U.
perldoc -f unlink
Perl's rmdir could be used, but it will only delete empty directories.
perldoc -f rmdir
You don't say what your platform is, but maybe system("rm -f -r $_")
would work in place of unlink. It might be slow.
...
> -Chris
> --
> Christian Gersch, chris@team.isneurope.com
> :: www.neukunden.myisn.de - Geld für Ihre Startseite ::
--
Bob Walton
------------------------------
Date: Sun, 4 Feb 2001 03:07:20 -0000
From: "Derek Paterson" <derek@dpat.fsnet.co.uk>
Subject: Re: input parameters
Message-Id: <95igvf$an1$1@news8.svr.pol.co.uk>
Thanks!
I already discover ARGV and it seems to assume anything passed is a
filename - which is how I've finally had to do it.
Garry Williams <garry@zvolve.com> wrote in message
news:ScLe6.587$Sn3.22756@eagle.america.net...
> On Sat, 3 Feb 2001 00:59:57 -0000, Derek Paterson
> <derek@dpat.fsnet.co.uk> wrote:
>
> >I' a turorial and some help files but no-where does it mention parameter
> >passing...
>
> You probably want to read the @ARGV section of the perlvar manual
> page. After that, you might want to read the Getopt::Std manual page.
>
> --
> Garry Williams
------------------------------
Date: 04 Feb 2001 00:35:20 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: JAPH
Message-Id: <itmrmjbb.fsf@macforce.sumus.dk>
Mona Wuerz <wuerz@yahoo.com> writes:
> In article <irrelevant>, <snipped> wrote:
>
> #!:perl -w
> use strict;
> use diagnostics;
To be fair I believe that just in JAPHs (and golf) -w and strict are
not mandatory. Some even promote platform dependency in JAPHs because
id adds to the obscurity.
The text produced by Godzillas JAPH is not very JAPH, but admittedly the
code is confusing as should be.
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: Sat, 03 Feb 2001 17:02:41 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: JAPH
Message-Id: <3A7CAA31.8B5AD051@stomp.stomp.tokyo>
Jakob Schmidt wrote:
> Mona Wuerz <wuerz@yahoo.com> writes:
> > In article <irrelevant>, <snipped> wrote:
> > #!:perl -w
> > use strict;
> > use diagnostics;
> To be fair I believe that just in JAPHs (and golf) -w
> and strict are not mandatory. Some even promote
> platform dependency in JAPHs because id adds to
> the obscurity.
> The text produced by Godzillas JAPH is not very JAPH,
> but admittedly the code is confusing as should be.
You will also note, on the fifth run
of this script, you are looking at,
or waiting on somewhat less than
48,000,000,000,000,000,000 iteration
'blocks' of, Godzilla Rocks!
I think... I should use a calculator.
This is why I mentioned it exhibits
exponential growth and, mentioned
RAM memory needs; it becomes a very
busy script, in a hurry, much like
a nitro-fueled dragster.
Heh!
Can't say I am up on today's high
class supercomputers, my knowledge
stops with the CRAY. I would surmise
ten runs or so this script would
cause a 'human eye' noticable slow
down of even a supercomputer.
I did incorporate a control to keep
my 'text block' iterations from being
exponential as well. Without this
control, this exponential growth
would be exponential within itself,
leading to a maximum of three runs
on an average home computer without
a need to wait a long period of time
for it to finish running.
It is exceptionally easy to control
this to only one block iteration,
to only one script write to another
file, by use of index,
if index script "#?" greater than
minus one, don't write to it again.
However, its exponential growth rate
is rather surprising and fun!
Godzilla Rocks!
------------------------------
Date: 03 Feb 2001 19:29:43 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: matching integer's and end of a string problem
Message-Id: <u26bjnns.fsf@pobox.com>
bernard.el-hagin@lido-tech.net (Bernard El-Hagin) writes:
> TMTWWTDI.
There's More Than Won Way To Do It?
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sun, 04 Feb 2001 04:34:21 GMT
From: misterfive@my-deja.com
Subject: Problem opening for writing, going nuts, please help!
Message-Id: <95im4d$7uc$1@nnrp1.deja.com>
Ok, I am going totaly nuts here. I'm modifying some existing BBS code. I am
trying to open a file for writing, and the program stops after the open
statement. (No, it does not execute the "die" statement, it just stop.)
I'd suspect a permission problem, except that other parts of the code happily
create files in the same directory I'm trying to create/write to with this
code. I've tried creating the file manually, setting write permissions for
everyone. It will read the file just fine, but will not write to it, and
still stops right after the open for write statement.
Here's the segment that's giving me a headache: (I've resorted to print
statements to pinpoint the problem: the code compiles just fine...)
if ($session ne $old_session) {
print "Inside session compare<br>";
print "$forum_dir/$userfile<br>";
open(USERFILE, ">$forum_dir/$userfile") ||
&CgiDie("Could't open $userfile for writing");
print "File opened for writing";
print USERFILE "$high_number\n";
print USERFILE "$session\n";
close (USERFILE);
print "end of write routine...";
}
The end result is:
----
Inside session compare
CorrectDir/CorrectFile
----
(and that's it. No writing to the file is done if the file is there, the file
is not created if it isn't.)
Other code that looks exactly like this write statement creating other files
works fine. If the userfile is there, it reads it fine using open
(USERFILE, "<$forum_dir/$userfile") || &CgiDie("Error Opening Userfile
$userfile\n");
so it's not something weird with the filename.
The directory has write permission, and other files have been created in the
same directory.
I just don't get it. Am I missing something basic? Something not so basic?
Does it just hate me?
Help!!
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sun, 04 Feb 2001 02:36:53 GMT
From: Benjamin Franz <snowhare@long-lake.nihongo.org>
Subject: Re: search index/stop words/performance
Message-Id: <9f3f6.3840$tv5.235696@news.flash.net>
Craig Bennett <theclyde@mindless.com> wrote:
: It does the search by opening the file, then going through each line to see
: if the requested keywords are in it. The search is working, but it is a bit
: slower than i would like it.
: Is there any easy way for me to increase the speed? Is having a large file
: slowing it down? Would using several smaller index files increase the
: speed?
You should use an inverted index. Try the 'Search::InvertedIndex'
module on CPAN. It can easily handle your problem.
--
Benjamin Franz
------------------------------
Date: Sun, 4 Feb 2001 00:19:04 +0100
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: Substituting variables in a text file
Message-Id: <MPG.14e6b05485eff2b1989839@news.btx.dtag.de>
In article <m80f6.369921$U46.10921884@news1.sttls1.wa.home.com>, Jeff
Schell aka jeffschell@home.com says...
> Here's the problem: I'd like to substitute words in a text file with their
> counterpart variable in a perl script. (That was horribly phrased, but maybe
> this will help explain...)
>
> Example: the text file might look like this: Hello $NAME. How are you?
>
> And let's say, for simplicity sake, that my perl file has a line like this:
> $NAME = "Joe";
>
> Of course, I have like 50 variables. Before I had to create "placeholders"
> for the names like:
>
> open (FILE, "filename.txt");
> $printtemp = join ('',<FILE>);
> close (FILE);
> $printtemp =~ s#<!-- NAME -->#$NAME#sg;
>
> But I really don't want to do that for ALL of them. Unfortunately, that's
> all I know how to do.
>
> Anybody have an easier way to open up a file and replace the exact variables
> without having to create variable placeholders and substitute them one at a
> time like I did in the above example?
#!/usr/local/bin/perl
use strict;
use warnings;
my $foo = 'hello $bar - are you all${baz}th $boo';
my $bar = 'world';
my $baz = 'rig';
my $boo = 'tonight?';
print $_ if ($_=$foo)=~s/(.*?)(\$[\w{]+}?)(.*?)/join'',$1,eval$2,$3/eg;
--
----------------------------------------------------------------------
Thoren Johne - 8#X - thoren@southern-division.com
Southern Division Classic Bikes - www.southern-division.com
------------------------------
Date: 04 Feb 2001 01:11:52 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Substituting variables in a text file
Message-Id: <hf2bmhmf.fsf@macforce.sumus.dk>
"Jeff Schell" <jeffschell@home.com> writes:
> Here's the problem: I'd like to substitute words in a text file with their
> counterpart variable in a perl script. (That was horribly phrased, but maybe
> this will help explain...)
[...]
> open (FILE, "filename.txt");
> $printtemp = join ('',<FILE>);
the idiom goes
undef $/; # use a block and local() in stead if you need $/ in other places
$printtemp = <FILE>;
> close (FILE);
> $printtemp =~ s#<!-- NAME -->#$NAME#sg;
> [...]
> Anybody have an easier way to open up a file and replace the exact variables
> without having to create variable placeholders and substitute them one at a
> time like I did in the above example?
Yeah - you _could_ look into eval (perldoc -f eval). But I like the
"placeholders" better. eval is generally viewed with a lot of suspicion
since it's generally an indicator of questionable design and can be
pretty dangerous (though of course it's called for in some cases).
I think you should use some kind of markup ($XXX or <%&XXX> or whatever)
and then use a substitution regex to extract the "keyword" and replace
the markup sequence with values that you keep in a hash. Dont let the
variable's names carry semanthics - it's bad design:
#!/usr/bin/perl -w
use strict;
my %symbols = (
NAME => "Albert",
DOG => "Fido",
CAR => "Dodge"
);
undef $/;
my $text = <DATA>; # this can be questioned by the way, but if the file's
# not huge it's OK
$text =~ s/%!([^!]+)!%/$symbols{ $1 }/g;
print $text;
__DATA__
Hello! My name is %!NAME!%, and all I ever do
is walking my dog %!DOG!%. That is unless
I'm out for a spin in my %!CAR!%.
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: Sun, 04 Feb 2001 01:59:20 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: System call correct?
Message-Id: <YH2f6.3974$l01.31211@news-server.bigpond.net.au>
Could some one tell me if this is a correct system call?
system ("C:/Program Files/Junker/junk.exe") || die "can't start proxy $!";
My understanding of the docs is yes but it is not working.
Yet an open like,
open BOGUS,"C:/Program Files/G6FTP/Users.ini" || die "can't open Users.ini
$!";
works a treat.
I am wondering if this is me not understanding the docs or not. (If not I
will go else where for help.)
------------------------------
Date: Sun, 04 Feb 2001 03:14:33 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: System call correct?
Message-Id: <3A7CC9C1.DC4DC867@rochester.rr.com>
John Boy Walton wrote:
>
> Could some one tell me if this is a correct system call?
> system ("C:/Program Files/Junker/junk.exe") || die "can't start proxy $!";
> My understanding of the docs is yes but it is not working.
> Yet an open like,
> open BOGUS,"C:/Program Files/G6FTP/Users.ini" || die "can't open Users.ini
> $!";
> works a treat.
> I am wondering if this is me not understanding the docs or not. (If not I
> will go else where for help.)
John, please provide full info in your posts: "is not working" covers a
lot of territory. Does it generate an error message? If so, what
exactly does it say? If not, what exactly does it do, and why do you
think it is not correct? Also, it would be good to state your platform
and OS (which is obviously some form of Windoze).
Having said that, I think you've probably got a DOS problem: you are
supplying what you want to be a DOS command that contains a space
character. It is necessary to quote this to DOS, or the (pathetic excuse
for a) command shell will take the part of the path/file name after the
space character as an argument. In addition, it looks like system()
doesn't convert /'s to \'s in the file name like open does (since one
wouldn't want arguments altered -- and depending on the shell [yes, you
can run a shell other than command.com on Windoze], you might not want
to alter the commands in that fashion, as the alternative shell might
accept radically different command syntax which you wouldn't want to
munge up). So something like this might work:
system("C:\\\"Program Files\"\\Junker\\junk.exe");
In the case of the open statement, the path/file is not being presented
to the (pathetic excuse for a) command shell, so the space character is
not a problem there and quoting is not required. The open command auto
converts /'s to \'s on Windoze, which it can do without creating
problems since the second argument must be a path/file (with maybe a few
extras on either end).
Finally, note that checking the return code may not be a reliable
indication of command success when using DOS's (pathetic excuse for a)
command shell. For example, attempting to execute a non-existent
command will cause DOS to print an error, but the return code will be 0,
and the die won't be executed. You might consider making your program
return a non-zero return code on success, and testing for that instead
of zero. Also, many Windoze programs don't bother with return codes,
and you'll get zero even if you "X" them off. And, of course, they might
return control to Perl before they even present their first window to
the user, and the Perl program will go merrily on its way before the
user even starts work.
--
Bob Walton
------------------------------
Date: Sun, 04 Feb 2001 03:39:16 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: System call correct?
Message-Id: <E94f6.4112$l01.32788@news-server.bigpond.net.au>
"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3A7CC9C1.DC4DC867@rochester.rr.com...
> John, please provide full info in your posts: "is not working" covers a
> lot of territory. Does it generate an error message? If so, what
> exactly does it say? If not, what exactly does it do, and why do you
> think it is not correct? Also, it would be good to state your platform
> and OS (which is obviously some form of Windoze).
>
> Having said that, I think you've probably got a DOS problem: you are
Sorry Bob for not supplying more info but I was not wanting to get a hot
foot for coming here with a DOS problem so I wanted to be sure I was not
making an error in trying to use system()
I will investigate my command com and see what it needs to be happy. Thanks
for confirming the use of system() for me.
------------------------------
Date: 04 Feb 2001 00:27:41 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Using Date::Manip to compute Fat Tuesday
Message-Id: <k877mjo2.fsf@macforce.sumus.dk>
Skip Montanaro <skip@mojam.com> writes:
> I figured out that
> the following call yields Fat Tuesday for 2001:
>
> ParseRecur("*2001:0:0:0:0:0:0*EASTER,BD47")
>
> I want to replace "2001" with something that means "this year"
I don't know anything about Time::Manip but
my $this_year = ( localtime )[ 5 ] + 1900;
should give you "this year", so
ParseRecur("*$this_year:0:0:0:0:0:0*EASTER,BD47");
should do i guess.
perldoc -f localtime;
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 208
**************************************