[19133] in Perl-Users-Digest
Perl-Users Digest, Issue: 1328 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 18 18:11:03 2001
Date: Wed, 18 Jul 2001 15:10:18 -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: <995494218-v10-i1328@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 18 Jul 2001 Volume: 10 Number: 1328
Today's topics:
Re: Including flock in code while developing in Windows <jeff@vpservices.com>
Re: Including flock in code while developing in Windows <mjcarman@home.com>
Re: Including flock in code while developing in Windows (Abigail)
Re: Including flock in code while developing in Windows <jeff@vpservices.com>
Re: Including flock in code while developing in Windows <bart.lateur@skynet.be>
Re: Including flock in code while developing in Windows <bart.lateur@skynet.be>
install ptkdb (Joe Chung)
Re: my (Mark Jason Dominus)
New to PERL/CGI question <news@privacy.net>
Pattern Matching Questions <mark.riehl@agilecommunications.com>
Re: Pattern Matching Questions <pne-news-20010718@newton.digitalspace.net>
Re: Pattern Matching Questions <godzilla@stomp.stomp.tokyo>
Re: Pattern Matching Questions (mc)
Re: Pattern Matching Questions (Mark Murray)
Re: Perl or PHP? (Jennie)
Re: Perl or PHP? <krahnj@acm.org>
Re: perl regular expression grammar (Abigail)
Printing results of a subroutine to a file <racso83@bellatlantic.net>
Re: Printing results of a subroutine to a file (Jay Tilton)
Re: Printing results of a subroutine to a file <pne-news-20010718@newton.digitalspace.net>
Re: Printing results of a subroutine to a file <ajamtgaa@cisco.com>
Re: Printing results of a subroutine to a file <ekulis@apple.com>
Re: Regex question (Abigail)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Jul 2001 11:24:52 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B55D474.A23F59F0@vpservices.com>
Mark Grimshaw wrote:
>
> Jeff Zucker wrote:
> >
> > Bart Lateur wrote:
> > >
> > > if(eval "use Fcntl qw(:flock); 1") # has flock()
> >
> > Except that that doesn't work (and uses evil string eval :-)). On my
> > win98, it lies and tells you flock is available. I wrote the correct
> > answer at the start of the thread:
> >
> > use constant HAS_FLOCK => eval { flock STDOUT, 0; 1 };
> >
> > --
> > Jeff
>
> That seems to work fine - thanks.
> What's wrong with string eval? I
> based my code on pp403-404 of Perl Cookbook which specifically states
> that you must use eval "string" rather than eval {BLOCK} to trap
> compile-time events (which 'use' is).
Just a joke, notice the smiley? String eval can be evil (especially
when you run it on strings submitted by users without checking them
first), but in this case it's fine.
--
Jeff
------------------------------
Date: Wed, 18 Jul 2001 13:39:14 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B55D7D2.67B0616E@home.com>
Mark Grimshaw wrote:
>
> Jeff Zucker wrote:
>>
>> Bart Lateur wrote:
>>>
>>> if(eval "use Fcntl qw(:flock); 1") # has flock()
>>
>> Except that that doesn't work (and uses evil string eval :-)).
>>
>> use constant HAS_FLOCK => eval { flock STDOUT, 0; 1 };
>>
>
> That seems to work fine - thanks.
I'm sure that Jeff is delighted that someone finally listened to him. :)
> What's wrong with string eval?
It's slow. Look at its entry in perlfunc; With eval BLOCK, the BLOCK is
parsed once at compile time along with everything else. Using eval EXPR
requires EXPR to be parsed -- at runtime -- each time it is encountered.
So that's why eval EXPR is kind of looked down on. It some cases,
though, it's flexibility makes it the best option.
> I based my code on pp403-404 of Perl Cookbook which specifically
> states that you must use eval "string" rather than eval {BLOCK}
> to trap compile-time events (which 'use' is).
Yes, which is another reason you also need to wrap it in a BEGIN block
to make it happen at compile time. In this case, the argument against
eval EXPR isn't relevant (since it only happens once at compile time
anyway) which may be why Jeff included the smiley.
-mjc
------------------------------
Date: 18 Jul 2001 20:12:36 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <slrn9lbrf7.nor.abigail@alexandra.xs4all.nl>
Jeff Zucker (jeff@vpservices.com) wrote on MMDCCCLXXVIII September
MCMXCIII in <URL:news:3B54DB79.9FA8A441@vpservices.com>:
-: Mark Grimshaw wrote:
-: >
-: > I've just done the same thing for a friend of mine: writing (on WinNT
-: > ActiveState) an OOP package that opens/closes and locks database
-: > files/ancilliary files and passing it on to my friend who uses Win98 -
-: > eventually it'll all go on UNIX. Hence I needed to test the operating
-: > system to see whether I can use flock. Given that flock works on
-: > WinNT/2000 but not Win9x and that $^O reports 'MSWin32' on both, is
-: > there any way to tell the two apart from within perl?
-:
-: But if you want to test for flock(), why not test for flock() instead of
-: testing for the OS? What about other OSs that don't support flock()?
-: The simplest thing is to do an eval on flock() as I suggested earlier in
-: this thread. That will give you a HAS_FLOCK constant on all OSs that
-: support flock() and won't on those that do not support it and you don't
-: even have to know which is which. Portable code shouldn't be OS
-: dependendant or need to test for OS. Code that works only on Windows
-: and *nix is not portable code. (though obviously, it's a good start
-: :-)).
I'd say that:
use Config;
my $has_flock = $Config {d_flock} eq 'define';
is an easier test than doing an eval.
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";`$@`'
------------------------------
Date: Wed, 18 Jul 2001 13:53:48 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B55F75C.F314A9B2@vpservices.com>
Abigail wrote:
>
> I'd say that:
>
> use Config;
> my $has_flock = $Config {d_flock} eq 'define';
>
> is an easier test than doing an eval.
Except that win32 erroneously defines d_flock as true.
On my win98 box:
C:\WINDOWS>perl -MConfig -e "print $^O . ' ' . $Config{d_flock}"
MSWin32 define
C:\WINDOWS>
--
Jeff
------------------------------
Date: Wed, 18 Jul 2001 22:00:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <ho1clt0npes7j0ort8pqjbrjh4eugcmbp7@4ax.com>
Michael Carman wrote:
>> What's wrong with string eval?
>
>It's slow. Look at its entry in perlfunc; With eval BLOCK, the BLOCK is
>parsed once at compile time along with everything else. Using eval EXPR
>requires EXPR to be parsed -- at runtime -- each time it is encountered.
Since this is supposed to be run only once, this argument isn't really
relevant. Once you know, you know.
--
Bart.
------------------------------
Date: Wed, 18 Jul 2001 22:02:50 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <sr1cltsh9ualgge1dor6ke7g9lnk8uju7d@4ax.com>
Jeff Zucker wrote:
>Abigail wrote:
>>
>> I'd say that:
>>
>> use Config;
>> my $has_flock = $Config {d_flock} eq 'define';
>>
>> is an easier test than doing an eval.
>
>Except that win32 erroneously defines d_flock as true.
>
>On my win98 box:
>
>C:\WINDOWS>perl -MConfig -e "print $^O . ' ' . $Config{d_flock}"
>MSWin32 define
>C:\WINDOWS>
Not exactly true.
But in the binary distributions for Win32, %Config in Config.pm was set
when perl.exe got compiled, once, and for everybody in the world. The
platform the executabe actually runs on, isn't taken into account.
--
Bart.
------------------------------
Date: Wed, 18 Jul 2001 17:33:51 GMT
From: m_010@yahoo.com (Joe Chung)
Subject: install ptkdb
Message-Id: <3b55c716.172726390@enews.newsguy.com>
When I install ptkdb, I got an error message during make:
=========================================================
cp ptkdb.pm blib/lib/Devel/ptkdb.pm
Manifying blib/man3/Devel::ptkdb.3
/usr/local/bin/pod2man: Invalid man page - no documentation in
ptkdb.pm
Couldn't install blib/man3/Devel::ptkdb.3
=========================================================
- what's man3? is it some kind of man page ( documentation )?
- why it said "/usr/local/bin/pod2man: Invalid man page"?
- Is "Couldn't install blib/man3/Devel::ptkdb.3" means can't install
man page for ptkdb?
==========================================================
the print out of my whole procedure is :
# perl Makefile.PL
Writing Makefile for Devel::ptkdb
#
# make
mkdir blib
mkdir blib/lib
mkdir blib/lib/Devel
mkdir blib/arch
mkdir blib/arch/auto
mkdir blib/arch/auto/Devel
mkdir blib/arch/auto/Devel/ptkdb
mkdir blib/lib/auto
mkdir blib/lib/auto/Devel
mkdir blib/lib/auto/Devel/ptkdb
mkdir blib/man3
cp ptkdb.pm blib/lib/Devel/ptkdb.pm
Manifying blib/man3/Devel::ptkdb.3
/usr/local/bin/pod2man: Invalid man page - no documentation in
ptkdb.pm
Couldn't install blib/man3/Devel::ptkdb.3
#
# make install
Installing /usr/local/lib/perl5/5.00503/Devel/ptkdb.pm
Installing /usr/local/lib/perl5/5.00503/man/man3/Devel::ptkdb.3
Writing
/usr/local/lib/perl5/5.00503/sun4-solaris/auto/Devel/ptkdb/.packlist
Appending installation info to
/usr/local/lib/perl5/5.00503/sun4-solaris/perllocal.pod
#
Thanks a lot
------------------------------
Date: Wed, 18 Jul 2001 20:14:40 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: my
Message-Id: <3b55ee09.655b$243@news.op.net>
In article <9ilps5$gfj$1@josh.sovintel.ru>, Alex <alex82p@svs.ru> wrote:
>What the statement "my" means?
See
http://perl.plover.com/~mjd/FAQs/Namespaces.html
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Wed, 18 Jul 2001 22:26:52 +0100
From: Steve <news@privacy.net>
Subject: New to PERL/CGI question
Message-Id: <njvblt4qui3kls6s2t7cg458ert86ofgbr@4ax.com>
I am experimenting with the use of PERL and server side includes. My
first investigations are getting a freebie text counter running,
however the only output I get on my pages is: [an error occurred
while processing this directive]
If I run the script from Telnet I get this
Content-type: text/html
2
Which looks fine to me. Can anyone suggest what I may be doing wrong
or how to find out why I am getting this error?
TIA
Steve
------------------------------
Date: Wed, 18 Jul 2001 14:54:31 -0400
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Pattern Matching Questions
Message-Id: <9j4m3t$ojh$1@news.monmouth.com>
All - I've got a input file that has the following format:
# Comments go here
key1=val1
key2=val2
...
After opening the file, I'm parsing the file using the following block (I
want to skip over the comments):
while (<INPUT>) {
chomp;
if ( !m/^\#/ ) {
($flag,$val) = split('=', $_);
print "\$flag = $flag, \$val = $val\n";
}
}
I run into problems when there is a blank line in between key/value pairs.
I tried adding (!m/^\\n/) and (!m/^\n) to skip over the newlines, but it
didn't seem to work. Any suggestions?
One more question - I've got a directory full of files that all have the
format of filename: foo 1.txt, foo 2.txt, etc. I can get all the names of
all the text files into an array using the following:
$dirname = ".";
opendir(DIR, $dirname);
@txt_files = grep { /\.txt$/} readdir (DIR);
Question - I'd like to be able to keep other .txt files in the same
directory, that is, I'd like to only match on the foo*.txt files. I tried a
few variations of the grep, but couldn't seem to get it to work. Any
suggestions?
Thanks for the help,
Mark
------------------------------
Date: Wed, 18 Jul 2001 21:35:28 +0200
From: Philip Newton <pne-news-20010718@newton.digitalspace.net>
Subject: Re: Pattern Matching Questions
Message-Id: <p3pbltsqg0qvrj8n1l3g1rubmpj8rhrruh@4ax.com>
On Wed, 18 Jul 2001 14:54:31 -0400, "Mark Riehl"
<mark.riehl@agilecommunications.com> wrote:
> while (<INPUT>) {
> chomp;
next if /^#/; # skip comments
next unless length; # skip completely empty lines -or-
next unless /\S/; # skip lines containing only whitespace
> One more question - I've got a directory full of files that all have the
> format of filename: foo 1.txt, foo 2.txt, etc. I can get all the names of
> all the text files into an array using the following:
>
> $dirname = ".";
> opendir(DIR, $dirname);
> @txt_files = grep { /\.txt$/} readdir (DIR);
>
> Question - I'd like to be able to keep other .txt files in the same
> directory, that is, I'd like to only match on the foo*.txt files.
/^foo.*\.txt$/ should work.
> I tried a few variations of the grep, but couldn't seem to get it to work.
Try variations on the pattern match instead :)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Wed, 18 Jul 2001 14:02:49 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Pattern Matching Questions
Message-Id: <3B55F979.C6B90EC1@stomp.stomp.tokyo>
Mark Riehl wrote:
> All - I've got a input file that has the following format:
My name is Kira, not All.
(snipped)
> # Comments go here
> key1=val1
> key2=val2
> ...
You have not qualified your data. A presumption is
made this example is literal. If not, you would be
prudent to provide clear and concise parameters.
It is not my habit to play guessing games although
others here appear to enjoy this. Most amusing are
those whom prove to be practicing internet mind
readers with an ability to provide absolutely
correct and perfect answers for the most incoherent
of article questions. Amazing, that.
With very little mental effort, a fifteen watt
light bulb might illuminate over your head...
if ($_ =~ /^[A-Z0-9]/i)
> while (<INPUT>) {
> chomp;
> if ( !m/^\#/ ) {
> ($flag,$val) = split('=', $_);
> print "\$flag = $flag, \$val = $val\n";
> }
> }
There is no need to chomp your input.
Do you really want to split on = then add
this back in later? Your data already has
this included. Seems rather illogical, as
illogical as chomping off a newline then adding
it back later. It would be more logical to
simply print your criteria indexed data.
> I run into problems when there is a blank line in between key/value pairs.
> I tried adding (!m/^\\n/) and (!m/^\n) to skip over the newlines, but it
> didn't seem to work. Any suggestions?
Yes, a suggestion. Use of a regex should be your second
or third choice for almost all circumstances.
You will discover my test script below my signature
to be quite quick and efficient, especially if you
plan ahead, a remarkable feat for most here, I know,
but if you plan ahead and use the same first character
for all keys. However, effective planning would not
present you with a mess of a data base, yes?
> $dirname = ".";
> opendir(DIR, $dirname);
> @txt_files = grep { /\.txt$/} readdir (DIR);
> Question - I'd like to be able to keep other .txt files in the same
> directory, that is, I'd like to only match on the foo*.txt files.
As with using a regex, use of grep should be your second
or third choice for programming. This snippet below will
prove to be as quick and efficient as my test script method.
opendir (DIRECTORY, $directory);
while (defined ($filename = readdir (DIRECTORY)))
{
if (substr ($filename, 0, 3) eq "foo")
{ push (@Array, $filename); }
}
closedir (DIRECTORY);
Godzilla! Queen Of Well Laid Plans Of Micey Men.
--
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
open (INPUT, "test1.txt");
while (<INPUT>)
{
if (substr ($_, 0, 3) eq "key")
{
($flag, $val) = split('=', $_);
print "\$flag = $flag, \$val = $val\n";
}
}
close (INPUT);
exit;
CONTENTS OF test1.txt:
______________________
# Comments go here
key1=val1
key2=val2
...
PRINTED RESULTS:
________________
$flag = key1, $val = val1
$flag = key2, $val = val2
------------------------------
Date: Wed, 18 Jul 2001 21:14:50 GMT
From: nospam@home.com (mc)
Subject: Re: Pattern Matching Questions
Message-Id: <3b55fbae.450529923@news>
On Wed, 18 Jul 2001 14:54:31 -0400, "Mark Riehl"
<mark.riehl@agilecommunications.com> wrote:
>All - I've got a input file that has the following format:
>
>
># Comments go here
>key1=val1
>key2=val2
>...
>
>
>After opening the file, I'm parsing the file using the following block (I
>want to skip over the comments):
>
>while (<INPUT>) {
>chomp;
>if ( !m/^\#/ ) {
> ($flag,$val) = split('=', $_);
> print "\$flag = $flag, \$val = $val\n";
> }
>}
>
>I run into problems when there is a blank line in between key/value pairs.
>I tried adding (!m/^\\n/) and (!m/^\n) to skip over the newlines, but it
>didn't seem to work. Any suggestions?
You don't need to explicitly match on \n. That's what $ does for you
(assuming that your end-of-line character is \n). How about:
/^$/ or /^\s*$/
mc
------------------------------
Date: Wed, 18 Jul 2001 22:02:01 GMT
From: mark@cowcud.demon.co.uk (Mark Murray)
Subject: Re: Pattern Matching Questions
Message-Id: <3b5606bb.769342@news.demon.co.uk>
"Mark Riehl" <mark.riehl@agilecommunications.com> wrote:
>One more question - I've got a directory full of files that all have the
>format of filename: foo 1.txt, foo 2.txt, etc. I can get all the names of
>all the text files into an array using the following:
>
>$dirname = ".";
>opendir(DIR, $dirname);
>@txt_files = grep { /\.txt$/} readdir (DIR);
>
>Question - I'd like to be able to keep other .txt files in the same
>directory, that is, I'd like to only match on the foo*.txt files. I tried a
>few variations of the grep, but couldn't seem to get it to work. Any
>suggestions?
Why not use the glob function? Then you can replace all of that code
with:
@txt_files = glob("./foo*.txt");
HTH,
--
o=| Mark |=o
"People don't know how nice I am"
------------------------------
Date: 18 Jul 2001 11:44:12 -0700
From: ef-foto@softhome.net (Jennie)
Subject: Re: Perl or PHP?
Message-Id: <86d749c8.0107181044.1282a97f@posting.google.com>
The best way to use JSP
Here just SOMETHING about RUSSIAN ATR
I did this website myself. Look and send me your comments pls.
http://www.arttradeinternational.com
------------------------------
Date: Wed, 18 Jul 2001 20:49:24 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl or PHP?
Message-Id: <3B55F653.6377C19@acm.org>
Jennie wrote:
>
> The best way to use JSP
>
> Here just SOMETHING about RUSSIAN ATR
> I did this website myself. Look and send me your comments pls.
>
> http://www.arttradeinternational.com
And this has what to do with Perl (or PHP?)
Here are some comments from the W3C HTML Validation Service.
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.arttradeinternational.com%2F&doctype=Inline
Error: no document type declaration; will parse without validation
Error: illegal character number 150
Error: illegal character number 133
Error: end tag for "META" omitted; possible causes include a missing end
tag, improper nesting of elements, or use of an element where it is not
allowed
Error: end tag for "IMG" omitted; possible causes include a missing end
tag, improper nesting of elements, or use of an element where it is not
allowed
Sorry, I can't validate this document.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 18 Jul 2001 21:13:47 GMT
From: abigail@foad.org (Abigail)
Subject: Re: perl regular expression grammar
Message-Id: <slrn9lbv1v.nor.abigail@alexandra.xs4all.nl>
[This message has also been posted.]
Alan Oursland (alan@oursland.net) wrote on MMDCCCLXXVIII September
MCMXCIII in <URL:news:01-07-080@comp.compilers>:
## I've been looking for a complete perl 5 regular expression grammar
## and, having been unsuccessful in my search, have attempted to write
## one myself. I was wondering if anyone could help me find any errors in
## it (excluding grammar syntax errors). I've left out embedded modifiers
## from the grammar -- I'm not sure how they fit into the grammar. I've
## also skimmed over the non-meta character production. One area I am
## confused is the "\c[" control character (described at
## http://www.perldoc.com/perl5.6/pod/perlre.html). How does this work?
##
## Alan Oursland
##
## Here is the grammar:
## <re> ::= <union>
## <union> ::= <concat>"|"<union> | <concat>
## <concat> ::= <quant><concat> | <quant>
## <quant> ::= <group>"*" | <group>"+" | <group>"?" | <group>"{"<bound>"}" | <group>
## <group> ::= "("<re>")" | <term>
## <term> ::= "." | "$" | "^" | <char> | <set>
## <bound> ::= <num> | <num>"," | <num>","<num>
## <char> ::= <non-meta> | "\"<escaped>
## <non-meta> ::= any non-meta char
## <escaped> ::= <meta>|<control>|<special>|<assert>
## <meta> ::= "."|"^"|"$"|"?"|"*"|"+"|"|"|"["|"("|")"|"\"|"{"
## <control> ::= "t"|"n"|"r"|"f"|"a"|"e"|"l"|"u"|"L"|"U"|"E"|"Q"
## <special> ::= <backoctal>|<hexchar>|<controlchar>|<class>
## <assert> ::= "b"|"B"|"A"|"z"|"Z"|"G"
## <backoctal> ::= <digit> | <digit><digit> | "0"<oct><oct> | "+" | "&" | "`" | "'"
## <hexchar> ::= "x"<hex><hex> | "x{"<hex><hex><hex><hex>"}"
## <controlchar> ::= "c["
## <namedchar> ::= "N{"<name>"}"
## <class> ::= "w"|"W"|"s"|"S"|"d"|"D"|"X"|"C" |"p"<name>|"P"<name>|"[:"<posixclass>":]"|"[:^"<posixclass>":]"
## <posixclass> ::= "alpha"|"alnum"|"ascii"|"cntrl"|"digit"|"graph"|"lower"|"print"|"punct"|"space"|"upper"|"word"|"xdigit"
## <name> ::= <unicodeclass>
## <unicodeclass> ::= "IsAlpha"|"IsAlnum"|"IsASCII"|"IsCntrl"|"IsDigit"|"IsGraph"|"IsLower"|"IsPrint"|"IsPunct"|"IsSpace"|"IsUpper"|"IsWord"|"IsXDigit"
## <set> ::= "[" <set-items> "]" | "[^" <set-items> "]"
## <set-items> ::= <set-item> | <set-item> <set-items>
## <set-item> ::= <range> | <char>
## <range> ::= <char> "-" <char>
## <num> ::= <digit><num> | <digit>
## <oct> ::= "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"
## <digit> ::= "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"
## <hex> ::= "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"a"|"b"|"c"|"d"|"e"|"f"|"A"|"B"|"C"|"D"|"E"|"F"
## <mod> ::= "\i"|"\m"|"\s"|"\x"
Some regexes that I cannot parse using the above grammar:
/3*?/
/g{,1}/
/\cM/
/aa/
/[*]/
/(?!!)/
Some regexes can be parsed ambigiously with the above grammar:
/\+/
(why are "+", "&", "`" and "'" mentioned in <backoctal>?)
Here are some modifications of the grammar that fixes some of the
issues:
Fixes /3*?/:
<quant> ::= <group><quantifier><greedy> | <group>
<quantifier> ::= "*" | "?" | "+" | "{" <bound> "}"
<greedy> ::= "?" | ""
Fixes /aa/:
<term> ::= "." | "$" | "^" | <chars> | <set>
<char> ::= <non-meta> | "\"<escaped>
Fixes /\cM/:
<controlchar> ::= "c" <any-char>
<any-char> ::= Any possible character.
(but that doesn't fix /\c/ and would allow /\c\/ which doesn't parse in Perl).
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'
------------------------------
Date: Wed, 18 Jul 2001 18:09:41 GMT
From: "Racso" <racso83@bellatlantic.net>
Subject: Printing results of a subroutine to a file
Message-Id: <Fhk57.2164$H37.32169@news.easynews.com>
Hi,
I've tried a number of things, and searched through Deja for
similar questions, poked around the perl docs, as well as other
perl information resources. Yet I still can't seem to figure
this out.
How does one print to a file the results of a specified subroutine.
Say something as simple as this:
----
open(FILE, '>somefile.txt') || die;
print FILE &some_sub;
close(FILE);
sub some_sub {
print "Hello World\n";
return();
}
----
I don't see why that does not work when this does:
----
print &some_sub;
sub some_sub {
print "Hello World\n";
return();
}
----
As good as perl is, I can't imagine that there is no way to
do something like this, yet I've not been able to find it.
So do any of you know if this is possible or not? If yes, could you
possibly supply a working example, or at least lead me to some documentation
on it. Something other than perfunc I'd hope. From that I managed to get only
this 'print FILEHANDLE LIST'.
"Because print takes a LIST, anything in the LIST is evaluated in list
context, and any subroutine that you call will have one or more of its
expressions evaluated in list context."
If the above is true, why is it not working for me? What magical element
am I missing?
I'd appreciate any light you could shed on this,
Thanks for your time,
--Racso
Henry D. Archut
------------------------------
Date: Wed, 18 Jul 2001 18:40:22 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Printing results of a subroutine to a file
Message-Id: <3b55d314.191347069@news.erols.com>
On Wed, 18 Jul 2001 18:09:41 GMT, "Racso" <racso83@bellatlantic.net> wrote:
> How does one print to a file the results of a specified subroutine.
Your example really is printing the result (return value) of the subroutine.
The return, however, is not what you are expecting.
> sub some_sub {
> print "Hello World\n";
That prints to STDOUT. It will never print to anywhere else.
> return();
> }
The sub returns an empty list to the caller,
so the line where the sub was called...
> print FILE &some_sub;
is equivalent to saying
print FILE ();
i.e. print absolutely nothing to FILE.
> I don't see why that does not work when this does:
>
> print &some_sub;
> sub some_sub {
> print "Hello World\n";
> return();
> }
This is not working as you expect either. The only output is being done
within the subroutine. The subroutine returns empty again, and the print
statement that called the sub...prints absolutely nothing again.
Try this
open(FILE, '>somefile.txt') || die;
print FILE &some_sub;
close(FILE);
sub some_sub {
return("Hello World\n");
}
------------------------------
Date: Wed, 18 Jul 2001 21:35:24 +0200
From: Philip Newton <pne-news-20010718@newton.digitalspace.net>
Subject: Re: Printing results of a subroutine to a file
Message-Id: <s0pbltooctbdt250fp9qebi06q7v77r6hu@4ax.com>
On Wed, 18 Jul 2001 18:40:22 GMT, tiltonj@erols.com (Jay Tilton) wrote:
> On Wed, 18 Jul 2001 18:09:41 GMT, "Racso" <racso83@bellatlantic.net> wrote:
>
> > print "Hello World\n";
>
> That prints to STDOUT. It will never print to anywhere else.
Not true. It prints to the currently selected file handle, which is
intially STDOUT but may be changed. That file handle, in turn, may be
connected to standard output, a file, a device, etc.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Wed, 18 Jul 2001 14:38:16 -0600
From: Arne Jamtgaard <ajamtgaa@cisco.com>
Subject: Re: Printing results of a subroutine to a file
Message-Id: <3B55F3B8.C05753A4@cisco.com>
Racso wrote:
>
> Hi,
>
> I've tried a number of things, and searched through Deja for
> similar questions, poked around the perl docs, as well as other
> perl information resources. Yet I still can't seem to figure
> this out.
>
> How does one print to a file the results of a specified subroutine.
>
> Say something as simple as this:
>
> ----
> open(FILE, '>somefile.txt') || die;
> print FILE &some_sub;
> close(FILE);
> sub some_sub {
> print "Hello World\n";
> return();
> }
> ----
> I don't see why that does not work when this does:
> ----
> print &some_sub;
> sub some_sub {
> print "Hello World\n";
> return();
> }
In both examples, you say "call the sub and print what it returns."
Then the sub says "print hello and return nothing."
Maybe you should 'return' what you want to print, rather than
printing and then returning nothing.
Arne
------------------------------
Date: Wed, 18 Jul 2001 13:56:54 -0700
From: Ed Kulis <ekulis@apple.com>
Subject: Re: Printing results of a subroutine to a file
Message-Id: <3B55F814.E99E5C5@apple.com>
Hi,
You can also
open(STDOUT,">out.tmp"); # redirect STDOUT to a file
print "xxxxxxx","\n"; # goes into "out.tmp"
&print_sub();
sub print_sub {
print "SSSSSSSSSSSSS","\n"; # STDOUT global so still goes into
"out.tmp"
}
-ed
Arne Jamtgaard wrote:
> Racso wrote:
> >
> > Hi,
> >
> > I've tried a number of things, and searched through Deja for
> > similar questions, poked around the perl docs, as well as other
> > perl information resources. Yet I still can't seem to figure
> > this out.
> >
> > How does one print to a file the results of a specified subroutine.
> >
> > Say something as simple as this:
> >
> > ----
> > open(FILE, '>somefile.txt') || die;
> > print FILE &some_sub;
> > close(FILE);
>
> > sub some_sub {
> > print "Hello World\n";
> > return();
> > }
> > ----
>
> > I don't see why that does not work when this does:
>
> > ----
> > print &some_sub;
> > sub some_sub {
> > print "Hello World\n";
> > return();
> > }
>
> In both examples, you say "call the sub and print what it returns."
> Then the sub says "print hello and return nothing."
>
> Maybe you should 'return' what you want to print, rather than
> printing and then returning nothing.
>
> Arne
------------------------------
Date: 18 Jul 2001 21:16:21 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Regex question
Message-Id: <slrn9lbv6q.nor.abigail@alexandra.xs4all.nl>
joe higton (joe@digital-hippy.com) wrote on MMDCCCLXXVIII September
MCMXCIII in <URL:news:Aza57.45857$WS4.7068155@news6-win.server.ntlworld.com>:
__ In article <3B4F71E4.591AA2B9@sequenom.com>, "BCC" <bcoon@sequenom.com>
__ wrote:
__
__ > How do I begin a match starting at a certain position?
__ >
__ > For example, if I have:
__ > $s = "ABC DEF GHI JKL";
__
__ My "hack and slash" answer to that would be to say match anything '.'
__ for the characters before e.g
__
__ $s =~ /......GHI/
substr ($s, 8) =~ /^GHI/;
Abigail
--
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'
------------------------------
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 1328
***************************************