[22017] in Perl-Users-Digest
Perl-Users Digest, Issue: 4239 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 10 09:06:12 2002
Date: Tue, 10 Dec 2002 06:05:13 -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 Tue, 10 Dec 2002 Volume: 10 Number: 4239
Today's topics:
Re: Cache the execution of a Perl CGI? <me@privacy.net>
Re: Cache the execution of a Perl CGI? <me@privacy.net>
convert a date-time to an absolute value (in seconds or <a@b.c>
Re: Filenames on Win32: the bane of my existence.... (drsmith)
Re: Getopt::Long::GetOptions and a command line option (Johan Vromans)
Re: Getopt::Long::GetOptions and a command line option <sacha.raybaud@hp.com>
Re: Getting a URL Page <kasp@NO_SPAMepatra.com>
Re: help with Can't modify constant item in scalar assi <dave@dave.org.uk>
Re: HELP! Looking for a cgi <flavell@mail.cern.ch>
How to do 32-bit calculations WITH overflow? <mikkon@excelsql.com>
Re: How to do 32-bit calculations WITH overflow? (Anno Siegel)
Re: Invalid Base64 data msg when sending email <flavell@mail.cern.ch>
Is there a module for Copying/Staging/Installing files <kaizers@hotmail.com>
Re: Is this a safe way to test for an empty hash? (Anno Siegel)
Re: log file monitor <me@privacy.net>
multi procs, how to stop child <someone@somewhere.com>
Re: need to create 2 perl administration scripts for wi <rubberducky703@hotmail.com>
placing modules manually <henrin69@remove-yahoo.com>
Re: porting a routine which uses uint32_t <nospam-abuse@ilyaz.org>
Problem - Array as Member of Object <dl19@le.academicplace.intheuk>
Re: Problem - Array as Member of Object <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: Problem - Array as Member of Object <dl19@le.academicplace.intheuk>
Re: Problem - Array as Member of Object <dl19@le.academicplace.intheuk>
Problem with range operator: for ($1 .. $2) <pry@iki.fi>
Re: Re FAQ: How can I capture STDERR from an external c (Peter J. Acklam)
Re: read return value from a sql script using piped ope <rereidy@indra.com>
Regular expression word replacement <newsgroupcontact@seseaz.org.uk>
Re: Regular expression word replacement <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: Two pppd's one after the other... <eldar@iki.fi>
Re: which UI for Perl? <erik@pax07e3.mipool.uni-jena.de>
XML::Parser 2.31 gives error "missing Expat.h" <henrin69@remove-yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 10 Dec 2002 16:56:57 +0800
From: "Peter Wu" <me@privacy.net>
Subject: Re: Cache the execution of a Perl CGI?
Message-Id: <at4a8r$10oe8m$1@ID-117651.news.dfncis.de>
"Bob Stutes" <bstutes@eskimo.com> wrote:
: Check out FastCGI at
: http://www.cpan.org/author/JHI/perl-5.8.0/lib/CGI/Fast.pm
I got a 404 error when visiting this URL.
--
Ciao, Peter
------------------------------
Date: Tue, 10 Dec 2002 21:41:50 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Cache the execution of a Perl CGI?
Message-Id: <at4gdf$10bp4p$1@ID-172104.news.dfncis.de>
"Peter Wu" <me@privacy.net> wrote in message
news:at4a8r$10oe8m$1@ID-117651.news.dfncis.de...
> "Bob Stutes" <bstutes@eskimo.com> wrote:
> : Check out FastCGI at
> : http://www.cpan.org/author/JHI/perl-5.8.0/lib/CGI/Fast.pm
>
> I got a 404 error when visiting this URL.
http://search.cpan.org/author/JHI/perl-5.8.0/lib/CGI/Fast.pm
or
http://search.cpan.org/author/LDS/CGI.pm-2.89/CGI/Fast.pm
------------------------------
Date: Tue, 10 Dec 2002 14:56:14 +0100
From: ZZT <a@b.c>
Subject: convert a date-time to an absolute value (in seconds or so)
Message-Id: <at4rpv$k3e$1@news1.wdf.sap-ag.de>
Hello,
I have the following time-format from a source:
Mon, 9 Dec 2002 14:14:57
and would like to convert it in a format like time() returns.
Is there a way?
thanks
------------------------------
Date: 10 Dec 2002 04:41:25 -0800
From: drsmithhm@hotmail.com (drsmith)
Subject: Re: Filenames on Win32: the bane of my existence....
Message-Id: <c7c208d1.0212100441.5d12f418@posting.google.com>
pkent <pkent77tea@yahoo.com.tea> wrote in message news:<pkent77tea-87D383.01101710122002@news-text.blueyonder.co.uk>...
> In article <c7c208d1.0212091255.6b0849cb@posting.google.com>,
> drsmithhm@hotmail.com (drsmith) wrote:
>
> > The problem is that many of the filenames contain dates, spaces, and
> > other special characters like umlat's. Perl's readdir function is
> > returning '?' characters in place of the special characters which
> > later on causes unlink() to fail.
>
> Is the filesystem where these files are stored a native windows local
> volume? I only ask because we use sharity, I think, on some linux
> machines to mount windows SMB shares and we get '?' is filenames in
> place of, say, Unicode characters. It might be the same thing, or maybe
> not.
>
> P
Yes - it's a Windows 2000 Server running NTFS. Every file on the
server with an 'extended' character fails to unlink() - If it weren't
for that, I wouldn't really care. Furthermore when a mac saves a file
with a date - 12/10/2002, the '/' characters get the macintosh
encoding and show up as '?' instead(as in 12?10?2002). These files
can't be unlink()'d either.
--drsmith
------------------------------
Date: 10 Dec 2002 09:53:34 +0100
From: jvromans@squirrel.nl (Johan Vromans)
Subject: Re: Getopt::Long::GetOptions and a command line option name that contains colon (":") character
Message-Id: <m2vg22s19t.fsf@phoenix.squirrel.nl>
"sacha raybaud" <sacha.raybaud@hp.com> writes:
> One of the command line argument is named "test:arg1". Therefore, I tried to
> write something like this:
> This does not work because the colon between test and arg1 has also a
> meaning for perl in the context of GetOptions.
>
> Do you have any ideas that could help?
GetOptions restrict option names to \w[-\w]* meaning letters, digits
and dashes only.
Maybe you can use a hash argument, e.g.,
GetOptions("test=s" => \%test)
Then "-test arg1=foo" will set $test{arg1} to "foo".
-- Johan
------------------------------
Date: Tue, 10 Dec 2002 11:11:41 +0100
From: "sacha raybaud" <sacha.raybaud@hp.com>
Subject: Re: Getopt::Long::GetOptions and a command line option name that contains colon (":") character
Message-Id: <77jJ9.3$be2.212033@news.cpqcorp.net>
Thanks for your answer.
Best regards,
Sacha
"Johan Vromans" <jvromans@squirrel.nl> wrote in message
news:m2vg22s19t.fsf@phoenix.squirrel.nl...
> "sacha raybaud" <sacha.raybaud@hp.com> writes:
>
> > One of the command line argument is named "test:arg1". Therefore, I
tried to
> > write something like this:
> > This does not work because the colon between test and arg1 has also a
> > meaning for perl in the context of GetOptions.
> >
> > Do you have any ideas that could help?
>
> GetOptions restrict option names to \w[-\w]* meaning letters, digits
> and dashes only.
>
> Maybe you can use a hash argument, e.g.,
>
> GetOptions("test=s" => \%test)
>
> Then "-test arg1=foo" will set $test{arg1} to "foo".
>
> -- Johan
------------------------------
Date: Mon, 9 Dec 2002 13:39:34 +0530
From: "Kasp" <kasp@NO_SPAMepatra.com>
Subject: Re: Getting a URL Page
Message-Id: <at1j4u$8gk$1@newsreader.mailgate.org>
I am using Perl v5.005 ("This is perl, version 5.005_03 built for
sun4-solaris")
So can someone tell me how do I install modules on Sun Solaris machine ?
Thanks.
"Peter A. Krupa" <pkrupa@redwood.rsc.raytheon.com> wrote in message
news:3DF1290D.FA34314F@redwood.rsc.raytheon.com...
> > LWP::Simple isn't included in the standard Perl distribution. I believe
> > that it's among a set of extra modules that are included with
ActivePerl.
>
> You're right, that's what made me suspect he wasn't using ActiveState on
> Windows.
>
> Somebody else will have to explain to him how to get the module, I just
use
> PPM.
>
------------------------------
Date: Tue, 10 Dec 2002 09:14:36 +0000
From: "Dave Cross" <dave@dave.org.uk>
Subject: Re: help with Can't modify constant item in scalar assignment but it does not tell me why?
Message-Id: <pan.2002.12.10.09.14.36.269704@dave.org.uk>
On Tue, 10 Dec 2002 01:31:45 +0000, Bob Stutes wrote:
[ Please don't top-post. It makes it far harder to follow your argument. ]
> Your line shuld read "$data =\%params,". Note the missing "$" in your code.
That's not the problem.
> Perl won't ket you assign to a "bareword".
That's true, but that's not what the problem is in this case. If you look
at the code around the offending line you'll see it looks like this:
my $vars = {
data =\%params,
};
There's no assignment to a bareword there. Mothra is trying to assign to a
hash value. As other have already pointed out, the problem is that he's
used '=' where he really needed '=>'.
hth,
Dave...
--
Two slightly distorted guitars
------------------------------
Date: Tue, 10 Dec 2002 11:18:45 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HELP! Looking for a cgi
Message-Id: <Pine.LNX.4.40.0212101108480.31610-100000@lxplus073.cern.ch>
On Dec 10, Bob Stutes inscribed on the eternal scroll:
> Jorge Mesa wrote:
[...]
> > print header(1,'301 Moved Permanently'),
> > print redirect('http://www.terra.es/');
[...]
> > Why my cgi can not send the header and redirect???
The redirect() call itself is a header-generating call; that's why the
documentation section in question is headed "Creating the Header for a
Redirection Request" - see http://stein.cshl.org/WWW/software/CGI/ -
and it adds "All other parameters recognized by the header() method
are also valid in redirect."
So the answer seems to be yes, you can "send the header and redirect",
but you do it by calling redirect() with appropriate arguments, _not_
by calling header() in addition.
> It appears to be a limitation of the CGI implementation.
If you call conforming to its own documentation a "limitation", then I
suppose you'd be right, in your own terms.
> According to the CGI Perldoc:
>
> The redirect() function redirects the browser to a different URL. If
> you use redirection like this, you should not print out a header as well.
Indeed. However, in the case of CGI.pm I usually recommend the
author's own HTML-maintained documentation.
------------------------------
Date: Tue, 10 Dec 2002 14:10:38 +0200
From: "Mikko Noromaa" <mikkon@excelsql.com>
Subject: How to do 32-bit calculations WITH overflow?
Message-Id: <at4ljr$6ir$1@phys-news1.kolumbus.fi>
I am porting a C program to Perl, and I have some difficulties with integer
math. The C program does a lot of calculations with unsigned 32-bit
integers, and it relies on every result to be a 32-bit integer.
In Perl I managed almost all cases by using a small utility function that
does "return (int($u) % 4294967296)". I use this function around every
multiplication in the program. However, it doesn't work in the following
case:
6 * 97296793 * 97296793 = 5.67999955685091e+016
When I do %4294967296 with this result, I get 2266681512. This is not
correct, I believe because of some lost precision in the floating-point
representation. The correct result (with overflowing 32-bit integers) is
2266681510.
How can use overflowing unsigned 32-bit integers in Perl? I tried doing "use
integer" but it changed the integers to signed and that screwed up my
calculations at a much earlier stage.
--
Mikko Noromaa (mikkon@excelsql.com)
Noromaa Solutions - see http://www.excelsql.com
------------------------------
Date: 10 Dec 2002 14:00:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to do 32-bit calculations WITH overflow?
Message-Id: <at4s1l$1fe$1@mamenchi.zrz.TU-Berlin.DE>
According to Mikko Noromaa <mikkon@excelsql.com>:
> I am porting a C program to Perl, and I have some difficulties with integer
> math. The C program does a lot of calculations with unsigned 32-bit
> integers, and it relies on every result to be a 32-bit integer.
>
> In Perl I managed almost all cases by using a small utility function that
> does "return (int($u) % 4294967296)". I use this function around every
> multiplication in the program. However, it doesn't work in the following
> case:
>
> 6 * 97296793 * 97296793 = 5.67999955685091e+016
>
> When I do %4294967296 with this result, I get 2266681512. This is not
> correct, I believe because of some lost precision in the floating-point
> representation. The correct result (with overflowing 32-bit integers) is
> 2266681510.
>
> How can use overflowing unsigned 32-bit integers in Perl? I tried doing "use
> integer" but it changed the integers to signed and that screwed up my
> calculations at a much earlier stage.
Not necessarily. The bit patterns you get are the same with signed and
unsigned arithmetic, so if you don't tell the C program they're signed
you'll be fine. The difference is just interpretation.
You may have problems during your calculations if you have to compare
quantities, but if you can disregard signs, just plow ahead under
"use integer". If you need the value a result would have under
unsigned arithmetic, you can use your modulo operation *without* "use
integer".
Anno
------------------------------
Date: Tue, 10 Dec 2002 11:24:14 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Invalid Base64 data msg when sending email
Message-Id: <Pine.LNX.4.40.0212101122440.31610-100000@lxplus073.cern.ch>
On Dec 9, bpaluch inscribed on the eternal scroll:
> Net::SMTP=GLOB(0x2d7353c)>>> MAIL FROM:
> Net::SMTP=GLOB(0x2d7353c)<<< 334 VXNlcm5hbWU6
I'm not sure if you were aware that base64-decoding that string
yields "Username:".
------------------------------
Date: Tue, 10 Dec 2002 07:52:56 GMT
From: "Kaizer H. Sogiawala" <kaizers@hotmail.com>
Subject: Is there a module for Copying/Staging/Installing files from one place to another
Message-Id: <s3hJ9.2457$oY3.46689514@newssvr21.news.prodigy.com>
I am looking for a module on Win32 that copies/stages/installs files from
one location to another. This is intended for post-build staging (copy) or
populate in nightly builds, etc.
Thanks in advance.
...KHS...
------------------------------
Date: 10 Dec 2002 13:07:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Is this a safe way to test for an empty hash?
Message-Id: <at4oun$sd5$1@mamenchi.zrz.TU-Berlin.DE>
According to Tina Mueller <usenet@tinita.de>:
> Malte Ubl <ubl@schaffhausen.de> wrote:
> > Tina Mueller wrote:
> >> Ronald Fischer <ronaldf@eml.cc> wrote:
> >>
> >>>$hr is a reference to an empty hash. I would like to test if the hash
> >>>is empty. Is this a safe way to
> >>>do this?
> >>
> >>> print "is empty" unless %$hr;
> >>
> >> print "is empty" unless keys %$hr;
>
> > Why would that be better?
>
> good question. it's not *better*, but i would have coded
> it like this because it tells me at the first glance what
> it is doing. just a matter of taste, probably.
> without keys() it is even more efficient, i'd guess.
Well, "scalar %hash" is indeed slightly faster than "keys %hash" for
empty hashes, but if a hash contains just a single element (or more)
"keys %hash" is faster. This is not entirely surprising because
"scalar %hash" retrieves more information than "keys %hash" does.
In practice, the difference will be unimportant.
Anno
------------------------------
Date: Tue, 10 Dec 2002 19:56:52 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: log file monitor
Message-Id: <at4a8m$10fm3j$1@ID-172104.news.dfncis.de>
"Ricardo Mesquita" <ricardo@nospam.pt> wrote in message
news:3df597f3$0$2158$a729d347@news.telepac.pt...
> i want to monitor one logfile for changes, and when some change occurs
> some function on my program will be called to take some action.
> What is the best way to implemment this logfile checker, without tieing
> up the processor with one "while (1)" loop cycle?
>
> Is there any function/module i can use to abstract this layer from my
> program, some suggest the use of tail as in tail nix command, is this
> the right approach?
Sounds like you're trying to recreate a swatch or logsurfer.
------------------------------
Date: Tue, 10 Dec 2002 21:15:23 +1100
From: who <someone@somewhere.com>
Subject: multi procs, how to stop child
Message-Id: <3DF5BEBB.3BC7CF95@somewhere.com>
Hi,
I have a shell script that I want to convert to perl and make a few
modifications. I understand that fork in perl is almost the same as C.
Is it possible to execute say 3 different functions in the background
and before each child completes the function call, exit before the
script is complete. I want the parent to execute some code after this
point, but the child procs should not.
I've been doing a few searches on the internet, but have not found
anything related to this. If you have a link or two, please post it.
Regards,
Michael
------------------------------
Date: Tue, 10 Dec 2002 09:14:27 -0000
From: "Rubber Duck" <rubberducky703@hotmail.com>
Subject: Re: need to create 2 perl administration scripts for windows
Message-Id: <at4b5m$10f712$1@ID-116287.news.dfncis.de>
i would start playing with the various win32 modules, like changenotify,
netadmin etc.
however i'm not sure that what you want is a good idea since it requires
perl on every workstation you want these scripts on. A C executable would
greatly reduce these dependancies.
"HamuNaptra" <hamunaptra@pandora.be.NOSPAM> wrote in message
news:Jj4J9.43039$Ti2.6715@afrodite.telenet-ops.be...
> I need to create 2 perl scripts for administrtaion on a win200.
> Since I am a newbie at perl, I'm asking here if someone can help me on
this?
>
> first script
>
> a script that uses a quota system for userdirectories
> a) the script needs to work automatically once a day
> b) if a user directory reaches x MB a warning is placed in the user
directory in
> a textfile
> c) if it reaches y MB a backup is made of all the files, the original
files are
> deleted and a file is placed containing a message
> d) warn the sysem admin of these operations
>
> second script
>
> a script that can remove profiles from a directory, the profile
Administrator,
> All users en Default User may not be deleted.
> the script shouldn't delete the running profile if a user is logged in.
>
> if someone can fill in some of the parts that I need to do, their very
welcome
> to do this.
>
>
------------------------------
Date: Tue, 10 Dec 2002 12:55:22 GMT
From: "hennir" <henrin69@remove-yahoo.com>
Subject: placing modules manually
Message-Id: <_ulJ9.22190$ws6.450368@news2.nokia.com>
i had activeperl (5.6.1) , I compied perl 5.8.0
but cannot install some modules.
Could I just copy active perl site directory over
my new 5.8.0 site dir?
Should I edit any file or something like that?
------------------------------
Date: Tue, 10 Dec 2002 08:27:40 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: porting a routine which uses uint32_t
Message-Id: <at48hs$1ab$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<fishbowl@conservatory.com>], who wrote in article <3df15ae3_3@corp.newsgroups.com>:
> Greetings,
>
> I am trying to port a routine that depends on the
> behavior and precision of uint32_t.
On all the platforms in existence perl integer values are wide enough
to support this. Moreover, the arithmetic with
use integer;
should be 100% compatible with uint32_t on 32-bit platforms. (Here
compatible mean that the result *when converted to uint32_t* should be
identical.) So just do your calculations with `use integer', then
clump to 0..2**32-1 by &= 0xffffffff.
(On 64-bit machines you can get different results if you use integer
division; you may need to clump often near division.)
[in XS you use T_UV for types which can be converted to unsigned integer.]
Hope this helps,
Ilya
------------------------------
Date: Tue, 10 Dec 2002 12:03:23 +0000
From: Dela Lovecraft <dl19@le.academicplace.intheuk>
Subject: Problem - Array as Member of Object
Message-Id: <at4l5p$a20n$1@rook.le.ac.uk>
Dear All,
I am writing a program which will read in a DEM (digital elevation
model/map) in basic ASCII format and then do stuff with it. The stuff
bit isn't important right now, as that's not where I am having problems....
A DEM in the format I am using has the following format:
North: <northern-most co-ord>
South: <ditto for south>
East: <ditto for east>
West: <ditto for west>
Rows: <number of rows>
Cols: <number of columns>
#Followed by all the spot-height data, which is in the format:
1 2 3 4 5 6 7 8 9 .... n
So, there are a number of lines of numbers, with each number being
seperated by exactly one space. I can easily send a DEM to interested
parties....
I am reading these in as an object, created as
Landscape::DEM->new(demfile, name), and the basic format I have is so:
sub new
{
my $type = shift;
my $class = ref($type) || $type;
my $self = {};
my $filename = shift;
$self->{NAME} = shift;
open(DEMFILE, $filename) || die "Could not open DEM file $filename\n";
#Fine up to here.
#This next variable will hold all the cell data when we read it in a
second:
my @hold;
while (<DEMFILE>)
{
$self->{ROWS} = $1 if $_ =~ /rows: (\d+)/; #regex to find rows - fine
$self->{COLS} = $1 if $_ =~ /cols: (\d+)/; #regex to find columns - fine
#This next big bit reads all the remaining lines, and if they match the
#regex will basically fill up the @hold array with the values of the
dem data
my $temp = $1 if $_ =~ /^([0-9 ]+)/;
if ($temp)
{
my @temparray = split(/ /, $temp);
foreach my $t2 (@temparray)
{
push(@hold, $t2);
}
}
}
close(DEMFILE); #I always do this for neatness.... :)
$self->{NUMCELLS} = $self->{ROWS} * $self->{COLS};
#Makes the value of $self->{CELLS} equal to an array of the data we
have just got hold of.
$self->{CELLS} = @hold;
bless($self, $class);
return $self;
}
### Snippet ends here
Now, I know the regex loops works okay, since I have run that through
the debugger. But when I make a construct such as:
my @array = $self->{CELLS};
print $array[10];
I get the message that there is the use of an uninitialised value in the
program at this point. All I want to simply do at this point in my
program is to return the value held at some point in the array of grid
cells. Obviously I will be putting this into a sub which can be called
by the DEM object itself once it is working.
I have looked at this sooooo very long I can no longer see the wood for
the trees. Does anyone have some idea as to why it is not working correctly?
Any help much appreciated,
Dela
------------------------------
Date: Tue, 10 Dec 2002 13:38:39 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Problem - Array as Member of Object
Message-Id: <newscache$fslw6h$qih$1@news.emea.compuware.com>
Dela Lovecraft wrote (Tuesday 10 December 2002 13:03):
> $self->{NAME} = shift;
Why not give this properties it's own method?
my $name = shift;
$self->name($name);
> $self->{ROWS} = $1 if $_ =~ /rows: (\d+)/; #regex to find rows - fine
> $self->{COLS} = $1 if $_ =~ /cols: (\d+)/; #regex to find columns - fine
Why not give these properties their own method?
$self->rows(...);
$self->columns(...);
> $self->{NUMCELLS} = $self->{ROWS} * $self->{COLS};
Why not give this property it's own method?
sub numcells {
my $self = shift;
return $self->rows * $self->cols;
}
> #Makes the value of $self->{CELLS} equal to an array of the data we
> have just got hold of.
> $self->{CELLS} = @hold;
You just stuffed a list in a scalar. Evaluating a list in a scalar context
yields the number of elements in that list. Store the ref instead:
$self->{CELLS} = \@hold;
or even nicer:
$self->cells(\@hold); # give it it's own method.
Do remember that giving properties their own method is has a lot of
advantages:
1: You hide the inner workings for the outer world
2: You can change variable names at will without consequences
for the rest of your code.
3: You make your code more portable
HTH
--
KP
------------------------------
Date: Tue, 10 Dec 2002 13:15:08 +0000
From: Dela Lovecraft <dl19@le.academicplace.intheuk>
Subject: Re: Problem - Array as Member of Object
Message-Id: <at4pca$a3ot$1@rook.le.ac.uk>
Koos Pol wrote:
> Why not give this properties it's own method?
>
> my $name = shift;
> $self->name($name);
These methods (and others like the ones you mention) are all listed in
the rest of the file:
$self->getRows;
$self->getCols;
$self->getNumCells;
$self->name;
The snippet I posted is just the constructor, and modelled pretty much
on the perldoc examples. I agree totally with you on using seperate
methods for these variables - so far, all the other pieces of code
follow this pattern as well, and the ease in maintaining is noticeable. :)
>>#Makes the value of $self->{CELLS} equal to an array of the data we
>>have just got hold of.
>>$self->{CELLS} = @hold;
>
>
> You just stuffed a list in a scalar. Evaluating a list in a scalar context
> yields the number of elements in that list.
I figured after posting this must be what was happening:
print $array[0]; #yields size of @hold, in this case 57000
> Store the ref instead:
>
> $self->{CELLS} = \@hold;
Tried that, and got the same error message as in the main program. If I
do the above print statement, I get the obvious:
print $array[0]; #output is ARRAY(0x815fb50)
> $self->cells(\@hold); # give it it's own method.
This, again makes no difference.... :(
Dela
------------------------------
Date: Tue, 10 Dec 2002 13:35:15 +0000
From: Dela Lovecraft <dl19@le.academicplace.intheuk>
Subject: Re: Problem - Array as Member of Object
Message-Id: <at4qi1$a3ui$1@rook.le.ac.uk>
Ok. I am dumb.
Koos, I didn't take in what you wrote fully about referencing and
dereferencing (I have a head cold - what can I say?!).
Solution (for future reference when I forget and have to look this up
again in Google):
1. Set variable $self->{CELLS} to hold the reference of @hold (as you said):
$self->{CELLS} = \@hold;
2. Create method to read a value:
sub getValue
{
my $self = shift;
my $cell = shift; #send it the cell number you need
my $h = $self->{CELLS}; #hold the reference locally....
my @array = @$h; #...dereference...
return $array[$cell]; #... and return the desired value.
}
I know this can be cut down to being shorter, but I like step-by-step
code. :)
Many thanks!
Dela
------------------------------
Date: Tue, 10 Dec 2002 13:31:15 GMT
From: Pasi Ryhanen <pry@iki.fi>
Subject: Problem with range operator: for ($1 .. $2)
Message-Id: <878yyyatlg.fsf@iki.fi>
I'm trying to use the range operator (..) with integers taken from a
previous regexp match. For some reason, it doesn't work as I expected,
if the range is from a negative number to zero.
I have the following Perl script:
------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
while (<DATA>) {
if (/^(-?\d+)\s+(-?\d+)$/) {
print;
for ($1 .. $2) {
print "\t$_\n";
}
}
}
__DATA__
-2 0
-2 0
------------------------------------------------------------------------
It gives the following output (when using perl versions 5.6.1 or
5.8.0):
-2 0
-2
-1
0
-2 0
I would expect it go give this (which is exactly what perl 5.005_03
gave):
-2 0
-2
-1
0
-2 0
-2
-1
0
Could somebody enlighten me on what is happening here?
(The documentation (perlop) talks about "magical auto-increment
algorithm", but I don't quite see how it could explain this.)
--
Pasi Ryhänen
------------------------------
Date: 10 Dec 2002 01:17:27 -0800
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Re FAQ: How can I capture STDERR from an external command?
Message-Id: <fe4612a5.0212100117.7dc9cbbd@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>
> Peter J. Acklam wrote:
> >
> > > 8.25: How can I capture STDERR from an external command?
> > >
> > > [...]
> > >
> > > To read both a command's STDOUT and its STDERR separately, it's
> > > easiest and safest to redirect them separately to files, and then
> > > read from those files when the program is done:
> > >
> > > system("program args 1>/tmp/program.stdout \
> > > 2>/tmp/program.stderr");
> >
> > That's what I need, except I need cycling of the output files,
> > like what is done with /var/adm/messages (at least on Solaris).
>
> The common term for renaming log files in this way is called
> "rotating".
Ok, thanks, I didn't know that.
> The disadvantages of FIFO files are:
>
> [...]
Thank you very much for your comments. I'll don't think I'll be
using FIFOs after all then.
> In what way do FIFO files seem cleaner?
I was scared by the all the warnings in the docs for Net::Open3.
There seems to be so much that can go wrong (deadlocks etc.), and
I don't yet have that much experience with IPC, so I was worried
about screwing things up. Separating stdout and stderr is so easy
in the shell, but seems to be so complicated in Perl. I'll
probably just redirect stdout and stderr to the same place and
avoid all the hassle.
I really appreciate what you have posted about IPC in this group.
Googling through your postings has been very educational.
Peter
------------------------------
Date: Tue, 10 Dec 2002 06:24:30 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: read return value from a sql script using piped open
Message-Id: <3DF5EB0E.68EC226D@indra.com>
Sunil wrote:
>
> All,
> I need to get the return value from a sql script and redirect the output
> to a file. One of the requirements is to avoid showing passwords to 'ps' and
> the same code needs to run on win and unix.
> I am now calling the script using code as below.
>
> --------- Start My Code
> open SQLP, "|sqlplus -s /nolog >> $output_file_name "
> or die "cannot open sqlplus $ERRNO
> \n";
> # Connect and execute the script. This is done by writing to the stream we
> open for sqlplus.
> SQLP "connect $user_name/$password \n" or die "cannot write in doScript";
> print SQLP "\@$script_name; \n" or die "cannot write in doScript";
> close SQLP or die "cannot close in doScript";
>
> print "Status is :" . ($? >> 8);
> --------- End My Code
>
> The sql script I execute is :-
> ****** Start t.sql
> select sysdate from dual
> /
> exit 77
> ****** End t.sql
>
> This works if the exit value is 0 but anything else fails.
> ................. Start Error I see
> Uncaught exception from user code:
> cannot close in doScript at sqlutils.pm line 160.
> sqlutils::doSqlScript('t.sql', 'scott', 'tiger@iasdb.local',
> 'a.log') called at tutils.pl ine 21
> ................. End Error I see
>
> I had tried using the here document operator
> ######## Start MyCode Using the here doc
> $ret = system << "EOF";
> sqlplus -s scott/tiger\@iasdb.local \@t.sql
> EOF
> print ($ret >> 8);
>
> ######## End MyCode Using the here doc
>
> This shows the return value properly but I am not able to redirect the
> output of the script to the file.
>
> Your suggestions please.
>
> Thanks & Regards,
> Sunil.
What you should use is a here doc...
my $cmd = qq{
sqlplus -s << EOF
connect $username/$password
@script_name
<quit|exit>
EOF
};
my $results = `$cmd`;
die "some message" if $?;
Voila!
--
Ron Reidy
Oracle DBA
------------------------------
Date: Tue, 10 Dec 2002 10:57:00 +0000 (UTC)
From: "CJ" <newsgroupcontact@seseaz.org.uk>
Subject: Regular expression word replacement
Message-Id: <at4h9r$iru$1@knossos.btinternet.com>
I want to a script/reg.exp to search out certain words in a string (may be
multiline) and replace them with an alternative. The r.e. must be able to
handle the disallowed words in forms where the letters of the words are
separated by any n u m b e r of s p a c e s or by a.n.y other
n:o:n:a:l:p:h:a:n:u:m:e:r:i:c
characters or spaced out on
n
e
w
l
i
n
e
.>:;s
as no doubt once the script is in place those who's words are replaced will
try to get round it.
My perl is really rusty. I reckon I could do the line by line bit easily
but the code would be large and not take into account words spread over
multiple lines. I'm hoping my perl is good enough to translate any Reg. exp
/ script into PHP. Alternatively if anyone could provide the script in PHP
form that would be great.
A I admit that it probably won't
r allow you to replace
s words separaeted by
e alpha characters
w like those at the start
i of these lines but thats
p just a problem I will
e have to live with.
------------------------------
Date: Tue, 10 Dec 2002 12:28:18 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Regular expression word replacement
Message-Id: <newscache$6jiw6h$2ih$1@news.emea.compuware.com>
CJ wrote (Tuesday 10 December 2002 11:57):
> I want to a script/reg.exp to search out certain words in a string (may be
> multiline) and replace them with an alternative. The r.e. must be able
> to handle...
The perlop and perlre documents provide excellent help on how to do this.
Try some. If you can't get it to work, then just hurry back here!
--
KP
------------------------------
Date: Tue, 10 Dec 2002 09:41:11 GMT
From: "perlsage" <eldar@iki.fi>
Subject: Re: Two pppd's one after the other...
Message-Id: <XEiJ9.22158$ZE1.468328@news1.nokia.com>
Not always, you can also use BEGIN block, it is
executed when the program loads, like:
sub BEGIN {
system ("/usr/sbin/pppd call callbacku");
system ("/usr/sbin/pppd call secondcall");
}
"Vittorio" <vic50@email.it> wrote in message
news:c942feb2.0212090503.1d7916fc@posting.google.com...
> Bart Lateur <bart.lateur@pandora.be> wrote in message
news:<b7h7uu03k0b5g7opqom42bknttv32apok3@4ax.com>...
>
> > system()? That will wait until the launched program exits.
>
>
> Well I did it the following:
> -----------------------------------------------------------
> #!/usr/bin perl -w
> #
> print "Begin firstcall\n";
> system ("/usr/sbin/pppd call callbacku");
> print"End callback\n";
>
> print "Begin answering\n";
> system ("/usr/sbin/pppd call secondcall");
> #system "ls ppp*";
> print "End answer\n";
>
> exit;
> --------------------------------------------------
>
> Without success. As a matter of fact - keeping an eye on
> /var/log/messages - I see starting and completing the first call pppd
> process only (not the second), whilst the perl program is executed to
> the end (It prints "End answer").
>
> PLEASE HELP
>
> Vittorio
------------------------------
Date: 10 Dec 2002 11:47:59 GMT
From: Erik Braun <erik@pax07e3.mipool.uni-jena.de>
Subject: Re: which UI for Perl?
Message-Id: <slrn4avbhiv.86eq.erik@pax07e3.mipool.uni-jena.de>
Erik Braun <erik@pax07e3.mipool.uni-jena.de> wrote:
> I'm looking for a Perl Module, which provides interactive dialogs,
> and some extensions like Radio buttons or file requestors.
thank you for all the answers. I forgot to write one important
detail: I look for an UI which runs in a Shell Window or on
the console (Linux), so I cannot use the graphical extensions.
Sorry about that.
Erik
------------------------------
Date: Tue, 10 Dec 2002 10:15:22 GMT
From: "hennir" <henrin69@remove-yahoo.com>
Subject: XML::Parser 2.31 gives error "missing Expat.h"
Message-Id: <_8jJ9.22163$ZE1.468814@news1.nokia.com>
I have win2k, self compiled perl 5.8.0
and I tried installing collection of modules.
When nmaking the XML::Parser I got his:
Expat.c
Expat.xs(12) : fatal error C1083: Cannot open include file: 'expat.h': No
such f
ile or directory
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.
------------------------------
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 4239
***************************************