[19546] in Perl-Users-Digest
Perl-Users Digest, Issue: 1741 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 13 14:05:31 2001
Date: Thu, 13 Sep 2001 11:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000404310-v10-i1741@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 13 Sep 2001 Volume: 10 Number: 1741
Today's topics:
Client Timeout <gortona@cs.man.ac.uk>
File name to process from standard input? <mmynsted@prodigy.net>
Re: File name to process from standard input? (Tad McClellan)
Help on Perl parsing file to locate and replace Include (Jennifer)
How to preallocate memory for my perl script (UNIX) (Stan Brown)
Re: How to preallocate memory for my perl script (UNIX) (Tad McClellan)
Re: implicit functions <Thomas@Baetzler.de>
Re: implicit functions <Thomas@Baetzler.de>
Re: implicit functions (Anno Siegel)
Re: implicit functions (Anno Siegel)
Re: implicit functions <goldbb2@earthlink.net>
Re: implicit functions <joe+usenet@sunstarsys.com>
Re: Net::NNTP <gerard@NOSPAMlanois.com>
not in pattern mathing... <kmojar@bmjgroup.com>
Novice:-How do i cleanUp of privious entries if form is <anpandey@cisco.com>
Re: Parsing problem (Please HELP ) (Laird)
Re: Parsing problem (Please HELP ) <goldbb2@earthlink.net>
Re: Parsing problem (Please HELP ) (Anno Siegel)
Re: recognize MS Windows with perl (Jonadab the Unsightly One)
Re: Recommendations for a PERL editor (Jonadab the Unsightly One)
Re: Regular Expression Peculiarity (Tad McClellan)
Retaint a variable (Miko O'Sullivan)
Re: Retaint a variable <goldbb2@earthlink.net>
Re: Retaint a variable <joe+usenet@sunstarsys.com>
Re: scalar global search <pilsl_@goldfisch.at>
Re: system() command not wrking in cgi / works fine in (Tad McClellan)
Re: system() command not wrking in cgi / works fine in <anpandey@cisco.com>
Re: Tk::fileevent eating all my CPU cycles <lusol@Pandora.CC.Lehigh.EDU>
using not as part of regular expressions... <kmojar@bmjgroup.com>
using not as part of regular expressions... <kmojar@bmjgroup.com>
using not as part of regular expressions... <kmojar@bmjgroup.com>
Re: using not as part of regular expressions... <comdog@panix.com>
Re: Using seek and print to insert data into a file. <robin_corcoran@3b2.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 13 Sep 2001 16:35:54 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: Client Timeout
Message-Id: <3BA0D25A.29291580@cs.man.ac.uk>
Hi,
I have a client/server running, but I need the client to end the
connection, if the server takes too long.
I am using IO::Socket. I have tried using the timeout function on the
client side but it does not work.
How could you wrap the client side so it can timeout
use strict;
use IO::Socket;
my $host = shift || 'localhost';
my $port = shift || 2025;
my $sock = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
);
$sock or die "no socket :$!";
print $sock "GET_DATA\n";
print scalar <$sock>;
Cheers
------------------------------
Date: Thu, 13 Sep 2001 16:09:47 GMT
From: Mark Mynsted <mmynsted@prodigy.net>
Subject: File name to process from standard input?
Message-Id: <m2d74vul9a.fsf@mmynsted.corp.vha.com>
Why won't the following work? It does nothing...
find . -name '*.[jJ][sS][pP]' -print0 | xargs -r -0 perl -ip -e
's!\</?font.*?\>!!ig'
I would think that would work fine or the following would work, but it
does not.
find . -name '*.[jJ][sS][pP]' -print0 | xargs -r -0 perl -ip -e
's!\</?font.*?\>!!ig' -
What am I doing wrong with perl? The find command works fine. The
perl command works fine if I tell it what file to process...
Thank you in advance for ANY help.
--
-MM
/"\
(No un-solicited email please.) \ / ASCII Ribbon Campaign
See following url, X Against HTML Mail
http://pages.prodigy.net/mmynsted/spamoff.htm / \
------------------------------
Date: Thu, 13 Sep 2001 17:48:21 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: File name to process from standard input?
Message-Id: <slrn9q1pf1.f36.tadmc@tadmc26.august.net>
Mark Mynsted <mmynsted@prodigy.net> wrote:
>
>Why won't the following work? It does nothing...
>
>find . -name '*.[jJ][sS][pP]' -print0 | xargs -r -0 perl -ip -e
^^^
-i takes an argument. You gave it a one character (p) argument.
Do you have some *.jspp files around now?
Use "-pi " instead if you want no backups made.
>'s!\</?font.*?\>!!ig'
^ ^
^ ^ useless use of backslashes, angle brackets aren't meta
>I would think that would work fine
Attempting to process HTML with regular expressions is doomed to failure.
<font
>
is legal HTML that will break your code, since you are reading
line-by-line.
There are a few dozen other gotchas to work out too. "perldoc -q HTML"
shows several more of them.
>The
>perl command works fine if I tell it what file to process...
Not the same perl command that you showed us. Maybe you got
the order right that time?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 13 Sep 2001 09:24:56 -0700
From: jennlee.2@eudoramail.com (Jennifer)
Subject: Help on Perl parsing file to locate and replace Include files in CGI app
Message-Id: <e836199f.0109130824.43745dd4@posting.google.com>
Hi all,
I have a number of Perl CGI programs running on our Intranet. To
enable our web designer to keep all our pages standard with the right
logos and headings and stuff, my programs all use HTML template files.
For example, my program prints the first part of the template file
and then adds whatever it needs to programmatically for the particular
application, and then prints the remainder of the template file. The
designer marks the insert location using particular comment tags.
This was all working fine - any changes by our designer were
immediately working on applications with no program changes, but now
our designer is doing a site redesign that encorporates a lot of SSI -
particularly include files.
I know that if I just output the HTML from the template files, the
server will not parse for SSI and so the pages aren't working.
I thought it should be possible to search the HTML templates myself
(perhaps using regular expressions?), locate any SSI includes, and
replace the references with the actual contents from the referenced
files, but I am having trouble getting my head around the specifics of
it.
Has anyone done this? Can you post an example? Or point me to one
someplace on the web? I've done some searching but haven't found
anything.
Thanks,
Jennifer
------------------------------
Date: 13 Sep 2001 09:46:15 -0400
From: stanb@panix.com (Stan Brown)
Subject: How to preallocate memory for my perl script (UNIX)
Message-Id: <9nqdb7$alq$1@panix2.panix.com>
I have a perl script that retrieves a fairly large amount of data from
Oracle. I'm trying to speed it up.
I have obsered that the first time I do a lareg fetch, and store it in a
perl variable, the process size of the script slowy increases. Now ehen I
do a second query, it runs _much_ faster.
I beleive that a part of this is because perl has to make many small
requests to the OS for emeory, the first time. So I would like to do
something, before the first fetch to get perl to request a large chunk of
memory from the OS, the undefine whatever is using this memeory, thus
making that memory available to perl for reuse.
Sugestions?
------------------------------
Date: Thu, 13 Sep 2001 14:09:51 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to preallocate memory for my perl script (UNIX)
Message-Id: <slrn9q1ckj.eec.tadmc@tadmc26.august.net>
Stan Brown <stanb@panix.com> wrote:
>I have a perl script that retrieves a fairly large amount of data from
>Oracle. I'm trying to speed it up.
>
>I have obsered that the first time I do a lareg fetch, and store it in a
>perl variable,
What kind of variable? Array? Hash?
>the process size of the script slowy increases. Now ehen I
>do a second query, it runs _much_ faster.
>
>I beleive that a part of this is because perl has to make many small
>requests to the OS for emeory, the first time. So I would like to do
>something, before the first fetch to get perl to request a large chunk of
>memory from the OS, the undefine whatever is using this memeory, thus
>making that memory available to perl for reuse.
>
>Sugestions?
You can preallocate memory:
my @array;
$#array = 1_000_000; # a million elements
or
my %hash;
keys %hash = 1_000_000; # a million buckets (perldata.pod)
And empty it out when you are done:
@array=(); # keep the large memory associated with @array 'cause
# you're going to use it again
undef @array; # return memory to perl process, no longer associated
# with the array, will need to realloc when you
# reuse the same array (so don't do this)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 13 Sep 2001 15:06:58 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: implicit functions
Message-Id: <nlb1qtc39ua4e5jclabuctc0tc49r0c495@4ax.com>
On Thu, 13 Sep 2001, peter pilsl <pilsl_@goldfisch.at> wrote:
>that means: I need a function only on time and dont want to declare it as a
>sub, but merely 'map' in on the given values.
>
>What do I want ?
>
>I have a sub that returns two values. The first need to be stored and the
>second need to delivered. All has to happen implicit, cause the delivered
>value is used in a s///-operator.
Would not returning two values be an option? If yes, you could try:
#! /usr/bin/perl -w
use strict;
my $c='aaaXaaaXaaa';
my $b='x';
my @r;
# sub fu {return 1,2;}
# $c=~s/X/(@r=fu(), $b.=$r[0], $r[1])/eg;
sub fu {
my $bref = shift;
${$bref} .= 1;
return 2;
}
$c=~s/X/fu(\$b)/eg;
print $c,"-",$b,"\n";
__END__
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Thu, 13 Sep 2001 15:48:36 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: implicit functions
Message-Id: <l6e1qtk7b8o5e7o12h7qh846hl69m4kg0f@4ax.com>
[F'up to my own post]
>On Thu, 13 Sep 2001, peter pilsl <pilsl_@goldfisch.at> wrote:
>
>>that means: I need a function only on time and dont want to declare it as a
>>sub, but merely 'map' in on the given values.
>>
>>What do I want ?
>>
>>I have a sub that returns two values. The first need to be stored and the
>>second need to delivered. All has to happen implicit, cause the delivered
>>value is used in a s///-operator.
[First solution snipped]
Different method:
#! /usr/bin/perl -w
use strict;
my $c='aaaXaaaXaaa';
my $b='x';
my @r;
sub fu {return 1,2;}
$c=~s/X/eval('$b.=' . join( ';', fu()))/eg;
print $c,"-",$b,"\n";
__END__
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 13 Sep 2001 14:07:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: implicit functions
Message-Id: <9nqeim$pkp$1@mamenchi.zrz.TU-Berlin.DE>
According to Thomas Bätzler <Thomas@Baetzler.de>:
> On Thu, 13 Sep 2001, peter pilsl <pilsl_@goldfisch.at> wrote:
>
> >that means: I need a function only on time and dont want to declare it as a
> >sub, but merely 'map' in on the given values.
> >
> >What do I want ?
> >
> >I have a sub that returns two values. The first need to be stored and the
> >second need to delivered. All has to happen implicit, cause the delivered
> >value is used in a s///-operator.
>
> Would not returning two values be an option? If yes, you could try:
>
> #! /usr/bin/perl -w
> use strict;
>
> my $c='aaaXaaaXaaa';
> my $b='x';
> my @r;
>
> # sub fu {return 1,2;}
> # $c=~s/X/(@r=fu(), $b.=$r[0], $r[1])/eg;
>
> sub fu {
> my $bref = shift;
> ${$bref} .= 1;
>
> return 2;
> }
>
> $c=~s/X/fu(\$b)/eg;
>
> print $c,"-",$b,"\n";
>
> __END__
You can also associate an action with the match (instead of doing it in
the substitution)
sub fu { 2 }
$c =~ s/X(?{ $b .= 1 })/fu()/eg;
where fu() only has to return the replacement value.
Anno
------------------------------
Date: 13 Sep 2001 14:37:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: implicit functions
Message-Id: <9nqgb9$1vd$1@mamenchi.zrz.TU-Berlin.DE>
According to Thomas Bätzler <Thomas@Baetzler.de>:
> [F'up to my own post]
> >On Thu, 13 Sep 2001, peter pilsl <pilsl_@goldfisch.at> wrote:
> >
> >>that means: I need a function only on time and dont want to declare it as a
> >>sub, but merely 'map' in on the given values.
Perl's map obviates the need for "pure functions" by accepting a block
(or expression) where similar constructs require a function. Since
the only relevant parameter is given in $_, that's all there is to it.
Sort works similarly.
> >>What do I want ?
> >>
> >>I have a sub that returns two values. The first need to be stored and the
> >>second need to delivered. All has to happen implicit, cause the delivered
> >>value is used in a s///-operator.
> [First solution snipped]
>
> Different method:
>
> #! /usr/bin/perl -w
> use strict;
>
> my $c='aaaXaaaXaaa';
> my $b='x';
> my @r;
>
> sub fu {return 1,2;}
>
> $c=~s/X/eval('$b.=' . join( ';', fu()))/eg;
>
> print $c,"-",$b,"\n";
>
> __END__
Ugh... Don't use string eval if there's a solution without it. You're
just being clever :)
Your earlier solution was standard: Let the function (fu) do any other
required actions and just return the replacement value. Until quite
recently, /e was the only way to associate actions with regular
expressions (or rather, replacements). Now we have (?{ CODE }) to
insert actions immediately into regex. In another posting I suggested
a solution based on that.
Anno
------------------------------
Date: Thu, 13 Sep 2001 11:15:45 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: implicit functions
Message-Id: <3BA0CDA1.9D53069D@earthlink.net>
peter pilsl wrote:
[snip]
> I have a sub that returns two values. The first need to be stored and
> the second need to delivered. All has to happen implicit, cause the
> delivered value is used in a s///-operator.
>
> $c='aaaXaaa';$b='x';
> $c=~s/X/(@r=fu(), $b.=$r[0], $r[1])/e;
> print $c,"-",$b,"\n";
> sub fu {return 1,2;}
>
> The X in $c gets replaced by the second value returned by the function
> and $b gets the first value added.
Either:
$c =~ s/X/fu($b)/ge;
print "$c-$b\n";
sub fu { $_[0] .= 1; 2 }
Or:
$c =~ s/X/$b .= 1;2/ge;
print "$c-$b\n";
Or possibly something else... it all depends on whay you really need it
for.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 13 Sep 2001 12:26:32 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: implicit functions
Message-Id: <m3g09rf45j.fsf@mumonkan.sunstarsys.com>
peter pilsl <pilsl_@goldfisch.at> writes:
> Does perl know such thing like implicit functions or pure functions (like
> known from mathematica or such things)
>
> that means: I need a function only on time and dont want to declare it as a
> sub, but merely 'map' in on the given values.
>
> What do I want ?
An anonymous sub?
my $foo = sub { $b.=$_[0]; $_[1] };
s/X/$foo->( fu() )/e;
or just
s/X/ sub { $b.=$_[0]; $_[1] } -> ( fu() ) /e;
but this might be a little slower, depending on how
perl optimizes this case.
>
> I have a sub that returns two values. The first need to be stored and the
> second need to delivered. All has to happen implicit, cause the delivered
> value is used in a s///-operator.
>
> $c='aaaXaaa';$b='x';
> $c=~s/X/(@r=fu(), $b.=$r[0], $r[1])/e;
> print $c,"-",$b,"\n";
> sub fu {return 1,2;}
Looks OK to me, but you might rewrite the s///e as:
$c =~ s{X} { # like a "do {BLOCK}"
my @r=fu();
$b.=$r[0];
$r[1];
}e;
--
Joe Schaefer "The eternal mystery of the world is its comprehensibility."
--Albert Einstein
------------------------------
Date: 13 Sep 2001 09:45:04 -0700
From: Gerard Lanois <gerard@NOSPAMlanois.com>
Subject: Re: Net::NNTP
Message-Id: <u4rq73ur3.fsf@NOSPAMlanois.com>
jonadab@bright.net (Jonadab the Unsightly One) writes:
> What you probably need is documentation
> on MIME, which really has nothing to do with Perl as such,
> although there might be a Perl module for it.
http://search.cpan.org/search?dist=MIME-tools
-Gerard
http://www.lanois.com/perl/
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
Check out our new Unlimited Server. No Download or Time Limits!
-----== Over 80,000 Newsgroups - 19 Different Servers! ==-----
------------------------------
Date: Thu, 13 Sep 2001 15:48:30 +0100
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: not in pattern mathing...
Message-Id: <3BA0C73E.4B48CC5@bmjgroup.com>
dear all,
just a quick question on how to do a pattern match as below but not to
include and ignore patterns that include " RCT:" as part of the end of
text between the bold tags in my html documents.
$line_in =~ s|<B>(.+?) RCT:</B>|</P>\n<H2>$1</H2>\n<P>|g;
^^^^^
find every pattern unless " RCT:" before closing bold tag
i often use . ? * + etc. for my expressions but how can i identify and
use "not" the specified string or characters within my expression??
thanking you in advance and for your kind attention,
kourosh
------------------------------
Date: Thu, 13 Sep 2001 19:33:59 +0530
From: "Anupam" <anpandey@cisco.com>
Subject: Novice:-How do i cleanUp of privious entries if form is submitted to itself
Message-Id: <1000390326.129016@sj-nntpcache-3>
Hi ,
there is a cgi in perl
i am submitting a form to itself.
Problem is that on refresh in Browser privious entries do not go ..
How do i clean it up ?? so that on every refresh from browser , form should
get empty
thanks
Anupam
------------------------------
Date: 13 Sep 2001 07:52:24 -0700
From: kenlaird@yahoo.com (Laird)
Subject: Re: Parsing problem (Please HELP )
Message-Id: <94a02505.0109130652.58991c44@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3BA08C65.F75B838B@earthlink.net>...
> Laird wrote:
> >
> > Benjamin Goldberg wrote:
> > > Laird wrote:
> > > >
> > > > Hi everybody,
> > > >
> > > > I changed the file in order to be more explicit.
> > > > This is what it looks like.
> > > >
> > > > ---
> > > > # name-1
> > > > service numberone COMMENTS
> > > >
> > > > # name-2
> > > > service numbertwo COMMENTS
> > > >
> > > > # name-3
> > > > service numberthree
> > > >
> > > > # name-4 name-5 COMMENTS
> > > > service numberfour
> > > > service numberfive
> > > >
> > > > # name-other COMMENTS
> > > > service numberother
> > > >
> > > > ---
> > > >
> > > > I'm trying to put numberone after name-1
> > > > numbertwo after name-2
> > > > numberthree after name-3
> > > > numberfour after name-4
> > > > numberfive after name-5
> > > > numberother after name-other
> > >
> > > my @names;
> > > while( <DATA> ) {
> > > if( /^#/ ) {
> > > @names = /\b(name-\S+)/g;
> > > } else if( my ($service) = /^\S+\s+(\S+)/ ) {
> > > foreach my $name ( @names ) {
> > > print "name = $name\n";
> > > print "service = $service\n";
> > > }
> > > }
> > > }
> >
> > Hello
> >
> > This seems to work half way. The outcome is this:
> [snip]
>
> After taking a second look at what you wanted, I think I see my mistake.
>
> my @names;
> while( <DATA> ) {
> if( /^#/ ) {
> push @names, /\b(name-\S+)/g;
> } else if( my ($service) = /^\S+\s+(\S+)/ ) {
> print "name = ", unshift(@names), "\n";
> print "service = $service\n";
> }
> }
Hello Benjamin
This problem seems a bit tougher than I thought.
Here is the outcome this time.
name = 1
service = numberon
name = 2
service = numbertwo
name = 3
service = numberthree
name = 5
service = numberfour
name = 5
service = numberfive
name = 6
service = numberother
...
numberfour got a wrong name as well as numberother
Best regards
Ken
------------------------------
Date: Thu, 13 Sep 2001 11:28:40 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Parsing problem (Please HELP )
Message-Id: <3BA0D0A8.144547C3@earthlink.net>
Laird wrote:
>
> Benjamin Goldberg wrote:
[snip]
> > > > Laird wrote:
[snip]
> > > > > # name-1
> > > > > service numberone COMMENTS
> > > > >
> > > > > # name-2
> > > > > service numbertwo COMMENTS
> > > > >
> > > > > # name-3
> > > > > service numberthree
> > > > >
> > > > > # name-4 name-5 COMMENTS
> > > > > service numberfour
> > > > > service numberfive
> > > > >
> > > > > # name-other COMMENTS
> > > > > service numberother
> > > > >
> > > > > ---
> > > > >
> > > > > I'm trying to put numberone after name-1
> > > > > numbertwo after name-2
> > > > > numberthree after name-3
> > > > > numberfour after name-4
> > > > > numberfive after name-5
> > > > > numberother after name-other
[snip]
> > my @names;
> > while( <DATA> ) {
> > if( /^#/ ) {
> > push @names, /\b(name-\S+)/g;
> > } else if( my ($service) = /^\S+\s+(\S+)/ ) {
> > print "name = ", unshift(@names), "\n";
> > print "service = $service\n";
> > }
> > }
> Hello Benjamin
>
> This problem seems a bit tougher than I thought.
> Here is the outcome this time.
>
> name = 1
> service = numberon
> name = 2
> service = numbertwo
> name = 3
> service = numberthree
> name = 5
> service = numberfour
> name = 5
> service = numberfive
> name = 6
> service = numberother
>
> ...
>
> numberfour got a wrong name as well as numberother
Unless you changed the code, this isn't your real output... all the
matches for name would have "name-" on their fronts, unless you moved
the left parenthesis to be after the "-".
Anyway, I don't see why the original data might have produced output
like that [even ignoring the lack of the "name-" prefix]. Maybe someone
else can see what's wrong?
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 13 Sep 2001 15:35:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Parsing problem (Please HELP )
Message-Id: <9nqjnm$gt5$1@mamenchi.zrz.TU-Berlin.DE>
According to Benjamin Goldberg <goldbb2@earthlink.net>:
[in reply to Laird]
> After taking a second look at what you wanted, I think I see my mistake.
>
> my @names;
> while( <DATA> ) {
> if( /^#/ ) {
> push @names, /\b(name-\S+)/g;
> } else if( my ($service) = /^\S+\s+(\S+)/ ) {
^^^^^^^
elsif
> print "name = ", unshift(@names), "\n";
^^^^^^^
shift
> print "service = $service\n";
> }
> }
Please, it you post untested code, at least clearly mark it as such.
Anno
------------------------------
Date: Thu, 13 Sep 2001 15:43:52 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: recognize MS Windows with perl
Message-Id: <3ba0ae4a.2418511@news.bright.net>
"Tintin" <tintin@snowy.calculus> wrote:
> > > What is the best way to determine whether my program is
> > > being run on a MS Windows box? Is there a sure fire way?
> >
> > Parse `ver`
>
> Buzzz. Doesn't work on VMS,OS/2, Unix, Mac
He didn't ask the best way to find out *which* platform he's
running on, just a simple foolproof binary test.
BTW, though, my response was too cryptic; success of `ver`
is not enough, and neither is finding "Windows" in the
result, unfortunately. You actually need to find either
"Windows 9" or "Windows M".
- jonadab
------------------------------
Date: Thu, 13 Sep 2001 13:01:15 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: Recommendations for a PERL editor
Message-Id: <3ba0ad48.2160710@news.bright.net>
tim@vegeta.ath.cx (Tim Hammerquist) wrote:
> So far I've found LaTeX to be a quite acceptable
> substitute/replacement for word.
I keep meaning to learn TeX, but I haven't done it yet. (Meanwhile
my paper-document-production needs are so simple, I could probably
use HTML for that if I didn't have MS Works.)
> (Ok, so the fact that there was no paper clip with eyes was a depressing
> shortcoming and I'm still mourning the loss.... Ok, done mourning.)
Yes, well, the version (6.0) of Word that I used in college predated
the paper clip. Such a shame, that.
- jonadab
------------------------------
Date: Thu, 13 Sep 2001 13:47:06 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular Expression Peculiarity
Message-Id: <slrn9q1aj4.e2s.tadmc@tadmc26.august.net>
Andy Marden <amarden@altavista.net> wrote:
>I must be missing something here!
>
>@values = /(%\w+)|##(\w+)/g;
>
>is behaving strangely. I'm expecting a list of values which match either
>pattern in my string, in the order they appear in the string. The ordering's
>fine, but I get values which are blank between them.
@values = grep defined, /(%\w+)|##(\w+)/g;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 13 Sep 2001 07:00:11 -0700
From: miko@idocs.com (Miko O'Sullivan)
Subject: Retaint a variable
Message-Id: <db27ea77.0109130600.69e1242e@posting.google.com>
Is there a way to make a variable tainted? Here's the situation: I
have a function that accepts a string input and uses a regex to find
the part of the string of interest. This is most easily done by using
a regex to find the data, then grabbing the data from $1. The problem
is that pulling from $1 untaints the data but the function isn't in
the business of validating the data enough to untaint it.
-miko
------------------------------
Date: Thu, 13 Sep 2001 11:20:04 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Retaint a variable
Message-Id: <3BA0CEA4.8FE1343F@earthlink.net>
Miko O'Sullivan wrote:
>
> Is there a way to make a variable tainted? Here's the situation: I
> have a function that accepts a string input and uses a regex to find
> the part of the string of interest. This is most easily done by using
> a regex to find the data, then grabbing the data from $1. The problem
> is that pulling from $1 untaints the data but the function isn't in
> the business of validating the data enough to untaint it.
Put "use re 'taint';" somewhere in the enclosing scope of the re which
does the match and capturing. See the documentation for the re pragma
for examples.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 13 Sep 2001 12:46:51 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Retaint a variable
Message-Id: <m3bskff37o.fsf@mumonkan.sunstarsys.com>
miko@idocs.com (Miko O'Sullivan) writes:
> Is there a way to make a variable tainted? Here's the situation: I
> have a function that accepts a string input and uses a regex to find
> the part of the string of interest. This is most easily done by using
> a regex to find the data, then grabbing the data from $1. The problem
> is that pulling from $1 untaints the data but the function isn't in
> the business of validating the data enough to untaint it.
>
> -miko
To taint a variable you could try something like this:
$tainted =~ /(..)/ or die "no (..) match for '$tainted'.\n";
$clean = $1;
$clean .= $tainted x 0; # taints $clean
--
Joe Schaefer "I hate a country witout a derrick."
--Mark Twain
------------------------------
Date: Thu, 13 Sep 2001 19:43:16 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: scalar global search
Message-Id: <3ba0f037@e-post.inode.at>
Rafael Garcia-Suarez wrote:
> The reading of the section of perlfunc that describes the pos() function
> may help you.
>
thnx - so they 'counter' is bound to the variable. Thats good.
I should have read the pos-entry on my own.
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Thu, 13 Sep 2001 13:47:06 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: system() command not wrking in cgi / works fine in .pl
Message-Id: <slrn9q1b0p.e2s.tadmc@tadmc26.august.net>
[ Please do not send stealth Cc copies of newsgroup postings ]
Anupam <anpandey@cisco.com> wrote:
>Hi ,
>
>Now i'm using CGI
>also absolute path with system. as suggested .
Did you do the fatalsToBrowser as suggested?
>system("/usr/users/svplus/webServer/cgi-bin/sql_user_connection > 123")
>if i execute the script contaning this line from command prompt like
>perl file_name ;
>output file 123 gets created as expected ,
>
>if the same is executed through web browser
>output file 123 gets created of zero size
>
>Please advise
You do not have a Perl problem.
Something is wrong with the other program that you are trying
to run. You need to see if it is making any error messages.
[snip Jeopardy quoted text]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 13 Sep 2001 19:36:51 +0530
From: "Anupam" <anpandey@cisco.com>
Subject: Re: system() command not wrking in cgi / works fine in .pl
Message-Id: <1000390327.798633@sj-nntpcache-3>
thanks a lot
problem was with env variables .
it worked when i set them
thanks again
~Anupam
"Thomas Bätzler" <Thomas@Baetzler.de> wrote in message
news:1p31qt41ga1qtt017ot309omee0623i022@4ax.com...
> On Thu, 13 Sep 2001, "Anupam" <anpandey@cisco.com> wrote:
> >system("/usr/users/svplus/webServer/cgi-bin/sql_user_connection > 123")
> >if i execute the script contaning this line from command prompt like
> >perl file_name ;
> >output file 123 gets created as expected ,
> >
> >if the same is executed through web browser
> >output file 123 gets created of zero size
> >
> >Please advise
>
> If the file is created, then the system() call is working. I don't
> have a clue what the program you run is supposed to do, but at this
> point it has stopped to be a Perl problem.
>
> Anyways, could it be that your external program depends on environment
> settings that are in your account, but not in the environment the web
> server is running under? Could it be that it uses the current
> username/userid?
>
> HTH,
> --
> use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
> split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
> '"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
> $_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 13 Sep 2001 13:08:31 GMT
From: "Stephen O. Lidie" <lusol@Pandora.CC.Lehigh.EDU>
Subject: Re: Tk::fileevent eating all my CPU cycles
Message-Id: <9nqb4f$epq@fidoii.CC.Lehigh.EDU>
Ben Kennedy <bkennedy99@Home.com> wrote:
> "Stan Brown" <stanb@panix.com> wrote in message
> news:9nq86k$om2$1@panix2.panix.com...
>> Any sugestiosn as to how to make the widget updates have a bit higher
>> priority in this?
> You can use the update method on your main window, which will explictly
> update everything - good for tight loops with sockets, DBI, etc
As well, you should post to comp.lang.perl.tk, instead of here ...
steve
--
@_=map{eval"100${_}"}split/!/,'/5!*2!+$]!/10+$]';use Tk;$m=tkinit;$t='just an'.
'other perl hacker';$z='createText';$c=$m->Canvas(-wi,$_[1],-he,25)->grid;$c->$
z(@_[2,3],-te,$t,-fi,'gray50');$c->$z($_[2]-$],$_[3]-$],-te,$t);$m->bind('<En'.
'ter>',sub{$y=int(rand($m->screenheight));$m->geometry("+$y+$y")});MainLoop;
------------------------------
Date: Thu, 13 Sep 2001 15:46:00 +0100
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: using not as part of regular expressions...
Message-Id: <3BA0C6A8.78C11A06@bmjgroup.com>
dear all,
just a quick question on how to do a pattern match as below but not to
include and ignore patterns that include " RCT:" as part of the end of
text between the bold tags in my html documents.
$line_in =~ s|<B>(.+?) RCT:</B>|</P>\n<H2>$1</H2>\n<P>|g;
^^^^^
find every pattern unless " RCT:" before closing bold tag
i often use . ? * + etc. for my expressions but how can i identify and
use "not" the specified string or characters within my expression??
thanking you in advance and for your kind attention,
kourosh
------------------------------
Date: Thu, 13 Sep 2001 15:46:05 +0100
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: using not as part of regular expressions...
Message-Id: <3BA0C6AD.5B3895E@bmjgroup.com>
dear all,
just a quick question on how to do a pattern match as below but not to
include and ignore patterns that include " RCT:" as part of the end of
text between the bold tags in my html documents.
$line_in =~ s|<B>(.+?) RCT:</B>|</P>\n<H2>$1</H2>\n<P>|g;
^^^^^
find every pattern unless " RCT:" before closing bold tag
i often use . ? * + etc. for my expressions but how can i identify and
use "not" the specified string or characters within my expression??
thanking you in advance and for your kind attention,
kourosh
------------------------------
Date: Thu, 13 Sep 2001 15:46:18 +0100
From: Kourosh A Mojar <kmojar@bmjgroup.com>
Subject: using not as part of regular expressions...
Message-Id: <3BA0C6BA.52160298@bmjgroup.com>
dear all,
just a quick question on how to do a pattern match as below but not to
include and ignore patterns that include " RCT:" as part of the end of
text between the bold tags in my html documents.
$line_in =~ s|<B>(.+?) RCT:</B>|</P>\n<H2>$1</H2>\n<P>|g;
^^^^^
find every pattern unless " RCT:" before closing bold tag
i often use . ? * + etc. for my expressions but how can i identify and
use "not" the specified string or characters within my expression??
thanking you in advance and for your kind attention,
kourosh
------------------------------
Date: Thu, 13 Sep 2001 10:58:08 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: using not as part of regular expressions...
Message-Id: <comdog-55BEDE.10580813092001@news.panix.com>
In article <3BA0C6AD.5B3895E@bmjgroup.com>, Kourosh A Mojar
<kmojar@bmjgroup.com> wrote:
> dear all,
>
> just a quick question on how to do a pattern match as below but not to
> include and ignore patterns that include " RCT:"
perhaps you are looking for negative lookahead?
http://www.perldoc.com/perl5.6.1/pod/perlre.html
--
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: Thu, 13 Sep 2001 10:01:42 -0400
From: "Robin Corcoran" <robin_corcoran@3b2.com>
Subject: Re: Using seek and print to insert data into a file.
Message-Id: <B03o7.46$x62.62999@news.uswest.net>
----- Original Message -----
>From: "Tad McClellan" <tadmc@augustmail.com>
>> Robin Corcoran <robin_corcoran@3b2.com> wrote:
> >I just want to insert new data, not overwrite existing data.
> Then you either need to hold the entire file in memory and
> write it _all_, or use a temporary file and rename() it.
I'm sorry, I should have mentioned that I tried keeping the file in memory
and then writing it out at the end. I was using pos, but not with any
success, and perhaps not correctly.
pos($contents)=$insert_point;#Set current position in string to
$insert_point
$contents=~s/(.)/$insert_statement$1/;
> >#Open the input file and store contents in a variable.
> >open (INPUT,"C:/PiTest.xml");
> You should always, yes *always*, check the return value from open():
I understand this. I'm actually running perl from inside 3b2 (sgml/xml
composition software which is populating my variables) and my understanding
is that 3b2 will kill the script if the file cannot be opened. I was told
(only when running perl from 3b2) that I shouldn't use die (although I'm
going to double check as soon as I finish this).
> >@contents=<INPUT>;
> >$contents = join('',@contents);
> >close (INPUT);
> But this is probably a "better" way of slurping a file:
> { local $/;
> $contents = <INPUT>;
> }
> close(INPUT);
99% of the time I've seen this done your way, but I've never read what the
differences are. I guess I don't have to understand it for it to be better,
but I'm curious what the advantages are. Is my way slower/less efficient?
> >#Get rid of hard returns.
> >$contents=~s/\n+//g;
> That can make your XML invalid, I don't recommend doing that.
The files are not *supposed* to have any returns within elements, but
that's probably not always the case. Thanks for the tip, I will modify this.
> modify $contents *before* you print() it.
> Replace the 2 lines above to modify $contents:
> substr($contents, $position, 0) = qq(<?linestrt
line="$Num_To_Insert"?>);
Thanks for the help and the advice.
Robin
------------------------------
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 1741
***************************************