[19300] in Perl-Users-Digest
Perl-Users Digest, Issue: 1495 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 11 09:05:34 2001
Date: Sat, 11 Aug 2001 06:05:08 -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: <997535108-v10-i1495@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 11 Aug 2001 Volume: 10 Number: 1495
Today's topics:
Re: 3 very easy ones 4 u <goldbb2@earthlink.net>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
FAQ: How can I make a filehandle local to a subroutine? <faq@denver.pm.org>
Re: FAQ: How can I manipulate fixed-record-length files (Eric Bohlman)
Re: FAQ: How can I manipulate fixed-record-length files <uri@sysarch.com>
Re: IO::Socket and signal problems <goldbb2@earthlink.net>
Re: Is regex in grep() automatically precompiled? (David Combs)
Re: Learning Perl, 2nd Edition (Randal L. Schwartz)
Re: my final word - i'll listen, though [Re: Pattern Ma <barsticus@earthling.net>
Re: Pattern Matching: Which subpattern (rather than sub <barsticus@earthling.net>
Re: Pattern Matching: Which subpattern (rather than sub <barsticus@earthling.net>
Re: perl "INFO" files? (emacs) Where? (Search for perl (David Combs)
Re: perl - write text file to server help (Martien Verbruggen)
Re: perl - write text file to server help benhopkins@mindspring.com
Quick question: do Parse::Recdescent-style grammars exs <ekliao@hotmail.com>
Re: repeating substituation <richard@sunsetandlabrea.com>
Re: Self-Searchable Perl documention - Extremely Useful (John Holdsworth)
tricky Question <trullock@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 11 Aug 2001 04:41:43 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: 3 very easy ones 4 u
Message-Id: <3B74EFC7.531096D5@earthlink.net>
Paul Fortescue wrote:
[snip questions which others answered quite well]
[snip code]
my $type = "filetype";
my @files = sort { $b <=> $a } grep s/^\Q$type\E\.(?=\d*$)//, glob("*");
my $count = @files;
print "$type files : the largest one is $files[0], ";
print "and the total number is $count\n";
Using glob("*") is an easy way to get all of the current directory.
Using grep of course means to only accept those list items for which the
expression is true.
The expression s/// replaces that which was matched between the first
two slashes with that which was between the second and third, and
returns the number of actual matches [replacements] made. If there's no
match, then the expression is false... so grep excludes it from the
result list.
Using (?=\d*$) means that we require that $type be followed by a number,
but we don't include the number in that which is matched (and replaced).
You don't need the \r, since perl automagically turns \n into \r\n, as
needed.
The above code is untested, but should work.
--
I need more taglines. This one is getting old.
------------------------------
Date: 11 Aug 2001 11:41:44 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_997530006@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Windows
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/emacs-elisp.html
Emacs Perl Modules
Cperl -- Perl programming mode
.ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
.<olson@mcs.anl.gov> Bob Olson (started 1991)
.<ilya@math.ohio-state.edu> Ilya Zakharevich
Major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
.http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Load source code into Emacs, like Devel::DProf.pm
o Grep through all Perl manpages (.pod)
o Follow POD manpage references to next pod page with TinyUrl
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o TinyUrl is used to jump to URLs (other pod pages, man pages etc)
mentioned in POD pages. (It's a general URL minor mode)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in the Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up datatbases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to run the find for you, You can adjust
recursive grep options, ignored case, add user grep options.
You can get `igrep.el' module from <kevinr@ihs.com>. Ask for copy.
Check also ftp://ftp.ihs.com/pub/kevinr/
TinyCompile -- Browsing grep results in Emacs *compile* buffer
TinyCompile is minor mode for *compile* buffer from where
you can collapse unwanted lines, shorten the file URLs
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Sat, 11 Aug 2001 12:17:04 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
Message-Id: <4n9d7.39$V3.170762752@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
The fastest, simplest, and most direct way is to localize the typeglob
of the filehandle in question:
local *TmpHandle;
Typeglobs are fast (especially compared with the alternatives) and
reasonably easy to use, but they also have one subtle drawback. If you
had, for example, a function named TmpHandle(), or a variable named
%TmpHandle, you just hid it from yourself.
sub findme {
local *HostFile;
open(HostFile, "</etc/hosts") or die "no /etc/hosts: $!";
local $_; # <- VERY IMPORTANT
while (<HostFile>) {
print if /\b127\.(0\.0\.)?1\b/;
}
# *HostFile automatically closes/disappears here
}
Here's how to use typeglobs in a loop to open and store a bunch of
filehandles. We'll use as values of the hash an ordered pair to make it
easy to sort the hash in insertion order.
@names = qw(motd termcap passwd hosts);
my $i = 0;
foreach $filename (@names) {
local *FH;
open(FH, "/etc/$filename") || die "$filename: $!";
$file{$filename} = [ $i++, *FH ];
}
# Using the filehandles in the array
foreach $name (sort { $file{$a}[0] <=> $file{$b}[0] } keys %file) {
my $fh = $file{$name}[1];
my $line = <$fh>;
print "$name $. $line";
}
For passing filehandles to functions, the easiest way is to preface them
with a star, as in func(*STDIN). See the section on "Passing
Filehandles" in the perlfaq7 manpage for details.
If you want to create many anonymous handles, you should check out the
Symbol, FileHandle, or IO::Handle (etc.) modules. Here's the equivalent
code with Symbol::gensym, which is reasonably light-weight:
foreach $filename (@names) {
use Symbol;
my $fh = gensym();
open($fh, "/etc/$filename") || die "open /etc/$filename: $!";
$file{$filename} = [ $i++, $fh ];
}
Here's using the semi-object-oriented FileHandle module, which certainly
isn't light-weight:
use FileHandle;
foreach $filename (@names) {
my $fh = FileHandle->new("/etc/$filename") or die "$filename: $!";
$file{$filename} = [ $i++, $fh ];
}
Please understand that whether the filehandle happens to be a (probably
localized) typeglob or an anonymous handle from one of the modules in no
way affects the bizarre rules for managing indirect handles. See the
next question.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
05.06
--
This space intentionally left blank
------------------------------
Date: 11 Aug 2001 07:07:49 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: FAQ: How can I manipulate fixed-record-length files?
Message-Id: <9l2lk5$7nd$1@bob.news.rcn.net>
PerlFAQ Server <faq@denver.pm.org> wrote:
> Here is a sample chunk of code to break up and put back together again
> some fixed-format input lines, in this case from the output of a normal,
> Berkeley-style ps:
> # sample input line:
> # 15158 p5 T 0:00 perl /home/tchrist/scripts/now-what
> $PS_T = 'A6 A4 A7 A5 A*';
> open(PS, "ps|");
> print scalar <PS>;
> while (<PS>) {
> ($pid, $tt, $stat, $time, $command) = unpack($PS_T, $_);
my %psvals;
my @pskeys = qw!pid tt stat time command!;
@psvals{@pskeys} = unpack ($PS_T, $_);
> for $var (qw!pid tt stat time command!) {
> print "$var: <$$var>\n";
for my $var (@pskeys) {
print "$var: <$psvals{$var}>\n";
> }
> print 'line=', pack($PS_T, $pid, $tt, $stat, $time, $command),
print 'line=', pack($PS_T, @psvals{@pskeys}),
> "\n";
> }
> We've used "$$var" in a way that forbidden by "use strict 'refs'". That
> is, we've promoted a string to a scalar variable reference using
> symbolic references. This is ok in small programs, but doesn't scale
> well. It also only works on global variables, not lexicals.
And get rid of the above weaselhood or replace it with something actually
useful like a mention of the hash slice idiom, i.e. something that's
actually useful and under-appreciated.
------------------------------
Date: Sat, 11 Aug 2001 07:31:37 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: FAQ: How can I manipulate fixed-record-length files?
Message-Id: <x7zo97kq7d.fsf@home.sysarch.com>
>>>>> "EB" == Eric Bohlman <ebohlman@omsdev.com> writes:
>> while (<PS>) {
>> ($pid, $tt, $stat, $time, $command) = unpack($PS_T, $_);
EB> my %psvals;
EB> my @pskeys = qw!pid tt stat time command!;
best put that name assignment before the loop or even better outside the
sub and do it only once.
EB> @psvals{@pskeys} = unpack ($PS_T, $_);
>> for $var (qw!pid tt stat time command!) {
>> print "$var: <$$var>\n";
EB> for my $var (@pskeys) {
EB> print "$var: <$psvals{$var}>\n";
>> }
>> print 'line=', pack($PS_T, $pid, $tt, $stat, $time, $command),
EB> print 'line=', pack($PS_T, @psvals{@pskeys}),
>> "\n";
>> }
>> We've used "$$var" in a way that forbidden by "use strict 'refs'". That
>> is, we've promoted a string to a scalar variable reference using
>> symbolic references. This is ok in small programs, but doesn't scale
>> well. It also only works on global variables, not lexicals.
EB> And get rid of the above weaselhood or replace it with something actually
EB> useful like a mention of the hash slice idiom, i.e. something that's
EB> actually useful and under-appreciated.
wow, an FAQ with a symref example. this must be excised ASAP. your
version is a fine improvement.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Sat, 11 Aug 2001 04:16:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: IO::Socket and signal problems
Message-Id: <3B74E9D8.1E761331@earthlink.net>
Emmanuel E wrote:
>
> hi,
>
> i want to timeout my socket after 2 minutes. the timeout() method in
> IO::Socket dosent work.
[snip code using alarm]
Instead of using alarm [which can work, but isn't pretty], or trying to
set a socket-timeout [which doesn't work for most versions of perl], you
should use select or IO::Select:
while( 1 ) ACCEPT: {
my $socket = $server->accept or die "accept: $!";
my $select = IO::Select->new($socket);
my ($expire,$now) = (time() + 120, time);
my $data;
do {
$select->can_read($expire - $now) and
sysread( $socket, $data, 100 - length $data )
or next ACCEPT;
$now = time;
} while( $now < $expire && length($data) < 100 );
next ACCEPT unless length($data) == 100;
# other stuff... /* */ does not mark comments.
}
This code is very similar in effect to what you appeared to intend -- it
will give the other end 120 seconds total to provide 100 bytes of data,
and if that isn't done, it goes on to the next connection.
As Ben Kennedy wrote, you probably should consider a forking server. To
change the above code to fork is very easy:
while( 1 ) ACCEPT: {
my $socket = $server->accept or die "accept: $!";
my $forked = fork and next ACCEPT;
my $select = IO::Select->new($socket);
..... # everything here is the same
exit if defined $forked;
}
Just add two lines, one right after the "my $socket =" and the other
right before the end of the block.
--
I need more taglines. This one is getting old.
------------------------------
Date: 11 Aug 2001 08:34:25 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Is regex in grep() automatically precompiled?
Message-Id: <9l2qmh$50t$1@news.panix.com>
In article <t4dimt45ecgduqld8r6h04sm0dacdu09v4@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
...
>.... Even then, you can always fall back on
>generating a sub on the fly, from a string:
>
> my $grep = eval 'sub { grep /$pat/o, @_ }'
^^^^^^^^^^^^
> or die "Cannot eval grep sub: $@";
> @result = $grep->(@array);
>
PLEASE explain that eval on what I guess is a ref
to an anon sub.
WHY the "eval"?
(I don't recall seeing *anything* like that in *any*
of the various perl books, of which I have most
of the "good" ones -- at the ones discussed in
this group).
WHAT gets assigned into $grep?
>Note that the first time you call the $grep sub (*with* a parameter),
>should be in the scope of $pat, perhaps like this:
>
> $grep->("");
>
Please say a bit more here -- thanks!
Looks like pretty neat stuff!
>
> Bart.
------------------------------
Date: 11 Aug 2001 00:43:37 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Learning Perl, 2nd Edition
Message-Id: <m1ae17dot2.fsf@halfdome.holdit.com>
>>>>> "Lou" == Lou Moran <lmoran@wtsg.com> writes:
>> Hmm. I can argue for both. The new third-edition llama is derived
>> from our current Stonehenge courseware, and our courseware was derived
>> from the first edition of the llama (with about a dozen major
>> revisions over the past seven years). There's no cut-n-paste between
>> the two books, because it lept media instead. We've learned from
>> watching students reactions how to talk about certain difficult
>> subjects, like regular expressions and why it's not @a[3], and that's
>> reflected in the new book organization and content. So, while the
>> first edition llama has recieved much praise for being easy to read,
>> I'd say this third edition stands head and shoulders above that.
Lou> Listen. I like your stuff. But the OP asked which one. Are you
Lou> saying go get the 3rd edition or not?
What part of "I can argue for both [sides]" are you unclear on? :)
The second edition is a fine book, but I also think the third edition
is better. Those are not contradictory positions! Although depending
on your goals they may end up supporting different behaviors.
print "Just another Perl [book] hacker,";
--
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: Sat, 11 Aug 2001 08:55:19 +0100
From: Simon Best <barsticus@earthling.net>
Subject: Re: my final word - i'll listen, though [Re: Pattern Matching: Which subpattern (rather than substring) was matched?]
Message-Id: <3B74E4E7.B3520370@earthling.net>
gimi wrote:
>
> hi again
Hello again.
> Simon Best wrote:
> > For example, I could have:
> > $STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
> > and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
> > blah.", I'd want to know that it was $SUBPATTERN2 that matched. I'd
> > like something like backreferences, but where it's $SUBPATTERN2 that's
> > given, not $SOMETHING_MATCHING_SUBPATTERN2.
> [zap]
> > Anyway, the reason I wish to do this is because I wish to find the
> > earliest match (the one furthest to the left in the string) out of a
> > number of alternatives, and know which alternative it was that matched.
> > (I intend to use the patterns as hash keys, so as to access stuff, in a
> > hash, that's relevant to each kind of string.)
>
> ok, i reconsidered it, and made this:
[...]
> gimi
>
> --
> going to bed now real soon. 10:16 am. ;D
> http://www.psico.ch/
Thanks for your offerings, but I've pretty much settled on something
like this:
sub MatchyThing( $@ )
{
my ( $string, @patterns ) = @_;
for( my $offset = 0; $offset <= length $string; ++$offset )
{
foreach $pattern ( @_ )
{
if( substr( $string, $offset ) =~ m/^$pattern/ )
{
return ( $pattern, $offset );
}
}
}
return ();
}
It works through the string gradually, checking all the patterns at each
offset from the start of the string. That way, the amount of pattern
searching is reduced to something like the amount of pattern searching
that would be done with:
my $patterns = '(' . join( ')|(', @patterns ) . ')';
$string =~ m/$patterns/;
The pattern match /^$pattern/ is the key to it, as it limits each
pattern match attempt to the start of each substring. (Though it
doesn't work with patterns that already start with ^, but it wouldn't be
difficult to add an extra bit to the function to handle such cases.)
Simon
--
_______________________________________________________________________________
Email: barsticus@earthling.net
Website: http://www.cydonia.f2s.com
------------------------------
Date: Sat, 11 Aug 2001 08:34:30 +0100
From: Simon Best <barsticus@earthling.net>
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <3B74E005.26F0ABFE@earthling.net>
Cussar wrote:
>
> Extending the "definedness of $1, $2..variables"(as said by Bart) you
> can try this also
> $STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
> $arr="|$1|$2|$3|$4...";
> Assuming "|" character will not occur in the matched pattern,
> then "index" of the "|" followed by a "non-|" character in $arr will
> give
> the pattern matched.
> (No better appoach, but probably no: of lines less)
> -Cussar
[...]
Ooh! Clever! I like clever solutions like that.
Thanks!
Simon
--
_______________________________________________________________________________
Email: barsticus@earthling.net
Website: http://www.cydonia.f2s.com
------------------------------
Date: Sat, 11 Aug 2001 09:59:20 +0100
From: Simon Best <barsticus@earthling.net>
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <3B74F3E8.2A2C6CD1@earthling.net>
Anno Siegel wrote:
[...]
> Last(?) time this subject came up, Abigail suggested using code
> subpatterns to identify various parts of a regex. It didn't work
> then because of a scoping bug, but with 5.6.1 the bug is gone.
> So let me re-submit it[1]:
>
> my $id;
> my $pat = qr/(?:aaa(?{ $id = 1})) # set $id to 1 if "aaa" matches
> | # or
> (?:bbb(?{ $id = 2})) # set $id to 2 for "bbb"
> | # or
> (?:ccc(?{ $id = 3})) # set it to 3 for "ccc"
> /x;
>
> my $str = 'cccxxxaaayyyzzz';
> $str =~ $pat;
> print "id: $id\n";
>
> The bit of Perl code in each "(?{ ...})" is executed whenever the
> pattern in front of it matches, so each alternative leaves its
> mark in $id.
>
> Since this kind of code interpolation doesn't interfere with the
> matching of the regex in any way, it is quite universal and can
> be used to identify parts of a regex anywhere. It doesn't make
> the regex more readable. Well, it isn't free lunch...
>
> Anno
>
> [1] Any errors in the implementation are mine.
Ooh! I do like that idea.
Thanks!
Simon
--
_______________________________________________________________________________
Email: barsticus@earthling.net
Website: http://www.cydonia.f2s.com
------------------------------
Date: 11 Aug 2001 10:09:10 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: perl "INFO" files? (emacs) Where? (Search for perl-info fails)
Message-Id: <9l3086$cvg$1@news.panix.com>
In article <9kghgl$21fn$1@agate.berkeley.edu>,
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>[A complimentary Cc of this posting was sent to
>David Combs
><dkcombs@panix.com>], who wrote in article <9kdq3e$99i$1@panix6.panix.com>:
>> Well, that was 1995, the most recent(!) version of
>> cperl-mode.
>
>???!!!
Sooorrrry:
;; $Id: cperl-mode.el,v 4.32 2000/05/31 05:13:15 ilya Exp ilya $
Re a perl-info file:
I did find one (on my own disk!) for 5.004.
smallest "node" is an entire perlxxx.pod file,
eg perltoot.
Nothing later than that around, I guess.
(at least google finds nothing later than 1996)
>
>> Does this exist, for eg 5.6?
>
>$CPAN/doc (sp?) contains pod2texi (sp?) which may be able to do the job.
>
>Ilya
Yes, looking at the code for that program, it
looks pretty neat.
Thanks!
David
------------------------------
Date: Sat, 11 Aug 2001 17:52:35 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: perl - write text file to server help
Message-Id: <slrn9n9p23.cq.mgjv@martien.heliotrope.home>
On 10 Aug 2001 06:28:18 -0700,
Charlie Abbott <charlie@disc7.com> wrote:
> mgjv@tradingpost.com.au (Martien Verbruggen) wrote in message news:<slrn9n57i0.cq.mgjv@martien.heliotrope.home>...
>>
>> [1] Your problem is totally underspecified. What do you mean with 'write
>> and update'? What do you mean by 'to a server'? What do you mean by
>> 'need a redirect'? Are you talking about CGI? If so, make sure that you
>> first understand CGI (and NO, this is not the place to ask or learn
>> about CGI).
>
> Im writing a Actionscript site that requires a Perl script to add some
> variables to a text.txt file [644] that sits in a folder on my server,
> once the variables have been passed to the text file the script will
> need to jump [redirect] to another page on my site - as i understand
> it this is a very simple action for Perl to perform and is in demand
> by quite a few [if the posts on other groups are anything to go on]
> Actionscript & Lingo programmers but there seems to be no pre written
> scripts for this function anywhere on the net.
The Perl FAQ answers the question how to update a text file. Someone
else already pointed you in that direction.
perldoc -q "change one"
As for the redirection bit, I supsect you're talking about webby stuff?
HTMl, CGI and that sort of thing?
use CGI;
In other words: Use the CGI module.
I don't know the first thing about ActionScript or Lingo, and I doubt I
ever will.
>> [2] I'm boldly assuming that you wanted a program written in Perl. If
>> not, then you are totally and utterly offtopic, and you should be
>> ashamed of yourself.
>
> As there don't seem to be any off the shelf solutions for this Perl
> script i will need a program written.
Then I would fire up my editor, and start programming. Alternatively,
you can open your wallet, and ire a Perl programmer.
There is NO general solution to your problem, because the format and
contents of your file are going to be specific to your needs, and not to
anyone else's. How do you expect there to be any general solution to
this (still totally underspecified) problem, in any language?
I doubt that it would take more than about 25 lines of Perl code to do
what you need. Shouldn't cost that much to get someone to do it for you.
Martien
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: Sat, 11 Aug 2001 00:49:48 -0700
From: benhopkins@mindspring.com
Subject: Re: perl - write text file to server help
Message-Id: <s2o2l9.8hp.ln@127.0.0.1>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
<snip>
>> As there don't seem to be any off the shelf solutions for this Perl
>> script i will need a program written.
> Then I would fire up my editor, and start programming. Alternatively,
> you can open your wallet, and ire a Perl programmer.
Uh, ahem, I, uh, think he's already done the
last thing you mentioned.
(Sorry, I just couldn't help myself.)
------------------------------
Date: 11 Aug 2001 03:48:10 -0500
From: Eric Liao <ekliao@hotmail.com>
Subject: Quick question: do Parse::Recdescent-style grammars exsit for parsing Java, C++ and perhaps Perl code?
Message-Id: <inr9ntk0vs135ceajcafbfrgks5kldljqm@4ax.com>
That'll save plenty of time translating.
Thanks!
------------------------------
Date: Sat, 11 Aug 2001 09:13:42 +0000
From: Richard Chamberlain <richard@sunsetandlabrea.com>
Subject: Re: repeating substituation
Message-Id: <pF5d7.17383$tq.1881540@news6-win.server.ntlworld.com>
Thomas Bätzler wrote:
> Hm, OTTOH:
>
> my %replace = ( "\'" => "\\\'",
> "ffffff" => "000000",
> "Times" => "Verdana" );
>
> my $strings = join '|', keys %replace;
>
> $sectionHTML =~ s/($strings)/$replace{$1}/g;
>
> This might not work well if you have substitutions where one key is a
> prefix of the other and of course it's still not very efficient - it
> just looks more efficient because we unload all of the work on the
> regex engine.
>
> HTH,
Thanks Thomas,
I've no idea what all that means so I'll sit down and work it out for bit
:-(.
But from what your saying in terms of efficiency I guess this would be no
better than my code - although it certainly looks better.
Thanks again,
Richard
------------------------------
Date: 11 Aug 2001 01:39:39 -0700
From: coldwave@bigfoot.com (John Holdsworth)
Subject: Re: Self-Searchable Perl documention - Extremely Useful!
Message-Id: <2a46b11e.0108110039.406bfe7@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3B74791C.D80D8AE5@earthlink.net>...
> John Holdsworth wrote:
> [snip]
> > You got me thinking here and I've published a short example
> > perl application with a browser interface (a version of du).
> > This could be a .html file but a ".hta" removes the IE-ness.
> >
> > http://www.openpsp.org/source/util/du.hta.gz
>
> This is a minor nitpick, but... shouldnt the two lines:
> open STDIN, "<& $fd";
> open STDOUT, ">& $fd";
> Actually be:
> open STDIN, "<&=$fd";
> open STDOUT, ">&=$fd";
> Since $fd is an integer, not a filehandle?
Hi Ben,
You're kind of missing the point here. I'm trying to
draw attention to something novel rather than get too
bogged down in perl. Its not really documented but it
turns out its better not to put the "=" in as it stops
open doing a dup() according to the source. This keeps
STDIN on fd 0, STDOUT on 1 which is important if
you later do a fork for a CGI script or such like.
...
> NB I only use netscape, not IE, so I have no clue if any of the above
> should work [well, I know that the IO::Scalar thing should work, but not
> about the rest of it]
NS users missing out on something thesedays. Even though IE is the work
of the devil it is a very fine browser. Besides it supports PerlScript
which opens up some new and rather interesting possibilities which
I'm trying to get out there such as:
Self searching documents:
http://www.openpsp.org/source/util/search.html.gz
Searchable perl docs:
http://www.openpsp.org/source/util/perltoc.pl
Turn your browser into a Sybase database browser:
http://www.openpsp.org/source/util/dbbrowser.html.gz
(requires sybperl+OpenClient)
These are interesting ideas. Give them a try.
john
(I dont' have anything to do with Microsoft)
Do report any bugs/suggestions to coldwave@thunder.it
------------------------------
Date: Sat, 11 Aug 2001 11:19:59 +0100
From: "Trull" <trullock@yahoo.com>
Subject: tricky Question
Message-Id: <EC7d7.17709$tq.1937373@news6-win.server.ntlworld.com>
i have 14 lists, each with various bits of data in them.
@one
@two
@three
etc..
and
@aaa
@bbb
@ccc
etc.
now, i need to take the data from the @one @ two @three lists, and enter it
into the @aaa @bbb @ccc lists.
however, they need to be in a certain order. whichever list (one two three
type) that has the highest number in the 1st entry needs to go into @aaa.
the 2nd biggest needs to go into @bbb
etc etc.
does that make sense?
any ideas how i can do this?
cheers
--
']['rull
------------------------------
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 1495
***************************************