[22415] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4636 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 27 18:05:57 2003

Date: Thu, 27 Feb 2003 15:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 Feb 2003     Volume: 10 Number: 4636

Today's topics:
        [mod_perl/Apache::Request] how can I really keep the PO <spamfilter@cheiron-it.nl>
    Re: Also religious: brackets <tzz@lifelogs.com>
    Re: Anyway to do away with ?: in the map function <oxmard.Rules@ab.ab>
    Re: Anyway to do away with ?: in the map function <shondell@cis.ohio-state.edu>
    Re: Anyway to do away with ?: in the map function <oxmard.Rules@ab.ab>
    Re: Anyway to do away with ?: in the map function <shondell@cis.ohio-state.edu>
    Re: Anyway to do away with ?: in the map function (James E Keenan)
        Brute Force Golf Solver (Quantum Mechanic)
        can locate the cursor to 1, 1 without clearing the scre <tyrannous@o-space.com>
    Re: can locate the cursor to 1, 1 without clearing the  <me@privacy.net>
    Re: can locate the cursor to 1, 1 without clearing the  <mothra@nowhereatall.com>
    Re: can locate the cursor to 1, 1 without clearing the  <usenet@dwall.fastmail.fm>
        driving me nuts! (Robert Reilly)
    Re: driving me nuts! <soballe@uiuc.edu>
    Re: driving me nuts! <NoSpamPleaseButThisIsValid2@gmx.net>
    Re: getting prmature end of script headers <urzaserra@home.com>
    Re: Including my perl functions in one file in another  nobull@mail.com
    Re: More help. <mail@annuna.com>
    Re: Necessary modules? (Anno Siegel)
        perl expect, vt102, and sending a function key. (john)
    Re: regexp to *not* match a certain character sequence (Bennett Haselton)
    Re: regexp to *not* match a certain character sequence (Bennett Haselton)
    Re: regexp to *not* match a certain character sequence <skuo@mtwhitney.nsc.com>
    Re: Regular Expression for Email Aliases <perl-dvd@darklaser.com>
        Retrieve data from flat file using http (Erik Summers)
    Re: Retrieve data from flat file using http <usenet@dwall.fastmail.fm>
    Re: Writing my own scripting language. Need advice. <tassilo.parseval@post.rwth-aachen.de>
    Re: Writing my own scripting language. Need advice. <sfandino@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 27 Feb 2003 21:13:57 +0100
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: [mod_perl/Apache::Request] how can I really keep the POST data with multiple handlers?
Message-Id: <3e5e72f3$0$145$e4fe514c@dreader7.news.xs4all.nl>

Hi group,

While writing several PerlHandlers for the same request I "lost" the posted
contents of a form. Digging into the docs I found that using
Apache::Request->new and ->param 'eats' the content data, so it cannot be
used
later on. This surprised me somehow, but I changed my code into
using ->instance
and it works.
However... I try to use CPAN modules as much as possible and they all seem
to favour the ->new method, thus eating my params... Now a solution would be
to use the Apache::RequestNotes (is that still favoured?), but then I still
have a problem with the CPAN modules that need access to the posted / cookie
data.

What would be a good solution here? And why is the functionality of ->new
not simply replaced by ->instance? [Or am I now really talking nonsense]?

Best regards,

--Frank






------------------------------

Date: Thu, 27 Feb 2003 14:33:11 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Also religious: brackets
Message-Id: <4n8yw1iknc.fsf@chubby.bwh.harvard.edu>

On Thu, 27 Feb 2003, uri@stemsystems.com wrote:
>>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
> 
>   TZ> Braces are not lines of code.  They can be on a line of their
>   TZ> own, but all the studies are relevant to lines of code, not
>   TZ> lines in the program.
> 
>   TZ> Also, lines of code is widely considered to be an ineffective
>   TZ> metric, and does not take into consideration a number of code
>   TZ> aspects.  This is especially relevant to languages like Perl,
>   TZ> where a single line of code (without tricks like merging
>   TZ> statements or multiple assignments) can be as highly complex
>   TZ> as a page of C.  So I disagree with your statement on a more
>   TZ> fundamental level than just "braces count as lines."
> 
> the real point is that 'unnecessary' extra braces and indents can
> obscure the code. 
> reducing their use by using statement modifiers is a good thing for
> that reason alone. 

As far as unnecessary braces go, you're absolutely right.  I don't
think you can consider the braces in a normal (without
post-modification) if() statement unnecessary, though.  Just because
you can convert

if (...)
{
 ...
}

to a one-line version, that doesn't make the 4-line version
unnecessarily verbose.  The one-line version merges functionality with
the logical condition for that functionality.  This is not necessarily
an improvement when the functionality or the condition are complex.
It's definitely not an improvement when one wishes to comment on the
condition and the functionality separately.

I agree with the rest of your points, especially that clarity leads to
fewer bugs.  That's been my experience as well.

Ted


------------------------------

Date: Thu, 27 Feb 2003 13:20:29 -0600
From: "Peter Shankey" <oxmard.Rules@ab.ab>
Subject: Re: Anyway to do away with ?: in the map function
Message-Id: <uiednSLJiY_8-MOjXTWcog@comcast.com>


"Ryan Shondell" <shondell@cis.ohio-state.edu> wrote in message
news:xcwd6ldoas2.fsf@psi.cis.ohio-state.edu...
> "Peter Shankey" <oxmard.Rules@ab.ab> writes:
>
> (snip map warnings/diagnostics stuff)
>
> > My goal with the map function was to 'grep' and 'split' the data in
> > one pass. My ulitate goal is to load data as quickly as possible
> > into an Oracle DB.  If you know a way to this let me know. Here is
> > the code and a small sample of the data:
> >
> >
> > use strict;
> > use warnings;
> > use diagnostics;
> > use DBI;
> >
> > my $dbh = DBI->connect('dbi:Oracle:to5',
> >    'scott',
> >    'tiger',
> >    {RaiseError => 1,
> >    PrintError => 0,
> >     AutoCommit => 0})
> >   or die "Unable to connect $DBI::errstr";
> >
> > map {
> >  / values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/
> >  ?($dbh->do("insert into customers values ( $1, $2, $3, $4 ) ")):()}
> >  <DATA>;
>
> I guess the point really, is why use map if you're not using it's
> return value? Instead of the map can you do...
>
> foreach (my $line = <DATA>) {
>   next unless $line =~ /values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/;
>
>   $dbh->do("insert into customers values ( $1, $2, $3, $4 ) ");
> }
>
> (untested)
>
> This seems to do the same thing.
>

I tried the foreach loop, unfortunately it would exit after the first pass.
I did work with the DATA section, however it did not seemto make much
difference. I added some prints to get an idea of what was going on. Here it
is:

stuff before

foreach (my $line = <DATA>) {
 print $line;
  next unless $line =~ /values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/;

  print "about to do some work";
  $dbh->do("insert into customers values ( $1, $2, $3, $4 ) ");
}
print "here i am";


__DATA__
 values (2102,'First Corp.',101,65000);
 values (2102,'First Corp.',101,65000);
 values (2102,'First Corp.',101,65000);
 values (2102,'First Corp.',101,65000);
dkdk
idjdjdjdjjd

dkdkdkd
dkdkkd

Here is the output:
C:\Documents and Settings\shankeyp\My Documents\ora\wip\perl>perl p2.pl
 values (2102,'First Corp.',101,65000);
about to do some workhere i am
C:\Documents and Settings\shankeyp\My Documents\ora\wip\perl>





------------------------------

Date: 27 Feb 2003 15:31:52 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Anyway to do away with ?: in the map function
Message-Id: <xcw8yw1o47b.fsf@psi.cis.ohio-state.edu>

"Peter Shankey" <oxmard.Rules@ab.ab> writes:

> "Ryan Shondell" <shondell@cis.ohio-state.edu> wrote in message
> news:xcwd6ldoas2.fsf@psi.cis.ohio-state.edu...
> > "Peter Shankey" <oxmard.Rules@ab.ab> writes:
(snip)
> > >
> > > map {
> > >  / values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/
> > >  ?($dbh->do("insert into customers values ( $1, $2, $3, $4 ) ")):()}
> > >  <DATA>;
> >
> > I guess the point really, is why use map if you're not using it's
> > return value? Instead of the map can you do...
> >
> > foreach (my $line = <DATA>) {
> >   next unless $line =~ /values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/;
> >
> >   $dbh->do("insert into customers values ( $1, $2, $3, $4 ) ");
> > }
> >
> > (untested)

Sorry, brain malfunction there. Change the foreach to while. That
should grab all the stuff in the file line by line.

-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


------------------------------

Date: Thu, 27 Feb 2003 14:29:29 -0600
From: "Peter Shankey" <oxmard.Rules@ab.ab>
Subject: Re: Anyway to do away with ?: in the map function
Message-Id: <OsKcnZwOVrRH6MOjXTWcpQ@comcast.com>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:b3lmdb$c23$1@mamenchi.zrz.TU-Berlin.DE...
> Peter Shankey <oxmard.Rules@ab.ab> wrote in comp.lang.perl.misc:
> >
> > "Ryan Shondell" <shondell@cis.ohio-state.edu> wrote in message
> > news:xcwsmu9oes0.fsf@psi.cis.ohio-state.edu...
> > > Please don't top-post. Text rearranged chronologically...I think.
> > >
> > > "Peter Shankey" <oxmard.Rules@ab.ab> writes:
> > >
> > > > "Tore Aursand" <tore@aursand.no> wrote in message
> > > > news:pan.2003.02.26.22.55.25.710423@aursand.no...
> > > > > Just a tip;  Try to avoid using 'map' in a void context.
> > > >
> > > >
> > > > I did run into some warning messages when I was trying to use map.
Any
> > > > particular reason why?
> > > >
> > >
> > > Well, what Tore was talking about doesn't generate a warning (at
> > > least, I don't think it does...). map returns a list, and using it in
> > > a void context means you're just throwing that list away. Why create
> > > it if you're not going to use it?
> > >
> > > As for the warnings...what did they say? Try adding
> > >
> > > use diagnostics;
> > >
> > > to your code and it will tell you more about your warnings.
> > >
> > >
> > > Ryan
> >
> >
> > I should have been clearer about the warnings. When I started working
with
> > map I was getting warnings. The final code is not. I did put 'use
> > diagnostics;' in the code. Thank you for explaining what Tore was
getting
> > at. I understand what Tore was getting at.
>
> It doesn't quite look like it.  The code below is the same you posted
> in your original post.  So far, you have taken none of the hints in
> this thread.
>
> >                                            I am indeed not using the
list
> > returned by map. I could not figure out a way to return the list and
have it
> > be what I wanted. I tried some stuff line:
> > print $_->[0], $_->[1], $_->[2], $_->[3] for map ....
> > however I would still get a newline returned to $_->[0] non matching
line. I
> > could not figure out a way to test for this.
> > I found I could get just the data I wanted into an array. This is fine
for
> > the small sample but for a very very large amount of data the RAM on the
> > host was being used up. My goal with the map function was to 'grep' and
> > 'split' the data in one pass.
>
> But if you're worried about space, map is exactly what you don't want
> to use.  Not because it returns a list, but because it also *takes* a
> list as an argument.  In your case this means that the whole file must
> be read into memory before map() can even begin.  What you want is deal
> with the file line by line.
>
> >                                My ulitate goal is to load data as
quickly as
> > possible into an Oracle DB.  If you know a  way to this let me know.
Here is
> > the code and a small sample of the data:
> >
> >
> > use strict;
> > use warnings;
> > use diagnostics;
> > use DBI;
> >
> > my $dbh = DBI->connect('dbi:Oracle:to5',
> >    'scott',
> >    'tiger',
> >    {RaiseError => 1,
> >    PrintError => 0,
> >     AutoCommit => 0})
> >   or die "Unable to connect $DBI::errstr";
> >
> > map {
> >  / values \((\w*),('[\W*|\w*]*'),([\w]*),([\w]*)/
>
> This regex is pretty botched and works more by coincidence than by
> design.  DWIM may be a good thing, but sometimes I hate it.
>
> For the data you show, split() is the better tool anyway, so I won't try
> to correct it.
>
> >  ?($dbh->do("insert into customers values ( $1, $2, $3, $4 ) ")):()}
>
> You do a *lot* of work inside the map block.  This is often (not always)
> a sign that map() is misapplied, apart from not using the returned list.
>
> >  <DATA>;
>
> This innocent-looking line slurps all the data into memory.
>
> > $dbh->commit;
> > $dbh->disconnect();
>
> I'm not commenting the DBI stuff, I know nothing about that.
>
> Instead of map(), use a simple loop over the data lines:
>
>     while ( <DATA> ) {
>         next unless /^ values/; # skip unwanted lines
>         chomp;
>         # use meaningful names in the next line instead of $d1 .. $d4
>         ( undef, my ( $d1, $d2, $d3, $d4)) = split /[(),]/;
>         $dbh->do(
>             "insert into customers values ( $d1, $d2, $d3, $d4 )"
>         ); # whatever
>     }
>
> [data snipped]
>
> This won't make it much faster, but it will save space.  Someone else
> in this thread has mentioned prepare() and related methods of DBI.
> If applicable, these could be time savers.
>
> Anno

I did not realize map would take the whole file into memory before working
on it. Thanks
I do not know what you mean by DWIM?
In looking out at Google I saw a number of messages from this newsgroup
about map being faster than split. Does it depend on the file size or memory
of the machine being run on?
I have not had a chance to look at the prepare statement yet, but I will.

Pete




------------------------------

Date: 27 Feb 2003 15:41:55 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Anyway to do away with ?: in the map function
Message-Id: <xcw4r6po3qk.fsf@psi.cis.ohio-state.edu>

Please try and trim the quoted portion to only what you are responding
to.

"Peter Shankey" <oxmard.Rules@ab.ab> writes:

> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:b3lmdb$c23$1@mamenchi.zrz.TU-Berlin.DE...

> > >  <DATA>;
> >
> > This innocent-looking line slurps all the data into memory.
(snip)

> I did not realize map would take the whole file into memory before working
> on it. Thanks

It's not necessarily map that Anno's referring to here. It's the use
of <DATA> as the argument to map, which expects a list. So perl
helpfully creates a list for you by dumping everything in <DATA> into
memory.

> I do not know what you mean by DWIM?

Do What I Mean


-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


------------------------------

Date: 27 Feb 2003 13:39:08 -0800
From: jkeen@concentric.net (James E Keenan)
Subject: Re: Anyway to do away with ?: in the map function
Message-Id: <b955da04.0302271339.20ad2961@posting.google.com>

"Peter Shankey" <oxmard.Rules@ab.ab> wrote in message news:<jeSdnUZo1vcQksOjXTWc3w@comcast.com>...
> I did run into some warning messages when I was trying to use map. Any
> particular reason why?
> 

See 'perldoc -f map'.  Since 'map' is designed to return a list
consisting of the results of processing each element of an initial
list, its most intuitive context is list context.  In scalar context,
it will return the total number of elements generated.  It's simply
not designed to do anything meaningful in void context.


------------------------------

Date: 27 Feb 2003 11:09:21 -0800
From: quantum_mechanic_1964@yahoo.com (Quantum Mechanic)
Subject: Brute Force Golf Solver
Message-Id: <f233f2f0.0302271109.12de30e6@posting.google.com>

Under the auspices of "There are no stupid questions"...

Has anyone done any work on a brute force golf solver?

I'm not very good at golf, but I like the idea of tinkering with a
program that writes programs.

I envision a semi-intelligent program that knows about the most useful
command line options, builtin functions and operators, and tries to
generate valid (i.e., "perl -c") programs, runs them against test
input, and validates the output against the expected output.

Obviously just trying every possible string as a program would take
too long, even starting with the shortest programs first.

Even a subset of this problem, such as limiting the "solution space"
to valid subroutines, could still take an eon. [BTW, which is longer,
"eon" or "epoch"? :]

A distributed approach would only help by a few orders of magnitude.

As a final question, I should ask for wild guesses as to
how impractical this idea is.

Cheers,
-QM


------------------------------

Date: Thu, 27 Feb 2003 20:03:00 -0000
From: <tyrannous@o-space.com>
Subject: can locate the cursor to 1, 1 without clearing the screen?
Message-Id: <b3lqti$ped$1@news6.svr.pol.co.uk>

Does anybody know how I can locate the cursor to 1, 1 without clearing the
screen?






------------------------------

Date: Fri, 28 Feb 2003 08:25:56 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: can locate the cursor to 1, 1 without clearing the screen?
Message-Id: <b3lvp8$1n3oe0$1@ID-172104.news.dfncis.de>


<tyrannous@o-space.com> wrote in message
news:b3lqti$ped$1@news6.svr.pol.co.uk...
> Does anybody know how I can locate the cursor to 1, 1 without clearing the
> screen?

WHAT IS WRONG WITH YOU!!!!!

You have asked this question, over and over and over.
You have ignored all the questions and advice given to you.




------------------------------

Date: Thu, 27 Feb 2003 13:48:33 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: can locate the cursor to 1, 1 without clearing the screen?
Message-Id: <3e5e8686$1@usenet.ugs.com>


<tyrannous@o-space.com> wrote in message
news:b3lqti$ped$1@news6.svr.pol.co.uk...
> Does anybody know how I can locate the cursor to 1, 1 without clearing the
> screen?

What was wrong with the answers you have already received on this issue?

Mothra




------------------------------

Date: Thu, 27 Feb 2003 22:42:33 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: can locate the cursor to 1, 1 without clearing the screen?
Message-Id: <Xns932FB425C6875dkwwashere@216.168.3.30>

Tintin <me@privacy.net> wrote on 27 Feb 2003:

><tyrannous@o-space.com> wrote in message
> news:b3lqti$ped$1@news6.svr.pol.co.uk...
>> Does anybody know how I can locate the cursor to 1, 1 without
>> clearing the screen?
> 
> WHAT IS WRONG WITH YOU!!!!!
> 
> You have asked this question, over and over and over.
> You have ignored all the questions and advice given to you.

It's a trait common to usenet lizards.



------------------------------

Date: 27 Feb 2003 11:09:23 -0800
From: robert.reilly@gecapital.com (Robert Reilly)
Subject: driving me nuts!
Message-Id: <e955026c.0302271109.547fedc0@posting.google.com>

All, I have a program that i want to assaign a value to a scalar which
has a scalar name appended to it i.e

$bar = 'server1';

$foo = getserv();

what I want to do is append the $bar to the scalar $foo so I would
have $fooserver1 of $foo_server1.
any help is appreciated.

Robert Reilly
rjreilly@slippy.com


------------------------------

Date: Thu, 27 Feb 2003 13:18:14 -0600
From: "Erik Soballe" <soballe@uiuc.edu>
Subject: Re: driving me nuts!
Message-Id: <ptt7a.4285$o7.44752@vixen.cso.uiuc.edu>

Robert Reilly wrote:
> All, I have a program that i want to assaign a value to a
> scalar which has a scalar name appended to it i.e
>
> $bar = 'server1';
>
> $foo = getserv();
>
> what I want to do is append the $bar to the scalar $foo
> so I would have $fooserver1 of $foo_server1.
> any help is appreciated.

$bar = 'server1';
$foo = getserv();
$foo .= $bar;

 The .= will append $bar onto $foo, in general the '.' operator can be used
to concatenate strings.

-Erik




------------------------------

Date: Thu, 27 Feb 2003 21:05:25 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid2@gmx.net>
Subject: Re: driving me nuts!
Message-Id: <3E5E6F85.F937FFF8@gmx.net>

Robert Reilly wrote:
> 
> All, I have a program that i want to assaign a value to a scalar which
> has a scalar name appended to it i.e
> 
> $bar = 'server1';
> 
> $foo = getserv();
> 
> what I want to do is append the $bar to the scalar $foo so I would
> have $fooserver1 of $foo_server1.
> any help is appreciated.

You want a variable called $fooserver?

  perldoc -q "variable name"

explains how to do it and why you shouldn't do that.

Wolf



------------------------------

Date: Thu, 27 Feb 2003 20:08:06 GMT
From: "matt" <urzaserra@home.com>
Subject: Re: getting prmature end of script headers
Message-Id: <Geu7a.5058$Pa.564210@news2.west.cox.net>


"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns932F526403DEDsdn.comcast@216.166.71.239...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "matt" <urzaserra@home.com> wrote in
> news:k_g7a.2317$Pa.285343@news2.west.cox.net:
>
> >
> > "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
> > news:Xns932EE1121F382sdn.comcast@216.166.71.239...
> >> Who the hell is handing this crap out?
> >
> > I got it from a free cgi script website after doing a search free perl
> > scripts this is the website from where i got it.
> >
> > http://www.summersault.com/software/db_browser/
> >
>
> I downloaded the DB_browser code and had a look at it.  It's not quite as
> horrible as I had first thought it would be, but it's not that good.  It
> does little or no input validation, so it opens your website to attack --
> not good.

This script as it is woudl be only used by me for easier database browsing
and adding.

I would have modidifed it so other users could only search certain tables in
my database.

>
> The best source of free CGI perl scripts on the web is nms-
> cgi.sourceforge.net.  Unfortunately, they don't seem to have a database
> browser, which is apparently what you're looking for.  You might want to
> try freeperlcode.com -- they seem to have a lot of stuff -- but I didn't
> download any of it, so I can't vouch for how good or how bad it is.
>
> I would still advise you to find a good book or two and get learning :-)
> Good luck.
>
> - --
> Eric
> print scalar reverse sort qw p ekca lre reh
> ts uJ p, $/.r, map $_.$", qw e p h tona e;
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPl4NM2PeouIeTNHoEQLnWQCbBTD3M6WFFwttwWheugc1YC1AFyQAn3Xj
> Rfvk45OcdSunC6UZ2fLOwWoo
> =lO9O
> -----END PGP SIGNATURE-----




------------------------------

Date: 27 Feb 2003 12:45:07 -0800
From: nobull@mail.com
Subject: Re: Including my perl functions in one file in another perl script file
Message-Id: <4dafc536.0302271245.3fb0332c@posting.google.com>

"Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<Xns932F919C93654elhber1lidotechnet@62.89.127.66>...
> Warren Ayling wrote:
> 
> > I have been reading various Perl books

They can't be very good ones.  Do they contain _any_ examples?

Do you not notice that most examples start with several use() or
require() lines?  Can you not infer from context that these are some
sort of "include" mechanism?

> > and searching the Perl Google group but with little luck.

"Luck"?  I don't think what you have little of can be characterised as
luck.

I just tried a search:

http://groups.google.com/groups?q=group:comp.lang.perl.*+insubject:include

The 17th hit was a thread asking the same question.

> > Is there any way to include Perl functions in one file, in anther Perl
> > file, e.g.:
> > 
> > include "../utils/my_perl_utils";
> 
> 
> perldoc -f require

Also:

 perldoc perlmod
 perldoc Exporter

Now is not the time to start learning to program in Perl4.


------------------------------

Date: Thu, 27 Feb 2003 15:35:52 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Re: More help.
Message-Id: <3E5E84B8.4030407@annuna.com>

These lines of code are are the player data and equipment list.  In my 
game I want to pick up and use different kinds equipment.

Bob Walton wrote:
> Joe Creaney wrote:
> 
>> I am trying to program a simple rpg.  I am a self taught programmer 
>> and not very good.  I am getting fustrated with the ammount of data I 
>> am trying to pass.  Right now I am having trouble with these snipis of 
>> code:
>>
>>
>> my %weapon = ('knife' => 2, 'club' => 4, 'spear' => 6, 'sword'=> 8, 
>> 'Ax' => 10);
>> my %armor = ('leather' => 9, 'ring mail' => 7, 'chain mail' => 
>> 5,'plate' => 3);
>>
>> my @p=(" ",10,1,0,$weapon {'kinfe'},$armor {'leather'});
> 
> 
> knife-------------------------^^^^^
> 
> 
>>
>>
>> foreach $v (@p) {
>>         print "$v : $p[$v] \n";
> 
> 
> 
> In the above, $v is aliased to each element of array @p in turn. 
> Printing that is fine, but using the array elements as array subscripts 
> generally won't work so well unless the array elements are integers, or 
> at least numbers or numeric strings.  The first element of p isn't such. 
>    But the numbers in your @p array don't really look like they are 
> intended to subscripts of the same array.  Perhaps if you described what 
> it is that you want your code to do, someone could give some better 
> suggestions.
> 
> 
>>
>>  From my knowlege of perl it should work but I get all kinds of errors.
> 
> 
> not helpful -- what errors exactly?------------------^^^^^^^^^^^^^^^^^^^
> 



------------------------------

Date: 27 Feb 2003 19:14:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Necessary modules?
Message-Id: <b3lo2h$d2c$1@mamenchi.zrz.TU-Berlin.DE>

Peter Cooper <newsfeed2@boog.co.uk> wrote in comp.lang.perl.misc:
> > To get a more complete list, you can insert a coderef into @INC
> > that prints out every module that is searched for:
> >
> >     BEGIN { unshift @INC, sub { warn "loading $_[ 1]\n"; return } }
> 
> Bravo. I've never seen that Perl trick before. Delightful in its simplicity!

/me bows

You can even write "use lib sub { ... };", as it turns out.

Anno


------------------------------

Date: 27 Feb 2003 14:38:16 -0800
From: jkw@carspot.com (john)
Subject: perl expect, vt102, and sending a function key.
Message-Id: <2561207f.0302271438.eff6b86@posting.google.com>

Hello,
I need to send a function key to a dial-up. I'm using perl expect to
spawn minicom to connect to the site. The problem comes when I need to
disconnect. I need to send a F3 in order to hangup cleanly.

This is what I'm currently doing for F3.

my $function_key = "\e[OR";
$exp->send( $function_key );

The above will send 0x1b 0x5b 0x4f 0x52. I'm assume those are the
correct codes. I haven't adjusted the stty/tty mode (ie raw -echo,
etc), I'm not sure if that will help with sending data. Minicom is
using vt102 terminal emulations and I have no problems doing this
manually.

Any help would be highly appreciated.

Thanks,
John


------------------------------

Date: 27 Feb 2003 11:11:06 -0800
From: bennett@peacefire.org (Bennett Haselton)
Subject: Re: regexp to *not* match a certain character sequence
Message-Id: <e614455c.0302271111.23ebcfd@posting.google.com>

"David" <perl-dvd@darklaser.com> wrote in message news:<Axp7a.41$7g4.12821@news-west.eli.net>...
> "Bennett Haselton" <bennett@peacefire.org> wrote in message
> news:e614455c.0302262232.25cbead2@posting.google.com...
> > Pretty elementary I know, but I've read the sections about regular
> > expressions in 3 Perl books and I can't find anything about how to
> > match a string of characters that does not contain a given character
> > sequence.  For example, if I have a string of the form:
> >
> > <a href = "http://www.yahoo.com/">first link</a><a href =
> > "http://www.peacefire.org/">This <b>might</b> work</a>
> >
> > and I'm not sure whether or not the first link will be present, but I
> > want to get the text of the second link, then how do I extract the
> > 'This <b>might</b> work' part?
> >
> > I can't do:
> >
> > $string =~ /<a href = ".*">(.*)<\/a>/;
> >
> > because the ".*" will expand as much as it can, to match all of this:
> >
> > first link</a><a href = "http://www.peacefire.org/">This <b>might</b>
> > work
> >
> > and I can't modify the regexp to exclude angle brackets in what it's
> > matching:
> >
> > $string =~ /<a href = ".*">([^<>]*)<\/a>/;
> >
> > because the text that I'm trying to match, contains angle brackets.
> >
> > How do I say that I don't want the ".*" part to have the string "</a>"
> > in it anywhere?
> 
> $string =~ /<a href = ".*?">(.*?)<\/a>.*?$/;
> 
> The question mark in this type of a usage says don't be greedy, match
> only what you must.
> The $ on the end says to match from the end of the string, and the .*?
> just before it causes the regex to match the last close a tag in the
> string.

I tried that, but it doesn't seem to work:

*****
$string = '<a href = "http://www.yahoo.com/">first link</a><a href =
"http://www.peacefire.org/">This <b>might</b> work</a>';

$string =~ /<a href = ".*?">(.*?)<\/a>.*?$/;

print $1;
*****

This still ends up printing "first link".  I'll bet what's happening
is that Perl does the matching left-to-right, and the left-to-right
rule overrides the "match only what you must" rule.

I'm using Perl 5.6.0, ActivePerl for Windows, if that matters.  I
tested it on Perl 5.6.1 for Linux and got the same result.

-Bennett


------------------------------

Date: 27 Feb 2003 11:59:39 -0800
From: bennett@peacefire.org (Bennett Haselton)
Subject: Re: regexp to *not* match a certain character sequence
Message-Id: <e614455c.0302271159.36d303d6@posting.google.com>

"Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<Xns932F4E7093D07elhber1lidotechnet@62.89.127.66>...
> Bennett Haselton wrote:
> 
> > Pretty elementary I know, but I've read the sections about regular
> > expressions in 3 Perl books and I can't find anything about how to
> > match a string of characters that does not contain a given character
> > sequence.  For example, if I have a string of the form:
> > 
> > <a href = "http://www.yahoo.com/">first link</a><a href =
> > "http://www.peacefire.org/">This <b>might</b> work</a>
> > 
> > and I'm not sure whether or not the first link will be present, but I
> > want to get the text of the second link, then how do I extract the
> > 'This <b>might</b> work' part?
> 
> 
> How about this:
> 
> 
> $string =~ m!<a href[^>]+>(.*)</a>$!;

That doesn't seem to work, same problem as before:

****
$string = '<a href = "http://www.yahoo.com/">first link</a><a href =
"http://www.peacefire.org/">This <b>might</b> work</a>';

$string =~ m!<a href[^>]+>(.*)</a>$!;

print $1;
****

gives:
first link</a><a href = "http://www.peacefire.org/">This <b>might</b>
work

The ".*" part is too "greedy".

> > I can't do:
> > 
> > $string =~ /<a href = ".*">(.*)<\/a>/;
> > 
> > because the ".*" will expand as much as it can, to match all of this:
> 
> 
> If that is indeed the problem you can make the match non-greedy by 
> changing ".*" to ".*?". To read more about this and other things you 
> asked about run the following:
> 
> 
>   perldoc perlre

It turns out this code does work:

***
$string = '<a href = "http://www.yahoo.com/">first link</a><a href =
"http://www.peacefire.org/">This <b>might</b> work</a>';

$string =~ /<a href = ".*">(.*?)<\/a>/;

print $1 . "\n";
***

but only because the first ".*" in the regexp *is* greedy, and expands
from the first link to the second link.  But then what if you want to
match the href of the second link, *and* the text of the second link? 
I tried making both .*'s non-greedy, per David's post, but that didn't
work:

***
$string = '<a href = "http://www.yahoo.com/">first link</a><a href =
"http://www.peacefire.org/">This <b>might</b> work</a>';

$string =~ /<a href = "(.*?)">(.*?)<\/a>$/;

print $1 . "\n";
print $2 . "\n";
***

That still outputs:
http://www.yahoo.com/
first link

because the left-to-rightness overrides the non-greediness,
apparently.

Ah, finally I did find a way to make it work -- put a greedy ".*" at
the beginning of the regexp:

***
$string = '<a href = "http://www.yahoo.com/">first link</a><a href =
"http://www.peacefire.org/">This <b>might</b> work</a>';

$string =~ /.*<a href = "(.*?)">(.*?)<\/a>/;

print $1 . "\n";
print $2 . "\n";
***

That greedy ".*" matches as much as it can, so the script outputs:

http://www.peacefire.org/
This <b>might</b> work

So now I know how to do what I need for my application, but I'm still
curious, is there a way to stay in a particular part of a regular
expression, "match any number of any character, as long as the
character sequence doesn't contain the sequence 'abc'"?

-Bennett


------------------------------

Date: Thu, 27 Feb 2003 12:36:35 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: regexp to *not* match a certain character sequence
Message-Id: <Pine.GSO.4.21.0302271231230.26752-100000@mtwhitney.nsc.com>

On 27 Feb 2003, Bennett Haselton wrote:

> (snipped) ...
> Ah, finally I did find a way to make it work -- put a greedy ".*" at
> the beginning of the regexp:
> 
> ***
> $string = '<a href = "http://www.yahoo.com/">first link</a><a href =
> "http://www.peacefire.org/">This <b>might</b> work</a>';
> 
> $string =~ /.*<a href = "(.*?)">(.*?)<\/a>/;
> 
> print $1 . "\n";
> print $2 . "\n";
> ***
> 
> That greedy ".*" matches as much as it can, so the script outputs:
> 
> http://www.peacefire.org/
> This <b>might</b> work
> 
> So now I know how to do what I need for my application, but I'm still
> curious, is there a way to stay in a particular part of a regular
> expression, "match any number of any character, as long as the
> character sequence doesn't contain the sequence 'abc'"?
> 
> -Bennett
> 




I believe you've already been advised by others to use a HTML parsing
package.  That was good advise.

However, to answer your question, you may want to try the zero-width
look-ahead assertion just to sate your curiosity:

my $string = '<a href = "http://www.yahoo.com/">first link</a><a href = "http://www.peacefire.org/">This <b>might</b> work</a>'; 

my (@matches) = $string =~ m,a href = "([^>]*?)">(?!first link)(.*?)</a>,;

{
    local ($,,$\) = ("\n", "\n");
    print @matches;
}


-- 
Hope this helps,
Steven



------------------------------

Date: Thu, 27 Feb 2003 20:55:09 GMT
From: "David" <perl-dvd@darklaser.com>
Subject: Re: Regular Expression for Email Aliases
Message-Id: <NWu7a.1$gx.257@news-west.eli.net>

"Daniel Fabian" <strap@fabiand.net> wrote in message
news:1046342304.883726@news.liwest.at...
> Hi,
>
> I guess you guys must be really tired of correcting regular
expressions in
> perl, but I have one I just don't understand.
>
> I'm trying to evaluate email aliases entered by users. They should
apply to
> following rules:
>
> - must not start or end with [\.\-_]
> - [\.\-_] in the first part of the alias (before the @) must occur 2
times
> at most
> - all the other rules that apply to email adresses
>
> I created the regex
> return 2 unless ($alias =~
>
/([0-9A-Za-z]+[\.\-_]?[0-9A-Za-z]+){1,2}@[\-0-9A-Za-z]+\.[\-\.0-9A-Za-z]
+/);
>
> But for some reasons .df.df@test.com passes the test. And I don't
quite
> understand why. Also the [\.\-_] can occur as many times as the length
> allows. Even though I know why that is, I don't have an idea for a
regex
> that fullfills this rule.

Looks like your mistake is forgetting the /^ and the $/ which tells it
to match from the beginning, and to the end.

Regards,
David




------------------------------

Date: 27 Feb 2003 12:41:47 -0800
From: mail@eriksummers.com (Erik Summers)
Subject: Retrieve data from flat file using http
Message-Id: <38d9dcbf.0302271241.20a78831@posting.google.com>

Details:
intranet uses perl/cgi to list dynamic information pulled from a flat
file within the same directory. Works Well.

Problem:
every time I update the flat file I have to go through an exhausting
qa process even though the page itself has not changed, only the data
on the flat file. This happens 2 times a month.

Desired Method:
I would like to move the flat file to one of our other servers so that
I can update it when ever I want without going through the QA.

Question:
Can I pull the data using http so that I don't need permissions to
access the other server when requesting the data.

Thnx


------------------------------

Date: Thu, 27 Feb 2003 22:31:58 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Retrieve data from flat file using http
Message-Id: <Xns932FB25A6AD0Bdkwwashere@216.168.3.30>

Erik Summers <mail@eriksummers.com> wrote on 27 Feb 2003:

> Question:
> Can I pull the data using http so that I don't need permissions to
> access the other server when requesting the data.

use LWP::Simple;
my $flatfile_contents = get 'http://server.domain/uri-path/flatfile';



------------------------------

Date: 27 Feb 2003 19:18:27 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Writing my own scripting language. Need advice.
Message-Id: <b3loa3$q10$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Salvador Fandiño García:

> Ryan Shondell wrote:

>> Whew, so we're done developing new languages? Excellent. I can finally
>> check that one off my day-planner.
>>
>> Luckily your ideas weren't "driving" innovation 30 years ago. We'd all
>> be slinging APL on our PDP-8's.
> 
> I didn't say "don't write a new language", I just asked why he need a 
> new one.

Sometimes things are done without a strict need backing them up.

> Anyway, usually it is not a good idea to write a new one from scratch 
> specially if you know nothing about language design and implementation.

I knew nothing about C, Perl etc. years ago. This changed not because I
refrained from trying them. Learning how to design and implement a new
language can only be done by doing it.

Since the OP posted into a Perl group as well: Perl 1.0 is still
obtainable through cpan:
    
    http://search.cpan.org/author/MSCHWERN/perl-1.0_15/

and has been updated to run on modern machines. Besides being a bit of
nostalgia, it's a good example of how things work together. Unlike the
modern Perls it is a small package that is not too hard to understand.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Thu, 27 Feb 2003 21:32:30 +0000
From: =?ISO-8859-15?Q?Salvador_Fandi=F1o_Garc=EDa?= <sfandino@yahoo.com>
Subject: Re: Writing my own scripting language. Need advice.
Message-Id: <3E5E83EE.80308@yahoo.com>



Tassilo v. Parseval wrote:

> Also sprach Salvador Fandi=F1o Garc=EDa:
>>Anyway, usually it is not a good idea to write a new one from scratch=20
>>specially if you know nothing about language design and implementation.=

>=20
>=20
> I knew nothing about C, Perl etc. years ago. This changed not because I=

> refrained from trying them. Learning how to design and implement a new
> language can only be done by doing it.

I don't thing so...


> Since the OP posted into a Perl group as well: Perl 1.0 is still
> obtainable through cpan:
>    =20
>     http://search.cpan.org/author/MSCHWERN/perl-1.0_15/
>=20
> and has been updated to run on modern machines. Besides being a bit of
> nostalgia, it's a good example of how things work together. Unlike the
> modern Perls it is a small package that is not too hard to understand.

That's the point, you don't start from scratch, it's better to study=20
what others have done first and later if you still believe it's worth=20
the trouble go and create your new language.

There are lots of languages out there that are still incomplete or a=20
work in progress, and that will appreciate new programmers joining their =

development and that was going to be my initial advice to the OP, if you =

want to learn, look for one of those and try to help to its=20
development... but the OP didn't really tell us why he wants to create a =

new language, if he just want some fun, if he wants to learn, if he has=20
some new ideas, if it's for a project with a very specific requirements, =

etc., so I asked.


Bye,

   - Salva



------------------------------

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 4636
***************************************


home help back first fref pref prev next nref lref last post