[16751] in Perl-Users-Digest
Perl-Users Digest, Issue: 4163 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 29 09:05:27 2000
Date: Tue, 29 Aug 2000 06:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <967554312-v9-i4163@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 29 Aug 2000 Volume: 9 Number: 4163
Today's topics:
@ARGV <baladimi@pilot.msu.edu>
Re: @ARGV <baladimi@pilot.msu.edu>
Re: A Proposal for BaseLib module (Hasanuddin Tamir)
ActiveState perl automatic installation on NT ? (Markus Fischer)
DBD installation problem <bGhassemlou@home.com>
Re: File access over a network (Colin Keith)
Re: Getting slices of this ...(not pizza) (Colin Keith)
Re: guestbook & file-upload under NT (Colin Keith)
how can i use net::ssleay to send a certificate to a se <eduard.hirsch@proofit.at>
Implementing the join relational database operation <heilper@il.ibm.com>
Re: Implementing the join relational database operation (Martien Verbruggen)
Re: making sure input is a certain way i.e. starting an <star@sonic.net>
Re: Perldoc help needed <nickco3@yahoo.co.uk>
Re: Programming Ethics <jgoldst@my-deja.com>
Reg Exp Problem - What is wrong with this?? <shamilton@plateausystems.holdthespam.com>
replace some word in text file <ps@sbor.ru>
Re: replace some word in text file <bcaligari@my-deja.com>
Re: replace some word in text file <timewarp@shentel.net>
Re: selling perl to management (Martien Verbruggen)
Re: The Hacker signature disciplin (Jakob Schmidt)
Re: The Hacker signature disciplin <cboyd@holyrood.ed.ac.uk>
Wierd problem with CGI.pm <andyh@littoralis.co.uk>
Re: Wierd problem with CGI.pm (Rafael Garcia-Suarez)
Re: Win32 path with spaces <sturdevr@yahoo.com>
Win32:Perms Problems <m.kozniewski@ewsa.com.pl>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 29 Aug 2000 08:17:21 -0400
From: "Michael Baladi" <baladimi@pilot.msu.edu>
Subject: @ARGV
Message-Id: <8og9k4$b78$1@msunews.cl.msu.edu>
I am using the @ARGV array to try to get variables from the command prompt.
I am running Perl from Windows NT. The line I have in my program to test
this array is simply a print command.
print ("Printing $ARGV[0] \n");
The only problem is that my output only ever reads Printing
Its as if the array isn't getting initialized or something, even when I have
arguments on my command line that I'm trying to pass in.
Anybody else have any problems with this on NT, or are there any
suggestions?
------------------------------
Date: Tue, 29 Aug 2000 08:24:09 -0400
From: "Michael Baladi" <baladimi@pilot.msu.edu>
Subject: Re: @ARGV
Message-Id: <8oga0o$c0s$1@msunews.cl.msu.edu>
Never mind, I figured it out. Files with the .pl extension were associated
wrong, they weren't passing the command line arguments from the command
prompt to the perl interpreter.
"Michael Baladi" <baladimi@pilot.msu.edu> wrote in message
news:8og9k4$b78$1@msunews.cl.msu.edu...
> I am using the @ARGV array to try to get variables from the command
prompt.
> I am running Perl from Windows NT. The line I have in my program to test
> this array is simply a print command.
>
> print ("Printing $ARGV[0] \n");
>
>
> The only problem is that my output only ever reads Printing
>
> Its as if the array isn't getting initialized or something, even when I
have
> arguments on my command line that I'm trying to pass in.
>
> Anybody else have any problems with this on NT, or are there any
> suggestions?
>
>
>
>
------------------------------
Date: Wed, 30 Aug 2000 02:32:22 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: A Proposal for BaseLib module
Message-Id: <slrn8qna83.5ip.hasant@borg.intern.trabas.co.id>
On Mon, 28 Aug 2000 11:43:06 -0500, mischief@motion.thispartfake.net wrote:
##
## "Hasanuddin Tamir" <hasant@trabas.co.id> wrote in message
## news:slrn8qdmj0.oao.hasant@borg.intern.trabas.co.id...
## > On 25 Aug 2000 14:20:58 -0400, mthurn@tasc.com wrote:
##
## > But I can't use `use lib LIST;' in BaseLib since it will defeat
## > the previous steps. Instead, I simply unshift the full path to
## > libdir to @INC manually. So, in your words, I do,
##
## push, unshift, whatever. depends upon where you want it in the
## array. The pragma use list does put it at the beginning, BTW.
I just found out that I can use this in import() routine,
my $libpath = "$BaseDir/libdir";
require lib;
lib->import($libpath);
So it borrows (again) a capability of lib.pm to include a
private lib, including standard hierarchy which might exist
under libdir. I've planned to add this capability to BaseLib
myself, but it's not necessary now.
##
## > use lib '/full/path/to/mail2sms/libdir';
## >
## > but not,
## >
## > use lib '/full/path/to/mail2sms';
##
## So what you're saying is you want to concatenate the $baselib and
## the $libdir. That's easy enough. (BTW, I did leave chop()ping the
## newline out of the configuration file as an exercise to the reader in
## my last post. I considered it a bit trivial, and should have included
## it for clarity's sake.)
Exactly. But as you can see, it only applies on OSes which use
'/' as path separator, portability is still on TODO list. (Yes,
I understand your intent :-)
##
## > The script provides the base and lib directories, BaseLib
## > takes care the rest.
## >
## > Let's take a look at the implementation a bit. Please consider
## > the following picture (if we may call it so.)
## >
## > -.- [/ROOTDIR] <--+ C -.-
## > | `--+ | B | D
## > | `-[/BASEDIR] <---+ |
## > | `-+ | |
## > | `-[/LIBDIR] | -.-
## > A | | |
## > -.- `-[/SCRIPTDIR]
## > |
## > `--[/SCRIPT.pl]
## >
## > SCRIPT.pl passes in what to look for (BASEDIR and LIBDIR)
## > to BaseLib. If any or both of arguments missing, BaseLib
## > will assume `appl_root' and `lib' respectively. So,
## >
## > use BaseLib qw(BASEDIR LIBDIR);
## >
## > will instruct BaseLib to do its job, which is,
## >
## > 1. Borrowing the full path to SCRIPTDIR (line A) from the
## > standard FindBin module.
## > 2. Searching upward up to BASEDIR (B), preserving full
## > path to it starting from ROOTDIR (C), and forgetting
## > the rest.
## > 3. Now that the path is found, the next is down-searching
## > to find LIBDIR (D), constructing the path lib, and put
## > it in @INC.
##
## This is much more clear than what I'd read before (at least to me).
## This is more involved than just finding out where the modules are.
## This is doing it in an almost seamless way. Earlier in the discussion,
## I thought you were concerned with the names of the base directory
## and the library directory changing. From this example, it seems
## more that these will be constant from a certain node down, and
## that yuo are interesting in finding where that common parent node
## happens to be in the overall file system. This makes more sense to
## me why you'd want to do the extra work. If someones moves the
## entire directory tree holding all the subdirectories, but does not
## change the names of any of the subdirectories therein, then this
## indeed could be a pretty handy package to use.
##
## The solutions offered by myself and others addressed a slightly different
## situation. I still think this could be done using relative
## directories, but it's making more sense to use FindBin and continue
## from there now that I see the scope and focus of your problem
## and proposed solution are different from what I previously thought.
##
## > It's that simple, IMHO.
##
## Now that I think I understand your particular purpose, it does
## seem that your argument is pretty simple, valid, and also relevant.
## I must admit, I'm not sure where the communication error was, but
## what seems to have caused so much dissension was not your
## argument, but the point from which you were perceived to be starting.
##
## To be honest, I personally don't remember the specifics of how
## your implementation is coded after the weekend, but your explanation of how
## it is implemented (as I understand your proposal currently) seems to be a
## sensible way to do what you want.
I have no doubt now that you fully understand what I meant.
And I think you're right about the communication error :-)
By the way, the package is located at,
http://www.zp.f2s.com/perl/modules/BaseLib-0.01.tar.gz
should you're interested in trying it out.
(The only thing I still feel uncomfortable with is the namespace.
Still waiting for respond from modules@perl.org. I'm thinking about
rename it to FindBin::DirTree.)
Thank you very much, Chris!
BR,
san
--
trabasLabs * hasant@trabas.com * http://www.trabas.com
Zero Point * hasant@zp.f2s.com * http://www.zp.f2s.com
------------------------------
Date: 29 Aug 2000 12:17:54 GMT
From: mfischer-news@josefine.ben.tuwien.ac.at (Markus Fischer)
Subject: ActiveState perl automatic installation on NT ?
Message-Id: <slrn8qnafi.8cp.mfischer-news@josefine.ben.tuwien.ac.at>
Hi,
Does someone know if it's possible to install active state perl
during an MSWindows NT unattended installation ? Since the latest
version is not an executeable anymore where I could pass any
switches which hopefully could work but only an MS Windows
Installer *.msi file, I don't know where to start to search for
an automatic installation.
thanks for taking time,
kind regards,
Markus
--
Markus Fischer, http://josefine.ben.tuwien.ac.at/~mfischer/
EMail: mfischer@josefine.ben.tuwien.ac.at
PGP Public Key: http://josefine.ben.tuwien.ac.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0
- Free Software For A Free World -
------------------------------
Date: Tue, 29 Aug 2000 10:42:10 GMT
From: "bjg" <bGhassemlou@home.com>
Subject: DBD installation problem
Message-Id: <6sMq5.130516$c5.3343904@news2.rdc1.on.home.com>
I am trying to use MySQL on NT. I finally installed, I had problem with DBI
and installed it too (took me 2 weeks) now I just found I need DBD! It was
down loaded and extracted (there are not installation instructions? I get
the following error message when running the test program.(It is frustrating
it is over 3 month that I am trying to run a query against MySQL and still
no hope!)
cand anyone give me a hint what is wrong???
This is the error message I get:
install_driver(mysql) failed: Can't locate loadable object for module
DBD::mysql in @INC (@INC contains: D:/Perl/lib D:/Perl/site/lib .) at (eval
1) line 3
Compilation failed in require at (eval 1) line 3.
Perhaps a module that DBD::mysql requires hasn't been fully installed
at d:\Xitami\webpages\cgi-bin\Behzad.pl line 17
How do I install the driver ??
Thanks
------------------------------
Date: Tue, 29 Aug 2000 10:07:37 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: File access over a network
Message-Id: <JXLq5.5$05.91864@nnrp2.clara.net>
In article <8oee39$t8e$1@nnrp1.deja.com>, kliquori <kliquori@my-deja.com>
wrote:
Nowt to do with Perl really. Unless you want to play with the Net::Telnet
module..
>1) Use NFS and access the file as if it's local.
>2) Use rcp with the system command to copy the files locally.
rsh, ftp or better: ssh, scp, sftp.
It depends on what you want to do though. If its rewriting the password file
then have a look at cfengine for a distribution mechanism.
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Tue, 29 Aug 2000 12:46:55 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: Getting slices of this ...(not pizza)
Message-Id: <3hOq5.6$05.102121@nnrp2.clara.net>
In article <39AA5EE8.97437996@ostas.lu.se>, webmaster@ostas.lu.se wrote:
>I also welcome any suggestion on how to make the rest of the program
>better.
Uh oh, he asked for comments. Oh well, here they come :)
>if ($ENV{'REQUEST_METHOD'} eq 'GET'){ KursModul::read_form_get(); }
>elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { KursModul::read_form_post();}
>else { KursModul::read_form_get();}
Since you default to read_form_get() you could compress this to:
$ENV{REQUEST_METHOD} eq 'POST' ? KursModul::read_form_post()
: KursModul::read_form_get();
>my $studentline;
>foreach $studentline (@students) {
> push(@student_rec, new_student($studentline));
> }
foreach my $studentline (@students) {
limits the scope of studentline even futher. Or if you want:
@student_rec = map { new_student($_) } @students;
>foreach $stud (@student_rec) { ############ Is there an
>easier / faster way to do this
>if (${$stud}{'epost'} eq '#') ############
> { push(@no_email, $stud);} ############
>else
>############
>{ push(@have_email, $stud);} ############
>
>}
$_->{epost} ? push(@no_email, $_) : push(@have_email, $_) for(@student_rec);
Couple of points about the rest of your code, you can save typing as much
using Perl syntax shortcuts. Instead of things like;
${$rec}{'key_name'}
you can use:
$rec->{key_name};
that combines Perl knowing that hash indicies strings are anything in the
{ } I.e. {'key_name'} => {key_name}, but obviously this doesn't cover
breaking characters like , or ' '. It also shows the dereferencing syntax of
turning ${$rec}{key} => $rec->{key}. You can also access array references
using a similar notation. I.e.:
maia% perl -w -Mstrict
my($arr) = [ 10, 20, 30, 40 ];
print "Total: ", $arr->[2] + $arr->[3], "\n";
Total: 70
>sub new_student {
>my($line) = @_ ;
> my @flds = split /:/, $line;
>
> my %stud_rec = (
> fnamn => $flds[2],
> enamn => $flds[3],
> epost => $flds[4]);
> return \%stud_rec;
> }
First thing is to dump the $line variable and just go for:
my(@flds) = split(':', $_[0]);
You can simplify this slightly using a scalar variable and an anonymous
hash. You can define an anonymous hash using { }
my($stud_rec) = { fnamn=> .. );
return $stud_rec;
or better still:
return {fnamn=> .. };
If you're only going to have these fields you could keep the order as say:
fnamn, enamn, epost (0, 1, 2) and use an array reference instead:
return [ @flds[2, 3, 4] ];
You'll then be using less memory because its an array not a hash. If you do
do this, then your dereferences above become:
$bob = new_student($student_details);
print "Fnamn = ", $bob->[0], "\n";
But to save you having to remember the index position you can use constants:
use constant FNAMN=>0;
...
print "Fnamn = ", $bob->[FNAMN], "\n";
Reasonably readable, and uses less memory and more importantly ...
people looking at your code are impressed :) :)
>my $year = localtime->year();#100
If this is all you need it for, don't use the Time::localtime module, just
use:
my($year) = (localtime(time()))[5];
>$year =~ /^1(\d\d)/;
>$year = $1;
I wouldn't advise this unless you absolutely have no choice about using a 2
digit year.
>
>my $username = $year . $kod;
>$fnamn =~ /(^[A-Z]{2})/;
Urm, the ^ should be outside of the ( ) I would think.
>$username = $username . $fnamn . $enamn;
You can use .= just like you can use x += y instead of x = x+y
>if ($user_error != 1) # This is a VERY
>clumsy/insecure way to do it , ANY SUGGESTIONS ?
That depends on what you're trying to do exactly. I can see its
something to do with making a unique username, but if its already in use you
concatenating the number 1 to the end of it and if that's taken add 1 to
that, so:
bob
bob1
bob11
That seems a little restrictive. If 3 people pick the same name you'll get
clashes. Personally I'd try the following. Its not brilliant, but it should
get the desired result:
sub validate_username {
# Make indexing easier (for us at least)
my(%tmphash);
$tmphash{$_} = 1 for(@users);
while(exists($tmphash{$_[0]})){
$_[0] =~ /^(\w+?)(\d*)$/;
$_[0] = $1. ($2 ? $2+1 : 1);
}
}
Since @_ is an array of aliases to the variables that are passed to the sub
if you modify $_[0] you change the value of the variable that you passed. Of
course, this breaks if you call validate_username('bob') as opposed to
$uname = 'bob'; validate_username($uname); But it has the advantages of not
needing to validate anything. It will just keep adding numbers until it
finds an account not in use. It will also find holes in a sequential list,
I.e.
@users = qw(bob bob1 bob2 bob3 bob5 bobs bobz bobt bobd bobsd bobsd1);
$username = 'bob';
validate_username($username);
Changes $username to bob4.
Right enough waffling, I'm gonna hit killfile line limits at this rate.
Sorry to those that know all this. Hope it helps anyone that didn't and has
learnt something :)
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Tue, 29 Aug 2000 12:50:42 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: guestbook & file-upload under NT
Message-Id: <CkOq5.7$05.102432@nnrp2.clara.net>
In article <Bbaq5.144203$dF5.2425033@news.infostrada.it>, "Dark" <darklord@libero.it> wrote:
>Can anyone tell me where to find a script for file-uploading and a script
>for a guestbook, both working under a win NT server?
Well, strictly this is nothing to do with Perl, its a CGI question. But
if you want to write your scripts in Perl, you can run up your own in a few
minutes. Grab the docs for CGI.pm and look at the documentation, it has
examples. Otherwise, there are plently of scripts about, have a look on
http://www.perl.com
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Tue, 29 Aug 2000 14:33:42 +0200
From: "edi" <eduard.hirsch@proofit.at>
Subject: how can i use net::ssleay to send a certificate to a secure sever
Message-Id: <967552600.947109@newsmaster-04.atnet.at>
i'am programming a perl script which sends data from one server to another
with
net::ssleay. this is working so far. but now i want to send a client
certificate to identify the
other computer. can somebody explain me how to do that? or can give me a
good
documentaion!
thx
------------------------------
Date: Tue, 29 Aug 2000 15:00:31 +0300
From: Andrei Heilper <heilper@il.ibm.com>
Subject: Implementing the join relational database operation
Message-Id: <39ABA5DF.104AF571@il.ibm.com>
I want to implement in Perl the join relational database operation.
For start, I would like to handle the simplest case.
The database rows are represented by array entries, where each entry is
separated into 2 fields - key and value - by a special character
(usually semicolon).
Any suggestions?
------------------------------
Date: Tue, 29 Aug 2000 23:41:21 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Implementing the join relational database operation
Message-Id: <slrn8qnbrh.ucf.mgjv@martien.heliotrope.home>
On Tue, 29 Aug 2000 15:00:31 +0300,
Andrei Heilper <heilper@il.ibm.com> wrote:
> I want to implement in Perl the join relational database operation.
>
> For start, I would like to handle the simplest case.
> The database rows are represented by array entries, where each entry is
> separated into 2 fields - key and value - by a special character
> (usually semicolon).
Ok... I read this as 'I want to use a subset of SQL against some stuff I
have in memory'. If that's not what you want to do, then I apologise.
Maybe what you want is DBI with the DBD::CSV driver for flat files, or
the DBD::RAM driver for memory based SQL-access. I don't know how
complete either of the two drivers are, but you can easily find out by
downloading them, and reading their documentation.
Alternatively, you can have a look at the SQL::Statement module, and you
can probably derive a class from that that does what you want.
I would use the DBI stuff. it'll make your life easier if you at some
point in the future decide that this data has to live in another place
than where it now lives.
All abovementioned modules are available from CPAN: http://www.cpan.org/
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Tue, 29 Aug 2000 10:53:57 GMT
From: arthur <star@sonic.net>
Subject: Re: making sure input is a certain way i.e. starting and ending with double quotes
Message-Id: <B5CF92E5.74A6%star@sonic.net>
in article 8ofkos$h0i$1@orpheus.gellyfish.com, Jonathan Stowe at
gellyfish@gellyfish.com wrote on 8/28/00 10:21 PM:
>> I need what the user (I love that name) inputs into 'question' to start and
>> end with double quotes. How can I check that and put up a warning message if
>> they have not started and ended in double quotes.
>>
>
> Sounds like a regular expression to me :
>
> if ( $question !~ /^".+"$/ )
> {
> print "No quotes\n";
> }
That works fine, thanks :+)
How could I get the program to quit after it prints "No quotes\n" if there
are not quotes around $question
------------------------------
Date: Tue, 29 Aug 2000 12:06:31 +0100
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: Perldoc help needed
Message-Id: <39AB9937.6E40FF03@yahoo.co.uk>
BUCK NAKED1 wrote:
> Thanks. Been there many times, but didn't know it was referred to as
> perldoc -f.
>
> Regards,
> Dennis
Your Perl installation should include an executable called 'perldoc'.
perldoc -f BuiltInFunction
extracts the onboard documentation for BuiltInFunction
------------------------------
Date: Tue, 29 Aug 2000 12:45:35 GMT
From: JL Goldstein <jgoldst@my-deja.com>
Subject: Re: Programming Ethics
Message-Id: <8ogb9a$2fm$1@nnrp1.deja.com>
In article <slrn8q7jbh.5ap.mgjv@martien.heliotrope.home>,
mgjv@tradingpost.com.au wrote:
> wrong. John Howard[1] is wrong. Brussels sprouts are borderlining on
> wrong. Four wheel drive trucks in yuppie inner city suburbs are wrong.
Hey, I happen to like Brussels sprouts! When properly prepared (steamed
to tenderness and topped with butter), they are divine....
----
Any sufficiently advanced magic is indistinguishable from Perl.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 29 Aug 2000 11:39:26 GMT
From: "Scott" <shamilton@plateausystems.holdthespam.com>
Subject: Reg Exp Problem - What is wrong with this??
Message-Id: <OhNq5.99814$eS6.1100543@news1.rdc1.md.home.com>
I am writing a filter to look for specific strings in submitted textarea
fields, specifically HTTP links (thanks to all who helped with that one) and
also email addresses, to turn into mailto links.
Here's the problem: under certain circumstances, and I'm not sure exactly
what those are, when the following regular expression is evaluated, the Perl
script seems to bomb out (all I get is an HTTP 500 response):
s!((?:[\w\-]*\.?)+\@(?:[\w\-])+(?:\.[\w\-]+)*)!<a
href="mailto:$1">$1</a>!xig
Interestingly enough, when I also tried this in JavaScript (granted, without
the (?:) parts since they didn't seem to be supported), the javascript line
would take an EXTREMELY long time to scan a line of only about 50
characters. Since the submitted text that cause this problem was about 25k,
I assume that the CGI script either timed out with the same problem or
caused some weird error.
Without tearing apart the above reg exp line's assumptions about the email
address format, can anyone tell me what might be wrong with it that it might
cause such an error?
Thanks in advance,
Scott
------------------------------
Date: Tue, 29 Aug 2000 14:39:02 +0400
From: "Serg Piskarev" <ps@sbor.ru>
Subject: replace some word in text file
Message-Id: <967545642.11620@relay2.sbor.ru>
sorry for stupid question
Is it possible to replace some word directly in text file (without coping
file content to an array)?
Thanx
______________
Sergey Piskarev
ps@sbor.ru
------------------------------
Date: Tue, 29 Aug 2000 11:16:45 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: replace some word in text file
Message-Id: <8og62i$sst$1@nnrp1.deja.com>
In article <967545642.11620@relay2.sbor.ru>,
"Serg Piskarev" <ps@sbor.ru> wrote:
> sorry for stupid question
> Is it possible to replace some word directly in text file (without
coping
> file content to an array)?
> Thanx
you cannot directly modify a text file which is a sequential access
thingie. However, to avoid loading a massive file into a memory array
you could always 'read line by line'....writing to a temporary file and
replacing the old file with the temporary one when finished processing.
Brendon
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 29 Aug 2000 08:53:15 -0400
From: Albert Dewey <timewarp@shentel.net>
Subject: Re: replace some word in text file
Message-Id: <39ABB23B.FC1A6A37@shentel.net>
Brendon Caligari wrote:
> In article <967545642.11620@relay2.sbor.ru>,
> "Serg Piskarev" <ps@sbor.ru> wrote:
> > sorry for stupid question
> > Is it possible to replace some word directly in text file (without
> coping
> > file content to an array)?
> > Thanx
>
> you cannot directly modify a text file which is a sequential access
> thingie. However, to avoid loading a massive file into a memory array
> you could always 'read line by line'....writing to a temporary file and
> replacing the old file with the temporary one when finished processing.
>
> Brendon
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Try this -
open(FILE,"<file.txt") or print "ERROR: 404<br>Cannot open file because
$!<br>";
while(<FILE>)
{
$File .= $_ if $. >= 0
}
close (FILE);
$File =~ s/old_word/new_word/;
open(FILE,">file.txt") or print "ERROR: 404<br>Cannot open file because
$!<br>";
print FILE $File;
close(FILE);
This loads the file into a scalar and replaces the first instance that s///
finds of 'old_word'. If you want to replace all instances of old_word add
the global switch as follows.
$File =~ s/old_word/new_word/g;
You can even replace the old_word with the contents of another scalar
($word) -
$File =~ s/old_word/$word/g;
Not sure if this is what you are looking for but here it is anyway . . . .
Albert Dewey
--
## Simple, I know, but it does work.
$Sig = "Jfhg&Amlgsvi&Pvio&Hzxpvi";
$Sig =~ tr/abcdefghijklmnopqrstuvwxyz&/zyxwvutsrqponmlkjihgfedcba /;
print $Sig;
------------------------------
Date: Tue, 29 Aug 2000 21:53:51 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: selling perl to management
Message-Id: <slrn8qn5hv.sk8.mgjv@martien.heliotrope.home>
On 28 Aug 2000 18:35:10 GMT,
Abigail <abigail@foad.org> wrote:
> Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMDLIV September
> MCMXCIII in <URL:news:slrn8qkh0d.3fr.mgjv@martien.heliotrope.home>:
> --
> -- But, Perl is very good at pointing out where things break. Of course, if
> -- the syntax is still acceptable, but the runtime effects are severely
> -- different, that would be bad. However, has that ever happened? Without a
> -- warning? And perldelta does tell us about things.
>
> Yes, it has happened. It happens over and over again. Here's a recent example:
>
> $ perl5.00503 -wle 'print 80.101.114.108'
> 80.101114.108
> $ perl5.6.0 -wle 'print 80.101.114.108'
> Perl
> $
>
> I'd call that severely different run time effects. And no, no warnings
> or deprecation cycle. The different run time effects are due to a change
> in _syntax_.
>
> Here's another. Also, no warning, not even a mentioning in perldelta.
>
> $ perl5.00503 -le 'sub AUTOLOAD {print $AUTOLOAD} *foo = *bar; foo ()'
> main::bar
> $ perl5.6.0. -le 'sub AUTOLOAD {print $AUTOLOAD} *foo = *bar; foo ()'
> main::foo
> $
>
> And in case you are not satisfied yet:
>
> $ perl5.00503 -le 'sub CHECK {print "foo"} if (1) {print "bar"; CHECK}'
> bar
> foo
> $ perl5.6.0 -le 'sub CHECK {print "foo"} if (1) {print "bar"; CHECK}'
> foo
> bar
> $
Neither of these examples are likely to occur in production code, except
for the AUTOLOAD one. And that could be easily written more sanely as
well.
I'm not trying to marginalise things, but you do come up with examples
that most likely wouldn't be defined by a standard anyway. But I do take
your point: If there _were_ a standard, the developers could _validly_
make the point I just made, while now it is unfounded. If there were a
standard, you could complain to the developers if something broke.
But that does not stop them from changing things in the first place. it
just forces them to justify it in a standard.
But the point from both sides of this argument has been made more than
often enough.
> -- Yes, Perl upgrades
> -- change some things, but no more than anything else (upgrades of other
> -- languages, compilers, interpreters), and not in a dangerous way, and
> -- always with as much care as reasonable for the backward compatibility.
>
> Please, you sound as unfounded as Godzilla. Recently, I went for
and this is offensive enough for me to not want to participate in this
thread anymore. it was a discussion, it's just become something
altogether more nasty. That was hardly necessary, was it?
I'll go play somewhere else.
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use
NSW, Australia | being a damn fool about it.
------------------------------
Date: Tue, 29 Aug 2000 14:20:19 +0200
From: sumus@aut.dk (Jakob Schmidt)
Subject: Re: The Hacker signature disciplin
Message-Id: <1eg4pud.17ljlpr1fuawfyN@[192.168.88.117]>
Tony L. Svanstrom <tony@svanstrom.com> wrote:
> jason <elephant@squirrelgroup.com> wrote:
>
> > I think the only rule that I'm aware of is that if you have to ask -
> > then you shouldn't use it *8^)
>
> I can't but agree. *L*
Hehe - I reckoned you'd give me that.
That's a standard rule of just about any subculture. Well - I'm a
determined subculture crasher and it's your turn :-)
It's the kind of rules that 10.000 lurkers decide to let themselves
scare off by. I'm the one who has little enough sense of occasion - or
maybe I'm just the only one who's priorities are twisted enough - to go
and break it.
--
Jakob
print "I'm a loser baby\n";
------------------------------
Date: 29 Aug 2000 12:25:53 GMT
From: Chris Boyd <cboyd@holyrood.ed.ac.uk>
Subject: Re: The Hacker signature disciplin
Message-Id: <8oga4h$fpd$1@scotsman.ed.ac.uk>
Jakob Schmidt <sumus@aut.dk> wrote:
: I find myself wondering if there are some written or unwritten rules
: about the "Just another Perl Hacker" sig that some posters use?
(snip)
"Just Another Perl
Hacker" or "Just Another
Perl Haiku"? Your choice.
--
ibid
------------------------------
Date: Tue, 29 Aug 2000 11:41:08 +0100
From: "Andy Holyer" <andyh@littoralis.co.uk>
Subject: Wierd problem with CGI.pm
Message-Id: <crMq5.30036$F6.138387@monolith.news.easynet.net>
This is just a bizarre problem that arose on Friday. Thinking it was just
me, I left it until this morning, but it's still doing it. Any advice
please...
I've been using CGI.pm for a couple of years, mainly on a production content
management system which we're developing.
Friday afternoon, the script I'm currently developing just... stopped taking
in any parameters.
Running it using
perl -d /usr/local./scripts/gather_handler
The first line is
$query = CGI->new();
This should pop up a command-line interface to allow me to type in the
params.
But it doesn't. I know this sounds lame, but it doesn't. The new() method
just returns.
We have two online servers, running FreeBSD-STABLE, and I have a local
development machine runnig the same software.
As a quick sanity check I tried the same thing on the other two servers.
Then I tried
doing perl -de1, and physically typing
use CGI;
$query= CGI-> new;
Same result. Either I've just entered the twilight zone, or there's
something funny that's just happened with my setup on three unconnected
servers. Oh, and I hadn't changed anything on the other two servers.
All systems are running perl 5.5003, and have done very happily for a long
while.
Any hints will be gratefully recieved.
Andy Holyer, Lewes, UK.
------------------------------
Date: Tue, 29 Aug 2000 12:22:08 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Wierd problem with CGI.pm
Message-Id: <slrn8qnb2i.2h9.rgarciasuarez@rafael.kazibao.net>
Andy Holyer wrote in comp.lang.perl.misc:
[...]
>
>The first line is
>
>$query = CGI->new();
>
>This should pop up a command-line interface to allow me to type in the
>params.
>
>But it doesn't. I know this sounds lame, but it doesn't. The new() method
>just returns.
Have you upgraded CGI.pm recently?
And, in this case, have you tried :
use CGI qw/-debug/;
--
Rafael Garcia-Suarez
------------------------------
Date: Tue, 29 Aug 2000 07:36:48 -0400
From: "BobS" <sturdevr@yahoo.com>
Subject: Re: Win32 path with spaces
Message-Id: <8og78d$jke$1@bob.news.rcn.net>
Thanks guys...double inside of single quotes does the deed. Thought I tried
all of these combos but guess I missed this one.
Bob
"Abe Timmerman" <abe@ztreet.demon.nl> wrote in message
news:juflqs8gkdo4bkglmkp7hpeaoahoop9qdn@4ax.com...
> On Mon, 28 Aug 2000 12:19:07 -0400, "BobS" <sturdevr@yahoo.com> wrote:
>
> > Hi,
> >
> > I'm having a problem with spaces in win32 path names. Specifically:
> >
> > system( 'C:/program files/windows nt/accessories/wordpad.exe',
> > 'c:/sms/readme.doc' );
>
> OT, but ok:
>
> system( '"C:/program files/windows nt/accessories/wordpad.exe"',
> 'c:/sms/readme.doc' );
>
> Like you do on the command line.
>
> > I've found that
> >
> > system( 'c:\program~1\window~2\access~1\wordpad.exe',
'c:\sms\readme.doc' )
> >
> > opens wordpad and displays the readme but I'm concerned the numerals in
the
> > DOS equivalent names may not be the same on all systems.
>
> my $short = Win32::GetShortPathName
> 'c:/program files/windows nt/accessories/wordpad.exe';
>
> Look at the doc for the Win32 module.
>
> Also NT doesn't have to be installed on C:, $ENV{SystemDrive} looks a
> better drive to start the path.
>
> --
> Good luck,
> Abe
------------------------------
Date: Tue, 29 Aug 2000 13:16:50 +0200
From: "Marek Kozniewski" <m.kozniewski@ewsa.com.pl>
Subject: Win32:Perms Problems
Message-Id: <8og633$fjb$1@news.ipartners.pl>
When i use Win32::Perms module i recive message access violation from Dr.
Watson (i work on Win NT) ;((((
help me please !!!
Pozdro
Marek
------------------------------
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 V9 Issue 4163
**************************************