[19072] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1267 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 8 21:05:41 2001

Date: Sun, 8 Jul 2001 18:05:06 -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: <994640706-v10-i1267@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 8 Jul 2001     Volume: 10 Number: 1267

Today's topics:
    Re: (csv) Split at a coma, how? <goldbb2@earthlink.net>
        FAQ: Is it a Perl program or a Perl script? <faq@denver.pm.org>
        FAQ: What's the difference between "perl" and "Perl"? <faq@denver.pm.org>
    Re: find() within find()? <goldbb2@earthlink.net>
    Re: handling a file with a perl script <gnarinn@hotmail.com>
    Re: handling a file with a perl script <dbe@wgn.net>
    Re: How do I use html name anchor tag when html generat <pne-news-20010708@newton.digitalspace.net>
    Re: MS proxy server <simon.hughes@bluewin.ch>
    Re: Multine REGEX <pne-news-20010708@newton.digitalspace.net>
        Need object files for CPAN modules <sforshee@umr.edu>
    Re: passing information between mutiple forms (David Efflandt)
    Re: Perl 6 (Randal L. Schwartz)
        Simple Reg Ex - Why not greedy? (mc)
    Re: Simple Reg Ex - Why not greedy? <krahnj@acm.org>
    Re: Simple Reg Ex - Why not greedy? <trondmm-usenet@crusaders.no>
    Re: Simple Reg Ex - Why not greedy? (mc)
    Re: Simple Reg Ex - Why not greedy? <bart.lateur@skynet.be>
    Re: Term::ANSIColor in Windows 2000's CMD <J.G.Ross@warwick.ac.uk>
    Re: timeout for perl / win32 ?? <dbe@wgn.net>
    Re: Upload probs <gnarinn@hotmail.com>
        variable require <daniel304@planet.nl>
    Re: variable require <dbe@wgn.net>
    Re: variable require <pne-news-20010708@newton.digitalspace.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 08 Jul 2001 15:05:46 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: (csv) Split at a coma, how?
Message-Id: <3B48AF0A.8669CD20@earthlink.net>

Steve Martin wrote:
> 
> Hi,
> 
> I am doing a small script that opens a weekly schedule that an admin
> assist is producing and saving in .csv.
> I need to know how to split at every coma in order to incert every
> separation in a nice html table.  I need the splitting codes that
> could be added to my own codes.  See the perl codes a the bottom of
> this post.
> 
> The schedule looks something like this:  <start>
> 
>       "Version finale, le 18 mai,
> 2001",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
>       Saison du 4 juin au 3 septembre
> 2001,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
[snip]

#!/usr/bin/perl -w
use strict;

use CGI::Pretty qw(:standard *table);
use CGI::Carp qw(fatalsToBrowser);
use HTML::Entities;
use Text::CSV_XS; # available from CPAN.

my $csv = Text::CSV_XS->new {binary=>1};
my $file = "D:/Apache/cgi-bin/horaire.csv"; # forward slash works.
open( my $fh, "<", $file ) or die "Couldn't open $file: $!\n";

print header, begin_html, begin_table;
while(<$fh>) {
	$_ .= <$fh> until( $csv->parse $_ or eof $fh );
	if( !$csv->status ) {
		die "Unexpected EOF at line $.\n" if eof $fh;
		my $err = $csv->error_input;
		die "Invalid CSV data: <$err> at line $.\n";
	}
	print &Tr td [ map{ encode_entities $_ }, $csv->fields ];
	# normally I don't use & with subs, but in this case, I want
	# it to prevent Td from looking like a filehandle.  I could add
	# parens, but this looks better.
}
print end_table, end_html;
__END__

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Mon, 09 Jul 2001 00:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Is it a Perl program or a Perl script?
Message-Id: <0K627.64$T3.177485312@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.

+
  Is it a Perl program or a Perl script?

    Larry doesn't really care. He says (half in jest) that "a script is what
    you give the actors. A program is what you give the audience."

    Originally, a script was a canned sequence of normally interactive
    commands--that is, a chat script. Something like a UUCP or PPP chat
    script or an expect script fits the bill nicely, as do configuration
    scripts run by a program at its start up, such .cshrc or .ircrc, for
    example. Chat scripts were just drivers for existing programs, not
    stand-alone programs in their own right.

    A computer scientist will correctly explain that all programs are
    interpreted and that the only question is at what level. But if you ask
    this question of someone who isn't a computer scientist, they might tell
    you that a *program* has been compiled to physical machine code once and
    can then be run multiple times, whereas a *script* must be translated by
    a program each time it's used.

    Perl programs are (usually) neither strictly compiled nor strictly
    interpreted. They can be compiled to a byte-code form (something of a
    Perl virtual machine) or to completely different languages, like C or
    assembly language. You can't tell just by looking at it whether the
    source is destined for a pure interpreter, a parse-tree interpreter, a
    byte-code interpreter, or a native-code compiler, so it's hard to give a
    definitive answer here.

    Now that "script" and "scripting" are terms that have been seized by
    unscrupulous or unknowing marketeers for their own nefarious purposes,
    they have begun to take on strange and often pejorative meanings, like
    "non serious" or "not real programming". Consequently, some Perl
    programmers prefer to avoid them altogether.

- 

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.

                                                           01.12
-- 
    This space intentionally left blank


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

Date: Sun, 08 Jul 2001 18:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: What's the difference between "perl" and "Perl"?
Message-Id: <ws127.59$T3.135468032@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.

+
  What's the difference between "perl" and "Perl"?

    One bit. Oh, you weren't talking ASCII? :-) Larry now uses "Perl" to
    signify the language proper and "perl" the implementation of it, i.e.
    the current interpreter. Hence Tom's quip that "Nothing but perl can
    parse Perl." You may or may not choose to follow this usage. For
    example, parallelism means "awk and perl" and "Python and Perl" look OK,
    while "awk and Perl" and "Python and perl" do not. But never write
    "PERL", because perl isn't really an acronym, apocryphal folklore and
    post-facto expansions notwithstanding.

- 

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.

                                                           01.11
-- 
    This space intentionally left blank


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

Date: Sun, 08 Jul 2001 15:39:58 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: find() within find()?
Message-Id: <3B48B70E.C271E62@earthlink.net>

Patrick Flaherty wrote:
> 
> John, Clinton,
> 
>   Thanx, both good points.
> 
>   I realized that find within find is _not_ what I want to do, and
> rewrote as:
> 
> use File::Find;
> my $this_subtree;
> 
> @ARGV = ('.') unless @ARGV;
> # print @ARGV[0];
> opendir(DIR, ".") or die "can't opendir $dirname: $!";
> while (defined($file = readdir(DIR))) {
>     if (-d $file && $file ne "." && $file ne "..") {
>         find sub { $this_subtree += -s }, $file;
>         write();
>         $this_subtree = 0;
>     }
> }

@ARGV ||= ".";
my @dirs = map {
	opendir(my $dh, my $dn = $_)
		or die "Can't opendir $dn: $!\n";
	grep -d, map "$dn/$_", grep !/^\.\.?$/, readdir $dh;
} @ARGV;
for (@dirs) {
	my $this_subtree = 0;
	find sub { $this_subtree += -s }, $_;
	write;
}

> 
> format STDOUT =
> @<<<<<<<<<<<<<<<<<<<<<          @###########
> $file                          $this_subtree
> .
> 
> This works quite well.  Now if I can just figure out how to pass @ARGV
> to opendir, I'll be even happier.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Sun, 8 Jul 2001 18:40:17 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: handling a file with a perl script
Message-Id: <994617617.536239380948246.gnarinn@hotmail.com>

In article <3B4672D4.257ABD4A@wgn.net>, $Bill Luebkert <dbe@todbe.com> wrote:
>Ka-Hing Cheung wrote:
>> 
>> how to hadle a requested file with a certain extension with a perl
>> script?
>
(snipped how to declare a cgi script in .htaccess)

I thin Bill is not understanding the original posters quetstion gere.

I think the OP should visit perl.apache.org to find docs about this
matter. look at some other handlers to get a idea.
http://perl.apache.org/src/apache-modlist.html

gnari


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

Date: Sun, 08 Jul 2001 17:38:23 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: handling a file with a perl script
Message-Id: <3B48FCFF.BCDE0998@wgn.net>

gnari wrote:
> 
> In article <3B4672D4.257ABD4A@wgn.net>, $Bill Luebkert <dbe@todbe.com> wrote:
> >Ka-Hing Cheung wrote:
> >>
> >> how to hadle a requested file with a certain extension with a perl
> >> script?
> >
> (snipped how to declare a cgi script in .htaccess)
> 
> I thin Bill is not understanding the original posters quetstion gere.
> 
> I think the OP should visit perl.apache.org to find docs about this
> matter. look at some other handlers to get a idea.
> http://perl.apache.org/src/apache-modlist.html

Might have helped if it was clearly stated. :)

Like maybe an example/scenario would help.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Sun, 08 Jul 2001 21:50:45 +0200
From: Philip Newton <pne-news-20010708@newton.digitalspace.net>
Subject: Re: How do I use html name anchor tag when html generated by perl?
Message-Id: <m8ehktc78dgui7gg4f6n41siqcs1t5a2mf@4ax.com>

[Crosspost and followup-to comp.infosystems.www.authoring.html]

On Sun, 8 Jul 2001 16:38:12 +0100, Mark Worsdall <perl@wizdom.org.uk>
wrote:

> I have perl generating some big web pages, so to make life easier for 
> the user I wanted to use the html name tag so the user ends up where 
> they were last.
> 
> I tried sticking #55 on the end of a POST method (program.pl#55) but the 
> html did not display at position 55 where the name 55 was.

That should work provided the HTML output of program.pl contains
something like '<a name="55">here</a>', or '<a id="55">here</a>' in
XHTML. Note that AFAIK some browsers don't recognise named anchors if
they do not contain text. If you can't put the <a>...</a> pair around
anything (a sub-heading perhaps), use a &nbsp; at least.

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: Sun, 8 Jul 2001 21:30:10 +0200
From: "Simon Hughes" <simon.hughes@bluewin.ch>
Subject: Re: MS proxy server
Message-Id: <3b48b4c3$1_2@news.bluewin.ch>

Assuming you're running on NT/Win2K, this isn't really a Perl question -
this applies to any script or executable. You have to execute the script in
the security context of a valid NT domain account with permissions to access
the Internet via MS Proxy. Probably the easiest way is to schedule the
script using the Task Scheduler (in Win2K, or install IE5.0 on NT4, which
updates the Schedule service to Task Scheduler). Task Scheduler allows you
to specify a user account to run the task, so you can launch it as
MYDOMAIN\myuser, assuming you have the account's password of course.

Incidentally, good practice is to create a new domain account for running
batch jobs - don't use your personal account, even if it's more convenient.
If your account is ever locked out or deleted, your batch jobs won't run.
Conversely, a bad batch job can lock out your personal account if it fails
to authenticate repeatedly. You also make a mess of your audit trail, as you
can't distinguish between actions performed by you personally and by your
scripts. Sorry if all this is preaching to the choir, but everyone does it,
and it's just not clever.

Alternatively, on Win2K only, you could use RUNAS to specify the security
context from a batch file wrapper, but you'd still have to schedule it. The
advantage here is that the wrapper would be easier to update when you change
the account or password, although possibly less secure, depending on how
good you are with your NTFS permissions (having passwords in plain text
batch files is not good). It would also be more flexible in terms of how you
launch the script.


"Lee Bennett" <talon@anytimenow.com> wrote in message
news:1104_994611426@sabre...
> Hi
>
> Does anyone know how to authenicate a user via a NT PDC or BDC to that a
perl script can access the web via a Mircosoft proxy server.
>
> Thanks
>




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

Date: Sun, 08 Jul 2001 21:53:00 +0200
From: Philip Newton <pne-news-20010708@newton.digitalspace.net>
Subject: Re: Multine REGEX
Message-Id: <peehkt0d9qaccke4jt8hgljnqshrsbl131@4ax.com>

On Sun, 08 Jul 2001 15:38:15 GMT, "Buck Turgidson"
<jc_va@spamisnotcool.hotmail.com> wrote:

>    if ( /TABLESPACE\s(\w+)/ ) {

This won't match since

>    ABSENCE_CLASS) TABLESPACE
>    TSORPHAN STORAGE (INITIAL 4096 NEXT 4096
>    /

you have initial whitespace at the beginning of lines, so there's 
"\n   " between the 'TABLESPACE' and the '\w+' and not just one
whitespace. Try using \s+ 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: Sun, 8 Jul 2001 13:17:32 -0500
From: "Seth Forshee" <sforshee@umr.edu>
Subject: Need object files for CPAN modules
Message-Id: <sr127.4798$Ib.499727@news1.primary.net>

Hello,

Can anyone tell me where I can get copies of the object files for the
Text::CSV_XS and SQL::Statement modules for HP-UX?  I'm trying to install
these modules into my home directory on the Unix system where I go to
school, but due to restrictions on memory useage, the installation fails
when it tries to compile the C code, and so far the university has not been
helpful when I ask about getting the modules installed.  So if anyone can
tell me where to find them or can send them to me, I would greatly
appreciate it.

Seth




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

Date: Sun, 8 Jul 2001 18:10:01 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: passing information between mutiple forms
Message-Id: <slrn9kh8fp.lh7.see-sig@typhoon.xnet.com>

On Thu, 05 Jul 2001 10:25:26 -0400, Umair Tariq Bajwa <ub98aa@brocku.ca> wrote:
> 
> I have a main script called "awards.pl" from where i execute another
> script called "investigator.pl" in a seperate popup window. Once the
> user enters all the information in investigator.pl he/she hits "Done"
> button. What I would like to do is once the user will hit Done,
> I would like to store all information in hash and pass it to "awards.pl"
> (the main script from where its being executed or called) something like
> that. Any suggestions? Does anyone know how can i do that? Any idea is
> most welcome. Thanks in advance.

Are you talking about CGI or JavaScript (both subjects for other 
newsgroups) or some other windowing method (tk?)?

I commonly use a single script that submits to itself and does different
things depending upon which variables have a value (or certain value).  
If no data is passed to it, a blank form would come up.  From there I
store previous values that need to be passed on as hidden fields (or
visible fields if anything needs editing or correction).

But anything that matters from a security standpoint should be entered and 
authenticated (or reauthenticated) on the last form before the data is 
acted upon.

-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 08 Jul 2001 15:07:40 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl 6
Message-Id: <m1u20nqdlf.fsf@halfdome.holdit.com>

>>>>> "None" == None  <pohanl@aol.com> writes:

None> Is it true Perl 6 will allow your scripts to run on the Java
None> virtual machine?

Ask Schroedinger's Cat, if you happen to see it.

-- 
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: Sun, 08 Jul 2001 20:32:00 GMT
From: nospam@home.com (mc)
Subject: Simple Reg Ex - Why not greedy?
Message-Id: <3b48c0ce.58676583@news>

Simple question for you...

$ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){0,2}//'
Hey diddle diddle the cat ...
$ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){1,2}//'
Hey the cat ...

Why isn't the former example greedy and swallow up the 
diddle's as one might expect?  I get the same behavior with
* and +.

$ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.)*//'
Hey diddle diddle the cat ...
$ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.)+//'
Hey the cat ...

Throwing a /g modifier makes it behave as I would expect
but I don't understand what's going on here.  Anybody care to
clue me in?

I'm using perl 5.005_03 if that's any help.




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

Date: Sun, 08 Jul 2001 22:58:10 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Simple Reg Ex - Why not greedy?
Message-Id: <3B48E5CB.41A830BA@acm.org>

mc wrote:
> 
> Simple question for you...
> 
> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){0,2}//'
> Hey diddle diddle the cat ...
> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){1,2}//'
> Hey the cat ...
> 
> Why isn't the former example greedy and swallow up the
> diddle's as one might expect?  I get the same behavior with
> * and +.
> 
> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.)*//'
> Hey diddle diddle the cat ...
> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.)+//'
> Hey the cat ...
> 
> Throwing a /g modifier makes it behave as I would expect
> but I don't understand what's going on here.  Anybody care to
> clue me in?

Since {0,2} and * can match _zero_ times there is no reason for the
regex to search any further.



John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 08 Jul 2001 23:14:49 GMT
From: "Trond Michelsen" <trondmm-usenet@crusaders.no>
Subject: Re: Simple Reg Ex - Why not greedy?
Message-Id: <JP527.8422$qR5.929766@news01.chello.no>

mc <nospam@home.com> skrev i meldingsnyheter:3b48c0ce.58676583@news...
> Simple question for you...

> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){0,2}//'
> Hey diddle diddle the cat ...
> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){1,2}//'
> Hey the cat ...

> Why isn't the former example greedy and swallow up the
> diddle's as one might expect?  I get the same behavior with
> * and +.
> Throwing a /g modifier makes it behave as I would expect
> but I don't understand what's going on here.  Anybody care to
> clue me in?

sure. The expression /(diddle.)*/ matches either nothing ('') or as many
'diddle's it can, so your first match is '' at the very beginning of the
line.

change your replacement to '-' to visualize all your matches:

[trondmm@dev1] ~> echo Hey diddle diddle the cat ... | \
   perl -pe 's/(diddle.)*/-/'
-Hey diddle diddle the cat ...

As you see - Your regex matches nothing at the beginning of the string.

[trondmm@dev1] ~> echo Hey diddle diddle the cat ... | \
   perl -pe 's/(diddle.)*/-/g'
-H-e-y- --t-h-e- -c-a-t- -.-.-.-

Here it matches nothing all through the string, and it also matches the
'diddle's

It's perhaps easier to understand with the regex /(diddle.)+|/
which basically says "I want 1 or more 'diddle's or nothing at all"

[trondmm@dev1] ~> echo Hey diddle diddle the cat ... | \
   perl -pe 's/(diddle.)+|/-/g'
-H-e-y- --t-h-e- -c-a-t- -.-.-.-


HTH

--
Trond Michelsen





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

Date: Mon, 09 Jul 2001 00:03:58 GMT
From: nospam@home.com (mc)
Subject: Re: Simple Reg Ex - Why not greedy?
Message-Id: <3b48f405.71789194@news>

On Sun, 08 Jul 2001 22:58:10 GMT, "John W. Krahn" <krahnj@acm.org>
wrote:

>mc wrote:
>> 
>> Simple question for you...
>> 
>> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){0,2}//'
>> Hey diddle diddle the cat ...
>> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.){1,2}//'
>> Hey the cat ...
>> 
>> Why isn't the former example greedy and swallow up the
>> diddle's as one might expect?  I get the same behavior with
>> * and +.
>> 
>> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.)*//'
>> Hey diddle diddle the cat ...
>> $ echo Hey diddle diddle the cat ... | perl -pe 's/(diddle.)+//'
>> Hey the cat ...
>> 
>> Throwing a /g modifier makes it behave as I would expect
>> but I don't understand what's going on here.  Anybody care to
>> clue me in?
>
>Since {0,2} and * can match _zero_ times there is no reason for the
>regex to search any further.

I thought about that too but {1,2} can match one or two times,
yet it matches two.  Why does {0,2} appear to follow a different rule?

Thanks.



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

Date: Mon, 09 Jul 2001 00:34:35 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Simple Reg Ex - Why not greedy?
Message-Id: <gguhkt0cr5psqbseushqlmpcpkhddradi2@4ax.com>

mc wrote:

>I thought about that too but {1,2} can match one or two times,
>yet it matches two.  Why does {0,2} appear to follow a different rule?

You know, there's both greed and laziness in a regex. The regex will
attempt to do an as greedy as possibly match at the current starting
point. Only if it fails, it will do a next attempt on the next character
position, i.e. right after the first character.

So /(diddle.){1,2}/ has to match at least one diddle something. Anything
less is a failure. So the regex will continue attempting matching
"diddle" something, until it succeeds. At that point there are two
diddles, so that is what it matches. Greediness: an as long as possible
match at the first position where it matches.

But /(diddle.){0,2}/ only needs to match... nothing. That match will
succeed on every starting point, including at the very start of the
string. So that's where it matches. No "diddle"s there, but that's good
enough. And there no reason to go on searching for a longer match. That
NEVER happens. So

	"abbabbba" =~ /b+/

will only match two b's, because that's how many there are at the first
position that the regex matches. The fact that there could have been a
longer match further on, is never even considered.

In fact, trying to find the longest match in a string, is not a trivial
question. It's a good exercise, even for experienced perlers.

-- 
	Bart.


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

Date: Sun, 8 Jul 2001 23:38:13 +0100
From: James Ross <J.G.Ross@warwick.ac.uk>
Subject: Re: Term::ANSIColor in Windows 2000's CMD
Message-Id: <Pine.SOL.4.30.0107082326450.16531-100000@mimosa.csv.warwick.ac.uk>

On Sun, 8 Jul 2001, Mark Dudley wrote:

> > Has anyone successfully used the Term::ANSIColor module in Windows 2000's
> > CMD using ActivePerl?  I've tried using code straight from the module's
> > documentation, but still see the standard colors.  If I run the same
> script
> > on a Linux console, everything works as expected.  Is this a limitation of
> > CMD or is there a special option to allow for ANSI colors in it?  Thanks
> for
> > your help.
>
> I have not seen this module, but..
> "Back in the old days", in order to get color from a prompt, you needed to
> run the ANSI.SYS driver (or better, NANSI.SYS) unless you were writing in a
> application that had a CRT interface or was written in assembly.

I also have not used this module, but I can be certain that the default
settings for the CMD prompt in Windows 2000 will work with the standard
ANSI commands, including the 8 basic colours. I assume (having not seen
the code) that Term::ANSIColor uses the standard ^[[3?m and ^[[4?m escape
codes (^[ is the standard representation of character 27, ESC, in case you
didn't know ;) ) to set the foreground and background colours,
respectivly.

I should also point out that, depending on the documentation for
Term::ANSIColor, your results may differ slightly from what you expect.
The main difference I've had people complaining about is the
representation of 'bold', which the CMD prompt, and IIRC the standard
Linux prompt, renders using a *lighter* colour, rather than bold. (FYI,
the ANSI command for bold is ^[[1m)

--
James Ross J.G.Ross@warwick.ac.uk

"I can't imagine ever needing more than 640K."
                    -- Bill Gates, 1981



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

Date: Sun, 08 Jul 2001 12:56:56 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: timeout for perl / win32 ??
Message-Id: <3B48BB08.44C569CB@wgn.net>

"Carlo B." wrote:
> 
> "Stefan Geißler" <stefan.geissler@temis-group.com> escribió en el mensaje
> news:9i4e6t$mvt1@news-1.bank.dresdner.net...
> > Hi all,
> >
> > does anyone know how to set a timeout for perl on win32 systems?
> >
> > Say you need to do a system call and if this doesn't return within a
> > specified time, you
> > The alarm() call that is mentioned in perl example for Unix does not exist
> > and I haven't been able to find another solution.
> >
> > Any help greatly appreciated.
> > Best,
> > Stefan Geißler
> >
> Im stuck in this problem too, with perl for win32 the alarm function is not
> implemented, so is supposed that the only way to add a timeout is using the
> select(2) system call.
> From perlfunc:
> ----
> select RBITS,WBITS,EBITS,TIMEOUT
> 
> This calls the select(2) system call with the bit masks specified, which can
> be constructed using fileno and vec, along these lines:
>     $rin = $win = $ein = '';
>     vec($rin,fileno(STDIN),1) = 1;
>     vec($win,fileno(STDOUT),1) = 1;
>     $ein = $rin | $win;
> If you want to select on many filehandles you might wish to write a
> subroutine:
> 
>     sub fhbits {
>         my(@fhlist) = split(' ',$_[0]);
>         my($bits);
>         for (@fhlist) {
>             vec($bits,fileno($_),1) = 1;
>         }
>         $bits;
>     }
>     $rin = fhbits('STDIN TTY SOCK');
> The usual idiom is:
> 
>     ($nfound,$timeleft) =
>       select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
> or to block until something becomes ready just do this
> 
>     $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
> Most systems do not bother to return anything useful in $timeleft, so
> calling select() in scalar context just returns $nfound.
> 
> Any of the bit masks can also be undef. The timeout, if specified, is in
> seconds, which may be fractional. Note: not all implementations are capable
> of returning the$timeleft. If not, they always return $timeleft equal to the
> supplied $timeout.
> 
> You can effect a sleep of 250 milliseconds this way:
> 
>     select(undef, undef, undef, 0.25);
> WARNING: One should not attempt to mix buffered I/O (like read or <FH>) with
> select, except as permitted by POSIX, and even then only on POSIX systems.
> You have to use sysread instead.
> 
> ----
> 
> Now i've triyed for weeks to find the way to make this work but since now
> seems all to complicate and i cannot find a good example about how to add a
> timeout for a socket connect call. Let me know if it works for you.

1) You can't use select in his case since he's in the middle of a system call 
and has no way to start the select since he's forced to wait for completion.

2) IO::Socket and IO::Select are easier to use IMO than the above.

3) Select only works on sockets in Win32 (not STDIN, files, etc.).

Obviously you could do something with a master task that starts a BG task
and uses sockets to get the data back.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Sun, 8 Jul 2001 18:50:12 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Upload probs
Message-Id: <994618212.529344995506108.gnarinn@hotmail.com>

In article <9i58oj$gkthn$1@ID-78897.news.dfncis.de>,
Emil Horowitz <mail@nexo.de> wrote:
>Hi,
>
>close to desperation, here is my call for help: In one of my scripts I have
>an upload routine to give the user the possibility to upload a picture. This
>should be quite simple, but it does not work. The file name arrives all
>right on the server, but not the file itself. After uploading, the file size
>is 0.
>
>The server is UNIX, the source file comes from a Windows PC with Windows
>path-syntax. I use this code:
>
>
>my $sourceFile = 'c:\img\mypic.gif';
>my $targetFile = '../img/tarpic.gif';
>open (OUTFILE, ">$targetFile");
>print "$targetFile<br>";
> while (my $bytesread = read($quellDatei, my $buffer, 1024))
>  print OUTFILE $buffer;
> }
>chmod (0404, "$targetFile");
>close (OUTFILE);
>
>This should work, should it not? Please help!
>

please make a minimal program that is supposed to do what you
want, and post that, telling us in what way it does not do what you
expect.

is this a cgi script using CGI.pm?

gnari


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

Date: Sun, 8 Jul 2001 20:30:32 +0200
From: "Daniel van den Oord" <daniel304@planet.nl>
Subject: variable require
Message-Id: <9ia8mb$kr2r$1@reader03.wxs.nl>

How can I make the required field partially variable ?!?
I want to be able to use a template file using the require command
I tried it like this and this works of course

require "c:/Inetpub/wwwroot/news/preedit.cgi";

However I want it to be partially variable something like this

require "c:/Inetpub/wwwroot/$page";

this doesn't work like duh *S*
so I tried this

require "c:/Inetpub/wwwroot/"+ $page +"";

doens't work either :(
Can anybody show me how it can be done ?!?

THanks Daniel




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

Date: Sun, 08 Jul 2001 12:49:17 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: variable require
Message-Id: <3B48B93D.96E21352@wgn.net>

Daniel van den Oord wrote:
> 
> How can I make the required field partially variable ?!?
> I want to be able to use a template file using the require command
> I tried it like this and this works of course
> 
> require "c:/Inetpub/wwwroot/news/preedit.cgi";
> 
> However I want it to be partially variable something like this
> 
> require "c:/Inetpub/wwwroot/$page";

That should work if $page is defined.  You may need to import it also.

> this doesn't work like duh *S*
> so I tried this
> 
> require "c:/Inetpub/wwwroot/"+ $page +"";

The concatenation operator is '.' not '+'.

> doens't work either :(
> Can anybody show me how it can be done ?!?

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Sun, 08 Jul 2001 22:13:09 +0200
From: Philip Newton <pne-news-20010708@newton.digitalspace.net>
Subject: Re: variable require
Message-Id: <hifhkton91836h9u9fg7j7l1hh9b75ct0e@4ax.com>

[Groups trimmed to clpmisc]

On Sun, 8 Jul 2001 20:30:32 +0200, "Daniel van den Oord"
<daniel304@planet.nl> wrote:

> How can I make the required field partially variable ?!?
> I want to be able to use a template file using the require command
> I tried it like this and this works of course
> 
> require "c:/Inetpub/wwwroot/news/preedit.cgi";
> 
> However I want it to be partially variable something like this
> 
> require "c:/Inetpub/wwwroot/$page";

That looks good, providing that $page is assigned a value before this
statement is executed.

> require "c:/Inetpub/wwwroot/"+ $page +"";

This will have the same effect as

    require 0;

, though you'll get some warnings about "argument is not numeric in add"
if you've enabled warnings.

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: 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 1267
***************************************


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