[12723] in Perl-Users-Digest
Perl-Users Digest, Issue: 133 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 13 20:17:20 1999
Date: Tue, 13 Jul 1999 17:07:49 -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 Tue, 13 Jul 1999 Volume: 9 Number: 133
Today's topics:
simple question <ruedas@geophysik.uni-frankfurt.de>
Re: simple question (John Borwick)
simple regex question phillip@rhoderunner.com
Re: simple regex question <aperrin@mcmahon.qal.berkeley.edu>
Simple Web Crawler??? <bloodlet19@hotmail.com>
Re: single instance log file (Abigail)
solved: simple question <ruedas@geophysik.uni-frankfurt.de>
Some one to install perl T1388@worldnet.att.net
Re: Some one to install perl (Abigail)
Something in Perl I can do but can't in PHP (Kiernan Holland)
Re: Something in Perl I can do but can't in PHP <gellyfish@gellyfish.com>
Re: Something in Perl I can do but can't in PHP (elephant)
Re: Something in Perl I can do but can't in PHP <kperrier@blkbox.com>
Re: Sort <rick.delaney@home.com>
Re: Statistics for comp.lang.perl.misc (Abigail)
Re: Statistics for comp.lang.perl.misc <sjs@yorku.ca>
Re: Statistics for comp.lang.perl.misc (Abigail)
stored procedure without using Win32::OLE <dlewright@nuworld.com>
Re: stored procedure without using Win32::OLE <matt@sergeant.org>
Re: Subroutine references and sort (Neko)
Re: Subroutine references and sort <rick.delaney@home.com>
Re: Subroutine references and sort (A.J. Norman)
Re: Subroutine references and sort (John Borwick)
Re: Subroutine references and sort (A.J. Norman)
Re: Subroutine references and sort (Anno Siegel)
Substitution not global (James W. Sandoz)
Re: Substitution not global (Eugene van der Pijll)
Re: The class is interfering with my script. (Tad McClellan)
Re: The class is interfering with my script. (foo)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Jul 1999 20:50:49 +0200
From: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
Subject: simple question
Message-Id: <378B8A89.6201@geophysik.uni-frankfurt.de>
I want to split the string
990710
into 99 07 10. Why does
open (DATE,"olddate.save");
($rptyear,$rptmonth,$rptday)=split(/\d\d/,<DATE>);
not work and how do I have to do it? I just can't find out :-(
--
--------------------------------------------
Thomas Ruedas
Institute of Meteorology and Geophysics,
J.W. Goethe University Frankfurt/Main
Feldbergstrasse 47 D-60323 Frankfurt/Main, Germany
Phone:+49-(0)69-798-24949 Fax:+49-(0)69-798-23280
e-mail: ruedas@geophysik.uni-frankfurt.de
http://www.geophysik.uni-frankfurt.de/~ruedas/
--------------------------------------------
------------------------------
Date: Tue, 13 Jul 1999 19:44:47 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: simple question
Message-Id: <378c95b5.114579296@newshost.unx.sas.com>
On Tue, 13 Jul 1999 20:50:49 +0200, Thomas Ruedas
<ruedas@geophysik.uni-frankfurt.de> wrote:
>I want to split the string
>990710
>into 99 07 10. Why does
>
>open (DATE,"olddate.save");
>($rptyear,$rptmonth,$rptday)=split(/\d\d/,<DATE>);
>
>not work and how do I have to do it? I just can't find out :-(
Your split should be returning a list of 3 null values and \n. It
does this because the delimiter for fields in <DATE> is \d\d. So you
could see the split algorithm doing this:
OK, I've got this string "990710\n"
Read everything up to two digits.
Oh, here are two digits, "99". The first field therefore is "".
Wait, here are two more digits, "07". The second field is "".
Hey now here are two more digits, "10". The third field is "".
And finally there are no more digits, so the last field is the rest of
the string, or "\n"
If your dates are always going to be in this format, you could use
unpack:
($rptyear, $rptmonth, $rptday) = unpack ("a2 a2 a2", <DATE>);
That might be more efficient.
Are you solving y2k problems, or creating them?
--
John Borwick
------------------------------
Date: Tue, 13 Jul 1999 14:32:42 GMT
From: phillip@rhoderunner.com
Subject: simple regex question
Message-Id: <7mfilp$k5p$1@nnrp1.deja.com>
Hi,
Trying to come up with a regex that would match against one or multiple
words, but not all spaces. No combination that I have come up with as
worked thus far.
Valid Strings:
x
xyz
x yz ab
Thanks a lot!
Phillip
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 13 Jul 1999 08:32:20 -0700
From: Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: simple regex question
Message-Id: <378B5C04.11EBBA69@mcmahon.qal.berkeley.edu>
If it's really as simple as you're suggesting, why not:
/\S+/ # If a 'word' can contain anything other than whitespace; or
/[a-zA-Z]+/ # If a 'word' can be only alphanumeric.
HTH-
Andy Perrin
phillip@rhoderunner.com wrote:
> Hi,
> Trying to come up with a regex that would match against one or multiple
> words, but not all spaces.
--
-------------------------------------------------------------
Andrew Perrin - NT/Unix/Access Consulting -
aperrin@mcmahon.qal.berkeley.edu
http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------
------------------------------
Date: Tue, 13 Jul 1999 22:18:14 GMT
From: bandhunt <bloodlet19@hotmail.com>
Subject: Simple Web Crawler???
Message-Id: <7mgdur$db$1@nnrp1.deja.com>
I'm trying to build a simple web crawler.
I need to know how I can get a document from a particular URL and save
it to a database file on my server.
Seems like it should be simple but I can't figure it out.
Any help would be great,
D.J.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 13 Jul 1999 00:18:09 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: single instance log file
Message-Id: <slrn7olivp.h7.abigail@alexandra.delanet.com>
sskinner@cloud9.net (sskinner@cloud9.net) wrote on MMCXLI September
MCMXCIII in <URL:news:931791053.710.56@news.remarQ.com>:
;;
;; I'm not sure if I have to unlock a file after I close it.
A close() unlocks the file. Usually, you don't want to unlock yourself.
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 13 Jul 1999 21:19:38 +0200
From: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
To: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
Subject: solved: simple question
Message-Id: <378B914A.52BF@geophysik.uni-frankfurt.de>
Matthew Amster-Burton <mamster@mamster.net>
>There are a few ways you can do it. Split is wrong because split
>splits on a separator, and you have no separator in your string.
>You can do this:
>/(..)(..)(..)/
>or you can use unpack. Or you can use substr. perldoc -f unpack and
>perldoc -f substr.
I see; now I also understand better the / */ example on the split man
page. I thought split would provide a more compact way of achieving my
goal than substr.
Thank you very much,
Thomas
--
--------------------------------------------
Thomas Ruedas
Institute of Meteorology and Geophysics,
J.W. Goethe University Frankfurt/Main
Feldbergstrasse 47 D-60323 Frankfurt/Main, Germany
Phone:+49-(0)69-798-24949 Fax:+49-(0)69-798-23280
e-mail: ruedas@geophysik.uni-frankfurt.de
http://www.geophysik.uni-frankfurt.de/~ruedas/
--------------------------------------------
------------------------------
Date: Mon, 12 Jul 1999 23:13:15 -0400
From: T1388@worldnet.att.net
Subject: Some one to install perl
Message-Id: <378AAECB.70623FE6@worldnet.att.net>
Help, I brought a chat room script but I can't install it. The seller
says that all I need to change the path to
/home/USERNAME and upload it in ASCII format. However, it doesn't work
no matter how I try it. Where I can find someone to install scripts in
reasonable price?
------------------------------
Date: 13 Jul 1999 01:40:18 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Some one to install perl
Message-Id: <slrn7olnpm.h7.abigail@alexandra.delanet.com>
T1388@worldnet.att.net (T1388@worldnet.att.net) wrote on MMCXLII
September MCMXCIII in <URL:news:378AAECB.70623FE6@worldnet.att.net>:
!! Help, I brought a chat room script but I can't install it. The seller
!! says that all I need to change the path to
!! /home/USERNAME and upload it in ASCII format. However, it doesn't work
!! no matter how I try it. Where I can find someone to install scripts in
!! reasonable price?
Try your local recuiting office. This group is not about job ads.
Abigail
--
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
for (??;(??)x??;??)
{??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 13 Jul 1999 01:39:36 -0600
From: kholland@swcp.com (Kiernan Holland)
Subject: Something in Perl I can do but can't in PHP
Message-Id: <7meqfo$qe7@kitsune.swcp.com>
This is a simple problem, since I couldn't find a single newsgroup
on PHP, I decided to share the problem with you guys..
Here is the problem..
I'm using regexpressions in PHP ,
how would a PHP enthusiast translate the follwing lines
of Perl code:
while ($_ =~ s/^([^\n=]+)=([^\n]+)\n(.*)$/$3/gi) {
$stuff{$1} = $2;
}
I've searched up and down the PHP man pages for about an hour or two
and looked under array functions, string functions, file functions..
Nothing.. I can think of really really dirty ways of doing this
but I was hoping there might be a few Perl/PHP hybrid enthusiasts..
PS- I found a error in PHP, the methods of a class cannot have
the same name as a external function.. PHP is nice for simple
database hacks but its pretty limited in text processing..
Man there needs to be a way to combine PHP and Perl,
and if it could have the security, OOP purity and syntactical
simplicity of java, without the JVM , and the ability to
generate standalone executables, life would be good for me..
------------------------------
Date: 13 Jul 1999 09:31:30 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Something in Perl I can do but can't in PHP
Message-Id: <378af962@newsread3.dircon.co.uk>
Kiernan Holland <kholland@swcp.com> wrote:
>
> This is a simple problem, since I couldn't find a single newsgroup
> on PHP, I decided to share the problem with you guys..
> Here is the problem..
>
> I'm using regexpressions in PHP ,
> how would a PHP enthusiast translate the follwing lines
> of Perl code:
>
I dont know - perhaps you ought to ask in a group that is interested in PHP
/J\
--
"I managed to take her completely by surprise" - Prince Edward
------------------------------
Date: Tue, 13 Jul 1999 18:48:55 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: Something in Perl I can do but can't in PHP
Message-Id: <MPG.11f5a88131499891989b31@news-server>
Kiernan Holland writes ..
>This is a simple problem, since I couldn't find a single newsgroup
>on PHP, I decided to share the problem with you guys..
NO NO NO NO NO !!!!!!!!!!!!!
first read all the FAQs in news.answers regarding the usenet and take
heed
then try www.php.net .. in fact - just to get you to go away .. here's
their support page .. FAQs / mailing lists / bug databases / list
archives / it's all there
http://www.php.net/support.php3
hth
--
jason - remove all hyphens for email reply -
------------------------------
Date: 13 Jul 1999 09:37:27 -0500
From: Kent Perrier <kperrier@blkbox.com>
Subject: Re: Something in Perl I can do but can't in PHP
Message-Id: <2AC8616EBACE4013.12E3A37542D7F543.3B34CFC183DBBF48@lp.airnews.net>
kholland@swcp.com (Kiernan Holland) writes:
> This is a simple problem, since I couldn't find a single newsgroup
> on PHP, I decided to share the problem with you guys..
bad move. prepare to be flamed,
------------------------------
Date: Tue, 13 Jul 1999 00:55:10 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Sort
Message-Id: <378A8E3C.76599753@home.com>
[posted & mailed]
Jimtaylor5 wrote:
>
> I know how to sort, I've read the notes, etc. But is there a way to sort by
> revalant
> words before writing without writing to a file, then re-reading again to post
> what I have sorted.
Perl's sort works in memory and has nothing to do with files. Use that.
> If there is someone who will answer this question (even by email if you feel
> intinidated), please remember I'm just starting out in programming in Pearl.
> can you point me in the right direction even if you can't answer?
No wonder you're having trouble. It's Perl, not Pearl. Start with
man perl
or
perldoc perl
and go from there. One of those should allow you to read the
documentation contained in perl.pod.
You'll eventually end up reading perldata.pod, which will tell you about
arrays and perlfunc.pod which tells you all about the sort function.
Don't forget to read perlfaq4 which contains the useful FAQ,
How do I sort an array by (anything)?
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 12 Jul 1999 21:16:45 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <slrn7ol8bk.h7.abigail@alexandra.delanet.com>
Greg Bacon (gbacon@cs.uah.edu) wrote on MMCXLI September MCMXCIII in
<URL:news:7mcuea$19n$1@info2.uah.edu>:
''
'' 178 414.2 (201.3/135.0/127.6) abigail@delanet.com
Why does it only give my email address and not the '(Abigail)' part?
Is there something missing in my headers?
Abigail
--
178 postings in a week.... must be someone with a social disorder!
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Mon, 12 Jul 1999 21:23:55 -0400
From: Steven Smolinski <sjs@yorku.ca>
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <931829104.2137252778@newshub.ccs.yorku.ca>
On Mon, 12 Jul 1999, Abigail wrote:
[...]
>Is there something missing in my headers?
[I can't miss a straight line this good]
I think you spelled "head" wrong :)
Steve
------------------------------
Date: 13 Jul 1999 01:04:19 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <slrn7ollm9.h7.abigail@alexandra.delanet.com>
Steven Smolinski (sjs@yorku.ca) wrote on MMCXLII September MCMXCIII in
<URL:news:931829104.2137252778@newshub.ccs.yorku.ca>:
\\ On Mon, 12 Jul 1999, Abigail wrote:
\\ [...]
\\ >Is there something missing in my headers?
\\
\\ [I can't miss a straight line this good]
\\
\\ I think you spelled "head" wrong :)
No... I checked. All the sawdust is there.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Mon, 12 Jul 1999 22:44:24 GMT
From: Dorr Lewright <dlewright@nuworld.com>
Subject: stored procedure without using Win32::OLE
Message-Id: <378A6FC8.3E30B3A5@nuworld.com>
I am trying to execute a stored procedure without using Win32::OLE.
When I use the following code, I get back "The object
'sp_Get_POSMvmtStats' does not exist in database 'ESS'"
use Win32::ADO;
use OLE;
$query_stmt = "sp_Get_POSMvmtStats $rtlr_nch_rqst_num, $actual_lines,
$actual_bytes, $rtlr_num";
$RS = $Conn->Execute($query_stmt);
if(!$RS) {
$errors = $Conn->Errors();
print "errors:\n";
foreach $error (keys %$errors) {
print $error->{Description}, "\n";
}
die;
}
Any ideas on what I am doing wrong. I am not using Win32::OLE because I
have not seen good examples that execute stored procedures.
------------------------------
Date: Tue, 13 Jul 1999 09:28:06 +0100
From: Matt Sergeant <matt@sergeant.org>
Subject: Re: stored procedure without using Win32::OLE
Message-Id: <378AF896.8DF24A1B@sergeant.org>
Dorr Lewright wrote:
>
> I am trying to execute a stored procedure without using Win32::OLE.
>
> When I use the following code, I get back "The object
> 'sp_Get_POSMvmtStats' does not exist in database 'ESS'"
>
> use Win32::ADO;
> use OLE;
ARGHHH!!!...
Don't "use OLE;"
Do "use Win32::OLE;".
use OLE is deprecated. For very good reasons.
> Any ideas on what I am doing wrong. I am not using Win32::OLE because I
> have not seen good examples that execute stored procedures.
Did you check the Perl-Win32-Database FAQ?
Matt.
------------------------------
Date: 12 Jul 1999 19:05:11 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Subroutine references and sort
Message-Id: <7mde97$3qd$0@216.39.141.200>
On Mon, 12 Jul 1999 15:47:29 GMT, John.Borwick@sas.com (John Borwick) wrote:
>On 12 Jul 1999 14:43:54 +0100, nja@le.ac.uk (A.J. Norman) wrote:
>
>> ? \&sort_by_hits
>> : \&sort_by_host;
>> my @list = sort &$sortsub keys %data;
> ^^^^^^^^^
>
>I think sort takes a reference to a function, so you might need
>
>sort $sortsub keys %data;
>
>because sort will dereference $sortsub for you.
It would be nice if perl would see a code ref and deref it for you. Maybe in
5.006?
#!/usr/bin/perl -w
$num = sub { $a <=> $b };
print sort $num 1..20;
__END__
Not a GLOB reference at jam line 4.
You can put the subroutine call inside a block instead:
$num = sub { $a <=> $b };
print sort { &$num } 1..20;
Or you can assign the code to a localized glob:
{
local *num = sub { $a <=> $b };
print sort num 1..20;
}
--
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: Tue, 13 Jul 1999 00:45:32 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Subroutine references and sort
Message-Id: <378A8BFA.F4224133@home.com>
[posted & mailed]
Neko wrote:
>
> It would be nice if perl would see a code ref and deref it for you. Maybe in
> 5.006?
How about in 5.005_03?
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 13 Jul 1999 09:48:36 +0100
From: nja@le.ac.uk (A.J. Norman)
Subject: Re: Subroutine references and sort
Message-Id: <7meuh4$m2i@harrier.le.ac.uk>
In article <378b0d4a.14114385@newshost.unx.sas.com>, John Borwick
<jobosw@unx.sas.com> wrote:
> There is probably no method param. You might want
> new CGI; $in->param('sort_type');
I would have thought it was obvious from the context and question that
I was using the standard version of the CGI module.
> I think sort takes a reference to a function, so you might need sort
> $sortsub keys %data; because sort will dereference $sortsub for you.
That works - as does enclosing &$sortsub in a block, and using a
typeglob rather than a reference. Many thanks to all the people who
suggested solutions.
> Please make sure warnings are turned on, you use C<use strict>, and
> please INCLUDE ERROR MESSAGES when you ask a question.
Here's the very helpful error message, from CGI::Carp
Software error: Execution of c:\Xitami\cgi-bin\getlogs2 aborted due
to compilation errors.
Running the dud script from the command line tells me there's a
syntax error near "$sortsub keys" in the line
my @list = sort &$sortsub keys %data;
which again is not terribly helpful. The -w flag does nothing because
I usually write programs which don't generate warnings.
> Your warnings and error message probably should have directed you to
> the problem, but in any case they will help other people answer your
> questions more effectively.
I doubt it, in this case. If the error messages had given me any
useful information I could have worked out the answer myself.
--
Andrew Norman, Leicester, England
nja@le.ac.uk || andrew.norman@le.ac.uk
http://www.le.ac.uk/engineering/nja/
------------------------------
Date: Tue, 13 Jul 1999 13:06:55 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: Subroutine references and sort
Message-Id: <378b3875.90705788@newshost.unx.sas.com>
On 13 Jul 1999 09:48:36 +0100, nja@le.ac.uk (A.J. Norman) wrote:
> In article <378b0d4a.14114385@newshost.unx.sas.com>, John Borwick
> <jobosw@unx.sas.com> wrote:
>
> > There is probably no method param. You might want
> > new CGI; $in->param('sort_type');
> I would have thought it was obvious from the context and question that
> I was using the standard version of the CGI module.
In your original code, you said:
my $sortsub = (param('sort_type') eq 'hits')
when you C<use CGI;>, a method called param is NOT loaded into the
main package space. If this line of code is to work, the method param
must be called on a CGI object, as I understand the CGI module.
> > I think sort takes a reference to a function, so you might need sort
> > $sortsub keys %data; because sort will dereference $sortsub for you.
> That works - as does enclosing &$sortsub in a block, and using a
> typeglob rather than a reference. Many thanks to all the people who
> suggested solutions.
Hey that is great!
> Here's the very helpful error message, from CGI::Carp
> Software error: Execution of c:\Xitami\cgi-bin\getlogs2 aborted due
> to compilation errors.
> Running the dud script from the command line tells me there's a
> syntax error near "$sortsub keys" in the line
> my @list = sort &$sortsub keys %data;
> which again is not terribly helpful. The -w flag does nothing because
> I usually write programs which don't generate warnings.
If you wrote programs that never generate warnings, then they would
work. If you want to find out why your program is not working, it is
a good idea to enable warning flags. I really think that you should
at least try turning on warnings; they might help you in command-line
debugging at least.
--
John Borwick
------------------------------
Date: 13 Jul 1999 15:27:00 +0100
From: nja@le.ac.uk (A.J. Norman)
Subject: Re: Subroutine references and sort
Message-Id: <7mfibk$qk1@harrier.le.ac.uk>
In article <378b3875.90705788@newshost.unx.sas.com>, John Borwick
<jobosw@unx.sas.com> wrote:
> On 13 Jul 1999 09:48:36 +0100, nja@le.ac.uk (A.J. Norman) wrote:
>
>> I would have thought it was obvious from the context and question
>> that I was using the standard version of the CGI module.
>>
> In your original code, you said:
> my $sortsub = (param('sort_type') eq 'hits')
> when you C<use CGI;>, a method called param is NOT loaded
> into the main package space.
Look at the documentation for the CGI module. I use CGI qw(:standard),
which means you don't need to use the O-O interface (I know O-O is the
current fashion, but its use in this sort of case seems excessive to
me - and to Lincoln Stein too, judging by the examples in his book).
> If you wrote programs that never generate warnings, then they would
> work.
Not at all - the program which started all this off generated no
warnings, just errors (not the same thing). Use of the -w flag made
no difference to the messages output by the interpreter - compare the
output of these two scripts with and without the -w flag:
#!c:/perl/bin/perl -w
use strict;
my $a;
print $a; # Warning - uninitialised value
print aardvark("banana"); # Error - undefined subroutine
#!c:/perl/bin/perl -w
use strict;
print aardvark("banana"); # Error - undefined subroutine
> If you want to find out why your program is not working, it is a
> good idea to enable warning flags. I really think that you should at
> least try turning on warnings; they might help you in command-line
> debugging at least.
I find "use strict" mops up the overwhelming majority of the things
that might give -w hiccups, and the warnings left over are usually
about uninitialised variables and can often be safely ignored - the
-w flag rarely indicates the source of fatal errors in my experience.
I know it's a heresy, but I think the use of -w is overrated.
--
Andrew Norman, Leicester, England
nja@le.ac.uk || andrew.norman@le.ac.uk
http://www.le.ac.uk/engineering/nja/
------------------------------
Date: 13 Jul 1999 18:27:16 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Subroutine references and sort
Message-Id: <7mg0e4$cv1$1@lublin.zrz.tu-berlin.de>
A.J. Norman <nja@le.ac.uk> wrote in comp.lang.perl.misc:
[biggish snip]
> I find "use strict" mops up the overwhelming majority of the things
> that might give -w hiccups, and the warnings left over are usually
> about uninitialised variables and can often be safely ignored - the
> -w flag rarely indicates the source of fatal errors in my experience.
> I know it's a heresy, but I think the use of -w is overrated.
Oh, I don't know. It's probably a matter of style, but in my
experience a warning about an uninitialized value is usually
the sign of an oversight, which may or may not be harmless.
In any case, it doesn't hurt to initialize to something reasonable.
The cases where you do want to use an undefined value as another
way of saying zero (e.g. $hash{ $key}++) are taken care of and
don't generate warnings.
I tend to make my scripts -w-clean and keep -w switched on in
production, so unexpected changes in data (say) have a chance
to trigger a warning instead of silently giving wrong answers.
Anno
------------------------------
Date: 13 Jul 1999 01:00:38 -0400
From: sandoz@umbc.edu (James W. Sandoz)
Subject: Substitution not global
Message-Id: <7meh5m$42iv9@umbc7.umbc.edu>
Uncle!
I'm trying to remove a bunch of extraneous stuff from mail headers
before gzipping them (wanna clean up some space, but don't want to
remove my old mail messages).
I have a Perl program to remove everything from the "From ..." to the
line which starts with "Date:". (This stuff is extraneous to me).
The script is:
#!/usr/local/bin/perl5 -wpi.old
use diagnostics;
undef $/;
s /From\s.*?(Date:)/$1/sg;
I have a test file:
From owner #these NOT removed -Bad
Return-Path: #
From here #these two lines removed
this should be removed. #
Date: Some date #kept, as it should be
Here's another line #kept, as it should be
From another address #These two lines removed
This should go #
Date: July12 #kept, as it should be
and yet another #kept, as it should be
From stuff #These NOT removed! -Bad
and more stuff #
From: #kept, as it should be
For the life of me, I can't figure out why I'm getting this behavior.
My understanding is that sg should ignore newlines and globally make
the replacement. That it's replacing the middle two matches and not
the end matches is puzzling.
Even more puzzling is that if I leave out the "?" in the match, I get
the very same result.
Any help will be greatly appreciated.
Jim Sandoz
--
Mr. James W. Sandoz, Instructor, UMBC Dept of Biol Sciences,
1000 Hilltop Circle
Catonsville, MD 21250
voice: (410) 455-3497; fax: 455-3875; net: sandoz@umbc.edu
------------------------------
Date: 13 Jul 99 07:56:53 GMT
From: pijll@phys.uu.nl (Eugene van der Pijll)
Subject: Re: Substitution not global
Message-Id: <pijll.931852613@ruunat.phys.uu.nl>
In <7meh5m$42iv9@umbc7.umbc.edu> sandoz@umbc.edu (James W. Sandoz) writes:
>I have a Perl program to remove everything from the "From ..." to the
>line which starts with "Date:". (This stuff is extraneous to me).
>The script is:
> #!/usr/local/bin/perl5 -wpi.old
> use diagnostics;
> undef $/;
> s /From\s.*?(Date:)/$1/sg;
>I have a test file:
>From owner #these NOT removed -Bad
>Return-Path: #
>From here #these two lines removed
>this should be removed. #
>Date: Some date #kept, as it should be
>Here's another line #kept, as it should be
>From another address #These two lines removed
>This should go #
>Date: July12 #kept, as it should be
>and yet another #kept, as it should be
>From stuff #These NOT removed! -Bad
>and more stuff #
>From: #kept, as it should be
>For the life of me, I can't figure out why I'm getting this behavior.
>My understanding is that sg should ignore newlines and globally make
>the replacement. That it's replacing the middle two matches and not
>the end matches is puzzling.
>Even more puzzling is that if I leave out the "?" in the match, I get
>the very same result.
The From at the end does not match in this example because it is not
followed by 'Date:'.
The reason that the first From does not match is more subtle: you have
an input loop because of the -p in the first line:
while(<>) {
$/=undef;
s/foo/bar/sg;
print;
}
The first time that the test in while is executed, it only reads one
line. Only after that, $/ is undef'ed, and in the second loop you
operate on the rest of your file. But the substitution does not work in
the first line, as it only contains a 'From', but not a 'Date'.
One possible remedy (perhaps the easiest, probably not the best):
Add another option to the first line of your script.
#!/usr/local/bin/perl5 -0777 -wpi.old
This sets $/ to 0777 *before* the fist line is executed. More info: see
'perldoc perlrun'.
Eugene
--
\
Eugene van der Pijll : pijll@phys.uu.nl
--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--
------------------------------
Date: Mon, 12 Jul 1999 10:17:38 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: The class is interfering with my script.
Message-Id: <2etcm7.gce.ln@magna.metronet.com>
foo (agon@unm.edu) wrote:
: # I get a compilation error for the open(F,">$edit_file"); which
: # says "Global symbol "rtgredit_file" requires explicit package name
: # at Splash.pl line 49."
: # when I take out "use Letter" the script works just fine.
: # A class I created.
: use Letter
^
^
Where is the semicolon?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 12 Jul 1999 21:32:36 GMT
From: agon@unm.edu (foo)
Subject: Re: The class is interfering with my script.
Message-Id: <378a5ed5.278427677@news.sandia.gov>
On 12 Jul 1999 18:46:42 GMT, klassa@aur.alcatel.com (John Klassa)
wrote:
>On Mon, 12 Jul 1999 17:44:47 GMT, foo <agon@unm.edu> wrote:
> > # A class I created.
> > use Letter
> >
> > my $edit_file = "foo.d";
>
>Try putting a semicolon after "use Letter"...
>
>--
>John Klassa / Alcatel USA / Raleigh, NC, USA
Thanks for the advice, the semicolon fixed it.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 133
*************************************