[14063] in Perl-Users-Digest
Perl-Users Digest, Issue: 1473 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 23 21:18:54 1999
Date: Tue, 23 Nov 1999 18:15:21 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <943409720-v9-i1473@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 23 Nov 1999 Volume: 9 Number: 1473
Today's topics:
Re: Reading a here-document? <flavell@mail.cern.ch>
Re: Reading a here-document? <uri@sysarch.com>
Re: Reading a here-document? (Eric Bohlman)
Re: Reading a here-document? (Randal L. Schwartz)
Regex question: matching characters that might have acc (Jed Parsons)
Re: Test for eval() without using eval() ?? (Abigail)
Re: Test for eval() without using eval() ?? <mkruse@rens.com>
Re: Test for eval() without using eval() ?? lee.lindley@bigfoot.com
Re: win32 alarm workaround??? <spammers@are-not-welcomed.com>
write(FILEHANDLE) ??? hmpeak8352@my-deja.com
Re: write(FILEHANDLE) ??? <lr@hpl.hp.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 23 Nov 1999 23:54:14 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Reading a here-document?
Message-Id: <Pine.HPP.3.95a.991123233354.5766C-100000@hpplus01.cern.ch>
On Tue, 23 Nov 1999, Larry Rosler wrote:
> Why bother with the array then? Just put the list in the foreach
> directly:
>
> foreach (split /\n/, <<EOD) { _process_record_ }
> ...
> ...
> EOD
Erm, (shuffles feet), yes... well, actually _process_record_
was a whole lump of code, previously within that
while (<FILE>) { ... } block, and I couldn't at first see how
the syntax worked for that.
I think I've muddled my way through to understanding that
the syntax would go like this:
foreach (split /\n/, <<EOD) {
eins
zwei
drei
EOD
_process_record_
}
and not vice versa. (Yes: a noddy test prog executes OK).
> However, someone as obsessed with compactness as I would write it this
> way:
>
> _process_record_ for split /\n/, <<EOD;
Right, but _process_record_ is standing for half a page of code ;-)
OK, thanks for the various advice, folks. I decided to go with
the DATA approach this time. I'll save up the other one for later.
I realised when I actually came to do the job that I couldn't
take the individual record processing out of the loop as easily as
I expected after all.
So I'm actually doing this now. (Howls from the gallery... look, this
is just a sketch, I'm not copying all the checking and stuff)
...
&parseit(*FILE);
&parseit(*DATA);
...
sub parseit {
my $fh = shift;
while (<$fh>) {
_process_record_
}
return 1;
}
and my additional data records at the end of the program file.
It's doing what I want, and no nastygrams under -wT and use strict;
so I think I'm OK.
thanks again.
------------------------------
Date: 23 Nov 1999 18:18:05 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reading a here-document?
Message-Id: <x7ln7on6fm.fsf@home.sysarch.com>
>>>>> "AJF" == Alan J Flavell <flavell@mail.cern.ch> writes:
AJF> I have in mind to supply them within the script, for example as a
AJF> here-document, but now I realise that whereas I can happily write
AJF> while (<FILE>) { _process_record_ }
AJF> I can't puzzle out how to code the corresponding thing to get records
AJF> from a here-document. (Yes, I've found the topic in perlfaq4).
the others showed you the DATA handle but you asked for a here doc. i
think you would know about DATA anyway but here is my take on using a
here doc.
this is a tied handle solution (tested):
#!/usr/local/bin/perl
tie *FOO, 'HereHandle', "foo\nbar\n0" ;
print "loop <$_>\n" while ( <FOO> ) ;
tie *FOO, 'HereHandle', <<EOT ;
first line
blah
0
last line
EOT
print "line: <$_>\n" while ( <FOO> ) ;
package HereHandle ;
sub TIEHANDLE {
my( $class, $string ) = @_ ;
#print "tying [$string]\n" ;
return( bless \$string, $class ) ;
}
sub READLINE {
my $self = shift ;
my( $nl_ind ) ;
length( $$self ) or return undef ;
$nl_ind = index( $$self, "\n" ) + 1 ;
$nl_ind = length( $$self ) unless $nl_ind > 0 ;
substr( $$self, 0, $nl_ind, '' ) ;
}
have the appropriate amount of fun.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 23 Nov 1999 23:37:05 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Reading a here-document?
Message-Id: <81f8f1$duj$2@nntp9.atl.mindspring.net>
Alan J. Flavell (flavell@mail.cern.ch) wrote:
: I find that I want to include into the processing, some fixed extra
: records (relatively few, let's say a dozen for example), that I'm going
: to supply in exactly the same format that they'd come from the main data
: file.
:
: I have in mind to supply them within the script, for example as a
: here-document, but now I realise that whereas I can happily write
:
: while (<FILE>) { _process_record_ }
:
: I can't puzzle out how to code the corresponding thing to get records
: from a here-document. (Yes, I've found the topic in perlfaq4).
If you have only one set of them and you don't have any other use for the
DATA filehandle, then I'd follow the suggestions to use it. Otherwise,
IO::Scalar to the rescue:
#!/usr/bin/perl -w
use strict;
use IO::Scalar;
my $s='';
tie *F,'IO::Scalar',\<<EOD;
this
is
a
test
EOD
my $c=0;
while (<F>) {
print "$c: $_";
++$c;
}
------------------------------
Date: 23 Nov 1999 16:44:02 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Reading a here-document?
Message-Id: <m1emdgu3al.fsf@halfdome.holdit.com>
>>>>> "Alan" == Alan J Flavell <flavell@mail.cern.ch> writes:
Alan> I think I've muddled my way through to understanding that
Alan> the syntax would go like this:
Alan> foreach (split /\n/, <<EOD) {
Alan> eins
Alan> zwei
Alan> drei
Alan> EOD
Alan> _process_record_
Alan> }
Alan> and not vice versa. (Yes: a noddy test prog executes OK).
Or, rather than convert the string into a list just to wander through
it, you could use scalar //g, as in:
while (<<EOD =~ /(.*\n?)/g) {
one
two
three
four
EOD
_process_record_ (using $1)
}
That's a nice trick... and you can even remember pos() if you wish,
and move around in it. Oh, Hmm, can't change pos, since you can't
name the "variable". Grr. :)
print "!JTuRs]t! Ta0n1o[t%h-eArL ]P&e-rUl* OhGaRcPk4e%rL," =~ /.(.)/g;
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 24 Nov 1999 01:54:36 GMT
From: jed@socrates.berkeley.edu (Jed Parsons)
Subject: Regex question: matching characters that might have accents
Message-Id: <81fggs$edv$1@nntprelay.berkeley.edu>
Greetings,
If $string="K\xF6nig" and $pattern="Kon", I would like to have
print $string if ($string =~ /$pattern/);
return $string. In other words, I would like not to have to specify
accents and diacritics in my search pattern, but still have any characters
in that pattern match all possible accented versions.
Is there a clever way to do this with locale?
Thanks for any advice,
Jed
--
Jed Parsons mailto:jed@socrates.berkeley.edu
http://socrates.berkeley.edu/~jed/
"Okay! You know, super ideas do not grow on trees!" --- Supergrover
------------------------------
Date: 23 Nov 1999 17:33:39 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Test for eval() without using eval() ??
Message-Id: <slrn83m98n.m2v.abigail@alexandra.delanet.com>
Matt Kruse (mkruse@rens.com) wrote on MMCCLXXV September MCMXCIII in
<URL:news:81eqt4$sn8$1@ffx2nh3.news.uu.net>:
~~
~~ What I meant by this is no modules, no required files, no 'standard'
~~ modules, etc.
~~ I've found that when creating a script that will be used by thousands of
~~ people in every environment you can comprehend, it's best to not rely on
~~ them having ANYTHING that I think they should.
Then don't assume they have perl. In fact, I bet there are hundreds
of times more people that don't have perl on their web server than
there are that have a crippled perl.
And why stop at assuming they don't have 'eval', 'system' or backticks?
They might lack open, fork and exec. They might not have print. Perhaps
some servers don't allow switches on the she-bang line, while others
require -T. Some might only do addition, while others only allow
multiplication.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 23 Nov 1999 17:56:02 -0600
From: "Matt Kruse" <mkruse@rens.com>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <81f9al$aiu$1@ffx2nh3.news.uu.net>
Abigail <abigail@delanet.com> wrote:
> And why stop at assuming they don't have 'eval', 'system' or backticks?
> They might lack open, fork and exec.
Actually, I wrap any fork in an eval, I wrap flock in an eval, etc. For
systems that do not support operations like these.
I don't really care if you don't share my objective. I wasn't asking for
your opinion on whether or not I should be trying to make the script work
transparently in most environments. It's something I want to do, and it
works beautifully right now.
My script will work on almost any OS and web server without a single line
needing changed or a single bit of configuration needing to be done. It
relies on no modules existing on the server (even relying on CGI.pm isn't
safe - there are thousands of users without it on their web server). This
benefits me because I don't need to answer as many questions from users
trying to make it work. It just works, no matter what environment they have.
I was curious to know if I could extend support to users who cannot use eval
(not many people, I've heard from maybe .01% out of 15,000 downloads). If
it's not possible, that's fine. That's a simple answer.
Don't assume that my goal is stupid and erroneous if you don't understand
it. Don't automatically cut me down as if I'm clueless simply because you
don't find my goal interesting or worthwhile.
Matt Kruse
mkruse@netexpress.net
http://www.mattkruse.com/
------------------------------
Date: 24 Nov 1999 00:29:26 GMT
From: lee.lindley@bigfoot.com
Subject: Re: Test for eval() without using eval() ??
Message-Id: <81fbh6$k03$2@rguxd.viasystems.com>
Matt Kruse <mkruse@rens.com> wrote:
:>kevin montuori <montuori@acs.neu.edu> wrote in message
:>news:yge7lj9ozi4.fsf@spot.acs.neu.edu...
:>> i think you're a bit confused: web servers do not disable perl
:>> commands; web servers and perl interpreters are not related
:>> entities. one can turn on (or off) the server side includes
:>> directive "eval" on a netscape enterprise server -- perhaps
:>> this is what you mean?
:>No, I'm not confused. I've been doing this stuff for 6 years. This is the
:>first time that I've encountered crippled versions of Perl on a web server,
:>though.
:>There are sites that exist that have a "crippled" version of perl running
:>for CGI scripts. I'm not sure how they accomplish it, and I'm not sure how
:>it works. All I know is that I've had a number of people tell me that a
:>script won't run because Perl will not do eval() or system() or back-ticks
:>with CGI scripts on their server. It's odd, yes. Makes no sense to me. I was
:>just wondering if there was a way to check for this situation within the
:>limits of the environment.
OK. You know what you are doing. Humor me. Tell me that these
people are not reporting a symptom of a script run under
taint mode that isn't taint free. (Forgive the double negative.)
I can't figure out how to disable eval. I've only thought about it
for a little while, but it looks to be non-trivial. This really
sounds like taint mode imposed on a script that doesn't play by
those rules.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Wed, 24 Nov 1999 01:34:36 GMT
From: "Sara" <spammers@are-not-welcomed.com>
Subject: Re: win32 alarm workaround???
Message-Id: <MgH_3.209$u4.10762@newsread1.prod.itd.earthlink.net>
Why perl for NT? why not just use asp? I thought people write perl in NT
only so it can work on both unix and nt
Darrin H <dthusma@home.com> wrote in message
news:38362607.96C1C305@home.com...
> okay, I think I have it this time. Try these scripts on Win32 .
>
> on unix, you would go
> eval {
> alarm(5);
> system("/usr/bin/vi");
> }
> if ( $? ) {
> print "alarm exception\n";
> .......
>
> here, you will write
> #-----------------------------------------
> use Win32::Process;
> use Getopt::Std;
>
> #this will run alarm1 over notepad
> $now=time;
> $App="c:\\perl\\bin\\perl.exe",
> $TMOUT=5000;
> #instead of system("/usr/bin/vi"), do Win32::Process to another shell
> that does
> # another Win32 process call to notepad with a $Process->Wait(5000),
> ## as Win32 timeouts are milliseconds.
> ### I was just running null.pl with sleep 35; or sleep 2; for testing
> #$Cmd="perl.exe c:\\apps\\perl_alarm\\alarm1.pl -t $TMOUT -a
> c:\\perl\\bin\\perl
> .exe -c \"perl c:\\apps\\perl_alarm\\null.pl\"";
> $Cmd="perl.exe c:\\apps\\perl_alarm\\alarm1.pl -t $TMOUT -a
> c:\\windows\\notepad
> .exe -c \"notepad.exe\"";
> $bInherit=1;
> $Flags=CREATE_NEW_PROCESS;
> $Dir=".";
>
> $PID=Win32::Process::Create ( $Process1,
> $App,
> $Cmd,
> $bInherit,
> $Flags,
> $Dir);
>
> print "started local process...waiting $TMOUT milliseconds\n";
> #I know, the other sub-Process also has a TMOUT of the same, call this
> # a backup, mkay?
> $Process1->Wait("$TMOUT");
> $delta= time - $now;
> print "end local process... runtime was $delta seconds\n";
>
> #-----------------------------------------------------
> #here is alarm1.pl
> use Win32::Process;
> use Getopt::Std;
>
>
> getopts("t:a:c:");
>
>
> $App=$opt_a;
> $Cmd=$opt_c;
> $bInherit=1;
> $Flags=CREATE_NEW_PROCESS;
> $Dir=".";
> $TMOUT=$opt_t;
> print "\t->started alarm1.pl gonna run $opt_a and $opt_c with $TMOUT\n";
>
> $PID=Win32::Process::Create ( $Process1,
> $App,
> $Cmd,
> $bInherit,
> $Flags,
> $Dir);
>
> $Process1->Wait("$TMOUT");
> print "\t->ended alarm1.pl with TMOUT=$TMOUT\n";
>
> $Process1->Kill($exitcode);
>
>
> #---------------------------------------------
>
> So far , this has worked for me, but I would like feedback before I
> deploy it to production.
>
>
------------------------------
Date: Wed, 24 Nov 1999 01:34:45 GMT
From: hmpeak8352@my-deja.com
Subject: write(FILEHANDLE) ???
Message-Id: <81ffbl$s3l$1@nnrp1.deja.com>
When I use
write(RPT1FILE);
where RPT1FILE is a file handle, I get the
following error message :
Undefined format "main::RPT1FILE" called ...
I thought this was the right syntax to use for
writing to a file.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 23 Nov 1999 17:57:02 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: write(FILEHANDLE) ???
Message-Id: <MPG.12a4e5cb6a924798a26a@nntp.hpl.hp.com>
In article <81ffbl$s3l$1@nnrp1.deja.com> on Wed, 24 Nov 1999 01:34:45
GMT, hmpeak8352@my-deja.com <hmpeak8352@my-deja.com> says...
> When I use
>
> write(RPT1FILE);
>
> where RPT1FILE is a file handle, I get the
> following error message :
> Undefined format "main::RPT1FILE" called ...
> I thought this was the right syntax to use for
> writing to a file.
perldoc -f print
If you thought it was 'write' and it didn't work, why didn't you look at
the documentation that came with your perl installation?
perldoc -f write
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1473
**************************************