[24077] in Perl-Users-Digest
Perl-Users Digest, Issue: 6272 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 18 03:05:40 2004
Date: Thu, 18 Mar 2004 00:05:08 -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 Thu, 18 Mar 2004 Volume: 10 Number: 6272
Today's topics:
Re: Double interpolatioin?? <tassilo.parseval@rwth-aachen.de>
Empty hash key produces funky results <aaron@deloachcorp.com>
Re: Empty hash key produces funky results <uri@stemsystems.com>
Re: Empty hash key produces funky results <aaron@deloachcorp.com>
Re: Empty hash key produces funky results <uri@stemsystems.com>
Re: Empty hash key produces funky results <aaron@deloachcorp.com>
Re: Empty hash key produces funky results <uri@stemsystems.com>
Re: Empty hash key produces funky results <devnull@example.com>
Re: Empty hash key produces funky results <mgjv@tradingpost.com.au>
Re: Empty hash key produces funky results (Bunny)
Re: Empty hash key produces funky results <aaron@deloachcorp.com>
Re: format printing <krahnj@acm.org>
Heavy processing in tie routines <devnull@example.com>
Re: Heavy processing in tie routines <tassilo.parseval@rwth-aachen.de>
HOW TO PARSE A VAST FILE! <luke@program.com.tw>
Re: HOW TO PARSE A VAST FILE! <todd@tdegruyl.com>
Re: List Scalar Hash question <tassilo.parseval@rwth-aachen.de>
Re: NT task <invalid-email@rochester.rr.com>
Re: Our Robin has flown the nest <matthew.garrish@sympatico.ca>
Perl script to transfer file via https (c0rum_z)
perl2exe can't locate DBI.pm (Bunny)
Re: perl2exe can't locate DBI.pm <todd@tdegruyl.com>
Re: Retrieving text between 2 tags. (Anno Siegel)
Re: Retrieving text between 2 tags. <krahnj@acm.org>
Re: seek help with regular expressions syntax <invalid-email@rochester.rr.com>
Re: stripping out ASCII chars using regexp? <invalid-email@rochester.rr.com>
Variable interpolation in regular expressions <dave@nospam.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Mar 2004 07:39:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Double interpolatioin??
Message-Id: <c3bjmu$kad$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Michael Watts:
> I have seen a scenario like the following work before but I cannot
> remember the exact syntax. Does anyone know how to get this to work?
>
> Say you have the following variables:
> $num1;
> $num2;
> $num3;
>
> then you have a for loop with an $i incrementer.
>
> I have seen something like the following that would allow you to loop
> through your $num variables and allow the $i to interpolate to the
> integer value that is on the variable name. Something like $num{$i} .
>
> What would happen is the $i is interpolated and the integer value
> would be placed next to the $num and the corrisponding $num would then
> be interpolated to its value.
>
> Any help would be greatly appreciated.
Others have provided an answer. But have you considered using a hash
for that? Or, since the suffix is numeric, an array even?
my @num;
...
for (0 .. 3) {
$num[$_] = ...;
...
}
Another benefit is that you can easily iterate over all variables
conveniently:
for (@num) {
...
}
Symbolic references have their place, but I doubt that it is to be found
in your program.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 17 Mar 2004 21:45:39 -0600
From: "Aaron DeLoach" <aaron@deloachcorp.com>
Subject: Empty hash key produces funky results
Message-Id: <pZednexwuc58hsTdRVn-gw@eatel.net>
Consider the following (an empty key value):
my $str = &test('1',"one", '2',"two", '3',, '4',"four");
print $str;
sub test
{
my %in = @_;
my ($str, $k, $v);
while (($k,$v)=each %in)
{
if ($v)
{
$str.="$k=>$v\n";
}
}
return $str;
}
Outputs the following:
1=>one
3=>4
2=>two
My question?
How can this be fixed?
------------------------------
Date: Thu, 18 Mar 2004 04:21:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Empty hash key produces funky results
Message-Id: <x78yhyg501.fsf@mail.sysarch.com>
>>>>> "AD" == Aaron DeLoach <aaron@deloachcorp.com> writes:
AD> Consider the following (an empty key value):
AD> my $str = &test('1',"one", '2',"two", '3',, '4',"four");
where did you get the idea that there is an empty key?
that is not a hash there but a list. and ,, in a list is the same as ,
so you have a key of 3 with a value of '4' and a key of 'four' which is
ignored since you provided no value for it.
AD> Outputs the following:
AD> 1=>one
AD> 3=>4
AD> 2=>two
AD> My question?
AD> How can this be fixed?
by not writing broken code. again, where did you read/learn that ,,
means an empty value?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 17 Mar 2004 22:35:28 -0600
From: "Aaron DeLoach" <aaron@deloachcorp.com>
Subject: Re: Empty hash key produces funky results
Message-Id: <Ru-dnRTj_fqJusTd4p2dnA@eatel.net>
Well explain this:
1=>"one", 2=>"two", 3=>, 4=>"four";
Let's say: 3=>param('some_param') - where "some_param" had no value or
didn't exist.
Produces the same output:
1=>one
3=>4
2=>two
Don't get so uptight (at least you read that way). :-)
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x78yhyg501.fsf@mail.sysarch.com...
> >>>>> "AD" == Aaron DeLoach <aaron@deloachcorp.com> writes:
>
> AD> Consider the following (an empty key value):
> AD> my $str = &test('1',"one", '2',"two", '3',, '4',"four");
>
> where did you get the idea that there is an empty key?
>
> that is not a hash there but a list. and ,, in a list is the same as ,
>
> so you have a key of 3 with a value of '4' and a key of 'four' which is
> ignored since you provided no value for it.
>
> AD> Outputs the following:
>
> AD> 1=>one
> AD> 3=>4
> AD> 2=>two
>
> AD> My question?
>
> AD> How can this be fixed?
>
> by not writing broken code. again, where did you read/learn that ,,
> means an empty value?
>
> uri
>
> --
> Uri Guttman ------ uri@stemsystems.com --------
http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and
Coding-
> Search or Offer Perl Jobs ----------------------------
http://jobs.perl.org
------------------------------
Date: Thu, 18 Mar 2004 04:50:47 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Empty hash key produces funky results
Message-Id: <x74qsmg3mk.fsf@mail.sysarch.com>
>>>>> "AD" == Aaron DeLoach <aaron@deloachcorp.com> writes:
AD> Well explain this:
AD> 1=>"one", 2=>"two", 3=>, 4=>"four";
AD> Let's say: 3=>param('some_param') - where "some_param" had no value or
AD> didn't exist.
and why would that be any different? what is =>? why would it change
things?
AD> Don't get so uptight (at least you read that way). :-)
i am not uptight. i just asked pointed questions to make you think. and
i want to know how/where you learned this misguided information so i can
avoid recommending it to anyone.
and finally don't top post. read the regularly posted guidelines
<snip of ENTIRE quoted message>
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 17 Mar 2004 23:01:25 -0600
From: "Aaron DeLoach" <aaron@deloachcorp.com>
Subject: Re: Empty hash key produces funky results
Message-Id: <u_2dnSKOQaS7sMTdRVn-gQ@eatel.net>
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x74qsmg3mk.fsf@mail.sysarch.com...
> >>>>> "AD" == Aaron DeLoach <aaron@deloachcorp.com> writes:
>
> AD> Well explain this:
> AD> 1=>"one", 2=>"two", 3=>, 4=>"four";
>
> AD> Let's say: 3=>param('some_param') - where "some_param" had no value
or
> AD> didn't exist.
>
> and why would that be any different? what is =>? why would it change
> things?
That's why I'm asking a question. Looking for an answer to something I
don't understand.
How would one compensate for the empty/missing param in the example above?
I don't know?
>
> AD> Don't get so uptight (at least you read that way). :-)
>
> i am not uptight. i just asked pointed questions to make you think. and
> i want to know how/where you learned this misguided information so i can
> avoid recommending it to anyone.
I didn't learn this from anywhere. Thanks for your attempt to help out.
Regards,
Aaron
>
> and finally don't top post. read the regularly posted guidelines
>
> <snip of ENTIRE quoted message>
>
> uri
>
> --
> Uri Guttman ------ uri@stemsystems.com --------
http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and
Coding-
> Search or Offer Perl Jobs ----------------------------
http://jobs.perl.org
------------------------------
Date: Thu, 18 Mar 2004 05:09:58 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Empty hash key produces funky results
Message-Id: <x71xnqg2qh.fsf@mail.sysarch.com>
>>>>> "AD" == Aaron DeLoach <aaron@deloachcorp.com> writes:
AD> "Uri Guttman" <uri@stemsystems.com> wrote in message
AD> news:x74qsmg3mk.fsf@mail.sysarch.com...
>> >>>>> "AD" == Aaron DeLoach <aaron@deloachcorp.com> writes:
>>
AD> Well explain this:
AD> 1=>"one", 2=>"two", 3=>, 4=>"four";
>>
AD> Let's say: 3=>param('some_param') - where "some_param" had no value
AD> or
AD> didn't exist.
>>
>> and why would that be any different? what is =>? why would it change
>> things?
AD> That's why I'm asking a question. Looking for an answer to something I
AD> don't understand.
AD> How would one compensate for the empty/missing param in the example above?
AD> I don't know?
explain compensate? you DON'T have a value there. you can't compensate
for it. you need to put a value there.
and answer my question. why do you think that is a valid list for a hash
assignment? where did you get the idea an empty value can be used?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 18 Mar 2004 13:33:23 +0800
From: Derek Fountain <devnull@example.com>
Subject: Re: Empty hash key produces funky results
Message-Id: <40593481$0$22528$5a62ac22@freenews.iinet.net.au>
Aaron DeLoach wrote:
> Consider the following (an empty key value):
>
> my $str = &test('1',"one", '2',"two", '3',, '4',"four");
Have a look at 'perldoc perldata' where you will find this explanation:
This interpolation combines with the facts that the open-
ing and closing parentheses are optional (except when nec-
essary for precedence) and lists may end with an optional
comma to mean that multiple commas within lists are legal
syntax. The list "1,,3" is a concatenation of two lists,
"1," and 3, the first of which ends with that optional
comma. "1,,3" is "(1,),(3)" is "1,3" (And similarly for
"1,,,3" is "(1,),(,),3" is "1,3" and so on.) Not that
we'd advise you to use this obfuscation.
If you want your list to have a key/value pair with a key of '3' and no
value, stick 'undef' between the commas. undef isn't really 'no value' but
it's as close as you'll get... :o)
------------------------------
Date: 18 Mar 2004 05:44:55 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Empty hash key produces funky results
Message-Id: <slrnc5idql.jqf.mgjv@verbruggen.comdyn.com.au>
On Wed, 17 Mar 2004 21:45:39 -0600,
Aaron DeLoach <aaron@deloachcorp.com> wrote:
> Consider the following (an empty key value):
>
> my $str = &test('1',"one", '2',"two", '3',, '4',"four");
That is not an empty key value. Two commas in a list is the same as
one comma. And to answer your question in another post in this thread,
the => operator is just a comma with some special behaviour (read the
perlop documentation to find out more about this).
If you want an "empty" value, you need to put one there.
my $str = test('1', 'one', '2', 'two', '3', '', '4', 'four');
or maybe
my $str = test('1', 'one', '2', 'two', '3', undef, '4', 'four');
also note that I fixed the way in which you call the subroutine. You
shouldn't use an ampersand when calling a subroutine, unless you
really mean to invoke the special behaviour that implies (read perlsub
to find out what that is).
> sub test
> {
> my %in = @_;
> my ($str, $k, $v);
> while (($k,$v)=each %in)
> {
> if ($v)
> {
> $str.="$k=>$v\n";
> }
> }
> return $str;
> }
If you have an "empty" value for the key 3, the output will be
1=>one
2=>two
4=>four
since you deliberately skip the ones with a false value. But I guess
that's the idea, right?
Martien
PS. Perl documentation is available with the perldoc tool (perldoc
perldoc at any command line), or maybe as HTML if you've installed a
Perl distribution that comes with HTML documentation.
--
|
Martien Verbruggen |
Trading Post Australia | Curiouser and curiouser, said Alice.
|
------------------------------
Date: 17 Mar 2004 23:22:54 -0800
From: bunny1112@yahoo.com (Bunny)
Subject: Re: Empty hash key produces funky results
Message-Id: <d4a4789a.0403172322.528e0b02@posting.google.com>
"Aaron DeLoach" <aaron@deloachcorp.com> wrote in message news:<pZednexwuc58hsTdRVn-gw@eatel.net>...
> Consider the following (an empty key value):
>
> my $str = &test('1',"one", '2',"two", '3',, '4',"four");
>
> print $str;
>
> sub test
> {
> my %in = @_;
> my ($str, $k, $v);
> while (($k,$v)=each %in)
> {
> if ($v)
> {
> $str.="$k=>$v\n";
> }
> }
> return $str;
> }
>
> Outputs the following:
>
> 1=>one
> 3=>4
> 2=>two
>
>
> My question?
>
> How can this be fixed?
set the empty value for three like below
my $str = &test('1',"one", '2',"two", '3',"", '4',"four");
this would give the output as
1=>one
2=>two
4=>four
And if you want the key three also to be displayed
set this
> if ($v)
to if($k)
hope you got it fixed??
Bunny
------------------------------
Date: Thu, 18 Mar 2004 01:42:48 -0600
From: "Aaron DeLoach" <aaron@deloachcorp.com>
Subject: Re: Empty hash key produces funky results
Message-Id: <ENidnQUIQLxpz8TdRVn-sw@eatel.net>
I found a solution to the problem. Thought I might share it.
I was assigning parameter values to a hash like so:
1=>param('one'), 2=>param('two') ... and so on.
The problem arised when a parameter didn't exist - or - it had no value (see
the post below).
The solution:
1=>param('one')||"", 2=>param('two')||"" ... and so on.
This way at least a "" value was being inserted into the hash.
"Aaron DeLoach" <aaron@deloachcorp.com> wrote in message
news:pZednexwuc58hsTdRVn-gw@eatel.net...
> Consider the following (an empty key value):
>
> my $str = &test('1',"one", '2',"two", '3',, '4',"four");
>
> print $str;
>
> sub test
> {
> my %in = @_;
> my ($str, $k, $v);
> while (($k,$v)=each %in)
> {
> if ($v)
> {
> $str.="$k=>$v\n";
> }
> }
> return $str;
> }
>
> Outputs the following:
>
> 1=>one
> 3=>4
> 2=>two
>
>
> My question?
>
> How can this be fixed?
>
>
>
>
------------------------------
Date: Thu, 18 Mar 2004 05:08:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: format printing
Message-Id: <40592E8E.EECAE06F@acm.org>
Brian wrote:
>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c3989q$9vt$1@mamenchi.zrz.TU-Berlin.DE>...
> > Brian <leetiger_cn@hotmail.com> wrote in comp.lang.perl.misc:
> > > Hello everyono
> > > Here is a question, how to print out the elements of a array according
> > > to a format? For example, print out the arry consists of float
> > > numbers, 6 numbers in every line?
> >
> > What do you mean by "format"? A Perl format in the technical sense?
> > A printf format? Something else? Do you just want lines of six each,
> > or should the columns be aligned? Do you want a fixed field width,
> > or should the width adapt to the data? Should there be separators
> > between the columns?
> >
> > Explain what you want to do. Here is how to print an array @x in
> > groups of six:
> >
> > print join( ", ", splice @x, 0, 6), "\n" while @x;
> >
> > If you want more, say what it is you want.
>
> Thanks Anno, What I want is just lines of six each and the columns be
> right aligned and a fixed field width,say f12.3. I try to use printf
> but I can not control the lines of six each
> for ($id=0; $id<100; $id++)
> printf '%12.3f',"$num[$id]";
>
> I will check if splice works.
You could do it with a for loop:
for ( my $id = 0; $id < $#num; $id += 6 ) {
printf '%12.3f' x 6 . "\n", @num[ $id .. $id + 5 ];
}
Or you could do it with splice:
printf '%12.3f' x 6 . "\n", splice @num, 0, 6 while @num;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 18 Mar 2004 11:31:56 +0800
From: Derek Fountain <devnull@example.com>
Subject: Heavy processing in tie routines
Message-Id: <4059180b$0$22506$5a62ac22@freenews.iinet.net.au>
Is there any limit, enforced or just practical, to the amount of work I can
do in the STORE subroutine of a hash's tie object?
I have a large data set in a hash and need to do some serious processing on
it whenever it changes (or at least when key parts of it change). The
processing will involve lots of CPU and updates being pushed down sockets
and written to files amongst other things. Because of the way the code is
laid out, doing this processing with a tie would work really nicely and
make the job relatively simple.
Can I expect any problems further down the road if I put this processing
into a tie object?
------------------------------
Date: 18 Mar 2004 07:34:05 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Heavy processing in tie routines
Message-Id: <c3bjdd$jib$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Derek Fountain:
> Is there any limit, enforced or just practical, to the amount of work I can
> do in the STORE subroutine of a hash's tie object?
>
> I have a large data set in a hash and need to do some serious processing on
> it whenever it changes (or at least when key parts of it change). The
> processing will involve lots of CPU and updates being pushed down sockets
> and written to files amongst other things. Because of the way the code is
> laid out, doing this processing with a tie would work really nicely and
> make the job relatively simple.
>
> Can I expect any problems further down the road if I put this processing
> into a tie object?
Not at all. For a tied hash, perl transforms
$tied{ key } = "value";
into
tied(%tied)->STORE(qw/key value/);
Now it's just an ordinary method call. Any method can be arbitrarily
complex. Naturally, a tied hash is slower than a non-tied counterpart.
But it can't be so slow that perl couldn't handle it.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 18 Mar 2004 15:08:18 +0800
From: "news.hinet.net" <luke@program.com.tw>
Subject: HOW TO PARSE A VAST FILE!
Message-Id: <c3bhtk$hmn@netnews.hinet.net>
I must parse 500M's logfile!
How to do this job while speed up.
Someone can give me good idea for this job.
Split file to small one and use fork to do that or
other method can make good result.
ps: its spend 3 hours to complete now!
------------------------------
Date: Thu, 18 Mar 2004 07:45:02 GMT
From: Todd de Gruyl <todd@tdegruyl.com>
Subject: Re: HOW TO PARSE A VAST FILE!
Message-Id: <190oi1-9l8.ln1@espresso.tdegruyl.com>
news.hinet.net wrote:
> I must parse 500M's logfile!
EEEK! the horror! Does the file have to grow that huge? Is it a
standard log format, with new records being appended to the bottom of
the file? If so, I would suggest that you (or appeal to the powers that
be) split the file up, and save the parsed data from the pieces that
will not change (that is, the parts of the file that are not the one
being appeneded to). That would cut the process down to a managable
size if it is done on a reasonable basis. All of this only makes sense
if the log isn't being generated in its entirety between each running of
the parser.
> How to do this job while speed up.
> Someone can give me good idea for this job.
> Split file to small one and use fork to do that or
> other method can make good result.
YMMV depending on what kind of processor(s) you are running the process
on, your disk setup, etc, whether fork()ing will do any good. All i
can suggest is try it and see.
> ps: its spend 3 hours to complete now!
How often does the job run?
What else is involved?
What's the bottleneck? (disk access? the parsing subs? trying to slurp a
500MB file?) Without further info, it is difficult to help.
--
Todd de Gruyl
todd@tdegruyl.com
http://www.tdegruyl.com
------------------------------
Date: 18 Mar 2004 07:14:12 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: List Scalar Hash question
Message-Id: <c3bi84$g4j$1@nets3.rz.RWTH-Aachen.DE>
Also sprach moller@notvalid.se:
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> writes:
>
>> Also sprach moller@notvalid.se:
>>
>> > Please look at my small example below.
>> >
>> > Why does @cdir get an extra undefined element in
>> > the first assignment?
>> >
>> > ActiveState perl v5.6.1
>> >
>> > #### Prog start
>> > use strict;
>> > use warnings;
>> >
>> > my %UserID;
>> >
>> > $UserID{ '(000883)' }{ dir } = ();
>>
>> This is the same as
>>
>> $UserID{ '(000883)' }{ dir } = undef;
>>
>> > my @cdir = $UserID{ '(000883)' }{ dir }; # First assignment
>>
>> And here you copy the previous undef into @cdir. It will now be the
>> first element.
>>
>> > warn scalar @cdir; # Prints 1
>>
>> That's because @cdir contains one element which is undef.
>>
>> > push @cdir, 'usr';
>> >
>> > warn join "/",@cdir; # This gives the following error:
>> > # "Use of uninitialized value in join
>> > # or string at news.pl line 14."
>> > # And it prints /usr
>>
>> As a matter of fact, it's only a warning. It happens because one of the
>> two elements that you want to join together is undef.
>>
>> > warn scalar @cdir; # Prints 2
>> > pop @cdir;
>> > warn scalar @cdir; # Prints 1
>> >
>> >
>> > @cdir = (); # Second assignment
>>
>> This assigns the empty list. After that @cdir will be empty. Note the
>> difference between an empty array and an array that contains one
>> undefined value.
>>
>> > warn scalar @cdir; # Prints 0
>> > push @cdir, 'usr';
>> > warn join "/",@cdir; # Works as I expect prints usr
>>
>> You don't get a warning here because all elements in @cdir (there is
>> only one) are defined.
>>
>> > warn scalar @cdir; # Prints 1
>> > pop @cdir;
>> > warn scalar @cdir; # Prints 0
>>
>> Maybe this post is a good example why sometimes spurious initialization
>> (when done improperly) can harm. We had this discussion recently.
>
> Do you remember the subject so that I can google for it?
The thread started with ID <FoL3c.7518$xL3.215@bignews1.bellsouth.net>.
Subject was "variable initialization question".
> What should I do instead? Should I test to see if the hash is undefined
> and then use an empty list instead?
Yes:
my @cdir = defined $UserID{'(000883)'}{ dir }
? $UserID{'(000883)'}{ dir }
: ();
Another way would be:
my @cdir;
if (defined $UserID{'(000883)'}{ dir }) {
push @cdir, $UserID{'(000883)'}{ dir };
}
Or you just assign regardless of definedness, and later nuke all
undefined values from the @array:
my @cdir = $UserID{'(000883)'}{ dir };
...
@cdir = grep defined, @cdir;
I'd probably go for the latter as it is less to type and doesn't clutter
the initialization process. "$UserID{'(000883)'}{ dir }" is a pretty
long hash subscript which I would try to avoid using too often.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 18 Mar 2004 02:43:36 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: NT task
Message-Id: <40590CD7.5090706@rochester.rr.com>
Andy Cook wrote:
> I have a scheduled job that runs daily, via the NT task scheduler. It does
> various functions and has to run with admin permission. This is NT 4.0 SP
> 6.
>
> Now what I want is way of firing this off via the WEB site residing on that
> sever, (so I can run it on demand) but when I have my perl script fire the
> task off, it fails. I've already changed the permissions, but it's still
> failing.
>
> Everthing is written in perl, of course. I know I could stash a bit of data
> somewhere and have a task run every five miuntes to pick it up, and use that
> as the trrigger. But if could actually run the script via the web page, I
> could pick up the output and script through the process using LWP.
>
> And ideas why my website can't run my Script? Any ideas how to debug it?
...
Well, you don't say what web server you are running or how it is
configured. Check to see what user your web server is running as (I
*hope* it isn't an admin user -- that would be almost as big a security
hole as running on Windoze is to start with). Since your script needs
to run as a user with admin authority, you will need to figure out how
to fire up a program so it is running with admin authority from a
program which is not running with admin authority. That is much more of
an OS issue than a Perl issue -- you might check on NT user groups to
see if that can be done. In any event, mind your security P's and Q's
if you actually carry this through -- it sounds risky.
You might be able to use NT's "at" command to cause your
existing scheduled task to start running via the web server.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Wed, 17 Mar 2004 23:51:19 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Our Robin has flown the nest
Message-Id: <7V96c.6579$QY2.206655@news20.bellglobal.com>
"Kirk Strauser" <kirk@strauser.com> wrote in message
news:87lllzgv27.fsf@strauser.com...
> OK, I really don't want to be a jerk, but I just couldn't resist this
"where
> are they now?" update. Something reminded me of our young acolyte, Robin,
> and his attempts to learn Perl without actually having to learn Perl.
>
> His web board (yes, he really put it online):
>
> http://www.infusedlight.net/design/bbs/bbs.pl?action=view&user=sysop
>
> Choice quote:
>
> "post: I think this board is awesome. Props to robin for his amazing
cgi
> skills, and self-props to me for the style sheet."
I have no idea what props means, but I find their self-congratulatory
posting amusing. To keep the laughs going, I tried to "log on" to his page
using robin/robin. Guess what... (I sure hope he didn't set up that
account!)
> OK, I know it's not cool to pick on the new guy but can't help it. I
guess
> I feel kind of bad that the only thing he got from his brief stay here was
> the belief that he can make a living writing Perl web boards for paying
> clients.
Come now, we all have dreams... : )
Matt
------------------------------
Date: 17 Mar 2004 23:47:58 -0800
From: c0rum_z@yahoo.com (c0rum_z)
Subject: Perl script to transfer file via https
Message-Id: <dcfb988b.0403172347.2951410e@posting.google.com>
Hi all,
I'm just very new to perl and I would like to transfer file from a
unix machine to a web server with a servlet that could accept file
Is there any available script that I could use?
rgds,
c0rum_z
------------------------------
Date: 17 Mar 2004 22:38:02 -0800
From: bunny1112@yahoo.com (Bunny)
Subject: perl2exe can't locate DBI.pm
Message-Id: <d4a4789a.0403172238.6aa57367@posting.google.com>
Hi!
I have perl5.00503 loaded on my Linux and I have downloaded and loaded
perl2exe V1.09U on Linux 6.1
I have written a small code for extracting data from database. Now my
perl script runs fine and an appropriate output is also rendered by
the web browser.
My perl file
#######################newsample.pl###################################
#!/usr/bin/perl
use strict;
use CGI qw(:standard);
use DBI;
my $dbh=DBI->connect("dbi:mysql:test2","root") or die "Cannot connect
to the database:$!";
my $usr="select * from table where username='bunny'";
my $pa1=$dbh->prepare($usr);
my $rv=$pa1->execute;
my @rows;
my $num_fields;
print header;
while(@rows=$pa1->fetchrow_array)
{
$num_fields=@rows;
print "Total number of fields : $num_fields <br>";
for(my $i=0;$<$num_fields;$i++)
{
print "$i - $rows[$1] <br>";
}
}
$dbh->disconnect();
###############################################################
But when I try creating an executable using perl2exe
I am getting -----
"This is an evaluation version of Perl2Exe, which may be used for 30
days.
For more information see the attached pxman.htm file,
or viist http://www.perl2exe.com
Converting 'newsample.pl' to newsample
Compiling newsample.pl
Warning module DBI.pm not found
Compiling .../perl2exe/perl5/lib/5.00503/strict.pm
Compiling .../perl2exe/perl5/lib/5.00503/CGI.pm
Compiling .../perl2exe/perl5/lib/5.00503/overload.pm
Compiling .../perl2exe/perl5/lib/5.00503/i686-linux/Config.pm
Compiling .../perl2exe/perl5/lib/5.00503/CGI/Apache.pm
Compiling .../perl2exe/perl5/lib/5.00503/CGI/Cookie.pm
Compiling .../perl2exe/perl5/lib/5.00503/shellwords.pl
Compiling .../perl2exe/perl5/lib/5.00503/exporter.pm
Compiling .../perl2exe/perl5/lib/5.00503/vars.pm
Compiling .../perl2exe/perl5/lib/5.00503/Carp.pm
"
The error displayed in logs is
"
Can't locate DBI.pm in @INC (@INC contains: PERL2EXE_STORAGE /tmp
lib\site ~../cgi-bin/lib/5.00503/i686-linux
~.../cgi-bin/lib/site_perl/5.005/i686-linux
~../cgi-bin/lib/site_perl/5.005 .) at newsample.pl line 4.
BEGIN failed--compilation aborted at newsample.pl line 4.
"
################################################################
Can any one help me out how to make the DBI available to perl2exe to
create binary executables???????????
thanx
bunny
------------------------------
Date: Thu, 18 Mar 2004 07:30:02 GMT
From: Todd de Gruyl <todd@tdegruyl.com>
Subject: Re: perl2exe can't locate DBI.pm
Message-Id: <elvni1-1k8.ln1@espresso.tdegruyl.com>
Bunny wrote:
> I have perl5.00503 loaded on my Linux and I have downloaded and loaded
> perl2exe V1.09U on Linux 6.1
<nitpicking>
I can't answer the question, but I am a little bit confused about what
you are running:
According to <http://kernel.org/> the latest stable version of linux is
2.6.4, so either you're running some fifteen years or so in the future,
or you're looking at the wrong number (perhaps your distribution release
number? IIRC Red Hat had a popular 6.1 release from about the same time
as the perl you're running)
Also, you might want to upgrade your perl, perl5.005_03.tar.gz is from
29-Mar-1999, we're up to 5.8.3 (stable), or 5.9.0 (dev)
</nitpicking>
--
Todd de Gruyl
todd@tdegruyl.com
http://www.tdegruyl.com
------------------------------
Date: 18 Mar 2004 05:01:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Retrieving text between 2 tags.
Message-Id: <c3baed$ij8$1@mamenchi.zrz.TU-Berlin.DE>
James Taylor <spam-block-@-SEE-MY-SIG.com> wrote in comp.lang.perl.misc:
> In article <c3a5e6$s6j$1@mamenchi.zrz.TU-Berlin.DE>,
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> >
> > The brute-force approach is simple: Slurp the file and do a capturing
> > match.
> >
> > my $begin = qr!:70E::ADTX//!;
> > my $end = qr/:16S|:95Q/; # two alternatives
> >
> > # /m not needed for these patterns, but perhaps for others
> > my ( $content) = do { local $/; <DATA> } =~ ^/$begin(.*?)$end/sm;
>
> Shouldn't the $end pattern be in grouping brackets like this?:
>
> my $end = qr/(?::16S|:95Q)/; # two alternatives
The grouping is necessary, the brackets aren't. A qr/.../ expression
implies a pair of grouping parentheses:
perl -le 'print qr/aaa|bbb/'
(?-xism:aaa|bbb)
Anno
------------------------------
Date: Thu, 18 Mar 2004 05:50:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Retrieving text between 2 tags.
Message-Id: <4059385C.BA86CE77@acm.org>
v796 wrote:
>
> Hi,
>
> This is beyond me. Maybe you can help.
>
> I am parsing a text file in PERL. Contents are
>
> ...
> :70E::ADTX//ABCS
> text
> text
> XYZ
> :16S:stuff OR :95Qstuff
> ...
> ...
>
> Now I have found the tag ':70E::ADTX//'
> This tag is followed by text and other tags on one or more lines.
> Eventually we will reach ':16S' or ':95Q'
> I want all the text between the // and the tag ':16S' or ':95Q',
> whichever is *earlier*
> The text may span multiple lines and the closing tags may not be at
> the start of a newline.
>
> So I need ABCS to XYZ stored in 1 scalar variable $myText.
You could do it like this:
while ( <DAT> ) {
if ( s!^:70E::ADTX//!! ) {
$_ .= <DAT> until s!^:(?:16S:|95Q).*?\z!!sm;
last;
}
}
$myText = $_;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 18 Mar 2004 02:28:57 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: seek help with regular expressions syntax
Message-Id: <40590968.2000002@rochester.rr.com>
Mad Scientist Jr wrote:
...
> i am trying to do a replace in HTML of all instances of
> <LI><FONT FACE="Times New Roman" SIZE="3" COLOR="#000000"></FONT></LI>
>
> for all font faces, all sizes, and all colors
>
> with
>
> <P> </P>
>
> for instance, my document of
>
> abc
> <LI><FONT FACE="Times New Roman" SIZE="3" COLOR="#000000"></FONT></LI>
> 123
>
> would look like
>
> abc
> <P> </P>
> 123
>
> when replaced
>
> i think regular expressions is the way to go,
> but i am getting caught up in the syntax
>
> some formulas have tried to use:
>
> <LI><FONT FACE="*" SIZE="*" COLOR="*"></FONT></LI>
>
> \<LI\>\<FONT FACE="*" SIZE="*" COLOR="*"\>\</FONT\>\</LI\>
>
> \<LI\>\<FONT*FACE="*"*SIZE="*"*COLOR="*"\>\<\/FONT\>\<\/LI\>
>
...
> reg expressions seem a really important thing to know
> and if i can just get the basics down then i think i'll be ok
...
Well, the * metacharacter means to repeat the previous term (in your
case, a " character) zero or more times. That isn't what you want. Try
something like (all on one line):
s!<LI><FONT FACE="[^"]*" SIZE="[^"]*"
COLOR="[^"]*"></FONT></LI>!<P> </P>!i;
That assumes that your attributes are always " quoted, and that
there are never any " characters within those strings.
Also that the attributes always appear in the same order, always
are separated by a single space character, etc. In other words,
it's "brittle" code. Properly, you should parse the HTML,
perhaps with the HTML::Parser module, and deal with the results
of the parse.
For docs on regexp's, see:
perldoc perlre
and the tutorials pointed to there.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Thu, 18 Mar 2004 02:12:01 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: stripping out ASCII chars using regexp?
Message-Id: <40590571.7090607@rochester.rr.com>
Greg wrote:
> I am trying to get rid of the ASCII chars from the end of a string
> that I download from a webpage using LWP::Simple. The script downloads
> the HTML from a webpage and then uses HTML::TableExtract to extract
> the information from specific tables on the page.
>
> This basically gives me a string like this:
>
> ���,Temper Tantrum�,Take Care Comb Your
> Hair�,,,CD�,23.56��,�,0 Days
> Ago�,Scotla�
>
Could you give us the URL of an example web page? And the (minimal)
code that grabs it and runs HTML::TableExtract? That is so we can run
it ourselves and see what is really going on. For example, is the above
the exact literal string which is generated? For debugging, that is
important to know.
> which I then split into an array using:
>
> my @line = split (',', $line) ;
>
> I then do a comparison on $line [6]:
>
> if ($line [6] >= 75) {
>
> ... do something
>
> When I run this using -w, I get the following error:
That isn't an error -- it's a warning, is non-fatal, and is for your
edification.
>
> Argument "15.99M- M- " isn't numeric in numeric ge (>=) at
> ./parse_wants.pl line 49.
>
> This is because somehow some extended ASCII chars got in the end of
> the string. If I do:
>
> my @chars = split ('', $line [6]) ;
> foreach $char (@chars) {
> print "$char ";
> print ord ($char) ;
> print "\n" ;
> }
>
> It gives me
>
> 1 49
> 5 53
> . 46
> 9 57
> 9 57
> � 160
So $char has the value '�' from the execution of
split('',$line[6])? That shouldn't (couldn't?) be. Again, some way to
sample your actual data and actual code would help tons. Also in this
case, the '160' is coming from whatever the first character of $char is.
> � 160
>
> I have tried stripping off these trailing ASCII 160 chars a number of
> ways:
>
> s/\240//g
You mean, I assume:
$char=~s/\240//g;
right? And etc below.
> s/[\200-\377]//g
> tr/\177-\377//d
> s/\�//g
>
> but the only way I could get rid of them was using:
>
> chop $line [6]
> chop $line [6]
>
> Can anyone figure out a way to get rid of these trailing ASCII
> characters using a regular expression?
Access to some real sample data would be a big help in that regard.
Another approach would be to use a regexp that matches everything you
*want* to see and ignores the rest. Maybe something like:
if($line[6]=~m/(\d+\.?\d*)/){
$line[6]=$1;
}
else{
die "Oops, wipeout due to bad number blah blah ...";
}
...
> Greg
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Thu, 18 Mar 2004 00:24:26 -0500
From: Dave <dave@nospam.com>
Subject: Variable interpolation in regular expressions
Message-Id: <405932a4$0$2838$61fed72c@news.rcn.com>
I realize that this "gotcha" has been discussed here ad nauseum
(verified by Google), but I don't understand why the Camel book says:
"Since patterns are processed as double-quoted strings, the normal
double-quoted interpolations will work." (Page 60 of Programming Perl,
2nd Ed.)
Wouldn't it be more appropriate to say that they're subject to "double
interpolation," for lack of better words? In a double quoted string, a
scalar variable is substituted by its value; however, that value is not
subject to interpolation itself. In a regular expression, the pattern
is also substituted by its corresponding value, but the resulting value
is *also* subject to interpolation.
Example:
my $string1 = 'A\n single\n quoted\n string\n';
print "\$string1 prints \"A\\n single\\n quoted\\n string\\n\" as one
would expect: $string1\n";
$_ = $string1;
print "This won't print\n" if m/$string1/;
print "But this will\n" if m/\Q$string1/;
So, how is it that "patterns are processed as double-quoted strings?"
I'm not trying to split hairs; I just want to understand why my logic
does not seem to agree with that statement, with the hope of avoiding
needless traps further down the road.
Thanks.
Dave
------------------------------
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 6272
***************************************