[12594] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6194 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 1 17:07:16 1999

Date: Thu, 1 Jul 99 14:00:20 -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           Thu, 1 Jul 1999     Volume: 8 Number: 6194

Today's topics:
    Re: "Pushing" keys from Perl program. <splattael@gmx.net>
    Re: 2 simple (not to me tho) questions (Steve Lamb)
    Re: 2 simple (not to me tho) questions (Steve Lamb)
        Building perl on Solaris 5.7 <Jochen.Stenzel.gp@icn.siemens.de>
    Re: Clueless and in need of help! <upsetter@ziplink.net>
    Re: compare two big files? (John Borwick)
    Re: Date Bug??? <sjs@yorku.ca>
        Embedding Perl in C++ on WIN32 <christos@alltelwbs.com>
    Re: HELP!!!! PLEASE!!!! gene158@my-deja.com
        how to trap errors in open ( | <process_name> ) ?? ochang9153@my-deja.com
        mon: Time-HiRes-01.20 not in @INC <daw@dect.com>
        Need to install perls DBI for NT gene158@my-deja.com
    Re: Net::FTP get with space in filename? <rick.delaney@home.com>
    Re: Net::FTP get with space in filename? <rick.delaney@home.com>
    Re: Newbie questions <martin@adoma.se>
    Re: Premature end of script headers: <mycheese@kconline.com>
        regex to match nested paranthesis bhaskaracharya@my-deja.com
    Re: regex to match nested paranthesis <rick.delaney@home.com>
    Re: Removing C and C++ comments (John Borwick)
    Re: Removing C and C++ comments (Damian Conway)
    Re: Robot email/poster (new proposal) (Greg Bacon)
    Re: Robot email/poster (new proposal) (John Stanley)
    Re: Robot email/poster for this group (Alastair)
    Re: sorting info from Hashes <splattael@gmx.net>
    Re: Top 10 responses to the Robot/email idea (I R A Aggie)
        WebAdverts and Win32 Perl <webmaster@ieo.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 01 Jul 1999 20:41:20 +0200
From: Peter Suschlik <splattael@gmx.net>
Subject: Re: "Pushing" keys from Perl program.
Message-Id: <377BB650.2291AAE4@gmx.net>

ktb wrote:

Hi.

> I would like to create a program that when run would type for me.  I
> have a problem getting the 'num lock' key to work under linux in X.

Try ``setleds''.

> I've tried several fixes to no avail.  I thought there must be someway
> to tell the computer to "turn" this key on. Is there a way to "push"
> keyboard keys with Perl?

Yes, indirectly. You need the "$include/kd.h" - convert to "kd.ph" by using
h2ph.
Use it with require "$inlcude/kd.h" and ``perldoc -f ioctl''.

It is not tested. Just an idea.

Regards.

Peter Suschlik

-- 
Learning German (lesson #444):
seiteneffektfrei, das Golfplaetze, dieses Klosettpapier, diese
AusSenwirtschaft,
diese Auslandsreferat, der Makroexpansionszeit, dieses Importplanung,
dieses Erzieher.


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

Date: 1 Jul 1999 19:23:31 GMT
From: morpheus@despair.rpglink.com (Steve Lamb)
Subject: Re: 2 simple (not to me tho) questions
Message-Id: <slrn7nng1i.or.morpheus@rpglink.com>

On Wed, 30 Jun 1999 19:36:56 -0400, Tad McClellan <tadmc@metronet.com> wrote:
>   print "$foo" is asking for them when they are not being used.

    And, so, what, exactly, is the problem then?

>   It is a code maintenance issue.

    It is also a consistancy issue.  Perl hackers seem to pride themselves in
coding in as few lines as possible.  They seem to forget their own motto and
insist everyone code in the One True Way (tm).  

print("The statement is ");
if ($foo =~/bar/){
  print("$blah");
}
print("\n");

    To me is more legible, more consistant, and causes no "dangers" or
"problems" than this little tidbit:

print "The statement is";
print $blah if ($foo =~ /bar/);
print "\n";

    So far, no one has come up with anything against print("$var") which is
the only example I have given and the only place I said I used it.  Everyone
was so quick to point out that stringifying things when passing to other
functions is bad.  I never have refuted that.  

    But in this case, it is a stylistic issue which, as far as I can see,
causes no problems.  People, such as yourself, have admited that they would
double quote the very same variable if they were appending a newline to the
string.  This suggests, to me, there is no problem *other* than the obsessive
nature of not wasting less CPU cycles and doing everything absolutely perfect
at the expense of code readability.

    To me, that isn't enough justification to jump down someone's throat,
getting all snobby, misquoting them, providing "examples" of what they are
doing as wrong when they state the do none of those and completely forget
something that is introduced to all people who read one of the staple books of
the language.

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



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

Date: 1 Jul 1999 19:35:13 GMT
From: morpheus@despair.rpglink.com (Steve Lamb)
Subject: Re: 2 simple (not to me tho) questions
Message-Id: <slrn7nngnd.or.morpheus@rpglink.com>

On 01 Jul 1999 01:31:04 -0400, Uri Guttman <uri@sysarch.com> wrote:
>but it wasn't a good solution so what use is it? 

    It got the job done and so far noone has said why, specifically, it was
wrong in that context.  How it, specifically, changed the outcome.

>well, go hang out in alt.perl then. he may come off sometimes in a less
>than polite way, but he has contributed far more to the perl community
>than you could ever do in multiple generations. so his word has a trifle
>more weight here (and elsewhere). so defending your silly style is
>pointless here especially with your shouting, cursing, and otherwise
>childish ways.

    So, what you're saying is, is that just because he is who he is, that
gives him the right to be a childish snot, misquote people, claim they said
things they did not and then flame them while said person is not allowed to
get upset in any way, shape or form?  

>but i get paid for that opinion. and i get asked for my opinion. and my
>opinion has garnered some respect in the perl world.

    I'd be surprised about that considering your willing to go to flames over
a minor point of style.

>or livelihood depend on it. then you will be doing humanity the greatest
>service possible.

    And I hope you're never in that position either for you'll be so busy
worrying about how to do something so perfectly everyone will just tremble in
fear instead of getting the work done.

>i have spent too many days cleaning up after the likes of you. such
>people get so caught up in some little detail of how they do something
>that any criticism of it is taken to be a full frontal assault on their
>being. 

    You mean, for example, like you and Tom?  I mean, I did point out I only
used it in prints yet Tom took that as being used everywhere.  Here you are
extrapolating the rest of my code based on this one small stylistic example.
Is it so much of a threat that a variable is double-quoted when by itself when
the same varialbe, more often than not, would be placed into the same quotes
if coupled with a \n that you and Tom simply must flame people for it?  

>you bring it upon yourself, the paranoia, anger, mistrust, etc of
>anyone whom you perceive knows more than you. 

    Nah, only from people who are snobbish twits, misquote me, take what I
said an expand it to something I didn't only to inflate their own egos. 

>try some humility and learn from your more experienced brethren instead of
>striking at them before you get hurt.

    Before striking at them?  Uh, newsflash, Tom "struck" first.  Not my fault
he, and you, have hit upon someone who doesn't take to bullshit snobbery by
quivering in fear and hiding in a corner.  Might I suggest you learn how to
instruct without coming off as a pretentious prick?

>oh, well, i tried to make some sense to you but you will keep living in
>your delusional world. 

    Quite the contrary, all you've done is toss insults.  I've also learned a
bit.  I've also learned some very important lessons.

1: Tom, because of who he is, can be an asshole and everyone has to deal with
it.

2: You, apparently, feel that being who you are also entitles you to be an
asshole and have everyone deal with it.

3: Neither of you can let minor points of style go and cannot prove your point
without taking the scope of the arguement outside what was given.  

>if you want to, try another language where you don't have to think so much
>and really understand the decisions you make. like VB.

    Might I suggest you change languages so you can continue to appear godlike
to those who actually give a crap?

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



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

Date: Thu, 01 Jul 1999 20:40:14 +0200
From: "Hr. Jochen Stenzel" <Jochen.Stenzel.gp@icn.siemens.de>
Subject: Building perl on Solaris 5.7
Message-Id: <377BB60E.97B6BCF7@icn.siemens.de>

Hello,

I tried to build perl 5.00503 on a Solaris 5.7 system, using  egcs
1.1.2. Make succeeded, but the tests failed. I got messages like this:

- snip --

Can't load '../lib/auto/Socket/Socket.so' for module Socket: ld.so.1:
 ./perl: fatal: relocation error: file ../lib/auto/Socket/Socket.so:
symbol main: referenced symbol not found at ../lib/DynaLoader.pm line
169.

- snip --

I found the comment in Dynaloader.pm above line 169 which says that this
could be an initialization error, but I don't know how to tune the
installation to make it work.

What could be the problem here?

Thanks

                    Jochen



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

Date: Thu, 01 Jul 1999 19:28:23 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: Clueless and in need of help!
Message-Id: <rjPe3.550$6M6.164782@news.shore.net>

Harmanie <harmanie@aol.com> wrote:
: # After making them, run the acecard.pl from the operating system:
: # %perl acecard.pl

: I have uploaded all of the pl files to my cgi-bin

: How in the heck to I run the acecard.pl from the operating system?

It looks like you're expected to run the script from the command line.
This would work the same on Unix or some Dos/Windows thingie; You'd have
to change directory to be in the same directory as your script and then
type "perl acecard.pl". If the file is on a remote server, you may have to
telnet in first.

If this is still confusing to you, than the script's author is assuming a
lot more knowledge from his users than you possess (not that that' syour
fault). Maybe you can get your money back or ask him to install it for
you.

--Art

-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: Thu, 1 Jul 1999 20:01:40 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: compare two big files?
Message-Id: <377ec8ef.28027551@newshost.unx.sas.com>

On Mon, 21 Jun 1999 14:07:23 GMT, bing-du@tamu.edu wrote:

>Can anybody suggest me what is the best way to compute difference
>between two big files in Perl?

>I ever dumped files into two different associative arrays and use the
>example suggested by CPAN to compare two associative arrays.  But
>unfortunately 'out of memory' occurred.


perldoc File::Compare
might help.

Just found the module myself.

hope this helps,
_ 
John Borwick


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

Date: Thu, 1 Jul 1999 14:13:59 -0500
From: Steven Smolinski <sjs@yorku.ca>
Subject: Re: Date Bug???
Message-Id: <930856676.72638925@newshub.ccs.yorku.ca>

>In article <7lg1jh$gk8$1@nnrp1.deja.com>,
>	fliboy@my-deja.com writes:
>> Does anyone know why Perl on my systems (tested
>> 5.004 and 5.005, on Solaris and NT) reports the
>> date one month prior to the current date?  There
>> is probably some simple explanation, but it
>> eludes me!  Maybe a hacked up Perl binary?
[...predictable code example snipped...]

Actually the month is 0-11 as returned by localtime, so a value of 6 is July.

May I suggest "Perl in a Nutshell" by O'Reilly & Associates as a useful and
fairly comprehensive resource for such things?

Steve
print "Just another amateur Perl hacker";


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

Date: Thu, 1 Jul 1999 19:40:05 GMT
From: Christos Tsoukalas <christos@alltelwbs.com>
Subject: Embedding Perl in C++ on WIN32
Message-Id: <377BC415.4F63@alltelwbs.com>

I have installed Perl on my NT machine and now I try to embed Perl code
into a C++ program. My objective is to call a small Perl script from
inside my main() function. My program looks like this:

#include <iostream.h>
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;
void PerlConvert()
{
	char* record[] = { "f1", "f2", "f3", "f4", NULL};

	dSP;
	int count;
	ENTER;
	SAVETMPS;

	count =	perl_call_argv("convert2", G_ARRAY, record);

	SPAGAIN;
	for (int i=0; i<4; i++)
		cout << "Value at " << i << "  :  " << POPp << endl;

	PUTBACK;
	FREETMPS;
	LEAVE;
}


int main(int argc, char **argv, char **env)
{
   char *my_argv[] = { "", "/export/home/christos/perl/rules.pl" };
   my_perl = perl_alloc();
   perl_construct( my_perl );
   perl_parse(my_perl, NULL, argc+1, my_argv, (char **)NULL);
   perl_run(my_perl);

   PerlConvert();

  perl_destruct(my_perl);
  perl_free(my_perl);
  
  return 0;
}



I compile using the Visual C++ compiler and I get errors at link time
saying:

perltest.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) unsigned int  PL_na" (__imp_?PL_na@@3IA)
perltest.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) struct sv *  PL_Sv" (__imp_?PL_Sv@@3PAUsv@@A)
perltest.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) long  PL_tmps_ix" (__imp_?PL_tmps_ix@@3JA)
perltest.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) long  PL_tmps_floor" (__imp_?PL_tmps_floor@@3JA)
perltest.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) struct sv * *  PL_stack_sp"
(__imp_?PL_stack_sp@@3PAPAUsv@@A)

In my VC++ project I have included the "perlxsi.c" and the "perl.h"
files. It seems that I am missing some libraries but I do not know which
ones.

I would appreciate any help.

Thanks,

Christos Tsoukalas


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

Date: Thu, 01 Jul 1999 19:34:10 GMT
From: gene158@my-deja.com
Subject: Re: HELP!!!! PLEASE!!!!
Message-Id: <7lgfri$mmf$1@nnrp1.deja.com>

In article <ysik8sk4gsa.fsf@blkbox.com>,
  Kent Perrier <kperrier@blkbox.com> wrote:
> Ice Nyne <anfinger@mediaone.net> writes:
>
> > How do I start the program activeperl?!?  please help!
>
> By reading the nice documentation that came with it.
>
I know when using NT you need to change the path in the control pannel
and then to run it go to command prompt.  I just started on it too but
that is how mine works

Good luck


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 01 Jul 1999 19:52:38 GMT
From: ochang9153@my-deja.com
Subject: how to trap errors in open ( | <process_name> ) ??
Message-Id: <7lggu0$n5r$1@nnrp1.deja.com>

Hi all,

I have the following bit of code:

open ( FILE_HANDLE," |myScript.pl > output.txt" );

print FILE_HANDLE, $inputStr;

where myScript.pl exits on error with

exit -1;

if it fails.  Is there any way to check the exit
code of myscript.pl in the code fragment above??

Any help is much appreciated. Thanks!

OC


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 01 Jul 1999 16:55:48 -0400
From: David Weaver <daw@dect.com>
Subject: mon: Time-HiRes-01.20 not in @INC
Message-Id: <377BD5D3.F0976F5D@dect.com>

Working on getting the script  mon,v 1.110 working and it requires a
package Time-HiRes-01.20.  The package was installed and everything said
it installed OK.

It's a RH5.2 box running Perl version 5.004_05 built for i386-linux.

*    Run this command to test the install.:

 ./mon -f -c mon.cf -s mon.d -a alert.d


*      And here's the result:

Can't locate Time/HiRes.pm in @INC (@INC contains:
/usr/lib/perl5/i386-linux/5.004
05 /usr/lib/perl5 /usr/lib/perl5/site_perl/i386-linux
/usr/lib/perl5/site_perl .)
at ./mon line 36.
BEGIN failed--compilation aborted at ./mon line 36.

Line 36 is "use Time::HiRes qw(gettimeofday tv_interval usleep);"


Saw this error and though I'd try and force HiRes into @INC with a use
lib "xxx" but that didnt't work either.

Any suggestions would be greatly welcomed.




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

Date: Thu, 01 Jul 1999 19:28:56 GMT
From: gene158@my-deja.com
Subject: Need to install perls DBI for NT
Message-Id: <7lgfh9$mis$1@nnrp1.deja.com>

I am trying to install a DBI for perl. I tried to do what the readme
file said  perl Makefile.PL but only makefile.pl works, then make did
something and make test said the error below...
I am very new to perl, so if smeone can explain the steps I need to
take and which directory I need to be...
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
        link -out:blib\arch\auto\DBI\DBI.dll -dll -nologo -nodefaultlib
-release
 -machine:x86 DBI.obj   C:\Pearl\lib\CORE\perlCAPI.lib c:
\Pearl\lib\CORE\PerlCRT
 .lib -def:DBI.def
   Creating library blib\arch\auto\DBI\DBI.lib and object
blib\arch\auto\DBI\DBI
 .exp
DBI.obj : error LNK2001: unresolved external symbol
__imp__Perl_no_security
perlCAPI.lib(perlCAPI.obj) : error LNK2001: unresolved external symbol
__imp__In
itializeCriticalSection@4
perlCAPI.lib(perlCAPI.obj) : error LNK2001: unresolved external symbol
__imp__De
leteCriticalSection@4
PerlCRT.lib(dllmain.obj) : error LNK2001: unresolved external symbol
__imp__Disa
bleThreadLibraryCalls@4
blib\arch\auto\DBI\DBI.dll : fatal error LNK1120: 4 unresolved externals
NMAKE : fatal error U1077: 'link' : return code '0x460'
Stop.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 01 Jul 1999 19:47:53 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Net::FTP get with space in filename?
Message-Id: <377BC5B3.F842FAAE@home.com>

[posted & mailed]

leow wrote:
> 
> I can use Net::FTP to get a file that has no spaces in its filename.
> But when I try to get a file that has spaces in its filename,
> I always get the following error:
> Bad remote filename 'blah blah'

It must have something to do with this line in FTP.pm:

 croak("Bad remote filename '$remote'\n")
	if $remote =~ /[\s\r\n]/s;

It was probably put there for a good reason but I'm sure I don't know
what it is.  You could ask the author.  Maybe he thinks spaces in file
names is silly.  

Comment it out and it will work for you.  Note that there are two such
lines: one for get and one for put & friends.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 01 Jul 1999 19:53:43 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Net::FTP get with space in filename?
Message-Id: <377BC711.D41D4EEF@home.com>

[posted & mailed]

Jody Fedor wrote:
> 
> leow wrote in message <377A60AF.4A90FD7A@ufl.edu>...
> >Hello,
> >Leo Wierzbowski
> >Univ of Florda
> >leow@ufl.edu
> 
> Try using %20 for the space....  ie. ....     this%20file.htm

Why would you quote everything except the text containing his question? 
Is it because you are answering a question he didn't ask?

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 01 Jul 1999 20:43:29 +0100
From: Martin Quensel <martin@adoma.se>
Subject: Re: Newbie questions
Message-Id: <377BC4E1.E17E8E4A@adoma.se>



CapWalker wrote:
> 
> Sorry to double post, but I can't find my first message...
> 
> As a total newbie I need some guidance, either to a FAQ or
> if someone can reply...

All documentation you need right now is already stored on your computer.
(FAQs as well)
if you did a standard install, then you should find some HTML files at
c:\perl\html.
Try opening the one that is called index.html.

Best regards 
Martin Quensel


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

Date: Thu, 1 Jul 1999 14:24:25 -0500
From: "Mike Lansing" <mycheese@kconline.com>
Subject: Re: Premature end of script headers:
Message-Id: <7lgf8j$77g$1@nix2.kconline.com>

Ok, I think I am on the right track with this. I know for fact that the r/w
is set chmod 755 I did that about 50 diffrent times and reuploaded it 50
diffrent times. I have moved the file to everywhich dir on the server. My
first thot is that the cgi-bin isn't setup right if thats possible?!?!  If
it is can you suggest a possible route to get this corrected. Does the
cgi-bin have its own r/w mode set?

- Mike

>So either your cgi-script has no execute permission or it is not in the
cgi-bin
>directory.





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

Date: Thu, 01 Jul 1999 20:02:55 GMT
From: bhaskaracharya@my-deja.com
Subject: regex to match nested paranthesis
Message-Id: <7lghh7$ndm$1@nnrp1.deja.com>

hi

i need a regex to match the ending parenthesis. There maybe several
nested paranthesis included within. Also the data is over multiple
lines. i need to grab everything enclosed(starting from Data( upto
the next program_type) and store it in a hash  as out->data[8], and so
on if Program_type is Data.

i tried various regex and ended up with parsing line by line until i
detect next Program_type. Is there a neat regex or better solution?

thanks
-bhaskar

sample data in text file:
Program_type Data (
     .out             (data[8] ),
     .d0             (data[8] ),
     .d1              (data[8] );
     .d2              (input[8]; ),
     .s0              (out[{1 +15}] ;);
     .s1              (s_bus[16] );
     dummy            (d_bus[17] ) );


Program_type perl (
	(though),
	perl is kool,
	alas this one,
	stumps me; );


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 01 Jul 1999 20:33:29 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: regex to match nested paranthesis
Message-Id: <377BD063.2192A5D5@home.com>

[posted & mailed]

bhaskaracharya@my-deja.com wrote:
> 
> i need to grab everything enclosed(starting from Data( upto
> the next program_type) and store it in a hash  as out->data[8], and so
> on if Program_type is Data.
> 
> sample data in text file:
> Program_type Data (
>      .out             (data[8] ),
                         ^^^^^^^^
It is not clear to me whether you can have parentheses nested in there. 
This solution assumes not.

    $/ = 'Program_type';

    while(<>) {
        next unless /^\s+Data\b/;
        chomp;
        my %hash = /^\W*(\w+)\s+\((.+?)\)/gm;
    }

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 1 Jul 1999 18:45:03 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: Removing C and C++ comments
Message-Id: <377db424.22703986@newshost.unx.sas.com>

[ courtesy cc to poster ]

On Thu, 01 Jul 1999 15:43:59 GMT, bmetcalf@nortelnetworks.com (Brandon
Metcalf) wrote:

>I'm trying to come up with an efficient algorithm for removing C and
>C++ style comments from source files.  I'm doing something like the
>following for C++ style comments:

>s/\/\/.*$//;

>And for C style comments I'm doing the following:

>undef $/;

>$_ = <INFILE>;

>while (/\/\*/)
>{
>   $left .= $`;
>   $_ = $';
>   die "Unterminated Comment" unless /\/*\//;
>   $_ = $';
>}

>$_ = "$left$_";

OK man, I have been working on some code and here's a little-tested
program that could work.  This program splits on a forwards slash,
hopefully making it a somewhat original response to your problem.

# --- begin ---
#!/usr/local/bin/perl5 -w

use strict;

sub parse_code;

$/ = '/';

open(C_CODE,"ahem.c") or die;

my $state = 0;
my $prevLine = "";
my $comment = 0;

while(<C_CODE>) { parse_code }  # for each line, parse the line
$_ = ""; parse_code;

sub parse_code
# this shouldn't really be a subroutine, but I needed to call it
# again after the while loop.
{
    if($_ eq "/" and $prevLine =~ s|/$||) {
	# if the previous line and this line ended in slash, it's
	# a comment.  remove the slash with the substitution above
	# and set the comment flag

        print "$prevLine\n";
        $prevLine = "";
        $comment = 1;
        return;
    } elsif(m|^\*| && $prevLine =~ s|/$||) {
	# if last line ended in a slash and this line starts with
	# an asterisk, you're looking at a big comment.  wait for
	# */.

        print $prevLine;

	$_ = substr $_, 1;  # don't match /*/!

        while(! $_ =~ m|\*/| ) {
	# wait for the proper closing comment

            if(! defined ($_ = <C_CODE>)) { exit };
		# the exit is dangerous i guess
        }
        return;
    } elsif($comment ne 0) {
	# if this is a comment, read it
        s|^.*?\n||;
        $comment=0;
    }
    print $prevLine;
    $prevLine = $_;
}

# --- end ---

OK, so this code splits on a slash character.  it then relies on a
FSM-style interpreter with two variables, $_ and $prevLine.

As I said I haven't tested the program too thoroughly but I think this
will give you a good basis for yr code.

_ 
John Borwick


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

Date: 1 Jul 1999 20:17:57 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Removing C and C++ comments
Message-Id: <7lgidl$92v$1@towncrier.cc.monash.edu.au>

bmetcalf@nortelnetworks.com (Brandon Metcalf) writes:

>I'm trying to come up with an efficient algorithm for removing C and
>C++ style comments from source files.  

	[SNIP]

>As you can see, this method requires undefining $/.  Furthermore, I'm
>having to parse each file twice.  Can someone give a hint on a way to
>achieve the same thing without parsing each file twice?

	# ORIGINAL BY Helmut Jarausch 
	# HEAVILY MUNGED BY YOURS TRULY

	use Parse::RecDescent;

	my $parser = new Parse::RecDescent $Grammar or die "invalid grammar";

	undef $/;
	my $text = <DATA>;

	my $parts = $parser->program($text)
	    or die "malformed C/C++ program";

	print "Comments:\n$parts->{comments}\n";
	print "\nCode:\n$parts->{code}\n";
	print "\nStrings:\n", map(qq{"$_"\n}, @{$parts->{strings}});

	BEGIN {
	$Grammar=<<'EOGRAMMAR';

	program	: <rulevar: local $Comm = "">
	program	: <rulevar: local $Code = "">
	program	: <rulevar: local @Str>

	program	: <skip:''> part(s)
			{ { code=>$Code, comments=>$Comm, strings=>[@Str]} }

	part	: comment | C_code | string

	C_code	: m{( [^"/]+ ( / [^*/] )? )+ }x
			{ $Code .= $item[1] }

	string	: m{" (( \\. | [^"] )* ) "}x
			{ $Code .= $item[1]; push @Str, $1 }

	comment	: m{\s* // [^\n]* \n }x
			{ $Code .= "\n"; $Comm .= $item[1] }
		| m{\s* /\* (?:[^*]+|\*(?!/))* \*/  ([ \t]*)? }x	
			{ $Code .= " "; $Comm .= $item[1] }

	EOGRAMMAR
	}

	__DATA__
	int test; // for decomment

	// using Parse::RecDescent

	int main()
	{
	/* this should
	   be removed
	*/
	  char *cp1 = "";
	  char *cp2 = "cp2";
	  int i;  // a counter
		  // remove this line altogehter
	  int k;  
	      int more_indented;  // keep indentation
	      int l;  /* a loop
		     variable */
	      // should be completely removed

	  char *str = "/* ceci n'est pas un commentaire */";
	  return 0;
	}

HTH,

Damian


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

Date: 1 Jul 1999 20:29:47 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Robot email/poster (new proposal)
Message-Id: <7lgj3r$q67$2@info2.uah.edu>

In article <377BB333.20354F5E@prism.gatech.edu>,
	andy barfoot <gt7202e@prism.gatech.edu> writes:
: It could accept all postings that contain a
: line /^\s*--\s*$/, which with we would prefix our sigs.

Umm.. /^\s*--\s*$/ describes a set of strings that happens to contain
the standard cutline, but it's a superset.  Use /^-- $/ to match a
cutline.

There are other groups that are unmoderated moderated.  See alt.hackers
or... what's the ciwa.* group that's self moderated?

Greg
-- 
Why do they call it a "building"? It looks like they're finished.  Why isn't
it a `built'?
    -- Jerry Seinfeld


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

Date: 1 Jul 1999 20:53:30 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Robot email/poster (new proposal)
Message-Id: <7lgkga$ip$1@news.NERO.NET>

In article <377BB333.20354F5E@prism.gatech.edu>,
andy barfoot  <gt7202e@prism.gatech.edu> wrote:
>If we want to reduce the traffic, we should use.. moderation!  Suppose

No, we should not use moderation.

>the moderator was a bot. It could accept all postings that contain a
>line /^\s*--\s*$/, which with we would prefix our sigs. 

And, of course, those without "sigs" will be prevented from posting.
If you are going to limit those who can post to those who have correct
sigdashes, then you should learn what a sigdash is and the correct regex
for it.

>(Of course, there's already a moderated perl group.

Yes, there is.

>But, this wouldn't 'really' be moderation, since discussions wouldn't be
>moderated!)

Yes, it would be. There are two options: moderated and unmoderated.

>And i would prefer it be called the "clpm traffic controller" (or
>something) rather than a cutsey name like "miscy".  :)

Why would it be called the clpm traffic controller when it would be
operating in a different group?

If you want to start the process for a new group which would be run by
the robot, feel free.



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

Date: Thu, 01 Jul 1999 20:57:44 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Robot email/poster for this group
Message-Id: <slrn7nnp77.65.alastair@calliope.demon.co.uk>

Daniel Grisinger <dgris@moiraine.dimensional.com> wrote:
>alastair@calliope.demon.co.uk (Alastair) writes:
>> It's a grey area.
>
>No, it's not.  Bots have no place in this newsgroup.

True, on reflection. As has been said, this group is for human traffic. I have
no problems with people building something offline though.

-- 

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


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

Date: Thu, 01 Jul 1999 20:25:54 +0200
From: Peter Suschlik <splattael@gmx.net>
Subject: Re: sorting info from Hashes
Message-Id: <377BB2B2.5F130B95@gmx.net>

Michboy832 wrote:

Hi.
 
> Ok, I want to print data from a hash into an email, but when I do this, the
> info comes up randomly on the email.  How would I manipulate this into the
> order I want?
  ^^^^^^^^^^^^

%your_hash is your data.

@keys=qw(Name EMail Adress Homepage);

foreach $key (@keys) {
  print $key ,": ", $your_hash{$key}, "\n";
}


-- 
Learning German (lesson #443):
das Fangquoten, dieses Abonnementsangebot, gedient, dieser Sportgeschaeft,
beigepflichtet, hinreisen, dieser Gottesglauben, diese Ministerratstreffen.


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

Date: 1 Jul 1999 19:40:55 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Top 10 responses to the Robot/email idea
Message-Id: <slrn7nnh6j.etb.fl_aggie@thepentagon.com>

On 1 Jul 1999 18:30:17 GMT, revjack <revjack@radix.net>, in
<7lgc3p$lpo$1@news1.Radix.Net> wrote:

+ Notice I don't post many questions here? It's not because I don't have 
+ any perl questions - I got a million of 'em. I just know how to 
+ find most of the answers now. It works.

<mr. burns>Excellent</mr. burns>

James


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

Date: Thu, 1 Jul 1999 15:14:26 -0400
From: <webmaster@ieo.com>
Subject: WebAdverts and Win32 Perl
Message-Id: <7lgemk$qup$1@gloup.linuxfr.org>

Has anyone gotten the shareware program WebAdverts to run correctly on a
Win32 machine. I can get the administration to work but not the displaying
of banners. I am running Active Perl 517 with WebAdverts 2.02
E-mails are acceptable to keep the newsgroup clear.
Greg Marler
webmaster@ieo.com





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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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