[24089] in Perl-Users-Digest
Perl-Users Digest, Issue: 6283 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 20 18:06:02 2004
Date: Sat, 20 Mar 2004 15:05:06 -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 Sat, 20 Mar 2004 Volume: 10 Number: 6283
Today's topics:
Re: Absolute wxPerl newbie: Create wxGrid (Sam Skielnik)
Re: Accessing a SQL Server Database from a Perl Script <mpeppler@peppler.org>
Re: Any Help would be great (Peter J. Acklam)
Re: Any Help would be great <jwillmore@remove.adelphia.net>
Re: Any Help would be great (Peter J. Acklam)
Re: Any Help would be great <gnari@simnet.is>
Re: Any Help would be great <jwillmore@remove.adelphia.net>
Re: dollar sign and spaces from a string <mr@sandman.net>
Re: dollar sign and spaces from a string (Anno Siegel)
Re: dollar sign and spaces from a string <mr@sandman.net>
How can I get the release number? <Tigerhillsideremove@removenetscape.net>
Re: How can I get the release number? <xaonon@hotpop.com>
Re: installing CPAN module <nowhere@somewhere.com>
Re: installing CPAN module <jwillmore@remove.adelphia.net>
Re: Perl upgraded = problem resurfacing (Anno Siegel)
Question about scope. <mail@annuna.com>
Re: Question about scope. <invalid-email@rochester.rr.com>
Re: Question about scope. (Anno Siegel)
Re: Question about scope. <roel-perl@st2x.net>
Re: regex (pcre) variable number of (captures)* - how? <janet@b3p0.com>
Re: regex (pcre) variable number of (captures)* - how? <invalid-email@rochester.rr.com>
Re: Truncating several lines of text into one line and (Anno Siegel)
using dynamic array names <pdconetwofour_numbers_@yahoo.co.uk>
Re: using dynamic array names <gnari@simnet.is>
Re: using dynamic array names <noway@jose.com>
Re: using dynamic array names <mr@sandman.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Mar 2004 13:17:07 -0800
From: skielnik@yahoo.com (Sam Skielnik)
Subject: Re: Absolute wxPerl newbie: Create wxGrid
Message-Id: <ea6a0a2b.0403201317.77d97a0a@posting.google.com>
Peter,
Looks like you need a BoxSizer or other Sizer widget before adding
your grid. I used wxGlade (http://wxglade.sourceforge.net/) to
generate the following wxPerl code. Wxglade is a great tool for
quickly generating a wxPerl layout.
Hope this helps,
Sam
#!/usr/bin/perl -w --
# generated by wxGlade 0.3.1 on Sat Mar 20 14:38:13 2004
# To get wxPerl visit http://wxPerl.sourceforge.net/
use Wx 0.15 qw[:allclasses];
use strict;
use Wx::Grid;
package MyFrame;
use Wx qw[:everything];
use base qw(Wx::Frame);
use strict;
sub new {
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef unless defined $parent;
$id = -1 unless defined $id;
$title = "" unless defined $title;
$pos = wxDefaultPosition unless defined $pos;
$size = wxDefaultSize unless defined $size;
$name = "" unless defined $name;
# begin wxGlade: MyFrame::new
$style = wxDEFAULT_FRAME_STYLE
unless defined $style;
$self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style,
$name );
$self->{grid_1} = Wx::Grid->new($self, -1);
$self->__set_properties();
$self->__do_layout();
return $self;
# end wxGlade
}
sub __set_properties {
my $self = shift;
# begin wxGlade: MyFrame::__set_properties
$self->SetTitle("frame_1");
$self->SetSize(400, 300);
$self->{grid_1}->CreateGrid(10, 3);
$self->{grid_1}->SetSelectionMode(wxGridSelectCells);
# end wxGlade
}
sub __do_layout {
my $self = shift;
# begin wxGlade: MyFrame::__do_layout
$self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL);
$self->{sizer_1}->Add($self->{grid_1}, 1, wxEXPAND, 0);
$self->SetAutoLayout(1);
$self->SetSizer($self->{sizer_1});
$self->Layout();
# end wxGlade
}
# end of class MyFrame
1;
package MyApp;
use base qw(Wx::App);
use strict;
sub OnInit {
my( $self ) = shift;
Wx::InitAllImageHandlers();
my $frame_1 = MyFrame->new();
$self->SetTopWindow($frame_1);
$frame_1->Show(1);
return 1;
}
# end of class MyApp
package main;
unless(caller){
my $app = MyApp->new();
$app->MainLoop();
}
------------------------------
Date: Sat, 20 Mar 2004 09:44:25 -0800
From: Michael Peppler <mpeppler@peppler.org>
Subject: Re: Accessing a SQL Server Database from a Perl Script on Linux
Message-Id: <pan.2004.03.20.17.44.25.571388@peppler.org>
On Fri, 19 Mar 2004 18:22:04 +0000, Stephen Patterson wrote:
> On Fri, 19 Mar 2004 04:04:50 GMT, Bob Walton wrote:
>> use DBI;
>
> With DBD::Sybase - we use this at work for some daily reports.
But don't forget that you need FreeTDS (www.freetds.org) as well.
Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler@peppler.org http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.peppler.org/resume.html
------------------------------
Date: 20 Mar 2004 17:04:48 +0100
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Any Help would be great
Message-Id: <ekrnqzbz.fsf@online.no>
James Willmore <jwillmore@remove.adelphia.net> wrote:
> Peter J. Acklam wrote:
>
> > For instance, when talking about the size of a hard disk, 1 MB
> > is often 10^6 bytes and 1 GB is 10^9 bytes.
>
> Try the following URL's to support the simple concept that ...
> 1024kb is, in fact, 1Mb
>
> [...]
>
> Maybe this is overkill, but it seems apparent that you want to
> make a statement without knowing all the facts. I suggest you
> *read* the URL's, report back what proves your point ... or just
> accept the fact you're wrong and move on :-)
Several disk partitioning tools consider 1MB to be 1000000B.
Microsoft's "fdisk" is one of them. Your URLs can't change that.
If you don't belive me, get hold of a few disk partitioning tools,
try them out and compare. It's quite annoying that hardly any of
them document how many bytes their MBs are.
You're making a fool of yourself being so condescending when
you're wrong.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Sat, 20 Mar 2004 11:41:47 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Any Help would be great
Message-Id: <pan.2004.03.20.16.41.45.477267@remove.adelphia.net>
On Sat, 20 Mar 2004 17:04:48 +0100, Peter J. Acklam wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote:
>
>> Peter J. Acklam wrote:
>>
>> > For instance, when talking about the size of a hard disk, 1 MB
>> > is often 10^6 bytes and 1 GB is 10^9 bytes.
>>
>> Try the following URL's to support the simple concept that ...
>> 1024kb is, in fact, 1Mb
>>
>> [...]
>>
>> Maybe this is overkill, but it seems apparent that you want to
>> make a statement without knowing all the facts. I suggest you
>> *read* the URL's, report back what proves your point ... or just
>> accept the fact you're wrong and move on :-)
>
> Several disk partitioning tools consider 1MB to be 1000000B.
> Microsoft's "fdisk" is one of them. Your URLs can't change that.
>
> If you don't belive me, get hold of a few disk partitioning tools,
> try them out and compare. It's quite annoying that hardly any of
> them document how many bytes their MBs are.
>
> You're making a fool of yourself being so condescending when
> you're wrong.
Micro$oft != rest of world
This apears to be the crux of the problem. I am well aware that M$ tells
users that 1Mb = 1,000,000 bytes. That's to make things simple for the
end user. OTOH, Partition Magic doesn't follow this dogma laid out my M$.
How about that :-)
In the world of programming, 1024 kb = 1 Mb :-)
Of course, you examined *none* of the URL's I posted which clearly show
that you (and Microsoft, once again) are in the minority.
--
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 ...
As the poet said, "Only God can make a tree" -- probably because
it's so hard to figure out how to get the bark on. -- Woody
Allen
------------------------------
Date: 20 Mar 2004 19:18:44 +0100
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Any Help would be great
Message-Id: <lllvpekb.fsf@online.no>
James Willmore <jwillmore@remove.adelphia.net> wrote:
> Micro$oft != rest of world
That doesn't matter. The point is that *some* consider 1 MB to be
1000000 B. Maxtor is one of the world's largest hard drive
manufacturers and their partitioning utility, MaxBlast, also uses
1 MB = 1000000 B.
> This apears to be the crux of the problem. I am well aware that
> M$ tells users that 1Mb = 1,000,000 bytes.
I don't think you are, because you said "1024kb is, in fact, 1Mb",
as if it was a universal fact.
> Partition Magic doesn't follow this dogma laid out my M$. How
> about that :-)
So what? I didn't say that *everybody* uses 1 MB = 1000000 B.
> In the world of programming, 1024 kb = 1 Mb :-)
No, not always. You really don't get this, do you?
> Of course, you examined *none* of the URL's I posted which
> clearly show that you (and Microsoft, once again) are in the
> minority.
Again, so what? I'm only saying that 1 MB isn't *always* 1048576 B.
*Usually*, 1 MB = 1048576 B, but *sometimes* 1 MB = 1000000 B.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Sat, 20 Mar 2004 18:37:53 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Any Help would be great
Message-Id: <c3i2vm$tkk$1@news.simnet.is>
"Peter J. Acklam" <pjacklam@online.no> wrote in message
news:lllvpekb.fsf@online.no...
> James Willmore <jwillmore@remove.adelphia.net> wrote:
>
[snipped Mb argument]
How about you two moving this discussion to private email?
Most of us here already know which one of you is right, and which
one is wrong, but we do not care enough about it to join the
fray. It is clear that you 2 will end in a
it is, too!
it is not !
it is, too !
kind of loop soon, so why not abort now?
gnari
------------------------------
Date: Sat, 20 Mar 2004 17:46:34 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Any Help would be great
Message-Id: <pan.2004.03.20.22.46.32.400862@remove.adelphia.net>
On Sat, 20 Mar 2004 18:37:53 +0000, gnari wrote:
> "Peter J. Acklam" <pjacklam@online.no> wrote in message
> news:lllvpekb.fsf@online.no...
>> James Willmore <jwillmore@remove.adelphia.net> wrote:
>>
> [snipped Mb argument]
>
> How about you two moving this discussion to private email?
> Most of us here already know which one of you is right, and which
> one is wrong, but we do not care enough about it to join the
> fray. It is clear that you 2 will end in a
> it is, too!
> it is not !
> it is, too !
> kind of loop soon, so why not abort now?
>
> gnari
You're right. I'll just drop my end.
I apologize to the group for continuing this off topic discussion.
--
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 ...
While anyone can admit to themselves they were wrong, the true
test is admission to someone else.
------------------------------
Date: Sat, 20 Mar 2004 20:58:10 +0100
From: Sandman <mr@sandman.net>
Subject: Re: dollar sign and spaces from a string
Message-Id: <mr-BD832A.20581020032004@news.fu-berlin.de>
In article <c3hf1t$d7h$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > >>> Right. You're new, you make mistakes, you're criticized. You leave
> > >>> or you learn. Anything wrong with that?
> > >>
> > >> Well, of course. Problem is that too many would rather make fun of
> > >> and insult the newbies than directing them to the appropriate
> > >> documentation - even though the latter is so much easier! I suppose
> > >> the former is more fun, but a lot of newbies are scared off due to
> > >> the elitist attitude.
> > >
> > > Care to show any evidence for that claim?
> >
> > Naturally! I wouldn't make a claim if I couldnt' back it up. This is from
> > just
> > two weeks ago, from a guy that wanted help with a transition from
> > JavaScript to
>
> [snip]
>
> Keep your line length reasonable.
>
> I asked for evidence, you give me an anecdote (no news there, I read this
> newsgroup too).
>
> How many newbies are scared off by the elitist attitude of this NG, and
> how do you know?
I have showed you exactly what I wanted to show and I have no doubt my claim is
adequately substantiated.
Thank you.
--
Sandman[.net]
------------------------------
Date: 20 Mar 2004 20:29:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: dollar sign and spaces from a string
Message-Id: <c3i9j9$rk7$2@mamenchi.zrz.TU-Berlin.DE>
Sandman <mr@sandman.net> wrote in comp.lang.perl.misc:
> In article <c3hf1t$d7h$1@mamenchi.zrz.TU-Berlin.DE>,
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> > > >> the former is more fun, but a lot of newbies are scared off due to
> > > >> the elitist attitude.
> > > >
> > > > Care to show any evidence for that claim?
> > >
> > > Naturally! I wouldn't make a claim if I couldnt' back it up. This is from
> > > just
> > > two weeks ago, from a guy that wanted help with a transition from
> > > JavaScript to
> >
> > [snip]
> >
> > Keep your line length reasonable.
> >
> > I asked for evidence, you give me an anecdote (no news there, I read this
> > newsgroup too).
> >
> > How many newbies are scared off by the elitist attitude of this NG, and
> > how do you know?
>
> I have showed you exactly what I wanted to show and I have no doubt my claim is
> adequately substantiated.
No, you have uttered an opinion which you failed to substantiate.
Facts are welcome, and so are insights. Opinions may be interesting
if they come from a powerful person, or a wise one, or a dear
acquaintance. You are neither.
And your lines are still too long.
Anno
------------------------------
Date: Sat, 20 Mar 2004 22:54:52 +0100
From: Sandman <mr@sandman.net>
Subject: Re: dollar sign and spaces from a string
Message-Id: <mr-0604FD.22545120032004@news.fu-berlin.de>
In article <c3i9j9$rk7$2@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> I have showed you exactly what I wanted to show and I have no doubt
>> my claim is adequately substantiated.
>
> No, you have uttered an opinion which you failed to substantiate.
No.
--
Sandman[.net]
------------------------------
Date: Sat, 20 Mar 2004 22:25:58 GMT
From: Tigerhillside <Tigerhillsideremove@removenetscape.net>
Subject: How can I get the release number?
Message-Id: <cvfp50tfsvcogkgojcjud2dqi62kllng7f@4ax.com>
How can I tell what release of perl is on my hosting system?
Their documentation says 5.80, but a script I borrowed says that
$] says it is 5.008.
I figured this would be in a FAQ, but I could not find it (and
release is too common a word to do an extensive search).
------------------------------
Date: 20 Mar 2004 22:33:16 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: How can I get the release number?
Message-Id: <slrnc5phmj.43e.xaonon@xaonon.local>
Ned i bach <cvfp50tfsvcogkgojcjud2dqi62kllng7f@4ax.com>, Tigerhillside
<Tigerhillsideremove@removenetscape.net> teithant i thiw hin:
> How can I tell what release of perl is on my hosting system?
> Their documentation says 5.80, but a script I borrowed says that
> $] says it is 5.008.
That's the same thing. The old version numbering system goes revision
number, version number / 1000, subversion number / 1000000. For example, on
my system:
$ perl -v
This is perl, v5.6.1 built for i586-linux
[etc...]
$ perl -e 'print "$]\n"'
5.006001
--
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
http://xaonon.dyndns.org/ Guaranteed content-free since 1999. No refunds.
"If I ever get to Heaven and it's filled with happy dancing clam strips, I
will find that disturbing and ask to leave." -- James "Kibo" Parry
------------------------------
Date: Sat, 20 Mar 2004 15:18:06 GMT
From: foobardude <nowhere@somewhere.com>
Subject: Re: installing CPAN module
Message-Id: <OgZ6c.629$o76.62@nwrdny02.gnilink.net>
Yup, I tried installing it many different ways with no success; James is
suggesting that GP/PARI needs to be installed as root and that in his
trials he couldn't get it to install as non-root either. I don't have
root access in the machine that I wanted to install this module so I
guess I'm going to have to find another way to do all this. Many thanks
for the replies though.
C.
James Willmore wrote:
> On Fri, 19 Mar 2004 21:14:49 +0000, foobardude wrote:
>
> [ ... ]
>
>> Any help greatly appreciated,
>>
>
>>
>>
---------------------------------------------------------------------------
>> Did not find GP/PARI build directory around.
>> Do you want to me to fetch GP/PARI automatically?
>> (If you do not, you will need to fetch it manually, and/or direct me to
>> the directory with GP/PARI source via the command-line option
>> paridir=/dir)
>> Make sure you have a large scrollback buffer to see the messages.
>> Fetch? (y/n, press Enter) Can't open PREFIX=~/perl5lib/: No such file or
>> directory at utils/Math/PariBuild.pm line 148.
>> Can't open LIB=~/perl5lib/lib: No such file or directory at
>> utils/Math/PariBuild.pm line 148.
>> Can't open INSTALLMAN1DIR=~/perl5lib/man1: No such file or directory at
>> utils/Math/PariBuild.pm line 148.
>> Can't open INSTALLMAN3DIR=~/perl5lib/man3: No such file or directory at
>> utils/Math/PariBuild.pm line 148.
>> Well, as you wish...
>> Rerun Makefile.PL when you fetched GP/PARI manually.
>> Could not find GP/PARI build directory, please run Makefile.PL
>> with paridir=/directory option.
>> Running make test
>> Make had some problems, maybe interrupted? Won't test
>> Running make install
>> Make had some problems, maybe interrupted? Won't install
>>
---------------------------------------------------------------------------
>
> A couple of things.
>
> Did you set a prefix for CPAN to use to install modules? If so, use a
> full path, not a '~' in the path. I'm not saying this is the problem, but
> from the output there *appears* to be a problem with where CPAN is looking
> for stuff.
>
> Have you tried to install without the CPAN shell? This *may* work for
> you. OTOH, the install may crap again, but it's worth a shot. One way
> to do this is (from the CPAN shell) type 'look Math::Pari' (which gets
> you out of the CPAN shell and into where the module tarball was
> extracted), then 'perl Makefile.PL', 'make', 'make test', and finally
> 'make install'. Make sure you read the messages during each step to see if
> all went well.
>
> HTH
>
------------------------------
Date: Sat, 20 Mar 2004 10:56:19 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: installing CPAN module
Message-Id: <pan.2004.03.20.15.56.16.912778@remove.adelphia.net>
[ don't top post - it's rude ]
On Sat, 20 Mar 2004 15:18:06 +0000, foobardude wrote:
> James Willmore wrote:
>
>> On Fri, 19 Mar 2004 21:14:49 +0000, foobardude wrote:
> ---------------------------------------------------------------------------
>>> Did not find GP/PARI build directory around. Do you want to me to
>>> fetch GP/PARI automatically?
>>> (If you do not, you will need to fetch it manually, and/or direct me
>>> to
>>> the directory with GP/PARI source via the command-line option
>>> paridir=/dir)
>>> Make sure you have a large scrollback buffer to see the messages.
>>> Fetch? (y/n, press Enter) Can't open PREFIX=~/perl5lib/: No such file
>>> or directory at utils/Math/PariBuild.pm line 148. Can't open
>>> LIB=~/perl5lib/lib: No such file or directory at
>>> utils/Math/PariBuild.pm line 148.
Okay. It appears that the module did not find the pari headers and
library. I *suggest* that an admin install pari (the library, *not* the
module) for you. I have no clue what will happen if you install pari
(again, library, not module) as a regular user.
And, as I pointed out before ... you might want to change the PREFIX to a
full path versus using the '~' in the path. I realize you're using your
home directory to install to, but, maybe, CPAN is seeing '~' as a real
directory instead of what the shell you use interprets '~' to mean.
>>> Can't open INSTALLMAN1DIR=~/perl5lib/man1: No such file or directory
>>> at utils/Math/PariBuild.pm line 148.
Ditto.
>>> Can't open INSTALLMAN3DIR=~/perl5lib/man3: No such file or directory
>>> at utils/Math/PariBuild.pm line 148.
Ditto.
>>> Well, as you wish...
>>> Rerun Makefile.PL when you fetched GP/PARI manually. Could not find
>>> GP/PARI build directory, please run Makefile.PL with
>>> paridir=/directory option.
Again, is pari (the library) installed? If so, then the module is not
finding it. Set your 'paridir' option during the 'perl Makefile.PL' step -
as directed in the message :-)
[ ... ]
>> Did you set a prefix for CPAN to use to install modules? If so, use a
>> full path, not a '~' in the path. I'm not saying this is the problem,
>> but from the output there *appears* to be a problem with where CPAN is
>> looking for stuff.
Same, again, as above.
>> Have you tried to install without the CPAN shell? This *may* work for
>> you. OTOH, the install may crap again, but it's worth a shot. One way
>> to do this is (from the CPAN shell) type 'look Math::Pari' (which gets
>> you out of the CPAN shell and into where the module tarball was
>> extracted), then 'perl Makefile.PL', 'make', 'make test', and finally
>> 'make install'. Make sure you read the messages during each step to see
>> if all went well.
>>
>> HTH
>>
> Yup, I tried installing it many different ways with no success; James is
> suggesting that GP/PARI needs to be installed as root and that in his
> trials he couldn't get it to install as non-root either. I don't have
> root access in the machine that I wanted to install this module so I
> guess I'm going to have to find another way to do all this. Many thanks
> for the replies though.
What ways? You showed just using the CPAN shell :-)
And, where did you get that I stated " ... James is suggesting that
GP/PARI needs to be installed as root ..." from my OP? I said there
appears to be an issue with your PREFIX :-) Nowhere did I state you need
to be root to install this module in my OP. I have an issue with someone
putting words in my mouth - a real hot button - don't press it :- ) This
post, I *suggest* installing pari (the base library, *not* the moodule) as
root.
Worst case - contact the author and ask how to install the module as a
regular user - and note that the pari library is *not* installed according
to your output. I'm thinking (s)he will make similar (if not the same)
suggestions I have made :-)
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 ...
"I think it is true for all n. I was just playing it safe with n
>= 3 because I couldn't remember the proof." -- Baker, Pure
Math 351a
------------------------------
Date: 20 Mar 2004 22:49:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl upgraded = problem resurfacing
Message-Id: <c3ihq4$2ep$1@mamenchi.zrz.TU-Berlin.DE>
Roel van der Steen <roel-perl@st2x.net> wrote in comp.lang.perl.misc:
> On Fri, 19 Mar 2004 at 17:43 GMT, Grant <tonearm@email.com> wrote:
> > I suppose I don't know that it is totally blank for sure, although the
> > If the above code should
> > still be working to correctly route a blank response, can anyone
> > suggest code that would check the response for something specific that
> > should be there (like "<?xml") and decide what to do based on that?
>
> What about (untested):
>
> if ($response =~ /^<\?xml/ ) {
> # *XML::Simple processing*
> }
> else {
> # *processing*
> }
Or even just
if $response =~ /\S/ ) { # process nonblank responses
That may be all that's needed, since non-empty input used to be okay.
Anyway, exploding on an empty input string is surely a bug in
XML::Simple (if it's there that it happens).
Anno
------------------------------
Date: Sat, 20 Mar 2004 19:07:54 GMT
From: Joe <mail@annuna.com>
Subject: Question about scope.
Message-Id: <eE07c.49532$aT1.40855@newsread1.news.pas.earthlink.net>
I am trying to create an class and then try to access the data members
in that class. When I run this piece of code the data prints out in the
constructor but when I use the function I get no out put. How do I get
this to work?
package Space;
my $space;
#spaces of the grid
sub new{
$space = {
loc => $_[0],
char => 0
};
print $space->{loc};
bless $space, 'Space';
return $space;
}
sub fchsym{ #returns the symbol for map printing.
print $space->{loc};
return $space->{loc};
}
------------------------------
Date: Sat, 20 Mar 2004 19:53:36 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Question about scope.
Message-Id: <405CA13D.3090507@rochester.rr.com>
Joe wrote:
> I am trying to create an class and then try to access the data members
> in that class. When I run this piece of code the data prints out in the
> constructor but when I use the function I get no out put. How do I get
> this to work?
>
>
> package Space;
>
> my $space;
>
> #spaces of the grid
>
> sub new{
> $space = {
> loc => $_[0],
> char => 0
>
> };
>
> print $space->{loc};
> bless $space, 'Space';
> return $space;
> }
>
> sub fchsym{ #returns the symbol for map printing.
>
>
> print $space->{loc};
> return $space->{loc};
> }
>
Works fine for me [AS Perl build 806, Windoze 98SE], verbatim with the
code you provide (I added a 1; statement at the end so "use Space;"
would succeed in my package main, and I provided a package main to call
your stuff). Although what it is outputting is probably not what you
actually want. When you call a method, $_[0] is the package name, so
that is what is getting stored in $space{loc}. You probably want to
store $_[1]. And you might want to add some labels and newlines to your
print statements so you can tell what printed where.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 20 Mar 2004 20:16:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Question about scope.
Message-Id: <c3i8ql$rk7$1@mamenchi.zrz.TU-Berlin.DE>
Joe <mail@annuna.com> wrote in comp.lang.perl.misc:
> I am trying to create an class and then try to access the data members
> in that class. When I run this piece of code the data prints out in the
> constructor but when I use the function I get no out put. How do I get
> this to work?
How are you calling the methods? We can't explain the behavior you're
seeing if you don't show the code you run. Your code indicates you are
not quite clear about what is involved in a method call, so guesses
are out.
> package Space;
>
> my $space;
>
> #spaces of the grid
>
> sub new{
There is an almost obligatory line missing here. All ->new methods
in Perl start with
my $class = shift;
There is hardly ever a reason not to start ->new that way, certainly
not here.
The ->new method is called as a class method, which means the first
argument will be a class name, "Space" in your case. You want to
shift that off, for later use. After that shift() the arguments in
@_ correspond to the arguments in the parentheses in the method call.
> $space = {
A method (->new or otherwise) has no business knowing about a variable
you eventually want to assign an object to. Don't mention "$space" here,
don't even declare it. Just return the result of bless().
> loc => $_[0],
Since you failed to shift off the class name, the first argument $_[ 0]
will be a class name, "Space" in your case.
> char => 0
>
> };
>
> print $space->{loc};
> bless $space, 'Space';
This is another OO faux-pas. You (almost) never bless into a fixed
class, but into the class that has been saved away in the beginning.
I won't go into the implications (every Perl OO tutorial has them),
but the line should be
bless $space, $class;
> return $space;
This isn't wrong, but unnecessary. bless() returns the blessed
reference, so if you close the sub just after bless(), that is
also what the sub returns.
> }
> sub fchsym{ #returns the symbol for map printing.
Again, a ritual bit of OO code is missing. "fchsym" is going to
be called as an object method, so its first parameter will be an
object, the one you're supposed to operate on. Shift it off in a
variable...
my $space = shift;
> print $space->{loc};
...instead of using a global variable. A general method doesn't have
to -- and shouldn't -- know about variables outside its lexical space.
(Exceptions, notable ones, granted.)
> return $space->{loc};
> }
>
So your class should look about like this:
package Space;
#spaces of the grid
sub new{
my $class = shift;
bless {
loc => $_[0],
char => 0
}, $class;
}
sub fchsym{ #returns the symbol for map printing.
my $space = shift;
print $space->{loc}, "\n";
return $space->{loc};
}
To test it, call like this:
my $space = Space->new( 'somewhere');
$sp->fchsym;
That prints the location "somewhere" once (it's not printed from ->new
anymore), which is, I suppose, what you want it to do.
Anno
------------------------------
Date: 20 Mar 2004 20:31:09 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: Question about scope.
Message-Id: <slrnc5pafr.606.roel-perl@195-86-124-242.dsl.easynet.nl>
On Sat, 20 Mar 2004 at 19:07 GMT, Joe <mail@annuna.com> wrote:
> I am trying to create an class and then try to access the data members
> in that class. When I run this piece of code the data prints out in the
> constructor but when I use the function I get no out put. How do I get
> this to work?
>
>
Actually, your code works. I'm not sure what you mean by "use the
function". See example below for sample contructor and method
call.
Always:
use strict;
use warnings;
> package Space;
>
> my $space;
^^^^^^^^^
Always declare your variables in the smallest possible scope, in this
case within the object constructor. (Your object instance will be
returned with the "return" statement from the sub "new"; no need to
have it in your class package as well.)
>
> #spaces of the grid
>
> sub new {
> $space = {
. . ^
Insert "my" before this variable name
> loc => $_[0],
. . . . . . . ^^^^^
I assume we have the real problem here -- why do you store the package
name in the object? I think you want to be able to give some argument
with the constructor call, but note that is passed in as $_[1].
> char => 0,
. . . . . . . ^
(You may consider renaming this property, since "char" could make a user
of your class think that this is some string property, but here you do a
numeric assignment...)
> };
. . .^
(Leave this one off)
>
> print $space->{loc};
This effectively prints out your class name: "Space" (but before your
object is blessed).
> bless $space, 'Space';
> return $space;
> }
>
> sub fchsym{ #returns the symbol for map printing.
. . . ^^^^^^
Consider revising this name as well -- the user of your class won't
get much of clue from this what this method does.
> print $space->{loc};
(I assume this "print" statement is only for testing.)
> return $space->{loc};
> }
>
# Now:
package main;
my $space_obj = Space->new(); # already prints the text "Space" once...
my $fchsym_result = $space_obj->fchsym(); # ... that's the 2nd "Space"...
print $fchsym_result; # ... and the 3rd.
__END__
This prints:
SpaceSpaceSpace
I suggest you re-read "perltoot", think the whole thing over, and then
explain us in somewhat more detail what your class needs to do. That
should get you swiftly on the right track.
------------------------------
Date: Sat, 20 Mar 2004 10:18:48 -0500
From: Janet <janet@b3p0.com>
Subject: Re: regex (pcre) variable number of (captures)* - how?
Message-Id: <BC81CB08.8C5D%janet@b3p0.com>
On 3/20/04 6:51 AM, in article 200320041151138348%x@x.x, "ben" <x@x.x>
wrote:
> regarding regular expressions (pcre):
>
> i keep wanting to do this but can't see how to do it: if, within the
> regex pattern, you repeat a capture, as in rounded brackets followed by
> a star, the capture results don't increase with the number of loops
> that the repeating star.
>
> the number or capture result spaces are fixed to the number of pairs of
> brackets, even if those brackets are set to repleat/loop.
>
> how can you capture a variable number of results?
>
> simple example:
>
> input text:
> a b c d e
>
> an attempt pattern that doesn't work:
> ((\\w)\\s*)*
>
> results:
> 2004-03-20 11:42:40.226 regexTest[29750] <AGRegexMatch: 0x5e240> {
> 0 {0, 9} a b c d e
> 1 {8, 1} e
> 2 {8, 1} e
> }
>
> (ok, i'm not doing this in perl but in the "cocoa" framework on apple
> os x using a pcre regex wrapper called AGRegex, but this groop seemed
> pretty appropriate)
>
> so the result show the problem -- only one fixed result which obviously
> keeps getting written over which is why it ends up with only the last
> result. what i want is the multiple matches to build up/ aggregate
> somehow to end up with:
> a
> b
> c
> d
> e
>
> how can this be done? any help much appreciated.
>
You could put the first result into a variable, then add (concatenate) other
results to it after each capture. This also keeps you from depending on $1
(or whatever) later in the program, when it may be rewritten by another
regex use.
--
The state, it cannot be too often repeated, does nothing and can give
nothing that it does not take from somebody.
William Graham Sumner
------------------------------
Date: Sat, 20 Mar 2004 18:34:17 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: regex (pcre) variable number of (captures)* - how?
Message-Id: <405C8EA6.1070606@rochester.rr.com>
ben wrote:
> regarding regular expressions (pcre):
>
> i keep wanting to do this but can't see how to do it: if, within the
> regex pattern, you repeat a capture, as in rounded brackets followed by
> a star, the capture results don't increase with the number of loops
> that the repeating star.
>
> the number or capture result spaces are fixed to the number of pairs of
> brackets, even if those brackets are set to repleat/loop.
>
> how can you capture a variable number of results?
>
> simple example:
>
> input text:
> a b c d e
>
> an attempt pattern that doesn't work:
> ((\\w)\\s*)*
>
> results:
> 2004-03-20 11:42:40.226 regexTest[29750] <AGRegexMatch: 0x5e240> {
> 0 {0, 9} a b c d e
> 1 {8, 1} e
> 2 {8, 1} e
> }
>
> (ok, i'm not doing this in perl but in the "cocoa" framework on apple
> os x using a pcre regex wrapper called AGRegex, but this groop seemed
> pretty appropriate)
>
> so the result show the problem -- only one fixed result which obviously
> keeps getting written over which is why it ends up with only the last
> result. what i want is the multiple matches to build up/ aggregate
> somehow to end up with:
> a
> b
> c
> d
> e
>
> how can this be done? any help much appreciated.
>
> thanks, ben.
>
Try:
my $input='a b c d e';
my @output=$input=~/(\w)\s*/g;
print join "\n",@output;
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 20 Mar 2004 23:01:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Truncating several lines of text into one line and putting in scalar
Message-Id: <c3iifv$2ep$2@mamenchi.zrz.TU-Berlin.DE>
Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> Maybe you would prefer the canonical canonicalisation of whitespace:
Can we canonicalize that term, please?
Anno
------------------------------
Date: Sat, 20 Mar 2004 21:07:19 GMT
From: p cooper <pdconetwofour_numbers_@yahoo.co.uk>
Subject: using dynamic array names
Message-Id: <bo27c.21705$ct4.475674811@news-text.cableinet.net>
im a bit new to this - have read what I can find about array references (not
sure of this is where I should be looking) and havent found the answer.
its the "use the array identified by the constructed name $q_array " that I
cant get.
@$q_array is what i think it should be - but it isnt
#!/usr/bin/perl
use CGI qw(:cgi-lib :standard carpout); # Include CGI functions
use CGI::Carp qw(fatalsToBrowser); # Send error messages to browser
use Fcntl ':flock'; # import LOCK_* constants
use strict;
my @times=qw(before during after);
my @before_questions=("question1_before", "question2_before" ...etc);
my @after_questions=("question1_after", "question2_after" ...etc);
foreach my $time(@times)
{
$q_array=$time."_questions";
foreach $question(array called $q_array)
^^^^^^^^^^^^^^^^^^^^^
{
print $question;
etc etc
}
}
------------------------------
Date: Sat, 20 Mar 2004 21:49:51 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: using dynamic array names
Message-Id: <c3ie7l$v17$1@news.simnet.is>
"p cooper" <pdconetwofour_numbers_@yahoo.co.uk> wrote in message
news:bo27c.21705$ct4.475674811@news-text.cableinet.net...
[snip question about symbolic array references]
use a hash instead of symbolic recerences
> my @times=qw(before during after);
> my @before_questions=("question1_before", "question2_before" ...etc);
> my @after_questions=("question1_after", "question2_after" ...etc);
my %questions=(
before=>\@before_questions,
after =>\@after_questions,
);
foreach my $time(@times) {
my $q_array=$questions{$time};
foreach $question (@$q_array) {
print $question;
# etc etc
}
}
or you could have skipped the intermediate arrays
my %questions=(
before=>["question1_before", "question2_before"],
after =>["question1_before", "question2_before"],
);
read
perldoc perlref
perldoc perlreftut
perldoc perllol
gnari
------------------------------
Date: Sat, 20 Mar 2004 22:29:34 -0000
From: "For example" <noway@jose.com>
Subject: Re: using dynamic array names
Message-Id: <405cc67f$0$28281$cc9e4d1f@news.dial.pipex.com>
"p cooper" <pdconetwofour_numbers_@yahoo.co.uk> wrote in message
news:bo27c.21705$ct4.475674811@news-text.cableinet.net...
> im a bit new to this - have read what I can find about array references
(not
> sure of this is where I should be looking) and havent found the answer.
>
> its the "use the array identified by the constructed name $q_array " that
I
> cant get.
> @$q_array is what i think it should be - but it isnt
>
>
>
> #!/usr/bin/perl
> use CGI qw(:cgi-lib :standard carpout); # Include CGI functions
> use CGI::Carp qw(fatalsToBrowser); # Send error messages to browser
> use Fcntl ':flock'; # import LOCK_* constants
> use strict;
> my @times=qw(before during after);
> my @before_questions=("question1_before", "question2_before" ...etc);
> my @after_questions=("question1_after", "question2_after" ...etc);
>
> foreach my $time(@times)
> {
> $q_array=$time."_questions";
> foreach $question(array called $q_array)
> ^^^^^^^^^^^^^^^^^^^^^
> {
> print $question;
> etc etc
> }
> }
>
You realy don't want to do that - no really you don't.
I imagine you *think* you want to do this:
eval "\@q_array=\@$time".'_questions';
and then
foreach $question(@q_array)
But I have never ever felt the need to do something like this. Testing that
was the first time I have ever used eval. I would advise you to think of a
better solution to your problem, you will be grateful in the long run.
It is crying out for a hash of arrays or an array of arrays. How about:
#!/usr/bin/perl
use strict;
use warnings;
my %times;
@{$times{before}}=('question1_before', 'question2_before');
@{$times{after}}=('question1_after', 'question2_after');
foreach my $time(keys %times)
# or you could list the keys like
# foreach my $time ('before','after')
# or hold them in an array as you had
{
foreach my $questions (@{$times{$time}} )
{
print "$questions \n";
}
}
------------------------------
Date: Sat, 20 Mar 2004 23:35:34 +0100
From: Sandman <mr@sandman.net>
Subject: Re: using dynamic array names
Message-Id: <mr-9CFA86.23353420032004@news.fu-berlin.de>
In article <bo27c.21705$ct4.475674811@news-text.cableinet.net>,
p cooper <pdconetwofour_numbers_@yahoo.co.uk> wrote:
> im a bit new to this - have read what I can find about array references (not
> sure of this is where I should be looking) and havent found the answer.
>
> its the "use the array identified by the constructed name $q_array " that I
> cant get.
> @$q_array is what i think it should be - but it isnt
>
>
>
> #!/usr/bin/perl
> use CGI qw(:cgi-lib :standard carpout); # Include CGI functions
> use CGI::Carp qw(fatalsToBrowser); # Send error messages to browser
> use Fcntl ':flock'; # import LOCK_* constants
> use strict;
> my @times=qw(before during after);
> my @before_questions=("question1_before", "question2_before" ...etc);
> my @after_questions=("question1_after", "question2_after" ...etc);
>
> foreach my $time(@times)
> {
> $q_array=$time."_questions";
> foreach $question(array called $q_array)
> ^^^^^^^^^^^^^^^^^^^^^
> {
> print $question;
> etc etc
> }
> }
>
Why separate it into different arrays, when you can store them all in one hash?
#!/usr/bin/perl
use strict;
use warnings;
my @times = qw(before during after);
my %questions = (
"before" => [ qw(foo bar) ],
"during" => [ qw(ofo rba) ],
"after" => [ qw(oof rab) ]
);
foreach my $time (@times){
foreach my $question (@{$questions{$time}}){
print qq{$question };
}
print "\n";
}
__END__
foo bar
ofo rba
oof rab
--
Sandman[.net]
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6283
***************************************