[29179] in Perl-Users-Digest
Perl-Users Digest, Issue: 423 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 10 14:10:02 2007
Date: Thu, 10 May 2007 11:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 10 May 2007 Volume: 11 Number: 423
Today's topics:
ANNOUNCE: OOPS 0.2002 released - major revision <muir@idiom.com>
Any way to access global variable in Perl script from o <Michael.Yxf@gmail.com>
Re: Any way to access global variable in Perl script fr (Jens Thoms Toerring)
Re: Any way to access global variable in Perl script fr <Michael.Yxf@gmail.com>
Re: Any way to access global variable in Perl script fr (Jens Thoms Toerring)
Re: Any way to access global variable in Perl script fr <nobull67@gmail.com>
Re: Any way to access global variable in Perl script fr <Michael.Yxf@gmail.com>
Re: Any way to access global variable in Perl script fr <Michael.Yxf@gmail.com>
Re: Any way to access global variable in Perl script fr <nobull67@gmail.com>
Data structure problem to solve Linux memory fault <dalyea@gmail.com>
Re: Determine whether a thread is still running in Perl xhoster@gmail.com
Forcing CPAN to ncftp?? <drawson1.take.this.out@earthlink.dot.net>
Re: Forcing CPAN to ncftp?? <spamtrap@dot-app.org>
How do I create a new text file with utf-8 encoding bk@docstream.no
Re: How do I create a new text file with utf-8 encoding <jurgenex@hotmail.com>
Re: How do I create a new text file with utf-8 encoding <nobull67@gmail.com>
Re: I'd like to create an array of unique values <nobull67@gmail.com>
Re: parsing a variable length record from a mixed forma <tadmc@augustmail.com>
Re: Please give me a good "rule-of-thumb" for back-slas <tadmc@augustmail.com>
Re: Please give me a good "rule-of-thumb" for back-slas <mritty@gmail.com>
Re: Please give me a good "rule-of-thumb" for back-slas <baxter.brad@gmail.com>
Reason for specified Error Occurence <ranjitmaddipatla@gmail.com>
Re: Reason for specified Error Occurence <thepoet_nospam@arcor.de>
warnings dilemma <socyl@987jk.com.invalid>
Re: warnings dilemma <nobull67@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 May 2007 16:16:34 GMT
From: David Muir Sharnoff <muir@idiom.com>
Subject: ANNOUNCE: OOPS 0.2002 released - major revision
Message-Id: <JHu32o.sDt@zorch.sf-bay.org>
OOPS is a persistent store for perl data. It handles most
kinds of perl objects (including oddities like references to
hash values). The data is stored with a relational backend
and is (potentially) querriable with SQL.
Version 0.2002 is a major release. It includes important
bugfixes (bugs found in production use with the outbound
mail quarantine: Qpsmtpd::Plugin::Quarantine). It adds a
garbage collector so that if you leak persistent data you
can recover the space (OOPS::GC).
Get it from CPAN.
http://search.cpan.org/~muir/OOPS/lib/OOPS.pod
-Dave
--
------------------------------
Date: 10 May 2007 01:03:31 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Any way to access global variable in Perl script from one module file?
Message-Id: <1178784211.214735.265260@e51g2000hsg.googlegroups.com>
I want to access one global variable saved in the main script from
another one module. Here is what it looks like:
A.pl: the main program, with one variable, e.g., $var, declared as
global.
#!/usr/bin/perl
use strict;
use warnings;
use B;
our $var = "hello";
testB();
B.pm: the module file, from which I want to access the $var variable
in A.pl
#!/usr/bin/perl
package B;
use strict;
use warnings;
require "A.pl"; ###########Actually I don't like this way, due
to some problem
sub testB{
print "In B.pm, the variable is $var\n";
############Here I want the $var value in A.pl be accessible.
}
Is there a way doing this like in C language, we just need to declare
it in B.pm, that the $var has been defined elsewhere, so it won't be
checked during compile time but in runtime.
The reason I don't want use 'require' statement, is the A.pl will be
evaluated. But I only need it to check the declaration and assignment
of the variable $var.
Thanks all.
------------------------------
Date: 10 May 2007 09:30:03 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Any way to access global variable in Perl script from one module file?
Message-Id: <5ag70rF2ocr5pU1@mid.uni-berlin.de>
Michael Yang <Michael.Yxf@gmail.com> wrote:
> I want to access one global variable saved in the main script from
> another one module. Here is what it looks like:
> A.pl: the main program, with one variable, e.g., $var, declared as
> global.
> #!/usr/bin/perl
> use strict;
> use warnings;
> use B;
> our $var = "hello";
> testB();
> B.pm: the module file, from which I want to access the $var variable
> in A.pl
> #!/usr/bin/perl
> package B;
> use strict;
> use warnings;
> require "A.pl"; ###########Actually I don't like this way, due
> to some problem
> sub testB{
> print "In B.pm, the variable is $var\n";
> ############Here I want the $var value in A.pl be accessible.
> }
> Is there a way doing this like in C language, we just need to declare
> it in B.pm, that the $var has been defined elsewhere, so it won't be
> checked during compile time but in runtime.
If you have A.pl
#!/usr/bin/perl
use strict;
use warnings;
use Bxx;
our $var = "hello";
Bxx::testB();
and Bxx.pm (I changed the name since there's already a packet called B)
#!/usr/bin/perl
package Bxx;
use strict;
use warnings;
sub testB{
print "In B.pm, the variable is $main::var\n";
}
1;
it simply works;-) The 'main::' if front of the variable name
tells that it's defined in the main package. If 'A' would be
another package instead you would need 'use A;' at the start
and would have to qualify '$var' with 'A::' in front of it,
i.e. as '$A::var'.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: 10 May 2007 03:29:37 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Re: Any way to access global variable in Perl script from one module file?
Message-Id: <1178792977.064823.246700@y5g2000hsa.googlegroups.com>
On May 10, 5:30 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> Michael Yang <Michael....@gmail.com> wrote:
> > I want to access one global variable saved in the main script from
> > another one module. Here is what it looks like:
> > A.pl: the main program, with one variable, e.g., $var, declared as
> > global.
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> > use B;
> > our $var = "hello";
> > testB();
> > B.pm: the module file, from which I want to access the $var variable
> > in A.pl
> > #!/usr/bin/perl
> > package B;
> > use strict;
> > use warnings;
> > require "A.pl"; ###########Actually I don't like this way, due
> > to some problem
> > sub testB{
> > print "In B.pm, the variable is $var\n";
> > ############Here I want the $var value in A.pl be accessible.
> > }
> > Is there a way doing this like in C language, we just need to declare
> > it in B.pm, that the $var has been defined elsewhere, so it won't be
> > checked during compile time but in runtime.
>
> If you have A.pl
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Bxx;
>
> our $var = "hello";
> Bxx::testB();
>
> and Bxx.pm (I changed the name since there's already a packet called B)
>
> #!/usr/bin/perl
> package Bxx;
> use strict;
> use warnings;
>
> sub testB{
> print "In B.pm, the variable is $main::var\n";
>
> }
>
> 1;
>
> it simply works;-) The 'main::' if front of the variable name
> tells that it's defined in the main package. If 'A' would be
> another package instead you would need 'use A;' at the start
> and would have to qualify '$var' with 'A::' in front of it,
> i.e. as '$A::var'.
> Regards, Jens
> --
> \ Jens Thoms Toerring ___ j...@toerring.de
> \__________________________ http://toerring.de
Thanks for your information.It really helps.
But does it work with indirect invoking?
For example:
If I have one A.pl same as the one you gave, but in A.pl:
I invoked another script "C.pl", in which the testB is called.
A.pl:
#!/usr/bin/perl
use strict;
use warnings;
our $var = "hello";
my @output = `perl C.pl`;
C.pl:
#!/usr/bin/perl
use strict;
use warnings;
use Bxx;
Bxx::testB();
In this way, the $main:: refers to the script invoking the module's
functions, that is C.pl here rather than A.pl.
Is it due to the sub-process?
Thanks.
------------------------------
Date: 10 May 2007 11:56:01 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Any way to access global variable in Perl script from one module file?
Message-Id: <5agfihF2om6fqU1@mid.uni-berlin.de>
Michael Yang <Michael.Yxf@gmail.com> wrote:
> But does it work with indirect invoking?
> For example:
> If I have one A.pl same as the one you gave, but in A.pl:
> I invoked another script "C.pl", in which the testB is called.
> A.pl:
> #!/usr/bin/perl
> use strict;
> use warnings;
> our $var = "hello";
> my @output = `perl C.pl`;
> C.pl:
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Bxx;
> Bxx::testB();
> In this way, the $main:: refers to the script invoking the module's
> functions, that is C.pl here rather than A.pl.
> Is it due to the sub-process?
This won't work because from A.pl you start a completely new
child process that knows nothing about any variables set in
the parent process that spawned it. In the example with the
original A.pl and Bxx.pm you had a single process and the
separation into A.pl and Bxx.pm is only something on source
code level, when the script get started, everything gets put
together. But if you start a program via backticks the ope-
rating system creates a process with its own memory and that
has no access to the memory of the parent process. Thus in
this case you somehow have to pass the value of '$var' to
the new process, the simplest method probably being via
command line arguments.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: 10 May 2007 04:59:41 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Any way to access global variable in Perl script from one module file?
Message-Id: <1178798381.517071.169900@q75g2000hsh.googlegroups.com>
On May 10, 11:29 am, Michael Yang <Michael....@gmail.com> wrote:
> On May 10, 5:30 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>
>
>
> > Michael Yang <Michael....@gmail.com> wrote:
> > > I want to access one global variable saved in the main script from
> > > another one module.
> > > Is there a way doing this like in C language, we just need to declare
> > > it in B.pm, that the $var has been defined elsewhere, so it won't be
> > > checked during compile time but in runtime.
>
> > it simply works;-) The 'main::' if front of the variable name
> > tells that it's defined in the main package. If 'A' would be
> > another package instead you would need 'use A;' at the start
> > and would have to qualify '$var' with 'A::' in front of it,
> > i.e. as '$A::var'.
> Thanks for your information.It really helps.
> But does it work with indirect invoking?
> For example:
> If I have one A.pl same as the one you gave, but in A.pl:
> I invoked another script "C.pl", in which the testB is called.
> A.pl:
> #!/usr/bin/perl
> use strict;
> use warnings;
> our $var = "hello";
> my @output = `perl C.pl`;
>
> C.pl:
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Bxx;
> Bxx::testB();
>
> In this way, the $main:: refers to the script invoking the module's
> functions, that is C.pl here rather than A.pl.
> Is it due to the sub-process?
Yes, a separate process has a completely separate memory space. This
is exactly the same as if one executable written in C called another -
they wouldn't share variables either.
There is a special variable %ENV that can carry information from
parent to child but not the other way.
I suspect you have an XY problem here. Can you explain what you are
trying to achieve? There is probably no reason to create a new perl
instance. Unless A.pl is a test harness for C.pl then C.pl should
probably just be another module.
------------------------------
Date: 10 May 2007 05:38:43 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Re: Any way to access global variable in Perl script from one module file?
Message-Id: <1178800723.343792.5710@y80g2000hsf.googlegroups.com>
On May 10, 7:59 pm, Brian McCauley <nobul...@gmail.com> wrote:
> On May 10, 11:29 am, Michael Yang <Michael....@gmail.com> wrote:
>
>
>
>
>
> > On May 10, 5:30 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
>
> > > Michael Yang <Michael....@gmail.com> wrote:
> > > > I want to access one global variable saved in the main script from
> > > > another one module.
> > > > Is there a way doing this like in C language, we just need to declare
> > > > it in B.pm, that the $var has been defined elsewhere, so it won't be
> > > > checked during compile time but in runtime.
>
> > > it simply works;-) The 'main::' if front of the variable name
> > > tells that it's defined in the main package. If 'A' would be
> > > another package instead you would need 'use A;' at the start
> > > and would have to qualify '$var' with 'A::' in front of it,
> > > i.e. as '$A::var'.
> > Thanks for your information.It really helps.
> > But does it work with indirect invoking?
> > For example:
> > If I have one A.pl same as the one you gave, but in A.pl:
> > I invoked another script "C.pl", in which the testB is called.
> > A.pl:
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> > our $var = "hello";
> > my @output = `perl C.pl`;
>
> > C.pl:
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> > use Bxx;
> > Bxx::testB();
>
> > In this way, the $main:: refers to the script invoking the module's
> > functions, that is C.pl here rather than A.pl.
> > Is it due to the sub-process?
>
> Yes, a separate process has a completely separate memory space. This
> is exactly the same as if one executable written in C called another -
> they wouldn't share variables either.
>
> There is a special variable %ENV that can carry information from
> parent to child but not the other way.
>
> I suspect you have an XY problem here. Can you explain what you are
> trying to achieve? There is probably no reason to create a new perl
> instance. Unless A.pl is a test harness for C.pl then C.pl should
> probably just be another module.- Hide quoted text -
>
> - Show quoted text -
Thank you all!
I am designing a Test Harness for automation testing purpose.
The A.pl I mentioned is the entrance script of the harness, I call it
as main.pl here.
In main.pl, I need to call the invocant that is processing the jobs of
executing test cases, I call it Testrunner.pl here.
So it should be like this:
main.pl --------> Testrunner.pl ---------|---------------------
>case1.pm
($handler)
|---------------------->case2.pm
|---------------------->case3.pm
The $handler is a reference variable saved in the main.pl. I want it
be accessible from each case module, case1.pm, case2.pm, without
interference of Testrunner.pl. Because Testrunner.pl has been
finalized as the agent of running test jobs. I have to keep it
untouched.
What I only could do now is to modify the main.pl and case module
file. That's why I want to define the $handle as a global variable,
and want it be accessed from the module file.
How can I call Testrunner.pl from main.pl without spawning a separate
child process? If it is a possibility, in this way, the solution Jens
gave will work by $main::handler.
Thanks
Michael
------------------------------
Date: 10 May 2007 05:45:11 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Re: Any way to access global variable in Perl script from one module file?
Message-Id: <1178801111.626096.235140@y5g2000hsa.googlegroups.com>
>
> main.pl --------> Testrunner.pl ---------|--------------------->case1.pm
>
> ($handler)
> |---------------------->case2.pm
>
> |---------------------->case3.pm
>
sorry for the ambiguity of this graph.
main.pl( $handler as its global variable) -------> Testrunner.pl -----
> (case1.pm, case2.pm, case3.pm)
Hope this would be clearer for understanding.
------------------------------
Date: 10 May 2007 10:07:06 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Any way to access global variable in Perl script from one module file?
Message-Id: <1178816826.268544.44760@o5g2000hsb.googlegroups.com>
On May 10, 1:38 pm, Michael Yang <Michael....@gmail.com> wrote:
> On May 10, 7:59 pm, Brian McCauley <nobul...@gmail.com> wrote:
> > I suspect you have an XY problem here. Can you explain what you are
> > trying to achieve? There is probably no reason to create a new perl
> > instance. Unless A.pl is a test harness for C.pl then C.pl should
> > probably just be another module.
> >
> I am designing a Test Harness for automation testing purpose.
> The A.pl I mentioned is the entrance script of the harness, I call it
> as main.pl here.
> In main.pl, I need to call the invocant that is processing the jobs of
> executing test cases, I call it Testrunner.pl here.
> The $handler is a reference variable saved in the main.pl. I want it
> be accessible from each case module, case1.pm, case2.pm, without
> interference of Testrunner.pl. Because Testrunner.pl has been
> finalized as the agent of running test jobs. I have to keep it
> untouched.
> What I only could do now is to modify the main.pl and case module
> file. That's why I want to define the $handle as a global variable,
> and want it be accessed from the module file.
The way you are using the term "global variable" is not the way it is
usually used in most languages. (You haven't been using MUMPS have
you?) Usually a global variable is only global within a given process.
> How can I call Testrunner.pl from main.pl without spawning a separate
> child process?
You could do() it. However this would possibly give odd effects if you
try to call Testrunner.pl more than once from main.pl. I say /
possibly/ because if Testrunner.pl has written following best
practices then it would probably run OK (and all you'd need to do is
suppress the subroutine redefined warning).
> If it is a possibility, in this way, the solution Jens
> gave will work by $main::handler.
Actually if Testrunner.pl already "thinks" that it "owns" main:: then
you should use another namespace.
------------------------------
Date: 10 May 2007 10:29:04 -0700
From: "dalyea@gmail.com" <dalyea@gmail.com>
Subject: Data structure problem to solve Linux memory fault
Message-Id: <1178818144.617422.38620@e51g2000hsg.googlegroups.com>
I am running into a memory fault error when processing the
contents of a database table into a lookup hash.
The problem is that I store item equivalencies (IE) in a db table IE
with primary key (a, b). a and b are integers and correspond
to productId values.
For IE products a and b, I insert as primary key (a, b) and, notably,
leave out (b, a). This obviously reduces the IE table size by 50%.
To build a single lookup data structure prior to writing to a lookup
file,
I try to create hash %ie which for each row has:
$ie{a}{b}=1;
$ie{b}{a}=1;
Then to get all the IE for a product a, one just looks at the slice
%ie{a} and gets all the values b1, b2, b3, ... for it.
The IE table has 1.4 million rows for 80,000 products, and sometimes
(b, a) is written [which is not a problem really]. When I create %ie,
it must
be upwards of 2.7 million rows, and hence, I am getting a memory fault
error.
The problem is, can I use a better (meaning smaller) data structure
to capture the IE data?
I could lookup each product's IE data as needed, but that would be
80,000+ single queries to the database. I don't even want to try
that.
Also, my algorithm for matching products as IE pretty much puts
all combinations of (a, b, c, d) in the table for products a b c d.
There are 4c2 or 6 combinations, not counting order, but up to 12
combinations if pairs such as (a, b) and (b, a) are entered. But it
is
possible that (a, b) and (b, c) exist, but not (a, c). Therefore, my
%ie
structure is technically incomplete as it is today. (Though I know
from the way I entered IE data that is probably 99% complete.)
The point is, a single query won't necessarily get all the IE data
for a single product. The whole data structure should be pre-loaded
all at once, as I'm trying to do.
Any ideas?
Thanks,
David
------------------------------
Date: 10 May 2007 16:40:08 GMT
From: xhoster@gmail.com
Subject: Re: Determine whether a thread is still running in Perl 5.8.8 with "interpreter threads"
Message-Id: <20070510124012.448$aB@newsreader.com>
Samuel <knipknap@gmail.com> wrote:
...
> How can I check whether a thread is still running? Note the comment in
> the code at "next unless $thread->running();".
Have you tried Thread::State or Thread::Running? I don't think I
understand the significance of 5.8.8 in your subject. Do you have a
solution that works with a newer (or older) perl?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 10 May 2007 07:49:36 -0400
From: Dan Rawson <drawson1.take.this.out@earthlink.dot.net>
Subject: Forcing CPAN to ncftp??
Message-Id: <46430482$0$9248$88260bb3@news.teranews.com>
Is there a way to prevent CPAN from using any method except ncftp??
I've got ncftp working through our firewall, but have consistent troubles
with Net::FTP and LWP. However, CPAN always starts out trying LWP, then
Net::FTP, then . . . .
'o conf' output doesn't show any specific variables related to either LWP or
Net::FTP. Other methods (wget, lynx) are off in the configuration.
Perl 5.8.4 on Solaris
Thanks!
Dan
------------------------------
Date: Thu, 10 May 2007 13:40:16 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Forcing CPAN to ncftp??
Message-Id: <m26470pofz.fsf@local.wv-www.com>
Dan Rawson <drawson1.take.this.out@earthlink.dot.net> writes:
> Is there a way to prevent CPAN from using any method except ncftp??
None that I know of.
> I've got ncftp working through our firewall, but have consistent
> troubles with Net::FTP and LWP.
Why not fix the troubles with Net::FTP? If your firewall requires passive
transfers, try setting the FTP_PASSIVE environment variable to non-zero.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 10 May 2007 05:37:39 -0700
From: bk@docstream.no
Subject: How do I create a new text file with utf-8 encoding
Message-Id: <1178800658.992029.23010@p77g2000hsh.googlegroups.com>
I use Activeperl version 5.8.8.817 on windows xp.
I try create a new text file and add some content but when I open it
in notepad, it says its a ansi encoded file. Why?
Here is my code snippit:
open my $fh, '>:encoding(UTF-8)', "testfile.txt";
print $fh "Welcome to Muppet Show\n";
close $fh;
What do I do wrong?
------------------------------
Date: Thu, 10 May 2007 14:05:09 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How do I create a new text file with utf-8 encoding
Message-Id: <pEF0i.6799$83.1506@trndny08>
bk@docstream.no wrote:
> I use Activeperl version 5.8.8.817 on windows xp.
>
> I try create a new text file and add some content but when I open it
> in notepad, it says its a ansi encoded file. Why?
>
> open my $fh, '>:encoding(UTF-8)', "testfile.txt";
> print $fh "Welcome to Muppet Show\n";
> close $fh;
>
> What do I do wrong?
Your sample text has the identical byte sequence in ASCII, Windows-1252 (aka
ANSI), UTF-8, ISO-Latin1, ISO-Latin15, and probably a dozen other encodings.
Therefore your sample is useless for testing for the correct encoding.
Notepad relies on the byte order mark (BOM) do identify Unicode files,
including UTF-8 where the BOM of course is meaningless and not used except
by Notepad itself. In not so many words: Notepad has no clue what it is
talking about. But for your sample text nor would any other tool.
Step 1: use some sample text that contains characters, that have different
code points in each encoding.
Step 2: don't use Notepad. Write to a (trivial) HTML file and then use a web
browser to view that file. There you can change the encoding and determine,
if those characters are displayed correctly for the desired encoding.
In over 8 years as software localization engineer and international program
manager this has proven to be the only practical and reliable way to
identify the actual encoding of a file.
jue
------------------------------
Date: 10 May 2007 10:59:57 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: How do I create a new text file with utf-8 encoding
Message-Id: <1178819997.485952.95100@l77g2000hsb.googlegroups.com>
On May 10, 3:05 pm, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> b...@docstream.no wrote:
> > I use Activeperl version 5.8.8.817 on windows xp.
>
> > I try create a new text file and add some content but when I open it
> > in notepad, it says its a ansi encoded file. Why?
>
> > open my $fh, '>:encoding(UTF-8)', "testfile.txt";
> > print $fh "Welcome to Muppet Show\n";
> > close $fh;
>
> > What do I do wrong?
>
> Your sample text has the identical byte sequence in ASCII, Windows-1252 (=
aka
> ANSI), UTF-8, ISO-Latin1, ISO-Latin15, and probably a dozen other encodin=
gs.
> Therefore your sample is useless for testing for the correct encoding.
>
> Notepad relies on the byte order mark (BOM) do identify Unicode files,
> including UTF-8 where the BOM of course is meaningless and not used except
> by Notepad itself.
You mean Windows not Notepad. Most Windows programs will recognise a
file with a utf8 BOM at the start as utf8.
In a situation where you've got a mixture of Windows-1252 and utf8
files knocking about then it's not a bad way to distinguish them. I'm
not saying I particularly liked Microsoft's unilateral adoption of BOM
in utf8 but I have to admit it makes the best of a bad job.
In Perl I'd like to be able to say something like
open my $fh, '>:encoding(UTF-8 BOM)', "testfile.txt";
But AFIAK I can't and I just have to
print $fh "\x{FEFF}"; # BOM
------------------------------
Date: 10 May 2007 01:18:48 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: I'd like to create an array of unique values
Message-Id: <1178785128.752667.229110@h2g2000hsg.googlegroups.com>
On May 9, 5:28 pm, Mirco Wahab <wahab-m...@gmx.de> wrote:
> @h{/(\w+)/g} = undef;
That is a list assignment so the RHS evaluates to a list containing a
single undef element.
Although that would work (as would _any_ list) it would be more
idiomatic to write:
@h{/(\w+)/g} = ();
------------------------------
Date: Thu, 10 May 2007 05:58:34 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: parsing a variable length record from a mixed format file
Message-Id: <slrnf45umq.4av.tadmc@tadmc30.august.net>
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
> chadmay@hotmail.com wrote:
> [ ... ]
>> Problem is solved now, Thanks John!
>
> What was the reason to quote the entire thread just to add a single line?
To cut down on the number of articles that I need to read.
:-(
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 10 May 2007 05:54:51 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Please give me a good "rule-of-thumb" for back-slashing in character classes
Message-Id: <slrnf45ufr.4av.tadmc@tadmc30.august.net>
Petr Vileta <stoupa@practisoft.cz> wrote:
> "Paul Lalli" <mritty@gmail.com> píse v diskusním príspevku
> news:1178723651.938407.63140@o5g2000hsb.googlegroups.com...
>> On May 9, 11:06 am, Mr P <MisterP...@gmail.com> wrote:
>> Second, the characters ], -, and ^ are special in a character class.
>> (Technically, ^ is only special if its the first character, however).
>
> Or ^ may be NOT in /abc[^abc]def/
^^
^^
You must have meant "and" instead of "or" because that is
how ^ is special when it is first in a character class,
just like Paul said...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 May 2007 04:01:56 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Please give me a good "rule-of-thumb" for back-slashing in character classes
Message-Id: <1178794916.463232.153760@h2g2000hsg.googlegroups.com>
On May 9, 10:12 pm, "Petr Vileta" <sto...@practisoft.cz> wrote:
> "Paul Lalli" <mri...@gmail.com> p=EDse v diskusn=EDm pr=EDspevkunews:1178=
723651.938407.63140@o5g2000hsb.googlegroups.com...
>
> > On May 9, 11:06 am, Mr P <MisterP...@gmail.com> wrote:
> > Second, the characters ], -, and ^ are special in a character class.
> > (Technically, ^ is only special if its the first character, however).
>
> Or ^ may be NOT in /abc[^abc]def/
Uhm, yes, that's how it's "special"....
Paul Lalli
------------------------------
Date: 10 May 2007 08:19:31 -0700
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: Please give me a good "rule-of-thumb" for back-slashing in character classes
Message-Id: <1178810371.805537.318430@y5g2000hsa.googlegroups.com>
On May 9, 11:06 am, Mr P <MisterP...@gmail.com> wrote:
> Sort of along the lines of : AIEOU and sometimes Y and W (is there
> really a case when W is a vowel I never did see one, but I digress)..
How now brown cow?
--
Brad
------------------------------
Date: 10 May 2007 07:58:49 -0700
From: Ranjit <ranjitmaddipatla@gmail.com>
Subject: Reason for specified Error Occurence
Message-Id: <1178809129.896591.266940@y5g2000hsa.googlegroups.com>
Hi Perl pals,
Could any one let us know the reason why the below error is showing
from this code.
ERROR :
Use of uninitialized value in subroutine entry at C:/Perl/lib/
Socket.pm line 373.
Bad arg length for Socket::pack_sockaddr_in, length is 0, should be 4
at C:/Perl/lib/Socket.pm line 373.
#!/usr/bin/perl
use Socket;
$proto = getprotobyname('tcp');
$domain = PF_INET;
$type = SOCK_STREAM;
socket(CLIENT,$domain,$type,$proto);
$port = 0 ;
$ipaddr = INADDR_ANY;
$sockaddr = sockaddr_in($port,$ipaddr);
bind(CLIENT,$sockaddr);
print "sathi";
$host = 'www.yahoo.com';
$port = getservbyname('http','tcp');
$ip_addr= inet_aton($host);
$sockaddr = sockaddr_in($port,$ip_addr);
connect(CLIENT,$sockaddr);
Thanks in Advance
Regards,
Ranjit
------------------------------
Date: Thu, 10 May 2007 18:02:26 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Reason for specified Error Occurence
Message-Id: <46434213$0$10183$9b4e6d93@newsspool4.arcor-online.net>
Ranjit wrote:
> Could any one let us know the reason why the below error is showing
> from this code.
>
> ERROR :
>
> Use of uninitialized value in subroutine entry at C:/Perl/lib/
> Socket.pm line 373.
> Bad arg length for Socket::pack_sockaddr_in, length is 0, should be 4
> at C:/Perl/lib/Socket.pm line 373.
>
>
> #!/usr/bin/perl
> use Socket;
> $proto = getprotobyname('tcp');
> $domain = PF_INET;
> $type = SOCK_STREAM;
> socket(CLIENT,$domain,$type,$proto);
>
> $port = 0 ;
> $ipaddr = INADDR_ANY;
> $sockaddr = sockaddr_in($port,$ipaddr);
> bind(CLIENT,$sockaddr);
> print "sathi";
>
> $host = 'www.yahoo.com';
> $port = getservbyname('http','tcp');
> $ip_addr= inet_aton($host);
> $sockaddr = sockaddr_in($port,$ip_addr);
> connect(CLIENT,$sockaddr);
Can you verify that the host your code is running on is able to
resolve www.yahoo.com?
-Chris
------------------------------
Date: Thu, 10 May 2007 16:28:51 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: warnings dilemma
Message-Id: <f1vh83$q8p$1@reader2.panix.com>
I've read the PODs (warnings, perllexwarn) but I still don't know
how to solve this problem. Here's a toy version of it.
First some random module:
# Foo.pm
package Foo;
use strict;
use warnings;
# calling foo() will result in an 'uninitialized' warning
sub foo { my %h; exists $h{ $_[ 0 ] } }
1;
__END__
The function Foo::foo represents one of those situtations in which
the author of the module, for whatever reason, has not taken steps
to avoid a default warning.
Next, my script
use strict;
use Foo;
{ no warnings; Foo::foo(); }
exit;
Now, despite the "no warnings" in the script, when I run it I still
get the "Use of initialized value in exists" warning.
I know that I can silence the warnings by setting $SIG{__WARN__}
in the script to a suitable handler, but this leads to parsing the
text of warning messages, which is an invitation for bugs, and
basically throws the nice warnings pragma warnings hierarchy out
the window. (If there's a way to define $SIG{__WARN__} to mimic
the effects of "no warnings 'foobar'" without having to parse
warning messages in order to *guess* whether a particular warning
belongs to the "foobar" category, please let me know.)
Of course, I could remove "use warnings" from Foo.pm (or pester
its author to do so), then the warnings would *never* show up even
if the script were changed to
use strict;
use Foo;
{ use warnings; Foo::foo(); }
exit;
This is not good. Why? Because module authors are fallible like
everyone else, and despite their best efforts, a situation warranting
a warning will slip through, so it is nice to make those warnings
visible. I.e. putting "use warnings" at the top of each module
file seems to me like a fine idea. Except that then the script
*can't* turn off warnings!
I am at a loss. It seems that either alternative (including "use
warnings" in Foo.pm or leaving it out) leads to an undesirable
behavior.
IMO, the calling executable should have the final say on which
warnings get emitted. Is there a way to do this without having to
resort to defining $SIG{__WARN__} and parsing warning messages?
Thanks!
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: 10 May 2007 10:41:28 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: warnings dilemma
Message-Id: <1178818888.039832.23680@y5g2000hsa.googlegroups.com>
On May 10, 5:28 pm, kj <s...@987jk.com.invalid> wrote:
> I've read the PODs (warnings, perllexwarn) but I still don't know
> how to solve this problem. Here's a toy version of it.
>
> First some random module:
>
> # Foo.pm
> package Foo;
> use strict;
> use warnings;
>
> # calling foo() will result in an 'uninitialized' warning
> sub foo { my %h; exists $h{ $_[ 0 ] } }
> 1;
>
> __END__
>
> The function Foo::foo represents one of those situtations in which
> the author of the module, for whatever reason, has not taken steps
> to avoid a default warning.
So you don't like something about the way the module works. Why is
this any different from anything else about the way the module works?
> Next, my script
>
> use strict;
> use Foo;
> { no warnings; Foo::foo(); }
> exit;
>
> Now, despite the "no warnings" in the script, when I run it I still
> get the "Use of initialized value in exists" warning.
That's right. That's the whole point of lexical scope. You can choose
one warning level in your script and the author of the module can
choose another without the two interacting.
> I know that I can silence the warnings by setting $SIG{__WARN__}
> in the script to a suitable handler, but this leads to parsing the
> text of warning messages, which is an invitation for bugs, and
> basically throws the nice warnings pragma warnings hierarchy out
> the window.
But if you objective is to break down the nice isolation that is
provided by lexically scoped warning control and want to fiddle with
warnings from another lexical scope then that's what you're stuck with
(AFAIK).
> (If there's a way to define $SIG{__WARN__} to mimic
> the effects of "no warnings 'foobar'" without having to parse
> warning messages in order to *guess* whether a particular warning
> belongs to the "foobar" category, please let me know.)
No the messages that passed to the $SIG{__WARN__} are just plain
strings they don't AFAIK have hidden information about the warning's
position in the hierarchy.
Anyhow I don't get it - I thought you wanted to filter out warning
that came from the module Foo, not warnings of a particular category.
> Of course, I could remove "use warnings" from Foo.pm (or pester
> its author to do so), then the warnings would *never* show up even
> if the script were changed to
>
> use strict;
> use Foo;
> { use warnings; Foo::foo(); }
> exit;
>
> This is not good. Why? Because module authors are fallible like
> everyone else, and despite their best efforts, a situation warranting
> a warning will slip through, so it is nice to make those warnings
> visible. I.e. putting "use warnings" at the top of each module
> file seems to me like a fine idea. Except that then the script
> *can't* turn off warnings!
Bugs in the module show up in the module. They are fixed by fixing the
module. Why is this a problem?
> I am at a loss. It seems that either alternative (including "use
> warnings" in Foo.pm or leaving it out) leads to an undesirable
> behavior.
You could, of course, edit the module do the right thing.
sub foo { my %h; no warnings 'uninitialized'; exists $h{ $_[ 0 ] } }
This gets rid of the warning and serves as a comment that the author
is intentionally treating undef as '' in the remainder of the block.
> IMO, the calling executable should have the final say on which
> warnings get emitted.
That's why $SIG{__WARN__} is still useful.
> Is there a way to do this without having to
> resort to defining $SIG{__WARN__} and parsing warning messages?
Well the alternative is to redirect STDERR.
{
local *STDERR;
open STDERR, '>', '/dev/null'; # IIRC /dev/null is special-cased
Foo::foo();
}
Note this won't stop warnings that are sent directly to FD2 by
subprocesses or non-Perl libraries. To intercept those see (my
contributions to) numerous previous threads on the subject of
capturing STDERR.
------------------------------
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 V11 Issue 423
**************************************