[29623] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 867 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 20 03:09:37 2007

Date: Thu, 20 Sep 2007 00:09:04 -0700 (PDT)
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, 20 Sep 2007     Volume: 11 Number: 867

Today's topics:
    Re: are you using Perl in your job? <brian.d.foy@gmail.com>
    Re: General way to run an exe with errors written to a  <ben@morrow.me.uk>
        Invoking a CGI method in external program trashes form   usenet@DavidFilmer.com
    Re: Invoking a CGI method in external program trashes f <ben@morrow.me.uk>
    Re: Invoking a CGI method in external program trashes f  usenet@DavidFilmer.com
    Re: List Variable becomes undefined inexplicably <tadmc@seesig.invalid>
        new CPAN modules on Thu Sep 20 2007 (Randal Schwartz)
    Re: Question on input password on ssh prompt <mluvw47@gmail.com>
    Re: Writing a C++ Style Checker <ben@morrow.me.uk>
    Re: Writing a C++ Style Checker <ishan.desilva@gmail.com>
    Re: Writing a C++ Style Checker <helmut@wollmersdorfer.at>
    Re: Writing a C++ Style Checker <benkasminbullock@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Sep 2007 19:27:38 -0700
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: are you using Perl in your job?
Message-Id: <190920071927386096%brian.d.foy@gmail.com>

In article <1190223010.878187.150140@i38g2000prf.googlegroups.com>,
Summercool <Summercoolness@gmail.com> wrote:

> I heard there are many many Perl programmers.  But the job interviews
> I went to lately, they either use Java, PHP, Python, or Ruby.  So I
> wonder for all the people who know Perl quite well, are you using Perl
> in your job?

It's not hard to get a Perl job. It's just hard to get one where you
are probably. :)


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

Date: Thu, 20 Sep 2007 03:08:29 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: General way to run an exe with errors written to a file
Message-Id: <t919s4-ci5.ln1@osiris.mauzo.dyndns.org>


Quoth bencejohn@gmail.com:
> Is there a purely Perl way to do the following (i.e., without relying
> on a system specific call)?
> 
>      use strict;
>      use warnings;
>      system("foo.exe bar > errs 2>&1");

IPC::Run

Note that what you have above works perfectly well under Unix, which
includes Mac OS X, and WinNT (including 2k/XP/&c.); this may be portable
enough for your purposes.

Ben



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

Date: Thu, 20 Sep 2007 02:08:54 -0000
From:  usenet@DavidFilmer.com
Subject: Invoking a CGI method in external program trashes form params
Message-Id: <1190254134.514183.91700@z24g2000prh.googlegroups.com>

Greetings. Kindly consider this simplified CGI script which
illustrates my question:

#!/usr/bin/perl
   use strict; use warnings;
   use CGI qw{ :standard };

   system('/var/www/cgi-bin/do_nothing.pl');

   print(
      header(),
      start_html(),
      start_form(),
         h2(param('xxx')),
         textfield({-name => 'xxx'}),
         submit(),
      end_form(),
      end_html()
   );
__END__

As you can see, the CGI first runs an external perl program.  OK,
fine.  Here is the external program:

#!/usr/bin/perl
   use strict; use warnings;
   use CGI qw{ header };

   open (my $file, '>', '/tmp/junk.xxx') or die "oops - $!\n";

   my $test_mode = 0;

   print $file $test_mode ? header()
                          :  "Content-Type: text/html;
charset=ISO-8859-1\n\n",
__END__

This external program simply prints an HTML content declaration to a
junk file.  But it has the option to use CGI.pm's header() method, or
to just print hardcoded text.  Either way, the resulting junk file is
identical (same md5sum).

When I run the CGI (in a browser), I should be able to type something
in the textbox and it will be shown to me when I click submit.  And if
I run everything as posted, that's exactly what happens.

But if I change $test_mode to non-zero then the value of the CGI
parameter 'xxx' is no longer carried.  I can type something in the
textfield and hit submit, but I won't see the value of the param.
Changing $test_mode back to zero causes the form to again work as
expected.

Somehow invoking the CGI.pm header method() in the external program is
causing my CGI form parameters to be lost between form invocations!

That's strange!  Does anyone have any idea why?

Thanks!

--
David Filmer (http://DavidFilmer.com)



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

Date: Thu, 20 Sep 2007 03:24:09 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Invoking a CGI method in external program trashes form params
Message-Id: <9729s4-3n6.ln1@osiris.mauzo.dyndns.org>


Quoth usenet@DavidFilmer.com:
> Greetings. Kindly consider this simplified CGI script which
> illustrates my question:
> 
> #!/usr/bin/perl
>    use strict; use warnings;
>    use CGI qw{ :standard };
> 
>    system('/var/www/cgi-bin/do_nothing.pl');
> 
>    print(
>       header(),
>       start_html(),
>       start_form(),
>          h2(param('xxx')),
>          textfield({-name => 'xxx'}),
>          submit(),
>       end_form(),
>       end_html()
>    );
> __END__
> 
> As you can see, the CGI first runs an external perl program.  OK,
> fine.  Here is the external program:
> 
> #!/usr/bin/perl
>    use strict; use warnings;
>    use CGI qw{ header };
> 
>    open (my $file, '>', '/tmp/junk.xxx') or die "oops - $!\n";
> 
>    my $test_mode = 0;
> 
>    print $file $test_mode ? header()
>                           :  "Content-Type: text/html;
> charset=ISO-8859-1\n\n",
> __END__
> 
> This external program simply prints an HTML content declaration to a
> junk file.  But it has the option to use CGI.pm's header() method, or
> to just print hardcoded text.  Either way, the resulting junk file is
> identical (same md5sum).
> 
> When I run the CGI (in a browser), I should be able to type something
> in the textbox and it will be shown to me when I click submit.  And if
> I run everything as posted, that's exactly what happens.
> 
> But if I change $test_mode to non-zero then the value of the CGI
> parameter 'xxx' is no longer carried.  I can type something in the
> textfield and hit submit, but I won't see the value of the param.
> Changing $test_mode back to zero causes the form to again work as
> expected.
> 
> Somehow invoking the CGI.pm header method() in the external program is
> causing my CGI form parameters to be lost between form invocations!
> 
> That's strange!  Does anyone have any idea why?

You are using POST, yes? POST parameters are passed on STDIN; when a CGI
object is created (with the function interface, the first time you call
a CGI.pm function) it reads the whole of STDIN and extracts the
information. The second script shares its STDIN with the first; the
first call to a CGI function occurs in the second. This call reads the
whole of STDIN, so when you get back to the first script there's nothing
left there to read, and the CGI object in that script ends up empty.

There are many solutions:

    Explicitly create a CGI object, or perhaps just call 'header()' and
    throw it away, before calling the second script.

    'do' the second script instead of executing it with system: you will
    lose some separation, but save a fork, and the two will share the
    same implicit default CGI object.

    Execute the second script with STDIN redirected from /dev/null (or
    File::Spec->devnull for portability).

    Refactor both scripts (I presume they're not really this trivial) so
    that you don't need to invoke the second at all; put the important
    stuff in modules, and call the right bits at the right times.

Ben


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

Date: Thu, 20 Sep 2007 04:00:23 -0000
From:  usenet@DavidFilmer.com
Subject: Re: Invoking a CGI method in external program trashes form params
Message-Id: <1190260823.814235.40630@t8g2000prg.googlegroups.com>

On Sep 19, 7:24 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> The second script shares its STDIN with the first; the
> first call to a CGI function occurs in the second. This call reads the
> whole of STDIN, so when you get back to the first script there's nothing
> left there to read, and the CGI object in that script ends up empty.

Thanks, Ben, for your great explanation and plethora of solutions!
This was exactly what I needed to know to solve this problem!

FWIW, in the "real" application, I'm using HTML::Template, but I build
the template with Perl using the CGI module (because I hate to write
raw HTML).  As I'm developing the program, the template-generating
program is changing constantly, so I want to rebuild the template each
time the CGI is invoked.

Thanks again, Ben!

--
David Filmer (http://DavidFilmer.com)



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

Date: Wed, 19 Sep 2007 20:18:09 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: List Variable becomes undefined inexplicably
Message-Id: <slrnff3iih.lgn.tadmc@tadmc30.sbcglobal.net>

mattbreedlove@yahoo.com <mattbreedlove@yahoo.com> wrote:

> the way that my PERL script


There is no PERL.

There is a Perl and there is a perl.


> At this point I think its a bug or something really strange.


The really strange something is your code.


> Any ideas?


Enable warnings when developing Perl programs.



>         push(@SLAVE_HOSTS, apple);


You should put quotes around strings in Perl programs.


>                 $REMOTE_HOST="$_";


Whitespace is not a scarce resource, feel free to use as much of it
as you like to help make your code easier to read and understand.

    perldoc -q vars

       What’s wrong with always quoting "$vars"?


So that should be:

    $REMOTE_HOST = $_;


>                 #open(CMD, "$SSH $REMOTE_HOST 'do some stuff'|");
>                 while(<CMD>) {


You are not going to get interesting input when you read
from a filehandle that has not been open()ed.


>                         chomp;
>                         $LINE="$_";


If you want the input in $LINE, then just put it there rather than
put it somewhere else and then move it there:

   while ( $LINE = <CMD> ) {
      chomp $LINE;



If you want to be taken seriously, then write an example that
illustrates your problem with

   use warnings;
   use strict;

near the top of the program.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 20 Sep 2007 04:42:16 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Sep 20 2007
Message-Id: <JonH2G.BoL@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-Dahut-Call-0.03
http://search.cpan.org/~perigrin/Acme-Dahut-Call-0.03/
replicates the melodious sound of the wild Dahut ... in Text. 
----
Angerwhale-0.061
http://search.cpan.org/~jrockway/Angerwhale-0.061/
filesystem-based blog with integrated cryptography 
----
App-Env-0.04
http://search.cpan.org/~djerius/App-Env-0.04/
manage application specific environments 
----
Audio-XMMSClient-0.03
http://search.cpan.org/~flora/Audio-XMMSClient-0.03/
Interface to the xmms2 music player 
----
Catalyst-Controller-Rose-Simple-0.01
http://search.cpan.org/~midnite/Catalyst-Controller-Rose-Simple-0.01/
Catalyst/Rose Simple Base Controller 
----
Catalyst-Model-Search-0.02
http://search.cpan.org/~mramberg/Catalyst-Model-Search-0.02/
----
Clutter-0.420
http://search.cpan.org/~ebassi/Clutter-0.420/
Simple GL-based canvas library 
----
Coat-0.1_0.3
http://search.cpan.org/~sukria/Coat-0.1_0.3/
A light and self-dependant meta-class for Perl5 
----
Config-PFiles-Path-0.02
http://search.cpan.org/~djerius/Config-PFiles-Path-0.02/
manipulate PFILES path for IRAF Compatible parameter files 
----
Crypt-Rijndael-1.04_02
http://search.cpan.org/~bdfoy/Crypt-Rijndael-1.04_02/
Crypt::CBC compliant Rijndael encryption module 
----
DBD-SQLite-1.14
http://search.cpan.org/~msergeant/DBD-SQLite-1.14/
Self Contained RDBMS in a DBI Driver 
----
Exception-Simple-0.0099_01
http://search.cpan.org/~berle/Exception-Simple-0.0099_01/
Exception classes and nothing more. 
----
FormValidator-Simple-Plugin-Math-0.02
http://search.cpan.org/~hedwig/FormValidator-Simple-Plugin-Math-0.02/
Math evaluation for FormValidator::Simple 
----
HTML-FromANSI-2.01
http://search.cpan.org/~nuffin/HTML-FromANSI-2.01/
Mark up ANSI sequences as HTML 
----
HTML-FromANSI-2.02
http://search.cpan.org/~nuffin/HTML-FromANSI-2.02/
Mark up ANSI sequences as HTML 
----
HTML-FromANSI-2.03
http://search.cpan.org/~nuffin/HTML-FromANSI-2.03/
Mark up ANSI sequences as HTML 
----
HTML-TableParser-0.35
http://search.cpan.org/~djerius/HTML-TableParser-0.35/
Extract data from an HTML table 
----
Hook-Modular-0.01
http://search.cpan.org/~marcel/Hook-Modular-0.01/
making pluggable applications easy 
----
InlineX-C2XS-0.12
http://search.cpan.org/~sisyphus/InlineX-C2XS-0.12/
Convert from Inline C code to XS. 
----
InlineX-CPP2XS-0.12
http://search.cpan.org/~sisyphus/InlineX-CPP2XS-0.12/
Convert from Inline C++ code to XS. 
----
KML-PolyMap-1.34
http://search.cpan.org/~ihaque/KML-PolyMap-1.34/
----
Linux-Inotify-0.05
http://search.cpan.org/~twerner/Linux-Inotify-0.05/
Classes for supporting inotify in Linux Kernel >= 2.6.13 
----
Mail-Postini-0.16
http://search.cpan.org/~scottw/Mail-Postini-0.16/
Perl extension for talking to Postini 
----
Math-Expression-Evaluator-0.0.4
http://search.cpan.org/~moritz/Math-Expression-Evaluator-0.0.4/
parses and evaluates mathematic expressions 
----
Math-GMPf-0.15
http://search.cpan.org/~sisyphus/Math-GMPf-0.15/
perl interface to the GMP library's floating point (mpf) functions. 
----
Math-GMPq-0.11
http://search.cpan.org/~sisyphus/Math-GMPq-0.11/
perl interface to the GMP library's rational (mpq) functions. 
----
Math-GMPz-0.22
http://search.cpan.org/~sisyphus/Math-GMPz-0.22/
perl interface to the GMP library's integer (mpz) functions. 
----
Math-MPC-0.45
http://search.cpan.org/~sisyphus/Math-MPC-0.45/
perl interface to the MPC (multi precision complex) library. 
----
Math-MPFR-2.01
http://search.cpan.org/~sisyphus/Math-MPFR-2.01/
perl interface to the MPFR (floating point) library. 
----
MojoMojo-0.999006
http://search.cpan.org/~mramberg/MojoMojo-0.999006/
A Catalyst & DBIx::Class powered Wiki. 
----
MooseX-Daemonize-0.02
http://search.cpan.org/~perigrin/MooseX-Daemonize-0.02/
provides a Role that daemonizes your Moose based application. 
----
MooseX-Workers-0.02
http://search.cpan.org/~perigrin/MooseX-Workers-0.02/
Provides a simple sub-process management for asynchronous tasks. 
----
NBU-0.91
http://search.cpan.org/~dutchman/NBU-0.91/
Main entry point for NetBackup OO Modules 
----
Net-Blacklist-Client-0.3
http://search.cpan.org/~dan/Net-Blacklist-Client-0.3/
Queries multiple RBLs or URIBLs in parallel. 
----
Net-DNS-Async-1.06
http://search.cpan.org/~shevek/Net-DNS-Async-1.06/
Asynchronous DNS helper for high volume applications 
----
Net-FullAuto-0.06
http://search.cpan.org/~reedfish/Net-FullAuto-0.06/
Perl Based Secure Distributed Computing Network Process Automation Utility 
----
Net-FullAuto-0.07
http://search.cpan.org/~reedfish/Net-FullAuto-0.07/
Perl Based Secure Distributed Computing Network Process Automation Utility 
----
Net-FullAuto-0.08
http://search.cpan.org/~reedfish/Net-FullAuto-0.08/
Perl Based Secure Distributed Computing Network Process Automation Utility 
----
OCR-Naive-0.06
http://search.cpan.org/~karasik/OCR-Naive-0.06/
convert images into text in a extremely naive fashion 
----
Perl-Critic-1.078
http://search.cpan.org/~elliotjs/Perl-Critic-1.078/
Critique Perl source code for best-practices 
----
Prima-prigraph-win32-1.04
http://search.cpan.org/~karasik/Prima-prigraph-win32-1.04/
binary prigraph.dll distribution for win32 
----
Regexp-Common-IRC-0.03
http://search.cpan.org/~perigrin/Regexp-Common-IRC-0.03/
provide patterns for parsing IRC messages 
----
SVN-Hook-0.28
http://search.cpan.org/~clkao/SVN-Hook-0.28/
Managing subversion hooks 
----
Shell-GetEnv-0.02
http://search.cpan.org/~djerius/Shell-GetEnv-0.02/
extract the environment from a shell after executing commands 
----
Slay-Makefile-0.09
http://search.cpan.org/~nodine/Slay-Makefile-0.09/
Wrapper to Slay::Maker that reads the rules from a file 
----
Slay-Makefile-0.10
http://search.cpan.org/~nodine/Slay-Makefile-0.10/
Wrapper to Slay::Maker that reads the rules from a file 
----
Slay-Makefile-Gress-0.03
http://search.cpan.org/~nodine/Slay-Makefile-Gress-0.03/
Use Slay::Makefile for software regression testing 
----
String-Interpolate-RE-0.02
http://search.cpan.org/~djerius/String-Interpolate-RE-0.02/
interpolate variables into strings 
----
Teamspeak-0.4
http://search.cpan.org/~maletin/Teamspeak-0.4/
Interface to administrate Teamspeak-Server. 
----
Template-Like-0.05
http://search.cpan.org/~askadna/Template-Like-0.05/
Lightweight Template Engine. 
----
Template-Plugin-deJSON-0.02
http://search.cpan.org/~strytoast/Template-Plugin-deJSON-0.02/
----
Term-VT102-Boundless-0.03
http://search.cpan.org/~nuffin/Term-VT102-Boundless-0.03/
A Term::VT102 that grows automatically to accomodate whatever you print to it. 
----
Test-Manifest-1.21
http://search.cpan.org/~bdfoy/Test-Manifest-1.21/
interact with a t/test_manifest file 
----
Test-Simple-0.72
http://search.cpan.org/~mschwern/Test-Simple-0.72/
Basic utilities for writing tests. 
----
Text-Starfish-1.10
http://search.cpan.org/~vlado/Text-Starfish-1.10/
and starfish - A Perl-based System for Text-Embedded Programming and Preprocessing 
----
Tk-PathEntry-3.00
http://search.cpan.org/~wittrock/Tk-PathEntry-3.00/
Entry widget for selecting paths with completion 
----
Tk-Wizard-2.114
http://search.cpan.org/~mthurn/Tk-Wizard-2.114/
GUI for step-by-step interactive logical process 
----
Transform-Canvas-0.03
http://search.cpan.org/~ronan/Transform-Canvas-0.03/
Perl extension for performing Coordinate transformation operations from the cartesion to the traditional drawing-model canvas coordinate systems. 
----
Web-Scraper-0.16
http://search.cpan.org/~miyagawa/Web-Scraper-0.16/
Web Scraping Toolkit inspired by Scrapi 
----
Web-Scraper-0.17
http://search.cpan.org/~miyagawa/Web-Scraper-0.17/
Web Scraping Toolkit inspired by Scrapi 
----
WebService-Google-Reader-0.01_1
http://search.cpan.org/~gray/WebService-Google-Reader-0.01_1/
Perl interface for Google Reader 
----
local-lib-1.001000
http://search.cpan.org/~apeiron/local-lib-1.001000/
create and use a local lib/ for perl modules with PERL5LIB 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
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: Thu, 20 Sep 2007 06:44:54 -0000
From:  Mav <mluvw47@gmail.com>
Subject: Re: Question on input password on ssh prompt
Message-Id: <1190270694.335166.102430@i38g2000prf.googlegroups.com>

On Sep 19, 10:25 am, Mav <mluv...@gmail.com> wrote:
> On Sep 17, 5:02 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
>
>
> > Quoth Mav <mluv...@gmail.com>:
>
> > > On Sep 17, 10:23 am, Ben Morrow <b...@morrow.me.uk> wrote:
> > > > Quoth "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>:
>
> > > > > Mav wrote:
>
> > > > > > In fact, The actual script I am working actually first generates the
> > > > > > public key on the PC side(for that PC), then append the public key
> > > > > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > > > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > > > > will not prompt the password. Any suggestion?
>
> > > > > You have to authenticate to have SSH work.  That authentication
> > > > > can be public key or by providing the password.  You might want
> > > > > to look at the Expect module, to automate the initial authentication
> > > > > with the password. Probably the best route is if the ssh keys don't
> > > > > exist, then to have the script prompt for the password when it
> > > > > runs, and have it pass it to SSH, using Expect.
>
> > > > No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> > > > I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> > > > log in with a password.
>
> > > I looks into the Net::SSH::W32Perl, when I tried to use that I got the
> > > error:
>
> > > use Net::SSH::W32Perl;
> > > my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
>
> > > The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/
> > > Perl.pm line
> > > 110.
>
> > > line 110 on Perl.pm regarding to environment variable $HOME on PC. Do
> > > you encounter the same problem? That means that I have to set the
> > > $HOME in my script?
>
> > Err... yes, looks like it. I always have %HOME% set to my profile
> > directory anyway under Win32... I guess this could be reported as a bug
> > in N:S:W32Perl or N:S:Perl: the correct answer would be to use
> > File::HomeDir. You should probably put
>
> >     use File::HomeDir;
> >     BEGIN { $ENV{HOME} ||= File::HomeDir->my_data }
>
> > at the top, which will cause N:S:Perl to look for its config file in
> > Local Settings\Application Data\.ssh\config . Alternatively, if you
> > already have an OpenSSH config file elsewhere, simply direct N:S:W32Perl
> > at it: you will still need to set $ENV{HOME}, even though it will be
> > ignored.
>
> > Ben
>
> Thanks Ben. Look like when I download the package from here:http://www.soulcage.net/ppds/
>
> It doesn't have that problem.
>
> Thanks,
> Mav

Well, I guess now it comes to another problem..using Par-packer(pp).
My perl (5.8.7 Build 813) on the PC, I have got a Par-packer version
that works with my perl version.
The W32Perl module install on


----------
  #This is y.pl
  use Net::SSH::W32Perl;
  $host = "192.168.0.101";
  $user = "user";
  $passwd = "passwd";

 my $ssh = new Net::SSH::W32Perl($host,protocol => '2,1',debug
=>1,options =>  ["BatchMode yes", "RhostsAuthentication no" ]);
 $ssh->login($user, $passwd);
 my ($out, $err, $exit) = $ssh->cmd('ls -la');

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

The code works fine if I do.
perl y.pl

However when I tried to using pp to create a a.exe
----------
c:\myperl>pp -o a.exe y.pl

c:\myperl>a.exe
pc: Reading configuration data /.ssh/config
pc: Reading configuration data /etc/ssh_config
pc: Connecting to 192.168.0.101, port 22.
pc: Socket created, turning on blocking...
pc: Remote protocol version 2.0, remote software version OpenSSH_4.3p2
Debi
an-9
Can't locate Net/SSH/W32Perl/SSH2.pm in @INC (@INC contains: C:
\DOCUME~1\Maveri
k\LOCALS~1\Temp\par-user\cache-1190269914/inc/lib C:\DOCUME~1\user
\LOCA
S~1\Temp\par-user\cache-1190269914/inc CODE(0xe8d788) .) at Net/SSH/
Perl.pm
line 55, <GEN3> line 1.
-----

my SSH2.pm is install in

C:\myperl>dir c:\perl\site\lib\Net\SSH\W32Perl\
 Volume in drive C has no label.
 Volume Serial Number is B04F-3453

 Directory of c:\perl\site\lib\Net\SSH\W32Perl

09/18/2007  09:09 PM    <DIR>          .
09/18/2007  09:09 PM    <DIR>          ..
10/22/2002  06:16 AM               560 SSH2.pm

is that something I am missing when doing pp?

Thanks,
Mav



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

Date: Thu, 20 Sep 2007 03:04:36 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Writing a C++ Style Checker
Message-Id: <k219s4-ci5.ln1@osiris.mauzo.dyndns.org>


Quoth Ben Bullock <benkasminbullock@gmail.com>:
> On Wed, 19 Sep 2007 17:18:21 +0100, Ben Morrow wrote:
> > Quoth ids <ishan.desilva@gmail.com>:
> >> 
> >> I'm new to Perl. I'm trying to use Perl to write a C++ Style Checker
> >> to validate various coding standards followed in our organization.
<snip>
> > 
> > This is going to be seriously hard work. What you need is a parser for
> > C++, and as C++ is a *very* complex language this is not going to be
> > easy to get right, unless you are content to only recognize simple
> > constructions without parsing the code properly.
> 
> Similarly, one also needs to completely parse the English language in order
> to write a spelling checker. For example to check for "right" misspelt
> as "write" requires one to comprehensively parse all possible English
> sentences, distinguish between verbs and adjectives, and detect the word
> "right" where a verb should be. Making such a spelling checker is going to
> be seriously hard work too - maybe it will take the rest of your life. But
> a simple system which catches 99% of errors is a few lines of code.

Heh, yes, of course. However, what 'ids' is looking for is more akin to
a grammar checker than a spellchecker; in fact, it's similar in spirit
to the MSWord 'grammar' checker (many of its admonitions are more
matters of style than incorrect grammar per se), which does actually
have a pretty good grasp of English grammar nowadays.

In any case, distinguishing a local variable from a class member (or,
indeed, identifying a declaration at all in C++) is going to require a
good deal more than a bit of pattern matching, which was really my
point.

Ben



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

Date: Thu, 20 Sep 2007 04:52:07 -0000
From:  ids <ishan.desilva@gmail.com>
Subject: Re: Writing a C++ Style Checker
Message-Id: <1190263927.954949.116610@e34g2000pro.googlegroups.com>

On Sep 19, 9:18 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
> This is going to be seriously hard work. What you need is a parser for
> C++, and as C++ is a *very* complex language this is not going to be
> easy to get right, unless you are content to only recognize simple
> constructions without parsing the code properly.
>
> There is a Parse::RecDescent grammar for some subset of C++ included in
> the Inline::CPP distribution. You may find it useful to start there.
>
> Alternatively, you may be able to persuade your compiler to do the
> parsing for you. While some of your criteria above (such as blocks on
> ifs) will be lost by such an approach, you may be able to handle these
> with a relatively simple parser, leaving the hard work of 'is this
> identifier a local or member variable' to the compiler.
>
> What you need to do is either persuade your compiler to produce some
> intermediate parsed form of output (such as from gcc's -fdump-* and -d*
> options), or compile objects with debugging info and then parse that.
> One example of a (now very old) program that does this is c2ph in the
> Perl distribution, which was intended to allow access to C structures by
> parsing stabs debugging information.
>
> > Are there any existing Perl based style checkers?
>
> There is Perl::Critic, for style-checking Perl, but that is based on the
> excellent PPI, a Perl module that parses Perl, which took a *lot* of
> work to produce.
>
> Basically: you have set yourself an *extremely* hard problem :(. You can
> either produce a very 'shallow' and rather incomplete solution, or
> produce a proper solution only after a lot of work. OTOH, a proper C++
> parser for Perl would probably be a good thing... :)
>

Well, I guess what I need is something in between the two ends that
two of you proposed.

What BenB suggested is not sufficient. Applying pattern matchings on a
line by line basis is not going help. For example, it won't allow me
to recognize a function implementation.

In a BNF grammar we can define a function using something similar to
the following.

    func_impl : type_spec IDENTIFIER '(' opt_param_list ')' block ;

    block : '{' opt_statement_list '}' ;

    // define the other non terminals here

In order to do this, you need to *build state* as and when you scan
through. i.e. you need to remember that you saw the opening brace in a
previous line and you find the matching end brace in another line
below. This gets even difficult because of nested blocks. So you need
to keep pushing and popping braces.

Building of state requires some well organized data structures. I can
visualize how this is to be done with a language like C++. What you
need is a set of classes with a suited inheritance structure. I don't
know how to do it with Perl. That's why asked about a mental model. I
suppose Perl does support the OO paradigm, but I didn't find any
material to read about it. I mean, I would like to read "OOA/D with
Perl" sort of thing.

The alternative here is to use Flex/Bison with C++. The problem is the
complexity of the grammar to handle C++. Why I thought I would try
with Perl is because of the powerful pattern matching ability. But,
whether I use Flex/Bison or I use Perl, the need to parse the grammar
is still there. That's what BenM has said.

I will try starting off with a very simple thing and then expanding
it.

Thanks for your help.

Cheers,
Ishan.



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

Date: Thu, 20 Sep 2007 08:14:39 +0200
From: Helmut Wollmersdorfer <helmut@wollmersdorfer.at>
Subject: Re: Writing a C++ Style Checker
Message-Id: <fct34h$7tl$1@geiz-ist-geil.priv.at>

ids wrote:

> What I see is that parsing line by line independently is not going to
> help. This parser needs to build context and remember stuff across
> lines to satisfy above goals.

You can start with simple "one-liners" to catch the "low hanging fruits".

My first Perl script was something like

    if ($line =~ m/$regex_pattern/) {
        print "$line\n";
    }

to find errors in a very large XML file.

> Are there any existing Perl based style checkers? If not, can you give
> some advice on how best to structure this program? 

You should look into the source code and documentation of PPI and 
Perl::Critic. Both have a very nice architecture.

Helmut Wollmersdorfer



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

Date: Thu, 20 Sep 2007 06:25:17 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Writing a C++ Style Checker
Message-Id: <fct3od$22j$1@ml.accsnet.ne.jp>

On Thu, 20 Sep 2007 04:52:07 +0000, ids wrote:


> What BenB suggested is not sufficient. Applying pattern matchings on a
> line by line basis is not going help. For example, it won't allow me
> to recognize a function implementation.

Well, if it gets you 50% of the result for 1% of the effort ...

> 
> In a BNF grammar we can define a function using something similar to
> the following.
> 
>     func_impl : type_spec IDENTIFIER '(' opt_param_list ')' block ;
> 
>     block : '{' opt_statement_list '}' ;
> 
>     // define the other non terminals here
> 
> In order to do this, you need to *build state* as and when you scan
> through. i.e. you need to remember that you saw the opening brace in a
> previous line and you find the matching end brace in another line
> below. This gets even difficult because of nested blocks. So you need
> to keep pushing and popping braces.

How much state do you really care about? I don't think you need to "parse
C++" to do this. Incidentally I once wrote a program to create C header
files from ANSI C code:

http://sourceforge.net/projects/cfunctions

This gets out function declarations from the C source based on a lex (flex)
parser and one stack written in C by basically discarding anything inside
a function. (If I had done it in Perl it would have been easier. I don't
recommend writing it in C.)

> Building of state requires some well organized data structures. I can
> visualize how this is to be done with a language like C++. What you
> need is a set of classes with a suited inheritance structure. I don't
> know how to do it with Perl. That's why asked about a mental model. I
> suppose Perl does support the OO paradigm, but I didn't find any
> material to read about it. I mean, I would like to read "OOA/D with
> Perl" sort of thing.

I don't know if it's what you want, but there are two O'Reilly books on
Perl objects, "Learning Perl Objects, References and Modules" and
"Intermediate Perl".
 
> The alternative here is to use Flex/Bison with C++. The problem is the
> complexity of the grammar to handle C++. Why I thought I would try with
> Perl is because of the powerful pattern matching ability. But, whether I
> use Flex/Bison or I use Perl, the need to parse the grammar is still
> there. That's what BenM has said.

But I expect you can just throw away most of the grammar - you don't need
to parse it but rather just discard most of it. If you're just
using the program to automatically check for style mistakes, where I
assume that it is not a fatal problem if you turn up a false positive or
miss one or two badly named variables, "lazy" methods can do most of the
job.


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 867
**************************************


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