[15451] in Perl-Users-Digest
Perl-Users Digest, Issue: 2861 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 25 18:05:57 2000
Date: Tue, 25 Apr 2000 15:05:17 -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: <956700317-v9-i2861@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 25 Apr 2000 Volume: 9 Number: 2861
Today's topics:
Re: (ActiveState) can't get PPMFIX to fix PPM <gellyfish@gellyfish.com>
Re: backslash escaping not metacharacters in a char cla (Tad McClellan)
Re: Best way to hide source (Tad McClellan)
calling a cgi morlou@my-deja.com
Re: calling a cgi <nomail@nomail.com>
Re: calling a cgi <rootbeer@redcat.com>
Re: Converting HTML hex characters to characters <nasinowski@hbesoftware.com>
Converting Macintosh files to UNIX siva_ayyar@my-deja.com
Re: Converting Macintosh files to UNIX <makarand_kulkarni@My-Deja.com>
Re: Converting Macintosh files to UNIX <rootbeer@redcat.com>
Re: Converting Macintosh files to UNIX <lr@hpl.hp.com>
Re: Critique My Code (Tad McClellan)
Re: Critique My Code (Tad McClellan)
Does opening files slow perl down? <sid@eurekanet.com>
Re: Does opening files slow perl down? <rootbeer@redcat.com>
Download file <foto35@siamvoice.com>
Re: Download file <rootbeer@redcat.com>
Re: Download file <makarand_kulkarni@My-Deja.com>
Re: E-mail Header Module qcoldiron@yahoo.com
Re: Efficient manipulation of simple date? <rootbeer@redcat.com>
Re: Efficient manipulation of simple date? (Neil Kandalgaonkar)
Re: exception handling <makarand_kulkarni@My-Deja.com>
find and replace a string in a huge file <prem@nortelnetworks.com>
Re: find and replace a string in a huge file <rootbeer@redcat.com>
Re: find and replace a string in a huge file <lr@hpl.hp.com>
Re: find and replace a string in a huge file <lr@hpl.hp.com>
Re: find and replace a string in a huge file <rootbeer@redcat.com>
how to measure processing time by millisecond unit <alice@dogcat.com>
Re: how to measure processing time by millisecond unit <makarand_kulkarni@My-Deja.com>
Re: how to measure processing time by millisecond unit <aqumsieh@hyperchip.com>
Re: how to measure processing time by millisecond unit <lr@hpl.hp.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Apr 2000 20:42:37 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: (ActiveState) can't get PPMFIX to fix PPM
Message-Id: <8e4sfd$meq$1@orpheus.gellyfish.com>
On Mon, 24 Apr 2000 18:15:52 GMT pt wrote:
> I installed "ActivePerl-5.6.0.613.msi" (from ActiveState) , then
> downloaded the "PPMFIX.ZIP" file. I've unzipped the fix and tried to
> get it to run without success.
>
> D:\Program Files\Perl>ppm verify --location=. --upgrade PPM
> Error verifying PPM: Package 'PPM' has not been installed by PPM
>
> I have set "HTTP_PROXY=proxy.seagate.com". PERL.EXE is in the first
> dir in my PATH. Running "ppm verify" yields :
>
> HTTP POST failed: 501 (Protocol scheme '' is not supported at
> D:/Program Files/Perl/site/lib/LWP/UserAgent.pm line 186),
> in SOAP method call. Content of response:
> at D:/Program Files/Perl/site/lib/PPM/SOAPClient.pm line 222
>
You need to supply a protocol scheme in the HTTP_PROXY environment
variable :
HTTP_PROXY=http://proxy.seagate.com
/J\
--
Heh Heh Heh! Lisa! Vampires are make believe, just like elves and gremlins
and eskimos!
--
fortune oscar homer
------------------------------
Date: Mon, 24 Apr 2000 09:09:27 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: backslash escaping not metacharacters in a char class
Message-Id: <slrn8g8hs7.390.tadmc@magna.metronet.com>
On Mon, 24 Apr 2000 12:54:15 +0200, Javier Hernandez <fjhernandez@recol.es> wrote:
>I have read something about a backslash trying to escape a
^^^^^^^^^^^^^^^
>non-metacharacter
What "about" it?
Did it say it was bad?
Good?
Benign?
>within a character class [ ... ].
>
>i.e. A regex like: /[a-z\:]+/
>
>What will happen with the '\' in that case ?
It will be discarded (i.e. it has no effect).
>I understand that the regex will try to match one or more letters, OR
>one or more colons, OR ????...
It matches one or more of the 27 chars in your char class.
>I put that example based on the fact that a colon ':' is not a
>metacharacter within a character class.
>My understanding is that the only metacharacters within a character
>class are: the dash '-' like a range, the leading caret at the begining
>like a negated, and the ']' to close the character class.
>Please, correct me if I am wrong.
There are 4 metachars in a char class. Your list is missing '\' :-)
But patterns are also double quoted strings, so '$' and '@'
might be seen as "meta" too.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 24 Apr 2000 15:30:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Best way to hide source
Message-Id: <slrn8g987b.4af.tadmc@magna.metronet.com>
On Mon, 24 Apr 2000 17:26:04 GMT, System Administrator <root@web3.valley-internet.com> wrote:
Please tell me that you are not doing routine things, like reading
news, from a privileged account.
>Ok first of all I don't want to get in any arguments about open source here:)
>If you feel the need to do so please make sure you read the entire message first.
You don't really expect folks to read it with that horrid
word-wrap, do you?
You could have just put "ignore me" in the Subject header
to get the same effect.
Good luck with whatever it was that your post said.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 25 Apr 2000 17:59:52 GMT
From: morlou@my-deja.com
Subject: calling a cgi
Message-Id: <8e4meh$ktp$1@nnrp1.deja.com>
I'd like to know how to call a Perl cgi script from a Perl cgi script
and pass a parameter.
Exactly, I have an HTML form which has a POST action calling xxx.cgi,
then in xxx.cgi I'd like to call yyy.cgi with a parameter which is the
content of the buffer (Content of the HTML form). This way, yyy.cgi
could process the information that is coming from the form... Somebody
knows how to do it??? Please help me! Thanks!
Louis Morin
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 25 Apr 2000 13:57:32 -0400
From: "Jonah" <nomail@nomail.com>
Subject: Re: calling a cgi
Message-Id: <8e4sae$2dp0$1@onlink3.onlink.net>
> Exactly, I have an HTML form which has a POST action calling xxx.cgi,
> then in xxx.cgi I'd like to call yyy.cgi with a parameter which is the
> content of the buffer (Content of the HTML form). This way, yyy.cgi
> could process the information that is coming from the form...
Look into LWP
and visit
http://www.home.unique.no/alf/libwww/index.html
LWP stands for libwwwperl
also, check the thread "emulate a browser" in this group
I just went through all that =)
hope this helps
------------------------------
Date: Tue, 25 Apr 2000 13:01:46 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: calling a cgi
Message-Id: <Pine.GSO.4.10.10004251259570.25963-100000@user2.teleport.com>
On Tue, 25 Apr 2000 morlou@my-deja.com wrote:
> I'd like to know how to call a Perl cgi script from a Perl cgi script
> and pass a parameter.
If you want to contact a webserver from Perl, use the LWP modules from
CPAN.
If you want to implement the server's side of the CGI protocol, it's not
trivial! But follow the CGI spec:
http://hoohoo.ncsa.uiuc.edu/cgi/
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 25 Apr 2000 21:11:18 GMT
From: Nelson Asinowski <nasinowski@hbesoftware.com>
Subject: Re: Converting HTML hex characters to characters
Message-Id: <390609F2.7090906@hbesoftware.com>
mongoose@wpi.edu wrote:
> =
> Well I just create html files I call templates, then I put special
> characters designating where I want my perl script to put in generated
> words. I don't have to type in lots of printfs for my html inside my
> perl script. And I can change the webpage without having to edit the
> perl script. Its a nice seperation. The perl script just takes care of
> filling in the special words on the page and other file management on
> the server. There really doesn't seem to be much to cgi other than
> getting data from the web browser. Other than that its just alot of
> parsing of data, database management...
Consider HTML::Templates .=A0 Check out www.perlmonth.com for an article =
on this.
It does exactly what you are coding yourself and can work with CGI.pm=A0 =
or
other modules when needed.
http://www.perlmonth.com/features/template/template.html?issue=3D11
Second time today that I have made this recomendation.=A0
------------------------------
Date: Tue, 25 Apr 2000 20:03:55 GMT
From: siva_ayyar@my-deja.com
Subject: Converting Macintosh files to UNIX
Message-Id: <8e4tn2$spp$1@nnrp1.deja.com>
Hello,
Macintosh files have a carriage return [ \r ] at the end of each line.
DOS files have [\r\n] both carriage return and newline.
UNIX has only [ \n ] terminating each line.
I am copying Macintosh files to UNIX. wc -l [filename] returns 0 as
these files have no newlines (i.e., the whole file is treated as one
line)
I'd like to translate each \r into a \n.
However, an s/\r/\n/g doesn't seem to being doing the trick and s/\0d/
\0a/g isn't working either.
Ideas?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 25 Apr 2000 13:23:05 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Converting Macintosh files to UNIX
Message-Id: <3905FEA9.B4DA314D@My-Deja.com>
> I'd like to translate each \r into a \n.
try this on Unix machine
tr '\015' '\012' < mac > unix
where mac is the Macintosh file and Unix is the unix file
There is a good article that appeared in
a magazine Server/workstation expert earlier
Link
http://genome-www.stanford.edu/perlOOP/lib/Bio/Root/Err.pm.html
Might be essential reading for you.
------------------------------
Date: Tue, 25 Apr 2000 13:23:18 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Converting Macintosh files to UNIX
Message-Id: <Pine.GSO.4.10.10004251320020.25963-100000@user2.teleport.com>
On Tue, 25 Apr 2000 siva_ayyar@my-deja.com wrote:
> Subject: Converting Macintosh files to UNIX
perl -pi -e 'tr/\r/\n/' mac_file*
> However, an s/\r/\n/g doesn't seem to being doing the trick
Hmmmm.
> and s/\0d/
> \0a/g isn't working either.
Well, besides the line break, you're not using the escapes you think
you're using; see the perlop manpage.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 25 Apr 2000 13:34:29 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Converting Macintosh files to UNIX
Message-Id: <MPG.136fa12de59574e698a97a@nntp.hpl.hp.com>
In article <8e4tn2$spp$1@nnrp1.deja.com> on Tue, 25 Apr 2000 20:03:55
GMT, siva_ayyar@my-deja.com <siva_ayyar@my-deja.com> says...
> Macintosh files have a carriage return [ \r ] at the end of each line.
>
> DOS files have [\r\n] both carriage return and newline.
>
> UNIX has only [ \n ] terminating each line.
>
> I am copying Macintosh files to UNIX. wc -l [filename] returns 0 as
> these files have no newlines (i.e., the whole file is treated as one
> line)
>
> I'd like to translate each \r into a \n.
>
> However, an s/\r/\n/g doesn't seem to being doing the trick and s/\0d/
> \0a/g isn't working either.
To achieve best performance, you should be using tr/// instead of s///g,
so I'll base my answer on that assumption.
Assuming you are trying to convert the Mac files by running Perl on the
Unix system, your first attempt should work.
But it might be better to be explicit, as in your second attempt, which
failed because you didn't escape the hex characters correctly.
tr/\x0d/\x0a/
This has the virtue of doing what you want when running on the Mac also,
because there the values of "\n" and "\r" are interchanged. But you
might do something amusing like this, which would work on either
machine:
tr/\r\n/\n\r/
The s///g approach can't do that without considerable complication.
s/([\r\n])/$1 eq "\r" ? "\n" : "\r"/eg
Yuck!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 24 Apr 2000 18:54:38 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Critique My Code
Message-Id: <slrn8g9k5e.4gf.tadmc@magna.metronet.com>
On Mon, 24 Apr 2000 15:14:44 -0700, Gabe <grichards@flashcom.net> wrote:
>
>"Tom Briles" <sariq@texas.net> wrote in message
>news:3904999C.821D0FA9@texas.net...
>> You'll want to turn on warnings and taint checking here (-wT).
>
>
>I've read the docs on the taint switch, but I don't understand it.
Then see also:
perldoc perlsec
> What does
>it do?
It tracks the "source" of data in your program.
If the source of the data is external to your program (e.g. read
from a file, from an env var, from a web form...), then it won't
let you do some "dangerous things" without checking out the
data first.
>Why is it useful?
Because there are lots of Bad Guys out there trying to break stuff,
making form entries like "somefile.gif ; rm -rf *" just to see
what happens.
You, as a site developer, would like to see that do nothing :-)
Taint checking helps you find places where such deviousness
could be introduced into your system.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 24 Apr 2000 19:08:01 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Critique My Code
Message-Id: <slrn8g9kuh.4gf.tadmc@magna.metronet.com>
On Mon, 24 Apr 2000 15:13:22 -0700, Gabe <grichards@flashcom.net> wrote:
><nobull@mail.com> wrote in message news:u9g0sbml3f.fsf@wcl-l.bham.ac.uk...
>> "Gabe" <grichards@flashcom.net> writes:
>> > use lib '/home/mopicmag/www/modules';
>>
>> Usually better to manipulate PERL5LIB outside Perl if you can.
>> Depends on you HTTP server s/w. If you can't manipulate PERL5LIB then
>> "use lib" is the next best thing.
>
>I didn't know you could manipulate PERL5LIB outside PERL.
PERL5LIB is an environment variable.
It "belongs" to the environment (not to perl), and can be
manipulated like any other env var, such as PATH.
>> >
>> > main: {
>> > &event;
>>
>> It's generally considered better style to declare your subroutines
>> before you use them rather than need to put in an explict & in the
>> call.
>
>How do I declare my subroutines before I use them?
Either:
1) put the subroutine _definition_ ( sub mysub { ... } )
before any calls to the subroutine.
2) put a subroutine _declaration_ ( sub mysub; ) before any calls.
"definition" and "declaration" are described in the first
20 lines of 'perlsub.pod'.
Please don't tell us you are posting subroutine questions without
first reading the docs for subroutines...
I think pre-(declaring|defining) is a pain so I never do that.
I also don't use ampersand.
I always [1] use parens instead, even if there are no arguments:
event();
[1] unless I _want_ the special treatment of @_, which I seldom do.
>Once I declare them, how
>do I use them without using &?
event;
>> What's that label for anyhow?
>
>Honestly, I didn't know that's what it was. I saw it on an old program I
>learned from, and have used that syntax to run my subprocedures.
Do not do that!
Ever!
That is called "cargo cult" programming.
Do not use code you get from the 'net without *first* understanding
what it does.
If you do not understand it, don't use it.
It may do something bad.
Some people make code available just to sucker you into running it...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 25 Apr 2000 14:02:37 -0500
From: Sid Mal <sid@eurekanet.com>
Subject: Does opening files slow perl down?
Message-Id: <3905ddc9$0$35171@news.eurekanet.com>
I am writing a script that allows users to post messages to a local
community board. I am unsure of how to store the data. I can either
store all the postings in subject files but this makes it a little
difficult to delete individual postings using a script.
The other option is to store each message in a different file with an
index file pointing to which messages are to be shown. My worry is that
opening 20 files instead of 2 will slow down the server.
Do I have to worry about that? Does perl slow down when you open
several files?
Sid.
------------------------------
Date: Tue, 25 Apr 2000 12:59:39 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Does opening files slow perl down?
Message-Id: <Pine.GSO.4.10.10004251257540.25963-100000@user2.teleport.com>
On Tue, 25 Apr 2000, Sid Mal wrote:
> Does perl slow down when you open several files?
Opening a file does take time, but it's not long. If your program is
competently written, opening and closing a dozen files should take a small
fraction of a second, whether you're using Perl or some other language.
Still, if this is going to be a big problem, perhaps you should consider a
real database or another solution. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 26 Apr 2000 02:16:29 +0700
From: "Foto35" <foto35@siamvoice.com>
Subject: Download file
Message-Id: <8e4qlg$veh$1@atom.nectec.or.th>
How to use cgi (perl) read some file on other URL. or save it to file?
Regards,
Thone
------------------------------
Date: Tue, 25 Apr 2000 13:07:54 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Download file
Message-Id: <Pine.GSO.4.10.10004251307360.25963-100000@user2.teleport.com>
On Wed, 26 Apr 2000, Foto35 wrote:
> How to use cgi (perl) read some file on other URL. or save it to file?
LWP, from CPAN.
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 25 Apr 2000 13:10:11 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Download file
Message-Id: <3905FBA3.FF42D2FD@My-Deja.com>
> How to use cgi (perl) read some file on other URL. or save it to file?
perldoc LWP::UserAgent
------------------------------
Date: Tue, 25 Apr 2000 20:37:36 GMT
From: qcoldiron@yahoo.com
Subject: Re: E-mail Header Module
Message-Id: <8e4vme$un7$1@nnrp1.deja.com>
I've been trying to build a web based mail program also and wonder if
your have an answer for me...
I can easily read email from a POP3 acount using Mail::POP3Client but I
don't know how to extract the attachments. The read message has the
base64 encoded message as part of the email body. I have a base64
decoding module from CPAN, but how can I parse the encoded attachment
out of the message so I can decode it and write it to disk?
Quinn
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 25 Apr 2000 12:41:10 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Efficient manipulation of simple date?
Message-Id: <Pine.GSO.4.10.10004251233500.25963-100000@user2.teleport.com>
On 25 Apr 2000, Jesse T Sheidlower wrote:
> I have a relatively simple problem with manipulating date formats, but
> the recent thread on Date::Manip seems to suggest that it's a large
> and slow module to use, so I was hoping to get some advice on the best
> way of approaching my problem.
Date::Manip is (mostly) slow only in starting up. For many people, it's a
fine solution. On my system, it seems to add about one-half second to
execution time of a null program. That's real time, not CPU time! If your
users won't mind waiting half a second for your program to start up,
you'll be fine. (If, on the other hand, you'll be starting this up more
than 1000 times per day, perhaps there's a better way.)
> I'm not doing especially complex manipulations, so perhaps there's a
> simpler way.
The docs for Date::Manip include a section on "SHOULD I USE DATE::MANIP"
which includes some alternatives. Have you seen that?
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 25 Apr 2000 19:58:36 GMT
From: nj_kanda@alcor.concordia.ca (Neil Kandalgaonkar)
Subject: Re: Efficient manipulation of simple date?
Message-Id: <8e4tdc$qd4$1@newsflash.concordia.ca>
In article <8e4kj9$f9h$1@panix.com>,
Jesse T Sheidlower <jester@panix.com> wrote:
>
>I have a relatively simple problem with manipulating date
>formats, but the recent thread on Date::Manip seems to
>suggest that it's a large and slow module to use, so I
>was hoping to get some advice on the best way of approaching
>my problem.
What I don't hear is something like "I tried Date::Manip
and it was too slow for me." Installing modules and trying them
out is the fastest answer to your problem.
>I am getting data into a bibliographic field that can be in
>various formats, such as "21 Nov.", "Nov. 21," "21 November,"
>plain "Nov." or "November", and things without months such
>as "Spring".
Out of curiosity I tried this:
perl -MDate::Manip -wlne 'print ParseDate ($_)'
And typed various stuff.
Plain old months don't work with Date::Manip, neither would
something like "Spring". But that seems to be close to
what you wanted anyway.
>This isn't a major part of my program so I don't want to
>clog it up with Date::Manip if that's really such a slow
>module, but it does seem as if that module would make it
>easy to deal with this.
It's slow to load, that's for sure. But I get reasonable
performance once it's started -- 100 parses per sec on a
433 Mhz Celeron.
>perhaps there's a simpler way.
I could imagine a simpler routine to handle this, but it
sounds like you are dealing with free-form data, which means
there will tons of exceptions. Much easier to use Date::Manip
as a first approximation, record the cases where it fails.
--
Neil Kandalgaonkar
neil@brevity.org
------------------------------
Date: Tue, 25 Apr 2000 13:13:11 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: exception handling
Message-Id: <3905FC57.F7DBFCF5@My-Deja.com>
> Hey people. I'm planning an OO Perl app, and I want real exception
> handling with full objects. I've looked at the CPAN, and I see Exceptions.pm,
> and Error.pm. They look very much alike. Did I miss anything else? Does anyone
> have any favorites?
> I also saw a news post about a Throwable.pm module. Anything on that?
Exception handling in perl is not very object aware.
Check this
http://genome-www.stanford.edu/perlOOP/lib/Bio/Root/Err.pm.html
---
------------------------------
Date: Tue, 25 Apr 2000 16:20:19 -0400
From: "Gadey, Prem [CAR:0C11:EXCH]" <prem@nortelnetworks.com>
Subject: find and replace a string in a huge file
Message-Id: <8e4uc3$gvp$1@bcarh8ab.ca.nortel.com>
Hi,
This one liner is great. But, please tell me how I can input binary files
to this. When I tried this on WinNT (there could be some special
characters like ^Z or it could be because of different flavour of Perl,
ActivePerl), it is giving the following error:
>perl -wpe 's/cats/cows/g' < sample.txt > sample3.txt
Useless use of a constant in void context at -e line 1.
>perl -wp 's/cats/cows/g' < sample.txt > sample3.txt
Can't open perl script "'s/cats/cows/g'": No such file or directory
Thanks.
--
With regards,
/Prem
(prem@nortelnetworks.com)
Craig Berry <cberry@cinenet.net> wrote in message
> Were I doing this, I'd express it as a one-liner from the command line,
> using redirection to read the input and write the output files:
>
> perl -wpe 's/foo/bar/g' <in >out
Hi,
I have a huge file (~10MB) and I want to replace 3-4 instances of a
string with another string. I am using the following script to do that
job.
--
my $old_string = shift(@ARGV);
my $new_string = shift(@ARGV);
my $file = shift(@ARGV);
my $file2 = shift(@ARGV);
open (FILE, "< $file") ||
die "Sorry, I couldn't open $file for read in replace.\n";
open (FILE2, "> $file2") ||
die "Sorry, I couldn't open $file for write in replace.\n";
while (<FILE>) {
$_ =~ s/$old_string/$new_string/g;
print FILE2 "$_";
}
close(FILE2);
close FILE;
--
This works fine on small files but not with the huge file. I am actually
getting an output file of 5KB for an input file of 10MB (the replacement
string is almost same size as the original string and is about 10
characters). I believe the reason is when an input line is read, perl is
allocating a buffer of certain length which is not able to read the long
lines in my input file.
Will appreciate any inputs.
Thanks.
--
With regards,
/Prem
------------------------------
Date: Tue, 25 Apr 2000 13:36:28 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: find and replace a string in a huge file
Message-Id: <Pine.GSO.4.10.10004251328021.25963-100000@user2.teleport.com>
On Tue, 25 Apr 2000, Gadey, Prem [CAR:0C11:EXCH] wrote:
> how I can input binary files to this. When I tried this on WinNT
Smells like 'binmode'. But that's tricky to add to a one-liner. Still, if
you have perl 5.6, see the 'open' pragma.
> >perl -wpe 's/cats/cows/g' < sample.txt > sample3.txt
> Useless use of a constant in void context at -e line 1.
If it's DOS/Windows, use single quotes.
> >perl -wp 's/cats/cows/g' < sample.txt > sample3.txt
> Can't open perl script "'s/cats/cows/g'": No such file or directory
Well, of course! :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 25 Apr 2000 13:51:18 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: find and replace a string in a huge file
Message-Id: <MPG.136fa5217a623e7d98a97b@nntp.hpl.hp.com>
[Your post is very difficult to follow. You refer to things which come
later, and include at the end an entire post which you don't refer to at
all. I have rearranged things to try to make them more sensible.]
In article <8e4uc3$gvp$1@bcarh8ab.ca.nortel.com> on Tue, 25 Apr 2000
16:20:19 -0400, Gadey, Prem [CAR:0C11:EXCH] <prem@nortelnetworks.com>
says...
> Craig Berry <cberry@cinenet.net> wrote in message
> > Were I doing this, I'd express it as a one-liner from the command line,
> > using redirection to read the input and write the output files:
> >
> > perl -wpe 's/foo/bar/g' <in >out
>
> This one liner is great. But, please tell me how I can input binary files
> to this. When I tried this on WinNT (there could be some special
> characters like ^Z or it could be because of different flavour of Perl,
> ActivePerl), it is giving the following error:
>
> >perl -wpe 's/cats/cows/g' < sample.txt > sample3.txt
> Useless use of a constant in void context at -e line 1.
For Windows/DOS systems, the command processor requires double-quotes
around arguments, not single-quotes. Double-quotes would work on Unix
too, and perhaps people who post here should use them for the sake of
portability, unless there are '$var' constructs inside which would then
become visible to the shell.
As for your question about treating files as binary, my understanding is
that at this time there is no way to binmode() an input file opened by
the default <> operator, which is how files are opened when processed
from the command line (see perlrun for details of the -p flag). So you
will have to write more code that opens each file explicitly and then
binmodes its filehandle. This has to be done for the output files also,
of course.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 25 Apr 2000 13:54:08 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: find and replace a string in a huge file
Message-Id: <MPG.136fa5cd63a4bae198a97c@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <Pine.GSO.4.10.10004251328021.25963-
100000@user2.teleport.com> on Tue, 25 Apr 2000 13:36:28 -0700, Tom
Phoenix <rootbeer@redcat.com> says...
> On Tue, 25 Apr 2000, Gadey, Prem [CAR:0C11:EXCH] wrote:
...
> > >perl -wpe 's/cats/cows/g' < sample.txt > sample3.txt
> > Useless use of a constant in void context at -e line 1.
>
> If it's DOS/Windows, use single quotes.
Ahem. s/single/double/. :-)
By the way, it has to be DOS/Windows, because the poster explicitly
referred to ActivePerl and issues of $^Z end-of-files.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 25 Apr 2000 14:46:38 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: find and replace a string in a huge file
Message-Id: <Pine.GSO.4.10.10004251444520.25963-100000@user2.teleport.com>
On Tue, 25 Apr 2000, Larry Rosler wrote, quoting me:
> > If it's DOS/Windows, use single quotes.
>
> Ahem. s/single/double/. :-)
Oops, thinko. My bad!
> By the way, it has to be DOS/Windows, because the poster explicitly
That's what I thought. But since I hadn't quoted that part, I wanted to
make my response explicit. Of course, then I got it backwards. Dang.
Thanks for catching it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 26 Apr 2000 04:06:12 +0900
From: "alice" <alice@dogcat.com>
Subject: how to measure processing time by millisecond unit
Message-Id: <8e4qb4$ot6$1@news01.iij4u.or.jp>
Hi,
I want to measure the following processing time by millisecond unit(e.g
1.50s=1500ms)
for ($a = 1;$a <=10;$a++){
...
}
By time function,I can get time *second unit* but now I want to get
*millisecond(1/1000sec)* or 1/10 second unit.
How should I solve it?
----------------------
alice
------------------------------
Date: Tue, 25 Apr 2000 12:52:08 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: how to measure processing time by millisecond unit
Message-Id: <3905F768.560451B7@My-Deja.com>
> By time function,I can get time *second unit* but now I want to get
> *millisecond(1/1000sec)* or 1/10 second unit.
use the BenchMark module to do this.
This is described in Programming Perl book Chapter 7.
---
------------------------------
Date: Tue, 25 Apr 2000 20:16:58 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: how to measure processing time by millisecond unit
Message-Id: <7ar9bu7x6u.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
"alice" <alice@dogcat.com> writes:
> By time function,I can get time *second unit* but now I want to get
> *millisecond(1/1000sec)* or 1/10 second unit.
>
> How should I solve it?
By reading the faqs, section 8:
How can I measure time under a second?
--Ala
------------------------------
Date: Tue, 25 Apr 2000 13:19:33 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to measure processing time by millisecond unit
Message-Id: <MPG.136f9dae2dc174bc98a979@nntp.hpl.hp.com>
In article <8e4qb4$ot6$1@news01.iij4u.or.jp> on Wed, 26 Apr 2000
04:06:12 +0900, alice <alice@dogcat.com> says...
> I want to measure the following processing time by millisecond unit(e.g
> 1.50s=1500ms)
>
> for ($a = 1;$a <=10;$a++){
> ...
> }
>
> By time function,I can get time *second unit* but now I want to get
> *millisecond(1/1000sec)* or 1/10 second unit.
>
> How should I solve it?
perlfaq8: "How can I measure time under a second?"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
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 2861
**************************************