[24171] in Perl-Users-Digest
Perl-Users Digest, Issue: 6363 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 5 03:05:40 2004
Date: Mon, 5 Apr 2004 00:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 5 Apr 2004 Volume: 10 Number: 6363
Today's topics:
Re: CGI::Carp and "useless quotes" (ko)
Re: CGI::Carp and "useless quotes" <noreply@gunnar.cc>
Re: CGI::Carp and "useless quotes" <matthew.garrish@sympatico.ca>
Re: CGI::Carp and "useless quotes" <noreply@gunnar.cc>
Re: CGI::Carp and "useless quotes" <matthew.garrish@sympatico.ca>
Re: free source for bbs <matthew.garrish@sympatico.ca>
Re: mod_perl ebooks at the web? <dave@dave.org.uk>
Re: PDF File Information thru PERL (Bill)
Re: real, simple sample OOP intro text??!! <tassilo.parseval@rwth-aachen.de>
Re: real, simple sample OOP intro text??!! <uri@stemsystems.com>
Re: real, simple sample OOP intro text??!! <tassilo.parseval@rwth-aachen.de>
Re: real, simple sample OOP intro text??!! <uri@stemsystems.com>
rename <anonymous@disneyland.com>
Re: rename <xaonon@hotpop.com>
Re: rename <invalid-email@rochester.rr.com>
Re: rename <xaonon@hotpop.com>
Re: rename (Peter J. Acklam)
Re: Search and replace a string in files (Kapil Khosla)
Re: Search and replace a string in files (Kapil Khosla)
Re: Search and replace a string in files <theaney@cablespeed.com>
Re: Weird timezone problems on Win2k <soon.the.sp@mmers.and.evil.ones.will.bow-down-to.us>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Apr 2004 16:10:42 -0700
From: kuujinbo@hotmail.com (ko)
Subject: Re: CGI::Carp and "useless quotes"
Message-Id: <92d64088.0404041510.443938b1@posting.google.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<c4phk8$2klsk8$1@ID-184292.news.uni-berlin.de>...
> I have made a weird observation when using CGI::Carp, version 1.26.
>
> This code:
>
> use CGI::Carp 'fatalsToBrowser';
> open FH, 'nonexistingfile' or die $!;
>
> results in the message " at ...test.pl line 10." being sent to STDERR,
> i.e. the error string is not printed.
>
> If I change the code to:
>
> use CGI::Carp 'fatalsToBrowser';
> open FH, 'nonexistingfile' or die "$!";
> --------------------------------------^--^
>
> the resulting error message instead reads "No such file or directory
> at ...test.pl line 10.", i.e. as expected.
>
> (Version 1.20 of CGI::Carp behaves as expected whether the $! variable
> is quoted or not.)
>
> Is the above a bug or a feature in CGI::Carp?
Sorry, this isn't an answer to your question, but wouldn't it be
better to include more debugging information rather than less? Even
something as simple as:
my $nonexistingfile = 'nonexistingfile';
open FH, $nonexistingfile or die "Couldn't open $nonexistingfile: $!";
For example, it would make a difference when you're munging data to
create the filename(s) because you'll be able to see the *exact*
filename. I make my share of errors/typos :( and try to keep the
number of bare '$!'s to a minimum.
HTH - keith
------------------------------
Date: Mon, 05 Apr 2004 02:46:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI::Carp and "useless quotes"
Message-Id: <c4qada$2hpnsn$1@ID-184292.news.uni-berlin.de>
ko wrote:
> Gunnar Hjalmarsson wrote:
>> This code:
>>
>> use CGI::Carp 'fatalsToBrowser';
>> open FH, 'nonexistingfile' or die $!;
>>
>> results in the message " at ...test.pl line 10." being sent to
>> STDERR, i.e. the error string is not printed.
>
> wouldn't it be better to include more debugging information rather
> than less? Even something as simple as:
>
> my $nonexistingfile = 'nonexistingfile';
> open FH, $nonexistingfile or die "Couldn't open $nonexistingfile:
> $!";
I typically do something like that, too. But sometimes I find it
sufficient to just say "... or die $!", and it has worked fine up to
now. Btw, I have made several posts to this group using "... or die
$!", and nobody has objected. ;-)
If the behaviour of CGI::Carp 1.26 *is* a bug, which has been/will be
taken care of in later versions, it's one thing. But if the behaviour
is something that you should expect, I'd better revise some code of
mine...
So if somebody could help me understand what's happening, it would be
much appreciated.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 4 Apr 2004 20:57:35 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: CGI::Carp and "useless quotes"
Message-Id: <V92cc.3468$wq4.356810@news20.bellglobal.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:c4phk8$2klsk8$1@ID-184292.news.uni-berlin.de...
> I have made a weird observation when using CGI::Carp, version 1.26.
>
> This code:
>
> use CGI::Carp 'fatalsToBrowser';
> open FH, 'nonexistingfile' or die $!;
>
> results in the message " at ...test.pl line 10." being sent to STDERR,
> i.e. the error string is not printed.
>
> If I change the code to:
>
> use CGI::Carp 'fatalsToBrowser';
> open FH, 'nonexistingfile' or die "$!";
> --------------------------------------^--^
>
> the resulting error message instead reads "No such file or directory
> at ...test.pl line 10.", i.e. as expected.
>
I tried 1.26 and all I got in the browser was '</p>' without quoting $!.
Must have been a bug in that release, because it's gone again in 1.27...
Matt
------------------------------
Date: Mon, 05 Apr 2004 04:47:31 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI::Carp and "useless quotes"
Message-Id: <c4qhgo$2i5t25$1@ID-184292.news.uni-berlin.de>
Matt Garrish wrote:
> Gunnar Hjalmarsson wrote:
>> This code:
>>
>> use CGI::Carp 'fatalsToBrowser';
>> open FH, 'nonexistingfile' or die $!;
>>
>> results in the message " at ...test.pl line 10." being sent to
>> STDERR, i.e. the error string is not printed.
>
> I tried 1.26 and all I got in the browser was '</p>' without
> quoting $!. Must have been a bug in that release, because it's gone
> again in 1.27...
Hmm.. For me, both 1.26 and 1.27 fails to print the error string when
$! is passed unquoted to die().
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 5 Apr 2004 00:38:02 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: CGI::Carp and "useless quotes"
Message-Id: <Co5cc.5611$wq4.466650@news20.bellglobal.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:c4qhgo$2i5t25$1@ID-184292.news.uni-berlin.de...
>
> Hmm.. For me, both 1.26 and 1.27 fails to print the error string when
> $! is passed unquoted to die().
>
Here's the culprit (in the die subroutine):
realdie @_ if ineval;
Sorry, I'm too tired to try and track the bug down to the source, but it
seems @_ is reset if $! is not quoted (try dumping @_ to STDERR before and
after this line ($arg is "join"ed with @_ in the following block, and the
'at line...' is appended, hence your stunted output)).
Matt
------------------------------
Date: Sun, 4 Apr 2004 22:07:41 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: free source for bbs
Message-Id: <Fb3cc.4476$wq4.392213@news20.bellglobal.com>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:fba07052o9ovcm7g7gjrufsc68bj3dndui@4ax.com...
>
> but *in any case* if he turns out to be willing to improve his
> programming/perl skills, then why should he be advised to avoid doing
> so a priori?!?
>
Have you really been paying attention to his posts? Nothing has sunk in in
the entire time, and I can understand why Uri has given up on him. He has
exhibited no knowledge of basic programming skills.
First off, security is lost on him. He patches holes only as they are made
aware to him, and has no idea the dangers his scripts pose. Worse, he seems
to believe that because he can't think of any more bugs there must not be
any.
Second, we all know that he stole the bulk of the code from somewhere and
has been trying to rewrite it as his own (despite his denials). And even
though he has been told numerous times that the code base he is working from
is garbage, he hasn't abandoned it. He uses neither strictures nor warnings
in his scripts (the two pragmas any decent beginner wouldn't avoid), nor
does he taint check the data in this particular one. He has also been told
over and over to use CGI.pm, but from what I've been reading he still hasn't
caught on there either.
I've got work to do so I'm going to stop myself there, but I hope you can
see my point. Should he abandon programming entirely, of course not (and I
don't think that's what Uri is necessarily advocating). Should he stop
posting his code online (and using it on his site) until he learns a lot
more, of course! The problem is he won't listen to this advice, and that is
why he is being told in no uncertain terms what people think of him and his
attitude.
Matt
------------------------------
Date: Mon, 05 Apr 2004 07:55:24 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: mod_perl ebooks at the web?
Message-Id: <pan.2004.04.05.06.55.24.717540@dave.org.uk>
[ please don't top-post ]
On Sun, 04 Apr 2004 19:46:36 +0200, PHP2 wrote:
> this is introduction of of mod_perl.. thanks..
>
> have someone more? :-))
Some sample chapters of the mod_perl developers cookbook are online at
http://www.modperlcookbook.org/.
Also some sample chapters of "Practical mod_perl" are online at
http://modperlbook.org/.
There are a number of complete books online at http://safari.oreilly.com.
Dave...
------------------------------
Date: 4 Apr 2004 22:05:09 -0700
From: wherrera@lynxview.com (Bill)
Subject: Re: PDF File Information thru PERL
Message-Id: <239ce42f.0404042105.73ca065f@posting.google.com>
Aqua (Dominic) wrote:
> I would like to get all the information about a PDF file. I dont want
> to modidy ot create a PDF file. Information like PDF Version, Total
> Pages, if possible total images, if it is bookmarked etc.
> In this regard I am trying various modules like PDF (PDF::Parse,
> PDF::Core) and PDF::API2. The first module work fine but not on all
> PDF files. The second one, actually I dont know how to get information
> without modifying the PDF.
Why do you think have to modify the PDF with API2? I can use this on a
read-only file:
==============================
use strict;
use warnings;
use PDF::API2;
my $pf = 'mypdffile.pdf';
my $pdf = PDF::API2->open($pf) or die $!;
print "Starting analysis of $pf...\n";
my $pagenumber = $pdf->pages;
print "$pagenumber pages.\n";
my %opts = $pdf->info;
while (my ($k, $v) = each %opts) { print "option $k is: $v\n" }
I think there is other PDF info that can be dug out of the module as
well.
--Bill
------------------------------
Date: 4 Apr 2004 18:20:36 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: real, simple sample OOP intro text??!!
Message-Id: <c4pjlk$ssg$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Geoff Cox:
> On 4 Apr 2004 08:52:54 GMT, "Tassilo v. Parseval"
><tassilo.parseval@rwth-aachen.de> wrote:
>
>
>>You said you were looking for <h2> tags. That would mean you'd at least
>>have to write:
>>
>> if ($tagname eq 'h2') {
>
> Tassilo,
>
> if above finds the <h2> text </h2>
It doesn't. It only finds <h2>. </h2> is handled by the end() method.
The part between those tags is handled by text() or again start() and
end() in case other tags are nested inside the header.
> how do I get at the text between the <h2> and the </h2> ? I know I
> ought not to have to ask you but how do I find the answer? Is it in
> the HTML::Parser docs?
You have to make your parser state-aware. The simplest solution would be
a global variable:
my $in_heading;
sub start {
my ($self, $tagname, undef, undef, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 1;
return;
}
print $origtext if $in_heading;
}
sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}
print $origtext if $in_heading;
}
sub text {
my ($self, $origtext) = @_;
print $origtext if $in_heading;
}
The above will effectively print only the stuff that shows up in <h2>
tags, excluding them.
Another way is using a real stack. Three helper closures can be used for
that:
{ my @stack;
sub pushstack { push @stack, shift }
sub popstack { pop @stack }
sub peekstack { $stack[shift] }
}
Essentially, start() always does a pushstack($tagname), end() always a
popstack(). With peekstack() you can have a look at the elements on the
stack. peekstack(-1) would be the last element (the tag that was just
pushed onto it).
A stack is useful when you want to do more complicated things. You might
need additional functions for it, such as instack($tagname) that checks
whether $tagname is on the stack which would mean that you are currently
dealing with a tag below $tagname. It also requires that every starttag
has a corresponding endtag, or otherwise more complex handling is
necessary.
You just go for the $in_heading approach. It will perfectly do for your
task.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 04 Apr 2004 19:47:44 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: real, simple sample OOP intro text??!!
Message-Id: <x7hdvzh6eb.fsf@mail.sysarch.com>
>>>>> "GC" == Geoff Cox <geoffacox@dontspamblueyonder.co.uk> writes:
GC> I have just been into London to look at Damian's OOP book. It does
GC> look very good but costs £38 here and may be a little more than I
GC> need at the moment. (On the other hand it may be just what I do
GC> need so may end up buying it)...It does annoy me that we pay the
GC> same figure in UK pounds as the US $ figure....is this a rip off
GC> somewhere along the line?!
damn, you found out that i sekritly control book prices all over the
world. i set them high in london just so you wouldn't buy the one book
you really need! now i will have to find some other suckers^Wreaders for
damian's book. and i don't even get a kickback from him for any books
sales!
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 4 Apr 2004 21:03:41 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: real, simple sample OOP intro text??!!
Message-Id: <c4pt7d$7bh$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Uri Guttman:
>>>>>> "GC" == Geoff Cox <geoffacox@dontspamblueyonder.co.uk> writes:
>
> GC> I have just been into London to look at Damian's OOP book. It does
> GC> look very good but costs £38 here and may be a little more than I
> GC> need at the moment. (On the other hand it may be just what I do
> GC> need so may end up buying it)...It does annoy me that we pay the
> GC> same figure in UK pounds as the US $ figure....is this a rip off
> GC> somewhere along the line?!
>
> damn, you found out that i sekritly control book prices all over the
> world. i set them high in london just so you wouldn't buy the one book
> you really need!
Putting aside the issue with prices, I wonder whether the OP really
needs this book. It's certainly nice when you want to learn how to do
fancy things in Perl fancily. A few chapters I found outright boring,
such as "Multiple Dispatch". Maybe it's because I don't write
widget-sets in Perl on a daily basis.
I'd rather suggest he has a look at Randal's "Learning Perl Objects,
References & Modules". And unlike Damian's book, this one comes with
excercises for the reader.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 04 Apr 2004 22:00:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: real, simple sample OOP intro text??!!
Message-Id: <x77jwvh08q.fsf@mail.sysarch.com>
>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@rwth-aachen.de> writes:
TvP> Also sprach Uri Guttman:
>> damn, you found out that i sekritly control book prices all over the
>> world. i set them high in london just so you wouldn't buy the one book
>> you really need!
TvP> Putting aside the issue with prices, I wonder whether the OP really
TvP> needs this book. It's certainly nice when you want to learn how to do
TvP> fancy things in Perl fancily. A few chapters I found outright boring,
TvP> such as "Multiple Dispatch". Maybe it's because I don't write
TvP> widget-sets in Perl on a daily basis.
i agree some of OOP's wackier stuff is just too wacky for most uses. but
the way damian explains basic OO perl is better than anything i have
seen. and he builds on the basics when ho covers the more exotic
stuff. also the appendix comparing OO perl to the OO features of other
languages is very useful.
TvP> I'd rather suggest he has a look at Randal's "Learning Perl
TvP> Objects, References & Modules. And unlike Damian's book, this
TvP> one comes with excercises for the reader.
i would expect that to be good too. i haven't snarfed a copy yet :)
but given the pricing of us books in london, i doubt the OP will get
much of any discount though i think PORM has a cheaper list price than
OOP.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 04 Apr 2004 20:33:16 GMT
From: "luc" <anonymous@disneyland.com>
Subject: rename
Message-Id: <gi_bc.60595$3j2.3888172@phobos.telenet-ops.be>
I frequently have to rename files like "MyPiCiNPaRiS.jpg" and I'm really
annoyed with the fact that sometimes there are hundreds of them. Is there a
program out there for xp that can help me automatically rename these files
into all small case?
------------------------------
Date: 4 Apr 2004 21:36:09 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: rename
Message-Id: <slrnc70vtj.8h4.xaonon@xaonon.local>
Ned i bach <gi_bc.60595$3j2.3888172@phobos.telenet-ops.be>, luc
<anonymous@disneyland.com> teithant i thiw hin:
> I frequently have to rename files like "MyPiCiNPaRiS.jpg" and I'm really
> annoyed with the fact that sometimes there are hundreds of them. Is there
> a program out there for xp that can help me automatically rename these
> files into all small case?
$ perl -e 'rename $_, lc $_ for @ARGV' *.jpg
Add error code and checks for pre-existing files as appropriate.
--
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
http://xaonon.dyndns.org/ Guaranteed content-free since 1999. No refunds.
"Since I do things on a regular basis that defies the laws of physics, I can
speak with some authority on the matter." -- vtailor@gte.net, in alt.atheism
------------------------------
Date: Mon, 05 Apr 2004 01:39:09 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: rename
Message-Id: <4070B8A1.9030600@rochester.rr.com>
Xaonon wrote:
> Ned i bach <gi_bc.60595$3j2.3888172@phobos.telenet-ops.be>, luc
> <anonymous@disneyland.com> teithant i thiw hin:
...
> $ perl -e 'rename $_, lc $_ for @ARGV' *.jpg
Uh, for Windoze, you'd better make it:
perl -e "rename $_,lc $_ for <$ARGV[0]>" *.jpg
or simply:
perl -e "rename $_,lc $_ for <*.jpg>"
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 5 Apr 2004 03:20:05 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: rename
Message-Id: <slrnc71k2e.9ln.xaonon@xaonon.local>
Ned i bach <4070B8A1.9030600@rochester.rr.com>, Bob Walton
<invalid-email@rochester.rr.com> teithant i thiw hin:
> Xaonon wrote:
>
> > Ned i bach <gi_bc.60595$3j2.3888172@phobos.telenet-ops.be>, luc
> > <anonymous@disneyland.com> teithant i thiw hin:
> ...
>
> > $ perl -e 'rename $_, lc $_ for @ARGV' *.jpg
>
> Uh, for Windoze, you'd better make it:
>
> perl -e "rename $_,lc $_ for <$ARGV[0]>" *.jpg
>
> or simply:
>
> perl -e "rename $_,lc $_ for <*.jpg>"
Now I remember why I always use Cygwin instead of the actual Windoze command
line.
--
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
http://xaonon.dyndns.org/ Guaranteed content-free since 1999. No refunds.
You were an atheist. You were stridently aligned. You were poison resistant.
You were invisible. You were a werejackal. You were lucky. You are dead.
------------------------------
Date: 05 Apr 2004 08:07:16 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: rename
Message-Id: <vfkf3qln.fsf@online.no>
Xaonon <xaonon@hotpop.com> wrote:
> $ perl -e 'rename $_, lc $_ for @ARGV' *.jpg
>
> Add error code and checks for pre-existing files as appropriate.
There is no point in checking for pre-existing files here, since
if "MyPiCiNPaRiS.jpg" exists, then "mypicinparis.jpg" exists, but
it is actually the same file.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: 4 Apr 2004 12:05:39 -0700
From: khoslakapil@yahoo.com (Kapil Khosla)
Subject: Re: Search and replace a string in files
Message-Id: <919aa2da.0404041105.6c5afb7d@posting.google.com>
> That RegExp is far more complicated than it needs to be. You're searching
> for: "Word boundary, followed by 'Main', then *optionally* followed by
> parenthesized text, followed by end-of-line. Why do you care about the
> parentheses and end of line? You said all you wanted to do was replace
> "Main" with "main". So the match could just be:
>
> m/\bMain/
I am sorry, I should have been more clear the first time. I want the
RegExp pattern to match
#define Main main - MATCH
int Main() - MATCH
int Main(String * str) - MATCH
but NOT
Mainframe -- NO MATCH
MainMain -- NO MATCH
DllMain -- NO MATCH
Do you now think that the RegExp is correct? How should I solve the
issue now.
Thanks,
Kapil
>
>
> > }
> > }
> >
> > #################
> >
> > Now, I dont know how to use this in a file and replace the string
> > matched with the corresponding lower case main.
> > This is what I could write till now.
> >
> >
> >
> > open FILEHANDLE,"E:\\file.cpp" or die ("Could not open file for
> > reading");;
> >
> > my @myfile = <FILEHANDLE>; # get the file in an arraylist
> >
> > for $line(@myfile)
> > {
> > # search for a pattern, if exists, replace with the correct str ?? #
> > This is what I dont know how to do :(
> > }
> > close FILEHANDLE;
> >
> >
> > Can you help?
>
>
> You said you read the chapter on RegExps. Did you somehow skip over the
> search-and-repalce operator? The line you're looking for is:
>
> s/\bMain/main/;
>
>
>
> HOWEVER, this is such a common task that your entire program can be
> reduced to *one line* of Perl code:
>
> perl -pi.bkp -e 's/\bMain/main/' filename.txt
>
> (the .bkp of that line will create backups of your original file, just in
> case you did something you didn't mean to.)
>
> To understand how this works, do
> perldoc perlrun
> and search for the -p and -i switches.
>
>
> Hope this helps,
> Paul Lalli
------------------------------
Date: 4 Apr 2004 12:09:04 -0700
From: khoslakapil@yahoo.com (Kapil Khosla)
Subject: Re: Search and replace a string in files
Message-Id: <919aa2da.0404041109.a35c9d3@posting.google.com>
>
> perl -pi.bkp -e 's/Main/main/' file.txt
I understand the line above and how it is working but for some reason
on my windows machine, it does not work. Would you know why? Is there
anything else which needs to be done on windows?
Thanks again,
Kapil
------------------------------
Date: Sun, 04 Apr 2004 16:10:45 -0400
From: Tim Heaney <theaney@cablespeed.com>
Subject: Re: Search and replace a string in files
Message-Id: <87n05rld16.fsf@mrbun.watterson>
khoslakapil@yahoo.com (Kapil Khosla) writes:
>
>> perl -pi.bkp -e 's/Main/main/' file.txt
>
> I understand the line above and how it is working but for some reason
> on my windows machine, it does not work. Would you know why? Is there
> anything else which needs to be done on windows?
Try double quotes
perl -pi.bkp -e "s/Main/main/" file.txt
But you seem to have missed at least one other post; I think you want
perl -pi.bkp -e "s/\bMain\b/main/g" file.txt
Tim
------------------------------
Date: Sun, 4 Apr 2004 18:24:18 -0400
From: FLEB <soon.the.sp@mmers.and.evil.ones.will.bow-down-to.us>
Subject: Re: Weird timezone problems on Win2k
Message-Id: <pv4273ne3bpm.6h3lx729gpqg$.dlg@40tude.net>
Regarding this well-known quote, often attributed to Chris Schadl's famous
"Sun, 04 Apr 2004 11:14:18 -0500" speech:
> Consider the following snippet of code:
>
> #!/usr/bin/perl
>
> use strict;
> use Date::Manip;
>
> my $date = &ParseDate("today");
> printf "Date is %s\n", UnixDate($date, "%u");
> printf "Hour according to localtime() is %s\n", (localtime())[2];
>
> On Linux:
>
> chris@lain:~/src/perl$ cat /etc/timezone
> America/Center
> chris@lain:~/src/perl$ ./datetime.pl
> Date is Sun Apr 4 11:14:55 -0500 2004
> Hour according to localtime() is 11
>
> However on Win2k, the time returned is 5 hours ahead:
>
> E:\Perl>echo %TZ%
> CDT
>
> E:\Perl>perl datetime.pl
> Date is Sun Apr 4 16:12:00 -0500 2004
> Hour according to localtime() is 16
>
> The system clock on the Win2k machine reports that the current time is
> 11:12am. Does anyone know wtf the problem is?
Are you sure you have the timezone set up right on the Win2K Machine? Check
the Date and Time Control panel, in one of the tabs.
--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6363
***************************************