[23663] in Perl-Users-Digest
Perl-Users Digest, Issue: 5870 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 28 14:05:47 2003
Date: Fri, 28 Nov 2003 11:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 28 Nov 2003 Volume: 10 Number: 5870
Today's topics:
Re: client/ server <invalid-email@rochester.rr.com>
Re: Curses %$#@! <REMOVEsdnCAPS@comcast.net>
Re: Curses %$#@! (Peter Scott)
Re: DBI error handling <jwillmore@remove.adelphia.net>
Re: DBI error handling <jwillmore@remove.adelphia.net>
Re: Does alarm work on w2k? <jwillmore@remove.adelphia.net>
Re: find2perl and File::Find examples (Randal L. Schwartz)
Re: help with reg ex <REMOVEsdnCAPS@comcast.net>
Re: help with reg ex (Tad McClellan)
Re: help with reg ex <usenet@morrow.me.uk>
Re: Here is the Code <jwillmore@remove.adelphia.net>
Newsgroup Searching Program <mikeflan@earthlink.net>
Re: Newsgroup Searching Program <invalid-email@rochester.rr.com>
Re: Newsgroup Searching Program <jwillmore@remove.adelphia.net>
Re: Packages and returning errors <someone@somewhere.com>
Re: Packages and returning errors <usenet@morrow.me.uk>
Re: Porblem installing DateTime::Format::Epoch <invalid-email@rochester.rr.com>
Reading subdirectories <no@e-mail.com>
Re: Reading subdirectories <jurgenex@hotmail.com>
Re: Reading subdirectories <xx087@freenet.carleton.ca>
Re: Reading subdirectories <invalid-email@rochester.rr.com>
subnets eating each other? <perl@my-header.org>
Re: Uri is mean <nobull@mail.com>
Re: Uri is mean (Tad McClellan)
Re: Using perl -e to remove times/dates from a file <ben.liddicott@comodogroup.com>
Re: Using perl -e to remove times/dates from a file <noreply@gunnar.cc>
Re: Using perl -e to remove times/dates from a file <rubberducky703@hotmail.com>
Re: Using perl -e to remove times/dates from a file <REMOVEsdnCAPS@comcast.net>
Re: Using perl -e to remove times/dates from a file <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 28 Nov 2003 16:55:38 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: client/ server
Message-Id: <3FC77C71.1060903@rochester.rr.com>
spleen wrote:
...
> Basically at the moment Im planning on using a python script to send a
> string of text to a website, I was woundering in perl, using the cgi-bin how
> I can accept this connection and take the text string and add it to a file
> (.txt)
Hmmmm...well, if Python has something along the lines of Perl's
use LWP::Simple;
and your string isn't too long, you could embed your text string
(properly quoted) into a URL as a parameter value and use a simple CGI
script to grab the string and append it to your file. Something like:
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print header,start_html;
if(param('string')){
open OUT,'>>file.txt' or die "Oops, couldn't open file.txt for
append, $!";
print OUT param('string');
close OUT;
print "Successful.";
}
else{
print "Bad URL, no string parameter";
}
print end_html;
[Tested with:
perl filename.pl string=foo
]
...
> greg
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Fri, 28 Nov 2003 08:43:33 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Curses %$#@!
Message-Id: <Xns9441631ABDF1Esdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Default@IO_Error_1011101.xyz [JDM] wrote in
news:UWxxb.7867$lF6.4841@nwrdny01.gnilink.net:
> btw what you just posted is completly useless and mean uri or norman
> or whoever you are. :p
Mean? Didn't seem mean to me. What's mean about it? Briam said that
something was a bad idea. Uri went out of his way to do a test, and said
it worked for him. Both comments were relevant to your program.
What's YOUR problem?
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP8dfTmPeouIeTNHoEQI6YwCeO6CppzQECfFBzWGqojBgcmFEkG0AnRAC
v2wjeGYzBJuWL8E4d5AAV0yr
=odyT
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 28 Nov 2003 16:43:14 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Curses %$#@!
Message-Id: <CWKxb.516895$9l5.288261@pd7tw2no>
In article <u9smk9boz0.fsf@wcl-l.bham.ac.uk>,
Brian McCauley <nobull@mail.com> writes:
>Eeek! You are using $^E. That means Win32.
Technically, it could also be VMS, OS/2, or MacOS. But Win32
is certainly the most likely of the possibilities in this case.
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http//www.perlmedic.com/
------------------------------
Date: Fri, 28 Nov 2003 17:50:46 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: DBI error handling
Message-Id: <20031128125046.46d457b0.jwillmore@remove.adelphia.net>
On Thu, 27 Nov 2003 13:44:32 +0100
Lars Purschke <purschke@uni-muenster.de> wrote:
> I've a perl script which inserts data to a database. Sometime I get
> an error on the execute() statement. Now I want the script not to
> die but to exit the loop and to try again with the next record. Does
> anyone know how to realize that?
>
>
> my $dbh = DBI->connect("dbi:ODBC:$dsn", "xyz", "xyz",
> { PrintError => 0,
> RaiseError => 0}) or die "$DBI::errstr\n";
>
> while( my(@row) = $sth->fetchrow_array ) {
> die $sth->errstr if $sth->err;
>
> $stmt = "Insert into .... ";
>
> $rs = $dbh->prepare($stmt);
>
> $rs->execute();
> }
What would be better is the following (untested)
my $dbh = DBI->connect("dbi:ODBC:$dsn", $user, $pass,
{PrintError=>1,
RaiseError=>1}
or die "Can't connect: ", $DBI::errstr,"\n";
#create a statement with placeholders
my $stmt =
'INSERT INTO table field1,field2, ... fieldn VALUES(?,?,... ?)';
#prepare *once*
#you *should* die here if you can't prepare the statement
#especial if you're only printing errors
$rs = $dbh->prepare($stmt)
or die "Can't prepare: ", $dbh->errstr,"\n";
#now execute the statement foreach value
while(my(@row) = $sth->fetchrow_array){
$rs->execute(@row)
or warn "Insert failed for the following:\n", join("|",@row),"\n",
$rs->errstr,"\n";
}
Again, untested.
You should read about using placeholders and binding columns in the
DBI documentation. This would help you're code.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
A jury consists of 12 persons chosen to decide who has the better
lawyer. -- Robert Frost
------------------------------
Date: Fri, 28 Nov 2003 18:08:19 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: DBI error handling
Message-Id: <20031128130819.30950a17.jwillmore@remove.adelphia.net>
On Fri, 28 Nov 2003 17:50:46 GMT
James Willmore <jwillmore@remove.adelphia.net> wrote:
> What would be better is the following (untested)
>
> my $dbh = DBI->connect("dbi:ODBC:$dsn", $user, $pass,
> {PrintError=>1,
> RaiseError=>1}
forgot the ....
)
This is what I get for *not* following direction :-)
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Brain fried -- Core dumped
------------------------------
Date: Fri, 28 Nov 2003 17:01:58 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Does alarm work on w2k?
Message-Id: <20031128120158.5ae66873.jwillmore@remove.adelphia.net>
On Fri, 28 Nov 2003 10:35:51 -0000
"Ben Liddicott" <ben.liddicott@comodogroup.com> wrote:
> use English qw(-no-match-vars);
> $OUTPUT_AUTOFLUSH=1;
Or more idiomatic Perl:
$| = 1;
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
In a museum in Havana, there are two skulls of Christopher
Columbus, "one when he was a boy and one when he was a man."
-- Mark Twain
------------------------------
Date: Fri, 28 Nov 2003 18:12:16 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: find2perl and File::Find examples
Message-Id: <4320d132d3d274acca104bd3fa8f6a58@news.teranews.com>
>>>>> "Sunil" == Sunil <sunil_franklin@hotmail.com> writes:
Sunil> Where can I find good ( & simple) examples of find2perl and
Sunil> File::Find. The perldoc documentation is not very helpful
Sunil> (for me).
It might help us if you elaborate the dividing line between the parts
you understand and the parts you don't. In other words, what's your
question to us?
Do you understand find(1) already?
Do you know what a coderef is?
Do you know what a hashref is?
Do you understand what a recursive filetree walk does?
What task were you trying to accomplish that you failed at?
See, when someone says "This isn't enough doc", I've got to wonder
what they would want.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 28 Nov 2003 08:34:09 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: help with reg ex
Message-Id: <Xns94416182A2A0Esdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Sunil" <sunil_franklin@hotmail.com> wrote in
news:n8Cxb.21$vy2.80@news.oracle.com:
> Hi,
> I have a pattern matching program which acts on a multi-line
> string.
> This works fine for me.
> But I need to ignore matches in lines that start with a '-' or '#'
> which
> is like a comment line and need not be checked.
> Any easy way of doing this?. Since I have a multi-line string
> variable
> I would like to avoid line by line processing.
Use two expressions:
if (!/[^#-]/ && /your working regex/)
{
...do your thing...
}
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP8ddFmPeouIeTNHoEQINpgCbBITNpt+f+FelVgcgRYJt6NqOAbgAn1W6
xZLnDPLE+CVaUDzhb/w98RVL
=gWvq
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 28 Nov 2003 08:07:13 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: help with reg ex
Message-Id: <slrnbselkh.i34.tadmc@magna.augustmail.com>
Ben Morrow <usenet@morrow.me.uk> wrote:
> "Sunil" <sunil_franklin@hotmail.com> wrote:
>> I need to ignore matches in lines that start with a '-' or '#'
^^^^^^^^^^
> (my $new = $old) =~ s/[-#].*?\n//;
>
> Then match against $new instead.
Need an anchor and "mg" options.
Don't need non-greedy (since there is no "s" option).
(my $new = $old) =~ s/^[-#].*\n//mg;
or maybe:
(my $new = $old) =~ s/^\s*[-#].*\n//mg;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 28 Nov 2003 17:53:46 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: help with reg ex
Message-Id: <bq823a$e9r$2@wisteria.csv.warwick.ac.uk>
tadmc@augustmail.com wrote:
> Need an anchor and "mg" options.
>
> Don't need non-greedy (since there is no "s" option).
>
> (my $new = $old) =~ s/^[-#].*\n//mg;
>
> or maybe:
>
> (my $new = $old) =~ s/^\s*[-#].*\n//mg;
Sorry, yes.
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: Fri, 28 Nov 2003 18:00:51 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Here is the Code
Message-Id: <20031128130050.087e1658.jwillmore@remove.adelphia.net>
On 28 Nov 2003 01:44:26 GMT
sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote:
> On Thu, 27 Nov 2003 20:21:00 -0500, Steve <itjobs@sympatico.ca>
> wrote:
> > Well I thought Memory allocation was by perl.
> > anyway here is the code, it fails on line 2 and dies on line 6
> >
> > $SqlString ="Select viewcontent from NewProfile where ID='Prof2'
> > and CUSTID='sandy' ";
> > if(($dbh->Sql( $SqlString )))
> > {
> > $ErrMsg = 'SQL-Err:'.$dbh->Error();
> > print "SQL ERR on: $SqlString $ErrMsg <BR>";
> > die
You have a 'die' statment by itself. Every time you enter this part
of the 'if' loop, the script will die. It's better to do something
like:
die "An error occured\nSQL: $SqlString\nError: ",$dbh->Error(),"\n"
unless ($dbh->Sql($SqlString));
I'll leave it up to you to find a good place to put this line. I can
tell you that this should remove the need for an if loop.
Go back and read the docs more closely :-)
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
The typewriting machine, when played with expression, is no more
annoying than the piano when played by a sister or near relation.
-- Oscar Wilde
------------------------------
Date: Fri, 28 Nov 2003 17:14:12 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Newsgroup Searching Program
Message-Id: <3FC78323.42A154FB@earthlink.net>
I know this is only marginally Perl related, but would
like some advice from the pros.
I'd like to get started doing some newsgroup searching.
Right now I use Netscape 4.72 for manually perusing
a few newsgroups. I'd like to do a broad search of
thousands of newsgroups on a daily basis. Just the
recent posts I guess.
I run ActiveState on Win2000. Don't really have a
server running yet.
One option I have found appears to be installing a
server and running Newspro:
http://www.elektrik-sheep.com/newspro/
I don't really need slick, but I do need a versatile
solution. If anybody would like to recommend a
starting point for a newby, please do. Otherwise
I will give Newspro a try.
I don't mind spending 100+ hours doing some
Perl programming to get this done, but I may
not quite be up to writing my own from scratch.
It's probably not as difficult as I think, but
I could use some examples.
Mike Flannigan
------------------------------
Date: Fri, 28 Nov 2003 17:59:02 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Newsgroup Searching Program
Message-Id: <3FC78B4C.9020505@rochester.rr.com>
Mike Flannigan wrote:
...
> I'd like to get started doing some newsgroup searching.
> Right now I use Netscape 4.72 for manually perusing
> a few newsgroups. I'd like to do a broad search of
> thousands of newsgroups on a daily basis. Just the
> recent posts I guess.
>
You could:
use Net::NNTP;
It should already be on your hard drive.
...
> Mike Flannigan
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Fri, 28 Nov 2003 18:10:49 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Newsgroup Searching Program
Message-Id: <20031128131025.1007c11f.jwillmore@remove.adelphia.net>
On Fri, 28 Nov 2003 17:59:02 GMT
Bob Walton <invalid-email@rochester.rr.com> wrote:
> Mike Flannigan wrote:
> > I'd like to get started doing some newsgroup searching.
> > Right now I use Netscape 4.72 for manually perusing
> > a few newsgroups. I'd like to do a broad search of
> > thousands of newsgroups on a daily basis. Just the
> > recent posts I guess.
>
> You could:
>
> use Net::NNTP;
>
> It should already be on your hard drive.
> ...
And ... use Google :-)
There is a *long* thread from about 2 months ago on this very subject
:-)
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Famous last words:
------------------------------
Date: Fri, 28 Nov 2003 11:51:15 -0000
From: "Bigus" <someone@somewhere.com>
Subject: Re: Packages and returning errors
Message-Id: <bq7crk$uia@newton.cc.rl.ac.uk>
"Brian McCauley" <nobull@mail.com> wrote in message
news:u91xrtd56z.fsf@wcl-l.bham.ac.uk...
[..]
> The "self" argument is logically separate from the rest of @_ so to
> make this clear I tend to write:
>
> sub not_a_method {
> my ( $arg1, $arg2 ) = @_;
> # Do stuff
> }
>
> sub is_a_instance_method {
> my $self = shift;
> my ($arg1, $arg2 ) = @_;
> # Do stuff
> }
>
> sub is_as_class_method {
> my $class = shift;
> my ($arg1, $arg2 ) = @_;
> # Do stuff
> }
I like the look of that approach too and the penny has finally dropped about
the first parameter passed to the method being the object. Phew!
[..]
> Go back at read the OO tutorial again. If there are bits you don't
> understand feel free to come here and ask for help. Comming here and
> asking for help without reading the tutorial first is a waste of
> everyone's time. The answers you get here will probably be inferior
> to the tutorial. And it there's anything unclear in the tutorial it
> won't help it get fixed.
There's lots in there I don't understand, but then it is quite alot to take
in in one go. I tend to learn far better by starting a project and tackling
each obstacle as they arise. I can read a tutorial like that and it largely
goes in one ear and out the other (metaphorically), hence my jump in the
deep end approach. Sorry if it is a bit irritating, but it's the only way
that works for me.
> > The line "$self->{last_error}" - in terms of hashes, the dereferencer
is
> > not something I've used before. I've used standard hashes like
> > "$self{last_error}", and hashes within hashes like
> > "$self{last_error}{blah}", but why is "$self->{last_error}" different
than
> > "$self{last_error}"?
>
> Ah, before you read the OO tutorial you need to read the reference
> tutorial. You've come here asking for some coaching with your running
> and you've just admitted you've never walked.
>
> > Back to my package (which I am currently thinking might be out of my
> > depth,
>
> You are. Way out of your depth.
Well, doing what I want the program to do is not a problem.. if I can just
get to grips with the method/object handling & calling / data returning..
hmmm.
[..]
> > # new constructer expects 2 values passed
> > sub new {
> > if ( $_[0] < 100 or $_[1] < 100 ) {
>
> $_[0] will be 'CG::MyGod' if new is called as a method of class
> GD::MyMod.
>
> Did you perhaps "forget" to enable warnings?
>
> I'm sure we've explained to you before how rude it is to come here and
> ask sentient entities to help you when you've not already asked your
> computer.
>
> Are you _trying_ to piss us off?
No, sorry. I was partly trying to get into good programming habits and put
use strict; in the package, but not in the calling script and wasn't using
warnings. Changed that now.
> > my $error = "";
>
> Always use the natual representation of things. If you want to
> represent the concept of "no value" in a scalar use the special value
> undef. Rather helpfully when you declare a variable using my()
> without an explicit initializtion it will be set to the natural
> representation of "no value" for that type of variable.
Noted. Thanks.
> > $error = "Specify values >= 100";
> > return;
> > }
>
> You are not saving that value anywhere that persists after the return
> is executed.
>
> Note your constructor does not construct anything if it gets an error.
>
> You need to fix the scope of $error by moving its declaration outside
> the subroutine.
Yes, I see. I've changed the structure a bit so that it doesn't need a
global var, so the package now looks like this:
===================
package GD::MyMod;
use strict;
use warnings;
use GD;
sub new {
my $class = shift;
my ($width, $height ) = @_;
if ( $width < 100 or $height < 100 ) {
rtnError("Specify values >= 100");
}
else {
# do stuff
}
}
sub rtnError {
my $class = shift;
my $error_msg = shift;
return $error_msg;
}
1;
===================
Is that a better way of doing things than creating a global error var?
> > else {
> > # do stuff
>
> I hope that some of that "stuff" includes actually constructing a
> CG::MyGod object. Otherwise new() is not a constuctor.
Yes, stuff will initiate a GD image object for subsequent manipulation..
[..]
> > Then, in the CGI script that calls it, I have:
> >
> > #!c:\perl\bin\perl.exe
> > use GD::MyMod;
> > $im = new GD::MyMod(20,20);
>
> It's probably bese not to get into the habit of using the indirect
> ibject syntax. Oh, and you forgot to declare $im.
>
> my $im = GD::MyMod->new(20,20);
I wondered why you could get away with new before the class name, but
various module documentation used that syntax, so I did, but I like this
more standard approach.
> > print "Content-type:text/html\n\n";
> >
> > if($im->rtnError) {
> > print $im->rtnError;
> > }
> > else {
> > print "no error";
> > }
> >
> > That generates an Apache 500 server error and the erro log shows:
> >
> > "Global symbol "$error" requires explicit package name at blah"
>
> You should not be runnning your scripts under a web server until
> you've at least syntax checked them.
I thought that any errors from strict or warnings would go to the browser
since I specified print content-type, but anyway, I'm testing it at the
command line now.
[..]
> > Can't call method "rtnError" on an undefined value at blah, where blah
is
> > the line if($im->rtnError) in my CGI script.
>
> Yep that is correct.
>
> > So, it seems that somethings not right with the new sub.. any ideas
what?
>
> You decided that your constuctor would not constuct an object if it
> didn't like it's arguments. If it didn't constuct an object you
> cannot use the object it constucted to look up the error because there
> is no object.
>
> You need to call the rtnError as a class method, just as you did with
> new.
>
> Having a class method to return your error is just one approach.
> There are other equally good ones.
So, how would one actualy define $im as the class instance object thingy? Is
that where this bless command comes in?
If I went with the package code above, then I'd presumably use different
calling ode anyway.. I'm going to try several things now, but if you happen
wot want to give me any clues, please do!
Anyway, many thanks for taking the time to write your reply.
Bigus
------------------------------
Date: Fri, 28 Nov 2003 17:50:23 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Packages and returning errors
Message-Id: <bq81sv$e9r$1@wisteria.csv.warwick.ac.uk>
"Bigus" <someone@somewhere.com> wrote:
> Yes, I see. I've changed the structure a bit so that it doesn't need a
> global var, so the package now looks like this:
>
> ===================
> package GD::MyMod;
>
> use strict;
> use warnings;
> use GD;
>
> sub new {
> my $class = shift;
> my ($width, $height ) = @_;
> if ( $width < 100 or $height < 100 ) {
> rtnError("Specify values >= 100");
> }
> else {
> # do stuff
> }
> }
>
> sub rtnError {
> my $class = shift;
> my $error_msg = shift;
> return $error_msg;
> }
This is completely pointless. You are not saving the value of
$error_msg anywhere.
You probably meant something like this:
{
my $last_error;
sub rtnError {
my $class = shift;
my $error_msg = shift;
$error_msg and $last_error = $error_msg;
return $last_error;
}
}
which will return the last thing it was called with if it is called
with no args.
> So, how would one actualy define $im as the class instance object thingy? Is
> that where this bless command comes in?
Yes. Understanding bless is critical to writing OO Perl. Read perlboot
until you understand it (you will *need* to understand perlsub,
perlref and perlmod first).
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Fri, 28 Nov 2003 16:29:01 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Porblem installing DateTime::Format::Epoch
Message-Id: <3FC77636.8030400@rochester.rr.com>
Nilendu wrote:
> Hello,
>
> I have run into a very interesting problem.
> I am using activePerl 5.6.1 on windows.I currently need the Module
------------------------^^^^^
That's a bit old now. Modules being checked out and ported these days
are probably only showing up on Perl 5.8 PPM sites (compiled modules
need to be recompiled between 5.6.1 and 5.8, so there are various
versions of PPM sites).
> DateTime::Format::Epoch to convert any give date to its corresponding
> Epoch value.
...
> Nilendu
>
There are other modules which will accomplish this task which are more
tried and true (and available for Perl 5.6.1). You might try
Date::Manip (my favorite) or Date::Calc . Note that you may have to
define $ENV{TZ} in order for Date::Manip to work since you are running
on Windoze.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Fri, 28 Nov 2003 17:28:43 -0000
From: "Colin" <no@e-mail.com>
Subject: Reading subdirectories
Message-Id: <3fc785d6$0$7363$cc9e4d1f@news.dial.pipex.com>
Hi, I am trying to use the following code to read the contents of a several
subdirectories in a single directory.
opendir(MainDir, "/home/colin/data")
while ($file = readdir(MainDir) {
print "$file\n";
opendir(SubDir, $file)
while($otherfiles = readdir(SubDir) {
print "$otherfiles\n";
}
}
Why can I not use $file to represent the directory I want to open in the
second opendir statement?
Can anyone help?
Thanks
------------------------------
Date: Fri, 28 Nov 2003 17:42:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Reading subdirectories
Message-Id: <YNLxb.26954$ZV6.1300@nwrddc02.gnilink.net>
Colin wrote:
> Hi, I am trying to use the following code to read the contents of a
> several subdirectories in a single directory.
You are missing a
use strict;
use warning;
at the beginning of your program
> opendir(MainDir, "/home/colin/data")
You are missing a semicolon in the line above
> while ($file = readdir(MainDir) {
You are missing a close bracket in the line above
> print "$file\n";
> opendir(SubDir, $file)
You are missing a semicolon in the line above
> while($otherfiles = readdir(SubDir) {
You are missing a close bracket in the line above
> print "$otherfiles\n";
> }
> }
It is very rude to post a program that doesn't even compile and ask people
to find some semantic problem.
If your problem is how to locate and fix the syntax errors, then you should
have said so, e.g. "The following program has syntax errors and I can't
figure out how to fix them."
> Why can I not use $file to represent the directory I want to open in
> the second opendir statement?
> Can anyone help?
Why don't you ask perl to help you:
opendir(SubDir, $file) or die "Cannot opendir $file because $!\n";
It is not nice to ask people to do a job that a machine can do much better.
jue
------------------------------
Date: 28 Nov 2003 17:51:06 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Reading subdirectories
Message-Id: <slrnbsf2pp.98d.xx087@smeagol.ncf.ca>
Colin <no@e-mail.com> wrote:
> Hi, I am trying to use the following code to read the contents of a several
> subdirectories in a single directory.
>
> opendir(MainDir, "/home/colin/data")
> while ($file = readdir(MainDir) {
> print "$file\n";
> opendir(SubDir, $file)
> while($otherfiles = readdir(SubDir) {
> print "$otherfiles\n";
> }
> }
... ignoring syntax errors in above code...
> Why can I not use $file to represent the directory I want to open in the
> second opendir statement?
because readdir does not prepend /home/colin/data.
Always check the return code of open and opendir.
You probably want:
my $maindir = '/home/colin/data';
opendir MainDir, $maindir or die "can't open $maindir: $!\n";
my @subdirs = grep { -d }
map { "$maindir/$_" }
grep { ! /^\.\.?$/ }
readdir MainDir;
foreach my $dir (@subdirs) {...}
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Fri, 28 Nov 2003 18:03:47 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Reading subdirectories
Message-Id: <3FC78C69.1090600@rochester.rr.com>
Colin wrote:
> Hi, I am trying to use the following code to read the contents of a several
> subdirectories in a single directory.
You should:
use File::Find;
for a job like that.
<buggy retyped uncompilable crap snipped>
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Fri, 28 Nov 2003 19:19:19 +0100
From: Matija Papec <perl@my-header.org>
Subject: subnets eating each other?
Message-Id: <vt3fsvcq6fl62jqjkqjib36n5mdo33k748@4ax.com>
I would like to discover situations when one ip/mask is able to cover
another one, eg. does 22.122.0.0/16 cover 122.0.0.0/24?
I made integer conversion for ip/mask but don't know what to do further..
my $r1 = {
source => '22.122.0.0/16',
};
my $r2 = {
source => '122.0.0.0/24',
};
for my $r ($r1, $r2) {
$r->{_source} = CalcIP($r->{source}) if !$r->{_source};
}
use Data::Dumper; print Dumper $r1, $r2;
sub CalcIP {
#
# calculate ip/mask
#
my ($source) = @_;
my %adr;
if ($source) {
my ($ip, $mask) = split /\//, $source;
$ip = unpack 'N', pack 'C4', split /\./, $ip;
if (!$mask) { $mask = 0xffffffff }
elsif ($mask =~ /^\d+$/) { $mask = 0xffffffff << (32-$mask) }
else { $mask = unpack 'N', pack 'C4', split /\./, $mask }
$ip = $ip & $mask;
%adr = ( ip => $ip, mask => $mask );
}
return \%adr;
}
--
Matija
------------------------------
Date: 28 Nov 2003 12:45:12 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Uri is mean
Message-Id: <u9oeuwbr1j.fsf@wcl-l.bham.ac.uk>
Scott Bryce <sbryce@singlepoint.net> writes:
> Default@IO_Error_1011101.xyz wrote:
>
> > btw what you just posted is completly useless and mean uri or norman or
> > whoever you are. :p
>
> You haven't been lurking long have you? Posts that say nothing more
> than "Uri is mean," or "Tad is mean," or "{name your favorite Perl
> guru} is mean" serve only to insure that your questions will not be
> answered in the future.
I'd say Uri and Tad are at least one standard deviation above the
mean.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 28 Nov 2003 08:00:29 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Uri is mean
Message-Id: <slrnbsel7t.i34.tadmc@magna.augustmail.com>
Brian McCauley <nobull@mail.com> wrote:
> Scott Bryce <sbryce@singlepoint.net> writes:
>> Posts that say nothing more
>> than "Uri is mean," or "Tad is mean," or "{name your favorite Perl
>> guru} is mean" serve only to insure that your questions will not be
>> answered in the future.
>
> I'd say Uri and Tad are at least one standard deviation above the
> mean.
My wife made an uncomplimentary comment regarding my bell-shaped
distribution while I was stretched out on the couch following
Thanksgiving dinner yesterday (I was just resting my eyes).
My parents are here for the holiday, so I called out...
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
... "Come look at this guy's cool .sig ma"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 28 Nov 2003 11:11:15 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: Using perl -e to remove times/dates from a file
Message-Id: <bq7agn$d8i$1@kylie.comodogroup.com>
Hi Paul,
You need an introduction to regular expressions.
The translation operator:
tr/09:36//
will remove all "0", "9", ":", "3" and "6" characters. It is really to =
be used for counting characters or tr/a-z/A-Z/ and suchlike.
You need to be looking at the s/find/replace/ regex operator.
perldoc perlrequick
perldoc perlretut
Cheers,
Ben Liddicott
"Paul Tomlinson" <rubberducky703@hotmail.com> wrote in message =
news:bq77c5$1vbnc1$1@ID-116287.news.uni-berlin.de...
> All I have a file called "DirList.txt" which was generated by =
redirecting
> the results of a DOS dir to a file.
>=20
> What I want is to have perl remove the times (and preferably dates) =
from
> this file.
>=20
------------------------------
Date: Fri, 28 Nov 2003 12:47:40 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using perl -e to remove times/dates from a file
Message-Id: <bq7cs0$1t9mbe$1@ID-184292.news.uni-berlin.de>
Paul Tomlinson wrote:
> All I have a file called "DirList.txt" which was generated by
> redirecting the results of a DOS dir to a file.
>
> What I want is to have perl remove the times (and preferably dates)
> from this file.
If it's not too late, and to create a file with only the file names,
wouldn't something like this be better:
open FH, '> DirList.txt' or die $!;
opendir DIR, '.' or die $!;
print FH join "\n", readdir DIR;
closedir DIR or die $!;
close FH or die $!;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 28 Nov 2003 13:01:17 -0000
From: "Paul Tomlinson" <rubberducky703@hotmail.com>
Subject: Re: Using perl -e to remove times/dates from a file
Message-Id: <bq7h1l$1v9lo0$1@ID-116287.news.uni-berlin.de>
Thanks i've sorted it Bernards answer more-or-less sorted me out.
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bq7cs0$1t9mbe$1@ID-184292.news.uni-berlin.de...
> Paul Tomlinson wrote:
> > All I have a file called "DirList.txt" which was generated by
> > redirecting the results of a DOS dir to a file.
> >
> > What I want is to have perl remove the times (and preferably dates)
> > from this file.
>
> If it's not too late, and to create a file with only the file names,
> wouldn't something like this be better:
>
> open FH, '> DirList.txt' or die $!;
> opendir DIR, '.' or die $!;
> print FH join "\n", readdir DIR;
> closedir DIR or die $!;
> close FH or die $!;
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
------------------------------
Date: Fri, 28 Nov 2003 08:30:57 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Using perl -e to remove times/dates from a file
Message-Id: <Xns944160F785C1Dsdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Paul Tomlinson" <rubberducky703@hotmail.com> wrote in news:bq77c5$1vbnc1$1
@ID-116287.news.uni-berlin.de:
> All I have a file called "DirList.txt" which was generated by redirecting
> the results of a DOS dir to a file.
>
> What I want is to have perl remove the times (and preferably dates) from
> this file.
On my windows 2000 computer, "dir /b" gives me just a bare list of
filenames. I don't know if this option is available on all versions of
dos/windows, but if it is, it'll be easier for you to change your input
than to post-process it with Perl.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP8dcUWPeouIeTNHoEQIoIACgmZ7xcE1mBTwjjnrsI8CsBpNtrRIAn1AW
xO8vdGMYS3Ab7M1J1M6OIH/b
=5n/i
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 28 Nov 2003 15:34:24 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using perl -e to remove times/dates from a file
Message-Id: <bq7mlq$1vuf3l$1@ID-184292.news.uni-berlin.de>
Eric J. Roode wrote:
> On my windows 2000 computer, "dir /b" gives me just a bare list of
> filenames. I don't know if this option is available on all
> versions of dos/windows, but if it is, it'll be easier for you to
> change your input than to post-process it with Perl.
I tested on W98, and it worked there, too.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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.
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 5870
***************************************