[9829] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3422 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 11 22:07:54 1998

Date: Tue, 11 Aug 98 19:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 11 Aug 1998     Volume: 8 Number: 3422

Today's topics:
    Re: ===> Parsing Cobol in Perl <Savage.Ron.RS@bhp.com.au>
    Re: Can't make flock work as described... (Gossamer)
    Re: checking if files exist <rootbeer@teleport.com>
    Re: checking if files exist <tchrist@mox.perl.com>
    Re: dates in excess of 2037 (A Problem???) (Michal Jaegermann)
    Re: Does anyone have a Win32 icon for Perl files? <REPLY_TO_lastronin@earthlink.net>
    Re: File updating question <kpatel@mathworks.com>
    Re: File updating question <rootbeer@teleport.com>
    Re: File updating question <ketanp@NOSPAMxwebdesign.com>
        How to test for failed command open useing FileHandle <enaiman@ndsisrael.com>
    Re: HTML & Javascript Tests (Andre L.)
        Incorporating basic SMTP functionality  into script posenj@lancet.co.za
    Re: Incorporating basic SMTP functionality  into script <rootbeer@teleport.com>
    Re: Incorporating basic SMTP functionality  into script (Alastair)
        Latent data on Perl Generated HTML <bobm@cunix.com>
    Re: line of text. (Mike Stok)
    Re: line of text. (Abigail)
    Re: Pattern matching (text all uppercase) (Ian McGowan)
        Perl CGI OLE Poligimy <davids@sdsc.edu>
    Re: Perl CGI OLE Poligimy <rootbeer@teleport.com>
    Re: Perl Debugger Problem? (Ilya Zakharevich)
        Problem calling executables from Win95 ('General failiu posenj@lancet.co.za
        Regexp this! (if possible anyhow...) <matthies@fsinfo.cs.uni-sb.de>
    Re: Regexp this! (if possible anyhow...) <rootbeer@teleport.com>
    Re: Regexp this! (if possible anyhow...) <dagon@halcyon.com>
    Re: removing elements from an array (Abigail)
        run external program from perl (Steve .)
    Re: run external program from perl (Alastair)
    Re: run external program from perl (Bob Trieger)
        Shared File Locking on Win32  :-[ <steph@hotkey.net.au>
        system() problem <aacwn100@york.ac.uk>
    Re: system() problem <rootbeer@teleport.com>
    Re: What's the most efficient regex to force NOT matchi <rootbeer@teleport.com>
    Re: What's the most efficient regex to force NOT matchi (Ilya Zakharevich)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 11 Aug 1998 23:19:36 GMT
From: "Ron Savage" <Savage.Ron.RS@bhp.com.au>
Subject: Re: ===> Parsing Cobol in Perl
Message-Id: <01bdc57f$102dd700$8aeb1286@steelres-pcm657.resmel.bhp.com.au>

I have code which parses PIC clauses. I guess if it's got a PIC is an id...
It's at home & I'm not. Want it?
-- 
Ron Savage
Home (preferred): rpsavage@ozemail.com.au
Office: Savage.Ron.RS@bhp.com.au
http://www.ozemail.com.au/~rpsavage

Naji Mouawad <naji.mouawad@cmpx.saic.com> wrote in article
<35d0a7f5.16533250@news>...
> I have need to parse cobol modules (about 100 of them) and build a
> rather simple symbol table of identifiers.
> 
> Anyone has written a cobol parser out there?
> 
> On a related issue, anyone has used Perl to do remedial/mitigation
> regarding Y2K on Cobol using Perl?
> 
> Successs, pitfalls, ideas?
> 
> Thanks,
> 
> Naji.
> 


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

Date: 12 Aug 1998 01:12:16 GMT
From: gossamer@tertius.net.au (Gossamer)
Subject: Re: Can't make flock work as described...
Message-Id: <slrn6t1peh.fnc.gossamer@penguin.glasswings.com.au>

Randal Schwartz (merlyn@stonehenge.com) wrote...
> >>>>> "Todd" == Todd B <tbeaulieu@mediaone.net> writes:
> Todd> this is why i HATE newgroups, and love compuserve.  there is
> Todd> such an enormous lack of professionalism on the net.
> This is why I hate the fact that "Netscape" and "MSIE" have a "post"
> button.  There is such an enormous lack of maturity on the net.
> (Note: all strictly tongue-in-cheek... if you're offended, you
> must be easily offended. :-)

Appreciated :)

As for the last, you'd be amazed at how much this helps (it's SLRN
scorefile synatx, but the gist is grokkable I suspect):

[alt.sysadmin.recovery, comp.databases*, comp.infosystems*, comp.mail*, comp.os*, comp.lang.perl*, news.*]
Score:: -99
   X-Newsreader: Microsoft
   X-Newsreader: Agent
   X-Newsreader: \<Win
   User-Agent: \<Win
   X-Http-User-Agent: Mozilla
   X-Mailer: Mozilla


Gossamer
Unashamadly Elitist.

-- 
: Gossamer     gossamer@tertius.net.au  | Xanadoodler
: http://www.tertius.net.au/~gossamer/  | And proud of it :)
: Programming today is a race between software engineers striving to
: build bigger and better idiot-proof programs, and the Universe trying
: to produce bigger and better idiots.  So far, the Universe is
: winning.  -- Rick Cook


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

Date: Tue, 11 Aug 1998 23:04:37 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: checking if files exist
Message-Id: <Pine.GSO.4.02.9808111603320.10161-100000@user2.teleport.com>

On Tue, 11 Aug 1998, Steve . wrote:

> I need to check if a directory is empty.  

Try rmdir. ;-)

> How do I go about checking if files exist in a directory?  

I think you want readdir and friends. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 12 Aug 1998 01:51:00 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: checking if files exist
Message-Id: <6qqse4$e6r$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, syarbrou@ais.net (Steve .) writes:
:How do I go about checking if files exist in a directory?  Thanks.

Assuming that you bothered to install a reasonable operating system and
traditional filesystem, the following is efficient and effective:

    $is_empty = (stat($dir))[3] == 2;

If one of my premises is false, you're on your own.

--tom
-- 
Unix is defined by whatever is running on Dennis Ritchie's machine.


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

Date: 12 Aug 1998 01:27:58 GMT
From: michal@gortel.phys.ualberta.ca (Michal Jaegermann)
Subject: Re: dates in excess of 2037 (A Problem???)
Message-Id: <6qqr2u$che$1@pulp.ucs.ualberta.ca>

Larry Rosler (lr@hpl.hp.com) wrote:

: Provided integer representations and arithmetic were also done using 64-
: bit quantities.  What plans are there for Perl to switch to 64-bit 
: internal integer representations Any Time Soon Now?

$ perl -e 'print (scalar localtime 2**55)'
Sat Jun 12 23:26:08 1141709097

This is on Alpha (and this is not really Perl but an undelying library :-)

  --mj



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

Date: Tue, 11 Aug 1998 20:33:38 -0400
From: "Ha" <REPLY_TO_lastronin@earthlink.net>
Subject: Re: Does anyone have a Win32 icon for Perl files?
Message-Id: <6qqn8a$na4$1@oak.prod.itd.earthlink.net>

What kind of icon are you looking for? We made a yellow happy face for ours.
Or, you can do a screen chapter and squish the ActiveState logo down to
32x32 and save it as *.ico. If you have a particular fancy, let me know and
I'll forward you want a nifty icon in a sec.

ha quach
mailto:info@r-go.com

Karl Forsberg wrote in message <6qqb85$9vl$1@cubacola.tninet.se>...
>Question as above. Active State Perl did not come with any specific icon.
>
>




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

Date: Tue, 11 Aug 1998 19:18:53 -0400
From: Ketan Patel <kpatel@mathworks.com>
Subject: Re: File updating question
Message-Id: <35D0D15D.F04F568E@mathworks.com>

This is similar to the 'updating array' problem, but only one file is
opened/updated/closed (instead of open/update/write to new)... I believe the
"slurping of a file into a fat array" that I am doing is causing some problems
considering this is run on a website after every hit... How would I go about
'optimizing' this process?

$dataPath = "sites.txt"; #sites.txt is a ~100 line text file (~25k) in which
fields are separated by "|"'s

sub check_status{
    open(DATA,"<$dataPath");
    flock DATA, 2;
    @databaseArray = <DATA>;
    close(DATA);

    $x = 0;

    foreach (@databaseArray) {
        @sitesArray = split(/\|/,$databaseArray[$x]);
        [do stuff to each element of @sitesArray]
        $databaseArray[$x] = join("\|",@sitesArray);
        $x++;
    }

    open(DATA,">$dataPath");
    flock DATA, 2;
    print DATA @databaseArray;
    close(DATA);
}



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

Date: Tue, 11 Aug 1998 23:39:37 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: File updating question
Message-Id: <Pine.GSO.4.02.9808111637170.10161-100000@user2.teleport.com>

On Tue, 11 Aug 1998, Ketan Patel wrote:

>     open(DATA,"<$dataPath");

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

>     flock DATA, 2;

You should really get this value from a module, rather than use a literal.
But if you mean that you want an exclusive lock, most systems won't give
it to you when you opened only for read.

>     @databaseArray = <DATA>;
>     close(DATA);

Uh oh. If you meant to keep that lock, this isn't going to work!

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 11 Aug 1998 21:08:22 -0400
From: Ketan Patel <ketanp@NOSPAMxwebdesign.com>
Subject: Re: File updating question
Message-Id: <35D0EB06.F7457814@NOSPAMxwebdesign.com>

Tom Phoenix wrote:

> 
> >     @databaseArray = <DATA>;
> >     close(DATA);
> 
> Uh oh. If you meant to keep that lock, this isn't going to work!
> 

This is part of my problem... As you can see in the original code, I
read in the whole file (as an array), go to each line (~100), split it
into another array (of 12 elements) and modify it.  Then, I write the
whole modified array back to the file (overwriting the previous data). 
What is a more efficient way of doing this?  Doing it the way I am now
(open input,read data,close input ---> modify data ---> open
output,write data,close output)?  Or should I leave the file open the
entire time (open input,read data,modify data,write data,close input)? 
If the second method is recommended, I'm not quite sure how to go line
by line (as recommended earlier) and make changes without reading in the
whole array in the beginning...


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

Date: 12 Aug 1998 00:56:26 GMT
From: "Ephrayim \"EJ\" Naiman" <enaiman@ndsisrael.com>
Subject: How to test for failed command open useing FileHandle
Message-Id: <01bdc588$e4375ea0$77140a0a@enaimanlt.ilndc.com>

I seem to be overlooking something here, any help would be appreciated.
--------------------------------------------
use FileHandle;
$fh = new FileHandle("non-existent-command |");
if(!defined($fh))
{
    die("Could not find command ...");
}

No matter what I do, the $fh still comes back defined.  What can/should I
test for?

-- -----------------------------------------
Ephrayim "EJ" Naiman
enaiman@ndsisrael.com


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

Date: Tue, 11 Aug 1998 20:44:38 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: HTML & Javascript Tests
Message-Id: <alecler-1108982044380001@dialup-725.hip.cam.org>

In article <Pine.GSO.4.02.9808111045440.10161-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:

[...]

> So, why are you posting this to a newsgroup about Perl? Perl isn't HTML,
> and Perl isn't JavaScript. Should movie reviews be posted to a newsgroup
> about Volkswagens merely because there are drive-in theaters? :-) 

A review of The Love Bug could be the exception, of course. :-)

Andre


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

Date: Mon, 10 Aug 1998 00:59:27 GMT
From: posenj@lancet.co.za
Subject: Incorporating basic SMTP functionality  into script
Message-Id: <35ce4548.2588325@news.saix.net>

I'm using an external mail client to send e-mail.

I would far prefer to incorporate basic SMTP functionality in my
script.

Please refer me to any modules and using instructions that might help.

Thanks,
Kevin Posen
posenj@lancet.co.za


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

Date: Tue, 11 Aug 1998 23:59:34 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Incorporating basic SMTP functionality  into script
Message-Id: <Pine.GSO.4.02.9808111655530.10161-100000@user2.teleport.com>

On Mon, 10 Aug 1998 posenj@lancet.co.za wrote:

> I'm using an external mail client to send e-mail.
> 
> I would far prefer to incorporate basic SMTP functionality in my
> script.
> 
> Please refer me to any modules and using instructions that might help.

The modules list on CPAN is a good resource for this sort of thing.

    http://cpan.perl.org/modules/00modlist.long.html

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 12 Aug 1998 00:02:24 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Incorporating basic SMTP functionality  into script
Message-Id: <slrn6t1qhs.9n.alastair@calliope.demon.co.uk>

posenj@lancet.co.za <posenj@lancet.co.za> wrote:
>I'm using an external mail client to send e-mail.
>
>I would far prefer to incorporate basic SMTP functionality in my
>script.
>
>Please refer me to any modules and using instructions that might help.
>

There's a Net::SMTP module distributed as part of the libnet bundle. You can get
it from CPAN (http://www.perl.com/CPAN).

-- 
Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Tue, 11 Aug 1998 21:42:33 -0400
From: Bob Mariotti <bobm@cunix.com>
Subject: Latent data on Perl Generated HTML
Message-Id: <35D0F308.1624A5DE@cunix.com>

We run a secured Netscape server using perl 5.004 for our .cgi scripts.
Very infrequently only one group of clients report that they are
receiving data on the delivered dynamic html page that is not theirs.
Our process works like this:  A request is made via a form.  The form is
parsed by a perl cgi script.  The script fabricates a request string
which is passed to a c program which communicates with the client's host
computer system (separate link).  The c program then passes the returned
records back to the perl script until an EOF is received (the perl will
keep reading).  Using the records just received the strings are split
and then dynamic HTML code is generated and output to stdout which
becomes the custom dynamic web page in response to the requestor.
We have the declaratives to eliminate blocking in the perl script as
well as clearing the buffers prior to any construct.  Also, the c
program clears its buffers prior to communicating with the host.  If no
information is received from the host the perl timeout function is used
to signal such.

Has anyone experienced this situation before?  What was done to correct
it?

Thanks in advance for all who may respond.


--
+-----------------------+---------------------------+
+ Bob Mariotti          + Financial DataCorp (FDC)  +
+ Executive V.P.        + Credit Union Specialists  +
+ email bobm@cunix.com  + 703 Hebron Avenue         +
+ (860) 657-8983 voice  + Glastonbury, CT 06033 USA +
+ (860) 657-8987 fax    + http://www.cunix.com      +
+---------------------------------------------------+




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

Date: 12 Aug 1998 00:02:39 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: line of text.
Message-Id: <6qqm2v$r1c@news-central.tiac.net>

In article <35D0B117.9493468E@richmd.demon.co.uk>,
Peter Richmond  <peter@richmd.demon.co.uk> wrote:
>Hi,
>
>$line = a line out of a text file.
>
>Does $line include the \n or not?

That depends.  If you have the default settings for perl's internal
variables then after

  $line = <FH>;

$line will contain an end of line sequence which (on most platforms) 
contains a \n, unless you're reading past EOF or the last record in a file
doesn't have an end of line sequence.

In recent perls chomp will safely dispose of the end of line stuff e.g.

  while (<FH>) {		# reads into $_
    chomp;			# chomps $_
    ...
  }

This should be covered in the supplied documentation for perl or any
reasonable book introducing perl like Learning Perl by Randal Schwartz &
Tom Christiansen, published by O'Reilly.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 12 Aug 1998 00:03:19 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: line of text.
Message-Id: <6qqm47$f2n$2@client3.news.psi.net>

Peter Richmond (peter@richmd.demon.co.uk) wrote on MDCCCVI September
MCMXCIII in <URL: news:35D0B117.9493468E@richmd.demon.co.uk>:
++ Hi,
++ 
++ $line = a line out of a text file.
++ 
++ Does $line include the \n or not?


That depends on your definition of 'a line out of a text file' and
how you put that line in $line.

The code fragment above is a syntax error.


Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET", "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content)) =~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: Tue, 11 Aug 1998 23:01:42 GMT
From: ian@netcom.com (Ian McGowan)
Subject: Re: Pattern matching (text all uppercase)
Message-Id: <ianExJryu.F8E@netcom.com>

Matt Knecht (hex@voicenet.com) wrote:
: Pgh Fan <none@this.time> wrote:
: >sub allcaps {
: >    $all_caps_found=0;
: >    if ($body =~ /w[A-Z]) {
: >         $all_caps_found = 1;
: >    }
: >    if ($all_caps_found == 1) {
: >      &error(allcaps);
: >   }
: This ignores locale (But all the world is a vt100, and everyone speaks
: English! :) ), but seems too simple to let it rot:
: $_ = $body;
: error('allcaps') unless /[a-z]/;

or, you could convert it to all caps (honoring locale) and compare?

   $cf=$body;
   #Stolen from http://www.perl.com/CPAN-local/doc/FMTEYEWTK/regexps.html
   $cf =~ s/(\w+)/\U$1/g;
   &error(allcaps) unless $body ne $cf;

hth,
ian
-- 
ian@netcom.com               Practice random lane changes and
                             commit senseless bursts of acceleration


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

Date: Tue, 11 Aug 1998 17:12:57 -0700
From: David Stockwell <davids@sdsc.edu>
Subject: Perl CGI OLE Poligimy
Message-Id: <35D0DE09.1B5803B3@sdsc.edu>

Can anyone share any experience in controlling an ole server by calling
it with an HTTP request. I am attempting to do this using CGI.pm and
Win32::OLE.  I am trying to launch an instance of an excel application
and populate it with data from a recordset called via ODBC.  This will
work from the command line but when I request this pl file from the
browser I get an error saying it cannot launch excel.

I am not tied to these modules and would welcome information on any
other strategy for performing the same task.

Thanks,

Bill West
UCSD



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

Date: Wed, 12 Aug 1998 00:24:44 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Perl CGI OLE Poligimy
Message-Id: <Pine.GSO.4.02.9808111724070.10161-100000@user2.teleport.com>

On Tue, 11 Aug 1998, David Stockwell wrote:

> Can anyone share any experience in controlling an ole server by
> calling it with an HTTP request.

Maybe someone in a newsgroup about HTTP or OLE would do that. Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 11 Aug 1998 23:45:33 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Debugger Problem?
Message-Id: <6qql2t$m03$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Richard Ferreri 
<raf@fc.hp.com>],
who wrote in article <35D0B4C8.572745AE@fc.hp.com>:
> Hi,
> 
> When debugging my perl scripts (that use SWIG-generated perl modules and
> wrapper code) using the perl debugger, I will eventually get the
> following message:
> 
>   "99 levels deep in subroutine calls!"
> 
> At this point, I'm pretty dead in the water.  This is strange only
> because I'm not really that many levels deep at all.  If I do a stack
> trace, I'm usually 0 to 3 levels deep.

Yes, I think I know what you are talking about.  DB::sub() is
incrementing $#stack on entry, and decrementing it on exit, instead of
doing something like

      local $stack_deep = $stack_deep + 1;

on entry, and nothing on exit.  Then one needs to replace probing for
$#stack and @stack by this variable.

Patches welcome,
Ilya


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

Date: Sun, 09 Aug 1998 02:31:16 GMT
From: posenj@lancet.co.za
Subject: Problem calling executables from Win95 ('General failiure' on A: when there is no reference to A:)
Message-Id: <35cd079d.5577055@news.saix.net>

When calling any external program (located on my C: drive) from the
script my A: drive is accessed. I get the following message:

	General failure reading device  LP!!?
	Abort, Retry, Fail?

After selecting 'Fail' twice the execution seems to continue as
normal.

I have searched my registry for any references to both 'Perl' and 'A:'
and removed them all. I also deleted all my histories ('Run',
'Documents', etc).

No success.

When callng any of these programs without using the script they work
perfectly.

Can anyone shed some light on this?

Kevin Posen
Johannesburg, South Africa


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

Date: 11 Aug 1998 22:47:01 GMT
From: Niklas Matthies <matthies@fsinfo.cs.uni-sb.de>
Subject: Regexp this! (if possible anyhow...)
Message-Id: <6qqhl5$5g3$1@hades.rz.uni-sb.de>

I got a tough parsing task. Consider a text file, collapsed in a single
scalar (i.e. a string containing newlines). It may contain C-style comments
("/* ... */"), Pascal(?)-style comments ("(* ... *)") and/or C++-style
comments ("// ... \n"). These may be freely nested and intermixed, and
may (except the C++-style comments) span multiple lines. Now, I need the
first line matching /^[ \t]* KEYWORD [ \t]+ (\w+) [ \t]*$/x that is _not_
contained in any comment. More precisely, I need the word following the
KEYWORD, plus the line number of that line, plus the remaining lines.

Example:

$a = <<EOT;
    we fewr we we (* ewr
    gqer *) qer gqe /* qer // KEYWORD bla wrt wrth
    (* qerg KEYWORD blarg qe *) qerg qe */ .
    wrt wrtb b   wrtrwtb
    df;we wef wef // KEYWORD bloerg wefd wef
    wfefwef(* KEYWORD bluwef qe //we ew*)wef wef wef
    we we f
    KEYWORD foo
    wer qerg (* eqrg ewtw r KEYWORD /* wet wr KEYWORD argl erg re */ r
    wrth *)gqerg  // KEYWORD qwrqe  qerg qer  qer
    eq eqr qegq ergqerg eq
EOT

What I'd want here is 'foo', 8 (the line number), and <<EOT;
    wer qerg (* eqrg ewtw r KEYWORD /* wet wr KEYWORD argl erg re */ r
    wrth *)gqerg  // KEYWORD qwrqe  qerg qer  qer
    eq eqr qegq ergqerg eq
EOT
(the remaining lines).

Now, I can't just strip out the comments iteratively, because I'd be
loosing the line numbers. And since the file might be large, I want
to avoid using substitutions anyway.

The crucial question is: Can I somehow use regexps that keep track of
comment nesting levels _and_ line numbers, or do I have to do almost
everything "by hand"? I looked through perlop and perlre but didn't find
anything really helpful.

Any clever ideas on how to simplify this task will be appreciated!

-- Niklas


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

Date: Tue, 11 Aug 1998 23:36:44 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Regexp this! (if possible anyhow...)
Message-Id: <Pine.GSO.4.02.9808111634330.10161-100000@user2.teleport.com>

On 11 Aug 1998, Niklas Matthies wrote:

> Subject: Regexp this! (if possible anyhow...)
> 
> I got a tough parsing task. Consider a text file, collapsed in a
> single scalar (i.e. a string containing newlines). It may contain
> C-style comments ("/* ... */"),

Start with the Hip Owls book (Mastering Regular Expressions, ISBN
1-56592-257-3). Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 11 Aug 1998 16:46:19 -0700
From: Mark Rafn <dagon@halcyon.com>
Subject: Re: Regexp this! (if possible anyhow...)
Message-Id: <6qql4b$bk0$1@halcyon.com>

Niklas Matthies arranged electrons in a pattern like this:
>I got a tough parsing task. Consider a text file, collapsed in a single
>scalar (i.e. a string containing newlines). It may contain C-style comments
>("/* ... */"), Pascal(?)-style comments ("(* ... *)") and/or C++-style
>comments ("// ... \n"). These may be freely nested and intermixed, and
>may (except the C++-style comments) span multiple lines.

There are a couple "pathological boundary conditions" in the definition
of "freely nested and intermixed" where you'll have to specify further.

For instance:
// /*
is this a comment?
// */ or this?

If these are allowed (or even plain nesting of similar comments (* like
(* this *) *)), then regexps won't cut it.  You'll need to parse
character by character and keep a depth count for multiline comments.

>Now, I can't just strip out the comments iteratively, because I'd be
>loosing the line numbers.

Not necessarily, depending on what the actual grammar is (i.e. are
newlines significant?  Is the meaning altered by replacing a comment
with N newlines?.  You might be able to strip out only non-newline
characters in comments.  However, then you lose comments in "rest of file",
and it's probably not the most efficient way anyway.

>The crucial question is: Can I somehow use regexps that keep track of
>comment nesting levels _and_ line numbers, or do I have to do almost
>everything "by hand"? I looked through perlop and perlre but didn't find
>anything really helpful.

It's got to be by hand, I think.  Regexps don't track state, which
is required for nested comments.   However, you might use a loop which
uses a regexp to find the next comment-indicator or keyword.
--
Mark Rafn    dagon@halcyon.com    <http://www.halcyon.com/dagon/>   !G


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

Date: 11 Aug 1998 23:59:55 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: removing elements from an array
Message-Id: <6qqltr$f2n$1@client3.news.psi.net>

Mike Stok (mike@stok.co.uk) wrote on MDCCCVI September MCMXCIII in
<URL: news:6qq7cv$ge6@news-central.tiac.net>:
++ 
++ A way which is not particularly economical might be
++ 
++   @name = grep {$_ ne 'smerf'} @name;
++ 
++ Another way to do it might be to explicitly use an index into the array
++ and use splice to chop elements out e.g.
++ 
++   for ($i = $#name; $i >= $[; $i--) {
++     if ($name[$i] eq 'smerf') {
++       splice @name, $i, 1;
++     }
++   }

Which is far less economical, as a splice as to rebuild (part) of the
array for each and every call. The splice method will take time worst case
Omega (N * m), where N is the size of the array, and m the number of
times 'smerf' appears in the array.

The grep on the other hand is O (N).



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Wed, 12 Aug 1998 01:12:44 GMT
From: syarbrou@ais.net (Steve .)
Subject: run external program from perl
Message-Id: <35d0ead5.16115120@news.ais.net>

I have a UNIX perl program, where if something is true, it runs a
program called "export" on the drive.  How do you go about running
programs outside of the perl program, let it do it's thing, and then
return to do something else?  Thanks.

Steve


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

Date: Wed, 12 Aug 1998 01:19:18 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: run external program from perl
Message-Id: <slrn6t1v22.9n.alastair@calliope.demon.co.uk>

Steve . <syarbrou@ais.net> wrote:
>I have a UNIX perl program, where if something is true, it runs a
>program called "export" on the drive.  How do you go about running
>programs outside of the perl program, let it do it's thing, and then
>return to do something else?  Thanks.
>
>Steve

You basically RTFM. You should look up 'system' and the use of the 'backticks'
characters i.e.

`ls -l`

All documented in files sitting on your hard disk. Try ;

perldoc -f system

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Wed, 12 Aug 1998 01:14:03 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: run external program from perl
Message-Id: <6qqqeb$t3v$2@ligarius.ultra.net>

[ posted and mailed ]

syarbrou@ais.net (Steve .) wrote:
-> I have a UNIX perl program, where if something is true, it runs a
-> program called "export" on the drive.  How do you go about running
-> programs outside of the perl program, let it do it's thing, and then
-> return to do something else?  Thanks.

perldoc -f system


HTH

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-400-1972 
  Ext: 1949 and let the jerk that answers know 
  that his toll free number was sent as spam. "


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

Date: Tue, 11 Aug 1998 21:33:38 +1000
From: Stephan Carydakis <steph@hotkey.net.au>
Subject: Shared File Locking on Win32  :-[
Message-Id: <35D02C12.B47@hotkey.net.au>

Hello All,

I have a problem with file locking on Win32 (win95..maybe its the OS!).
The problem is I can't get a file lock, let alone a shared file lock to
work. I have read the docs on flock() and I have tried it.

All it did was delete the contents of the fuile I was trying to lock.

I have searched the contents of my hard drives for info pertaining to
locking semantics on Win 95 and didn't locate anything at all.

Also the windows help files are definately not adequate for my purposes.

Could anyone point me in the direction of documents/info/anything
pertaining to file locking , particularly shared file locking, on Win32?

And yes, I have checked the Camel and the Lama and the html docs that
come with perl which are not Win32 specific(not that I'm complaining).

Thanks in advance,
_______________________________________________
Stephan Carydakis     steph@hotkey.net.au
_______________________________________________


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

Date: Wed, 12 Aug 1998 00:55:19 +0100
From: Andy Ng <aacwn100@york.ac.uk>
Subject: system() problem
Message-Id: <35D0D9E6.BB799F97@york.ac.uk>

Can anyone help a novice to Perl?

I want to execute a program so I
used system() and the command line in backticks aswell. the program
works
manually from unix, but doesn't work when I execute it from the webpage.

How do I then wait for the output of the program (which will already be
a
pre-defined variable). Really sorry to trouble you again! ;)

#my simple program!

#!/usr/local/bin/perl

$file = 'sound1.aiff';

$shell = `accel sound.aiff sound1.aiff 2 1"`;

system "$shell","/";

print "Content-type: text/html\n\n";
print "<BODY><TT>\n";

print "cdp was executed man!";

print "<\TT><\BODY>\n";

exit (0);


Thanks for your time

        --Andy Ng  aacwn100@york.ac.uk





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

Date: Wed, 12 Aug 1998 00:18:36 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: system() problem
Message-Id: <Pine.GSO.4.02.9808111717110.10161-100000@user2.teleport.com>

On Wed, 12 Aug 1998, Andy Ng wrote:

> the program works manually from unix, but doesn't work when I execute
> it from the webpage.

Then you don't have a Perl problem. It sounds like a permissions problem.
Maybe the docs, FAQs, and newsgroups about servers and related issues will
be able to help you. Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 11 Aug 1998 23:20:56 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: What's the most efficient regex to force NOT matching any char? (repost)
Message-Id: <Pine.GSO.4.02.9808111605390.10161-100000@user2.teleport.com>

On Tue, 11 Aug 1998, Marco Moreno wrote:

> If I want to force the conversion of every char, what is the most
> efficient regex I should use to force an unsuccessful match of the
> pass-thru regex?

I don't get this. Do you want a pattern that will never match any input?
If so, use /\b\B/ . I can't say that it's the most efficient pattern ever,
but you won't have to wait long for it to fail to match!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 11 Aug 1998 23:41:48 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: What's the most efficient regex to force NOT matching any char? (repost)
Message-Id: <6qqkrs$lja$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Phoenix 
<rootbeer@teleport.com>],
who wrote in article <Pine.GSO.4.02.9808111605390.10161-100000@user2.teleport.com>:
> I don't get this. Do you want a pattern that will never match any input?
> If so, use /\b\B/ . I can't say that it's the most efficient pattern ever,
> but you won't have to wait long for it to fail to match!

Hmm, I would use (?!).  Benchmarks welcome.

Ilya


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3422
**************************************

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