[22607] in Perl-Users-Digest
Perl-Users Digest, Issue: 4828 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 10 18:06:20 2003
Date: Thu, 10 Apr 2003 15:05:09 -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 Apr 2003 Volume: 10 Number: 4828
Today's topics:
Re: A better way to extract a substring? Thanks. <fcanton@rei.edu>
A better way to extract a substring? <fcanton@rei.edu>
Re: A better way to extract a substring? <noreply@gunnar.cc>
Re: A better way to extract a substring? <ddunham@redwood.taos.com>
Re: A better way to extract a substring? <grazz@nyc.rr.com>
Re: A better way to extract a substring? <jurgenex@hotmail.com>
a Perl script complete newbe (Remove NOSPAM to replly)
Re: a Perl script complete newbe <noreply@gunnar.cc>
Re: a Perl script complete newbe <jurgenex@hotmail.com>
compare elements of n lists (banjo)
Re: compare elements of n lists (Jay Tilton)
Convert curses screen output to space-delimited text ou <sean@deletethistorespond.seanoneill.deletethistorespond.info>
Re: Deep Recursion problem in Win32 clipboard.pm <tassilo.parseval@rwth-aachen.de>
extract the first word in a string (Raj Thejaswi)
Re: extract the first word in a string <grazz@nyc.rr.com>
Re: hashes as lists (Sara)
Re: How it wipe out or delete or init an array? <spam@jimryan.com>
Re: irregular expression ? (Tad McClellan)
Re: irregular expression ? <ericosman@rcn.com>
Re: irregular expression ? <jurgenex@hotmail.com>
Re: irregular expression ? (Jay Tilton)
list of parameter files based on date input <robw@linkline.com>
mod_perl uses old values in subroutines (Tom Cat)
Re: mod_perl uses old values in subroutines <noreply@gunnar.cc>
Re: mod_perl uses old values in subroutines <rgarciasuarez@free.fr>
Re: Piping Perl output through nroff? <nospam@raytheon.com>
Re: Ugly code; what does it do? <michael.p.broida@boeing.com>
Re: Ugly code; what does it do? <michael.p.broida@boeing.com>
Re: Using Eval Statement To Trap Module Not Present Fat <lyvoise@aol.com>
Re: Weird behavior of PERL counter (Pablo Rodriguez)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 Apr 2003 21:16:30 GMT
From: "federico" <fcanton@rei.edu>
Subject: Re: A better way to extract a substring? Thanks.
Message-Id: <Oalla.4941$2x2.2338733@dca1-nnrp1.news.algx.net>
This is what I am talking about! Thank you all.
federico
"federico" <fcanton@rei.edu> wrote in message
news:WTila.4927$2x2.2329774@dca1-nnrp1.news.algx.net...
> I am new to Perl. I am currently using this line to remove the quotes
> around a string:
>
> if ($line =~ /^\'/ && $line =~ /\'$/){$line = substr $line, 1, (length
> $line) - 2};
>
> As the code indicates, the quotes should be removed only when they are
found
> at both ends of the string.
>
> I am liking Perl, and I feel there must be a more elegant or economical
way
> of doing this.
>
> Would anyone please teach me how?
>
> Thank you very much.
>
> federico
>
>
------------------------------
Date: Thu, 10 Apr 2003 18:39:50 GMT
From: "federico" <fcanton@rei.edu>
Subject: A better way to extract a substring?
Message-Id: <WTila.4927$2x2.2329774@dca1-nnrp1.news.algx.net>
I am new to Perl. I am currently using this line to remove the quotes
around a string:
if ($line =~ /^\'/ && $line =~ /\'$/){$line = substr $line, 1, (length
$line) - 2};
As the code indicates, the quotes should be removed only when they are found
at both ends of the string.
I am liking Perl, and I feel there must be a more elegant or economical way
of doing this.
Would anyone please teach me how?
Thank you very much.
federico
------------------------------
Date: Thu, 10 Apr 2003 21:29:37 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: A better way to extract a substring?
Message-Id: <b74h6s$b4qcb$1@ID-184292.news.dfncis.de>
federico wrote:
> I am new to Perl. I am currently using this line to remove the quotes
> around a string:
>
> if ($line =~ /^\'/ && $line =~ /\'$/){$line = substr $line, 1, (length
> $line) - 2};
>
> As the code indicates, the quotes should be removed only when they are found
> at both ends of the string.
>
> I am liking Perl, and I feel there must be a more elegant or economical way
> of doing this.
You'd better use the s/// operator:
$line =~ s/^'(.*)'$/$1/;
http://www.perldoc.com/perl5.8.0/pod/perlre.html
http://www.perldoc.com/perl5.8.0/pod/perlop.html
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 10 Apr 2003 19:41:44 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: A better way to extract a substring?
Message-Id: <YNjla.644$485.35308790@newssvr21.news.prodigy.com>
federico <fcanton@rei.edu> wrote:
> I am new to Perl. I am currently using this line to remove the quotes
> around a string:
> if ($line =~ /^\'/ && $line =~ /\'$/){$line = substr $line, 1, (length
> $line) - 2};
> As the code indicates, the quotes should be removed only when they are found
> at both ends of the string.
> I am liking Perl, and I feel there must be a more elegant or economical way
> of doing this.
Nothing particularly wrong there. But since you're invoking regular
expressions for the match, you can use them for the modification, too.
$line =~ s/^\'(.*)\'$/$1/;
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Thu, 10 Apr 2003 19:51:27 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: A better way to extract a substring?
Message-Id: <3Xjla.1816$TR5.1502@twister.nyc.rr.com>
federico <fcanton@rei.edu> wrote:
> I am new to Perl. I am currently using this line to remove
> the quotes around a string:
[ line-wrapping fixed ]
> if ($line =~ /^\'/ && $line =~ /\'$/) {
> $line = substr $line, 1, (length $line) - 2
> };
You don't need a semicolon after the block;
>
> As the code indicates, the quotes should be removed only when
> they are found at both ends of the string.
>
> I am liking Perl, and I feel there must be a more elegant or
> economical way of doing this.
$line =~ s/^'(.*)'$/$1/s;
And a slightly more complicated regular expression will let you
match single quotes or double quotes:
$line =~ s/^(['"])(.*)\1$/$2/s;
HTH
--
Steve
------------------------------
Date: Thu, 10 Apr 2003 20:29:48 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: A better way to extract a substring?
Message-Id: <0vkla.49298$aQ3.13567@nwrddc02.gnilink.net>
federico wrote:
> I am new to Perl. I am currently using this line to remove the quotes
> around a string:
>
> if ($line =~ /^\'/ && $line =~ /\'$/){$line = substr $line, 1, (length
> $line) - 2};
>
> As the code indicates, the quotes should be removed only when they
> are found at both ends of the string.
You may want to RTFM: "perldoc -q space"
"How do I strip blank space from the beginning/end of a string?"
Just replace 'space' with 'quote' and you got your answer.
jue
------------------------------
Date: Thu, 10 Apr 2003 20:27:36 GMT
From: zathross@NOSPAMjuno.com (Remove NOSPAM to replly)
Subject: a Perl script complete newbe
Message-Id: <3e95d3ae.8809635@news2.wwnet.net>
Greetings,
I want to automate a process.
I have a script that I believe will do the job.
The site says to run the .pl script from a command prompt.
I run Windows 98
When I run the script I get bad command or fie name error.
I realize that Windows doesn't know how to run Perl Script but I
believe Internet Explorer 6 runs Perl scripts when I surf the web. I
dunno.
What do I need to do, to be able to run Perl scripts from a command
prompt?
Thanks
Jay
------------------------------
Date: Thu, 10 Apr 2003 22:23:59 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: a Perl script complete newbe
Message-Id: <b74kd5$a7ell$1@ID-184292.news.dfncis.de>
Remove NOSPAM to replly wrote:
> What do I need to do, to be able to run Perl scripts from a command
> prompt?
A wild guess: Install the Perl interpreter. :)
Tip: http://www.indigostar.com/indigoperl.htm
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 10 Apr 2003 21:16:50 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: a Perl script complete newbe
Message-Id: <6blla.50248$aQ3.41747@nwrddc02.gnilink.net>
Remove NOSPAM to replly wrote:
[Same stuff as in another NG]
Would you please stop multi-posting?
jue
------------------------------
Date: 10 Apr 2003 12:29:35 -0700
From: c_sheehanuk@hotmail.com (banjo)
Subject: compare elements of n lists
Message-Id: <59387f51.0304101129.b9480f7@posting.google.com>
I'm a beginner at perl and have a confusing (for me) problem.
I have an array of n list references, lets say n = 3.
list1 = a b c d e f g h i j k l
list2 = b g h k p
list3 = c d g x y z
I need to compare the elements of each list, with the elements
of the largest list. The result of the compare and list sorting
needs to be:
list1 = a b c d e f g h i j k l
list2 = b g h k p
list3 = c d g x y z
what is the simplest method for comparing and sorting (bearing
in mind im a beginner :)
Do i compare elements of list2 one at a time with list1 and
unshift the array with empty values? and push values of list2
that don't appear in list1..... and so on with list3?
To be honest I'm not sure at all what is the best way to approach
this so any help is appreciated.
thx
------------------------------
Date: Thu, 10 Apr 2003 21:49:00 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: compare elements of n lists
Message-Id: <3e95ddde.99418228@news.erols.com>
c_sheehanuk@hotmail.com (banjo) wrote:
: I'm a beginner at perl and have a confusing (for me) problem.
:
: I have an array of n list references,
What's a list reference? Do you mean array references?
: lets say n = 3.
:
: list1 = a b c d e f g h i j k l
: list2 = b g h k p
: list3 = c d g x y z
:
: I need to compare the elements of each list, with the elements
: of the largest list.
What do you mean by "compare?" Are you looking for the intersection
of two lists? The difference of two lists?
The information in perlfaq4, "How do I compute the difference of two
arrays? How do I compute the intersection of two arrays?" may be
useful.
: The result of the compare and list sorting
: needs to be:
:
: list1 = a b c d e f g h i j k l
: list2 = b g h k p
: list3 = c d g x y z
Not sure how to interpret that. Whitespace may or may not be
significant to your meaning. Try writing it in real Perl, e.g.
@list1 = ('a','b','c','d','e','f','g','h','i','j','k','l');
@list2 = ( ... );
@list3 = ( ... );
Perhaps this approximates what you want:
#!perl -l
use warnings;
use strict;
my @foo = (
[qw/a b c d e f g h i j k l/],
[qw/b g h k p/],
[qw/c d g x y z/],
);
my %seen;
for my $c ( 0 .. $#foo ) {
$seen{$_} |= 1<<$c for @{$foo[$c]};
}
my @bar;
for my $c ( 0 .. $#foo ) {
$bar[$c] = [
map $seen{$_} & 1<<$c ? $_ : ' ', sort keys %seen
];
}
print "@$_" for @bar;
------------------------------
Date: Thu, 10 Apr 2003 22:44:46 GMT
From: Sean O'Neill <sean@deletethistorespond.seanoneill.deletethistorespond.info>
Subject: Convert curses screen output to space-delimited text output ?
Message-Id: <sgpb9v4c1up553okvve3clg1fjki4ieddr@4ax.com>
Does anyone know of a modules or combo of modules that will take
curses screen output and convert it to space-delimited text output ?
Basically, this:
^[[1;40r^[[m^[[?7h^[[H^[[J^[[6Cusers Load^M^[[2BMem:KB
REAL^[[3;27HVIRTUAL^[[21CVN PAGER SWAP PAGER^[[4;9HTot
Share^[[6CTot Share Free^[[9Cin out in
out^M^[[BAct^[[43Ccount^M^[[BAll^[[43Cpages^[[7;59Hzfod
Interrupts^M^[[BProc:r p d s w Csw Trp Sys Int Sof
Flt^[[8Ccow^[[9Ctotal^[[9;59Hwire^[[B^H^H^H^Hact^M^[[B . %Sys .
%Intr . %User . %Nice . %Idle^[[9Cinact^M^[[B| | | |
| | | | | | |^[[7Ccache^[[13;59H
to this:
users Load 0.11 0.20 0.24 Apr 10 16:19
Mem:KB REAL VIRTUAL VN PAGER SWAP
PAGER
Tot Share Tot Share Free in out in
out
Act 46432 13140 186304 104904 14180 count
Any thoughts or ideas appreciated :)
------------------------------
Date: 10 Apr 2003 18:56:26 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Deep Recursion problem in Win32 clipboard.pm
Message-Id: <b74eoq$k0t$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Phil Hibbs:
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<b5n1v5$r6r$1@nets3.rz.RWTH-Aachen.DE>...
>> And in this case he has to reinstall the module since a missing
>> constant() functions suggests that the XS portion of the module either
>> isn't there or is not properly loaded by DynaLoader.
> I don't understand that - I didn't install perl, it came as part of
> another package. I don't know what an XS or a Dynaloader is.
XS refers to a sort of mini-language that is used to write Perl modules
that interact with C code. They define the interface between Perl and C
in both directions in a rather declarative way and add all the C code
that is necessary to do the conversion between the different types.
Installing modules that contain XS code requires a C compiler.
DynaLoader is then used to dynamically load such a module from Perl.
XS-modules compile to DLLs (or .so files on Linux for instance) so there
must be a mechanism to access these shared libraries.
Things can more easily go wrong with XS than pure-Perl so perhaps your
setup somehow changed without your noticing it. Reinstalling the
components in question is often a solution in such a case.
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: 10 Apr 2003 12:18:28 -0700
From: thejaswi@hotmail.com (Raj Thejaswi)
Subject: extract the first word in a string
Message-Id: <a19b3874.0304101118.64e8a866@posting.google.com>
I have many strings like
"Settled Date:04/30/02BostonSale"
"Settled Date:04/30/02New YorkSale"
"Settled Date:04/30/02San FranciscoSale"
Can someone help me figure out how I can get "Boston","New York","San
Francisco"
into a variable ?
I am chopping of "Settled Date" and "Sale" from the string using
substr() with index(), since these two strings are constant. My
problem is in extracting the words from what is left:
04/30/02Boston"
05/15/02New York"
02/17/03San Francisco"
Thanks in advance,
- RT
------------------------------
Date: Thu, 10 Apr 2003 19:33:59 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: extract the first word in a string
Message-Id: <HGjla.1685$mC1.689928@twister.nyc.rr.com>
Raj Thejaswi <thejaswi@hotmail.com> wrote:
> I have many strings like
> "Settled Date:04/30/02BostonSale"
> "Settled Date:04/30/02New YorkSale"
> "Settled Date:04/30/02San FranciscoSale"
> Can someone help me figure out how I can get "Boston","New York","San
> Francisco"
> into a variable ?
Use a regular expression:
while (<DATA>) {
next unless /\d{2}([\w ]+)Sale$/;
print "Matched [$1]\n";
}
__END__
Settled Date:04/30/02BostonSale
Settled Date:04/30/02New YorkSale
Settled Date:04/30/02San FranciscoSale
There's a good introduction here:
$ perldoc perlrequick
--
Steve
------------------------------
Date: 10 Apr 2003 11:20:19 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: hashes as lists
Message-Id: <776e0325.0304101020.20b6e59f@posting.google.com>
Eric Wilhelm <ericw@nospam.ku.edu> wrote in message news:<pan.2003.04.10.07.52.06.315922.23897@nospam.ku.edu>...
> Perl never ceases to amaze me.
>
> %a = (%b, %c);
>
> When I needed to join two hashes, I thought I would have to write
> something like:
>
> foreach $key (keys(%b)) {
> $a{$key}=$b{$key};
> }
> foreach $key (keys(%c)) {
> $a{key}=$b{$key};
> }
>
> But then I realized that that would be clumsy and stupid for more than
> two hashes, so there must be a better way. Lo and behold, there is!
>
> --Eric
Homer's voice: "DOH!" <slaps forehead>
Why didn't *I* think of that.. ack
Thanks Eric, although seemingly obvious, these little hints can be
invaluable!
Along the same lines, something I picked up in like my 5th re-read of
Camel:
%h = reverse %h
makes the keys of %h the values and visa versa..
Treating hashes with list-type ops can be very handy indeed and leads
to some succint syntax.
-Gx
------------------------------
Date: Thu, 10 Apr 2003 16:18:17 -0400
From: "jtpr" <spam@jimryan.com>
Subject: Re: How it wipe out or delete or init an array?
Message-Id: <b74jia$b4p2k$1@ID-181664.news.dfncis.de>
Thanks all, I got it.
-Jim
"Jeff D Gleixner" <glex_nospam@qwest.net> wrote in message
news:vqgla.436$Aa.37815@news.uswest.net...
> jtpr wrote:
> > If I have an array @array that has a bunch of stuff in it, how can I
"zero
> > it out" so to speak? So I can reuse it.
>
> @array=();
> or
> undef @array;
>
------------------------------
Date: Thu, 10 Apr 2003 14:07:27 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: irregular expression ?
Message-Id: <slrnb9bg7f.406.tadmc@magna.augustmail.com>
[ Please don't top-post again. ]
Eric Osman <ericosman@rcn.com> wrote:
> Tad McClellan wrote:
>> Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
>>>Also sprach Eric Osman:
>>
>>
>>>>However, I didn't find it in perldoc
>>>See 'perldoc perlfunc' => "Perl Functions by Category".
>> Or, you can run this one-liner:
>>
>> perl -ne 'print if /^=item/' `perldoc -l perlfunc` | more
> No, it's not as simple as that.
Yes, it is as simple as that.
> I'm on xp not unix :
That's too bad.
I don't use Windows, so I can't translate it for your shell.
> >perl -ne 'print if /^=item/' `perldoc -l perlfunc` | more
> Can't find string terminator "'" anywhere before EOF at -e line 1.
If you do not know how to modify it for your "operating system",
then modify it into a Perl program instead of a one-liner
----------------------------
#!/usr/bin/perl
use strict;
use warnings;
@ARGV = `perldoc -l perlfunc`;
while ( <> ) {
print if /^=item/;
}
----------------------------
and remove the need for OS-specific knowledge altogether.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 10 Apr 2003 14:29:11 -0400
From: Eric Osman <ericosman@rcn.com>
Subject: Re: irregular expression ?
Message-Id: <3E95B7F7.8040501@rcn.com>
what's your objection to "top posting" ?
I like to read top posting because then I don't have to wade through all
the old stuff in order to read new stuff.
It would be great if the news reader (I'm using netscape what are you
using ?) had the ability to merely show the succession of new postings
rather than repeating all the quoted material at all.
Such a feature seems years overdue.
/Eric
------------------------------
Date: Thu, 10 Apr 2003 21:06:21 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: irregular expression ?
Message-Id: <h1lla.50073$aQ3.27124@nwrddc02.gnilink.net>
Eric Osman wrote:
> what's your objection to "top posting" ?
> I like to read top posting because then I don't have to wade through
> all the old stuff in order to read new stuff.
You remember all the 'old' stuff from some 100-200 postings daily?
Wow, impressive. Unfortunately that fast majority of earth population does
not have such an incredible memory.
> It would be great if the news reader (I'm using netscape what are you
> using ?) had the ability to merely show the succession of new postings
> rather than repeating all the quoted material at all.
> Such a feature seems years overdue.
That feature exists. It is called "sensible quoting by the honorable
usenaut".
If you quote only the relevant parts of the posting you are replying to then
typically your posting will fit on a single page. No need to wade through
anything.
jue
------------------------------
Date: Thu, 10 Apr 2003 21:51:24 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: irregular expression ?
Message-Id: <3e95e6e6.101730609@news.erols.com>
Eric Osman <ericosman@rcn.com> wrote:
: what's your objection to "top posting" ?
:
: I like to read top posting because then I don't have to wade through all
: the old stuff in order to read new stuff.
That's fine when you are writing for yourself.
In this case, you are writing for an audience, and the audience's
needs and desires deserve higher priority than your own.
------------------------------
Date: Thu, 10 Apr 2003 13:02:14 -0700
From: <robw@linkline.com>
Subject: list of parameter files based on date input
Message-Id: <v9bje751g2ofd6@corp.supernews.com>
I am trying to build a list of parameter files based on date input. How
hard is it to do? I am learning it right now. Can you give me some tips on
what I should do?
Here are my output parameter files:
list of file names contents of the files
account.parameter.txt [s_Account]
$$BEGIN_TXN_DATE=04/08/2003
$$END_TXN_DATE=04/09/2003
service.parameter.txt [s_Service]
$$BEGIN_TXN_DATE=04/08/2003
$$END_TXN_DATE=04/09/2003
partner.parameter.txt [s_Partner]
$$BEGIN_TXN_DATE=04/08/2003
$$END_TXN_DATE=04/09/2003
The date input should be incremented by one day on the files when the script
is run. Let say if I run the script again for account.parameter.txt file,
the $$BEGIN_TXN_DATE should be 04/09/2003 and $$END_TXN_DATE should be
04/10/2003.
Can someone tell me what would be the easiest way to build this Perl script?
Here are my thoughts. One way is to have parameter files for Session name
([s_Account]), begin date and end date. Then, build the files based on the
parameter files. The other way is to read the list of the file names then
search everything after the '=' then increment the date with a Perl date
function. Does this sound crazy?
Anyway, whatever input(s) you have would be great.
Thanks
R-
------------------------------
Date: 10 Apr 2003 11:48:45 -0700
From: stry_cat@yahoo.com (Tom Cat)
Subject: mod_perl uses old values in subroutines
Message-Id: <fa408b52.0304101048.632d3223@posting.google.com>
I recently found out that mod_perl "saves" subroutines and apparently
uses values passed to the subroutines from previous runs instead of
the current values.
Is there anyway around this "feature"?
What I have is a multi-page form. The user inputs data and clicks
submit. The submit page first calls a subroutine to make sure the
required data has been submitted. if not it calls the subroutine that
makes the first page. the first page subroutine is supposed to checks
for $incomplete == 1 and then highlights the incomplete fields. If
the required data has been submitted properly it moves on to the next
page.
The problem I'm having is that when the info is incomplete either
$incomplete sometimes still has a value of 0 or the array that keeps
track of the incomplete fields has old values in it (making complete
fields be highlighted as incomplete). $incomplete and @field_errors
are both supposed to be global variables, but the subroutine half the
time doesn't seem to read their current value. Instead it uses the
value from two or three tests ago.
Is there an easier way to do what I'm doing?
Thanks,
Tom
P.S. I would post the code but it's rather long and I really don't
expect y'all to debug it for me.
------------------------------
Date: Thu, 10 Apr 2003 21:37:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: mod_perl uses old values in subroutines
Message-Id: <b74hls$b0p37$1@ID-184292.news.dfncis.de>
Tom Cat wrote:
> I recently found out that mod_perl "saves" subroutines and apparently
> uses values passed to the subroutines from previous runs instead of
> the current values.
>
> Is there anyway around this "feature"?
Your way to describe mod_perl makes me believe that you should do some
reading about it. ;-)
You can run a subroutine in the beginning of your script where all
package global variables are initialized, like:
initialize();
sub initialize {
@array = ();
%hash = ();
$scalar = '';
}
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 10 Apr 2003 20:04:12 GMT
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Subject: Re: mod_perl uses old values in subroutines
Message-Id: <slrnb9bjod.105.rgarciasuarez@dat.local>
Tom Cat wrote in comp.lang.perl.misc :
> I recently found out that mod_perl "saves" subroutines and apparently
> uses values passed to the subroutines from previous runs instead of
> the current values.
>
> Is there anyway around this "feature"?
You're probably using Apache::Registry to run perl programs as
pseudo-CGI scripts. And there are [non-anonymous] subroutines in your
scripts.
Have you enabled warnings ? If so, have you noticed that
"variable $foo will not stay shared" in your logs ? (if you didn't,
please do, when developing. Warnings are helpful.)
See : "CGI to mod_perl Porting. mod_perl Coding guidelines."
http://perl.apache.org/docs/1.0/guide/porting.html#The_First_Mystery
HTH
--
Binary compatibility between compilers is an exercise in frustration
-- from makedef.pl in the perl 5.8.0 sources
------------------------------
Date: Thu, 10 Apr 2003 14:29:48 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Piping Perl output through nroff?
Message-Id: <LDjla.275$35.1043@dfw-service2.ext.raytheon.com>
Benjamin Goldberg wrote:
> Chris Olive wrote:
> [snip]
>
>>my $nroff = "/usr/bin/nroff";
>>open( NROFF, "| $nroff" ) || die "open: $nroff ($!)"
>>print NROFF $tmpl->process( 'template.ttml', $vars );
>>close( NROFF );
>
>
> The only thing you are printing to NROFF is the *return value* of the
> process method, which in this case, is 1. The output of the processing
> is written to STDOUT. If you'd read the documentation for the ->process
> method, then you would know this.
>
> Instead, you should do:
>
> $tmpl->process( 'template.html', $vars, \*NROFF );
>
> Which will cause ->process to send it's output to the NROFF filehandle.
>
M,m,m... Do I ever deserve that public scolding. I knew it had to be
something like this... Thanks. This did it.
Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN
email: olivec(AT)indy(DOT)raytheon(DOT)com
------------------------------
Date: Thu, 10 Apr 2003 18:37:35 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Ugly code; what does it do?
Message-Id: <3E95B9EF.AA9EA9B5@boeing.com>
Walter Roberson wrote:
>
> In article <3E94B18A.425CC592@boeing.com>,
> Michael P. Broida <michael.p.broida@boeing.com> wrote:
> : Ah-ha! Got some parts figured out:
> : $)[!$3] is an element of array @)
> : $([!$2] is an element of array @(
>
> : That clears up a couple ugly bits. <grin>
> : Does the "!" in those limit interpolation similar to
> : what \Q \E does?
>
> No, ! is the "not" function.
>
> : $@!~/unmatched/ is still mostly a mystery to me,
> : but I'll keep poking at it. <grin>
>
> The scalar named '@' is tested for NOT matching against /unmatched/
Thanks! I had not used !~/.../ before, so didn't
recognize that construct within that code. Your
explanation cleared that up nicely.
Mike
------------------------------
Date: Thu, 10 Apr 2003 18:39:38 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Ugly code; what does it do?
Message-Id: <3E95BA6A.84397503@boeing.com>
"John W. Krahn" wrote:
>
> "Michael P. Broida" wrote:
> >
> > "Michael P. Broida" wrote:
> > >
> > > "Michael P. Broida" wrote:
> > > >
> > > > Steven Kuo wrote:
> > > > >
> > > > > On Wed, 9 Apr 2003, Michael P. Broida wrote:
> > > > >
> > > > > > > ... I also found a bit of code at the end of the output from
> > > > > > > "perldoc -q nest". Here's that chunk of code:
> > > > > > >
> > > > > > > # $_ contains the string to parse
> > > > > > > # BEGIN and END are the opening and closing markers for the
> > > > > > > # nested text.
> > > > > > > @( = ('(','');
> > > > > > > @) = (')','');
> > > > > > > ($re=$_)=~s/((BEGIN)|(END)|.)/$)[!$3]\Q$1\E$([!$2]/gs;
> > > > > > > @$ = (eval{/$re/},$@!~/unmatched/);
> > > > > > > print join("\n",@$[0..$#$]) if( $$[-1] );
> > >
> > > <snipped lots of stuff>
> >
> > Ah-ha! Got some parts figured out:
> > $)[!$3] is an element of array @)
> > $([!$2] is an element of array @(
> >
> > That clears up a couple ugly bits. <grin>
> > Does the "!" in those limit interpolation similar to
> > what \Q \E does?
>
> '!' is logical not so if $3 is true !$3 will evaluate to 0 and if $3 is
> false, !$3 will evaluate to 1.
Ah. Of course. I didn't realize there would be
any kind of logical thing in the $3 or $2, so didn't
even think of "not".
> > $@!~/unmatched/ is still mostly a mystery to me,
> > but I'll keep poking at it. <grin>
>
> If you add some whitespace:
>
> $@ !~ /unmatched/
>
> True if $@ does not contain the string 'unmatched' or false if it does.
OK, packed together code hides so many details
like that. I much prefer to write CLEAR code.
<grin>
Thanks!
Mike
------------------------------
Date: Thu, 10 Apr 2003 20:41:23 GMT
From: "Lyvoise" <lyvoise@aol.com>
Subject: Re: Using Eval Statement To Trap Module Not Present Fatal Error
Message-Id: <TFkla.16250$n2.15273@clmboh1-nws5.columbus.rr.com>
Thanks everyone for the help. It correctly trapping all errors now. Very
much appreciated.
Lyvoise
"Lyvoise" <lyvoise@aol.com> wrote in message
news:iQXka.15987$n2.12232@clmboh1-nws5.columbus.rr.com...
> Can someone please tell me what's wrong below. I am trying to trap a
fatal
> error if a module is not installed when calling that module via a use
> statement but doing the eval statement first is not catching the error is
> the File::Find module is not present.
>
> # get our total disk space
>
> # we are using the File::Find module but just in case
> # it is not available on a server, we want to trap
> # a fatal error first.
>
> $result = eval("use File::Find");
>
> if ($@) { # then File::Find isn't available
>
> my $disk_space = "Unable To Determine";
>
> } else { # we can use it so let's get our disk space
> find(\&stat, "$cgi_path");
> find(\&stat, "$public_path");
>
> my $megabytes = $filesize / 1000000;
> $disk_space = sprintf("%.02f",$megabytes);
> $disk_space .= " MB";
>
> }
>
> sub stat
> {
> $filesize += (stat("$_"))[7];
> }
>
> Thank you.
>
>
------------------------------
Date: 10 Apr 2003 14:11:55 -0700
From: PTIVRIHOJPNR@spammotel.com (Pablo Rodriguez)
Subject: Re: Weird behavior of PERL counter
Message-Id: <d0d3055c.0304101311.68e23a16@posting.google.com>
Nothing happened, the problem is still there (BTW, those are my usual settings).
D'oh <D'oh@a.deer> wrote in message news:<3E955386.307786C5@a.deer>...
> Pablo Rodriguez wrote:
> >
> > The problem is that from time to time I access the count.txt file
> > directly from my browser just to know how many visits have been
> > recorded so far without incrementing the count. Since its just a text
> > file, I assume I should get the number without any incrementing, but
> > that's not happening. In fact, every time I write the URL
> > (http://www.rodriguezgarcia.com/count.txt) in the address bar and
> > refresh (F5) the screen the count is incremented (to replicate the
> > increment I need to visit another page, then type the URL and press
> > F5).
> >
> > If I remove the .cgi file from the server then the number is not
> > incremented with the refreshs. It seems to me that either my browser
> > or the webserver remembers that count.txt was accessed using
> > textcount.cgi and executes it before showing the file contents. File
> > permissions for textcount.cgi are "rwxr.xr.x" and I'm using IE5.5.
> >
>
> It doesn't sound like a Web Server problem.
>
> Check the cache settings on IE:
> Tools -> Internet Options -> General tab -> Temporary Internet File - Settings
> Change the setting to "Every visit to the page".
>
> Then delete all temporary files:
> Tools -> Internet Options -> General tab -> Temporary Internet files - Delete files
>
> Then try accessing counter.txt via the browser again.
>
> What happens how?
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4828
***************************************