[28914] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 158 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 21 14:10:10 2007

Date: Wed, 21 Feb 2007 11:09:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 21 Feb 2007     Volume: 11 Number: 158

Today's topics:
    Re: behavior of my print function call <joe@inwap.com>
        CGI:Session & MS SQLServer <benjamin.m.morley@gmail.com>
    Re: Finding Background processes? <greg.ferguson@icrossing.com>
    Re: getOptions for object oriented Perl anno4000@radom.zrz.tu-berlin.de
        how to handle Multi Value Hash output? <hgehrts@gmail.com>
    Re: how to use system command to launch a shell script  <greg.ferguson@icrossing.com>
    Re: how to use system command to launch a shell script  <joe@inwap.com>
        Mystry CGI Perl from new Redhat server <raymond.chui@nospam.noaa.gov>
    Re: Mystry CGI Perl from new Redhat server <scobloke2@infotop.co.uk>
    Re: Mystry CGI Perl from new Redhat server <joe@inwap.com>
        Newlines and deprecations <jesse_hardy@premierinc.com>
    Re: Newlines and deprecations <mritty@gmail.com>
    Re: Newlines and deprecations <marora@gmail.com>
    Re: Newlines and deprecations <jgibson@mail.arc.nasa.gov>
    Re: Newlines and deprecations <kenslaterpa@hotmail.com>
        Passing an array of arrays to an external function joakim.grahl@gmail.com
    Re: Performance project for the SigEx Foundry bearophileHUGS@lycos.com
        printing all commands' return value in debugger <not.com@gmail.com>
    Re: printing all commands' return value in debugger <jl_post@hotmail.com>
    Re: printing all commands' return value in debugger <not.com@gmail.com>
    Re: Regex: Why is overreaching necessary? anno4000@radom.zrz.tu-berlin.de
    Re: Regex: Why is overreaching necessary? <nospam-abuse@ilyaz.org>
        Subclassing CGI::Pretty dies instantly in ->new , bug? <jeremy@chaos.org.uk>
    Re: Subclassing CGI::Pretty dies instantly in ->new , b <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 21 Feb 2007 10:20:48 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: behavior of my print function call
Message-Id: <oIudnUMht_IfEEHYnZ2dnUVZ_vTinZ2d@comcast.com>

John W. Krahn wrote:
> Joe Smith wrote:

>>     print $fh ($a+$b)/$c;    <==>   (print $fh ($a+$b)) / $c;
> 
> Incorrect:
> 
> $ perl -MO=Deparse,-p -e'print $fh ($a+$b)/$c;'
> print($fh (($a + $b) / $c));

That wasn't what I expected, but you're right.
	-Joe


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

Date: 21 Feb 2007 11:04:00 -0800
From: "Ben_Morley" <benjamin.m.morley@gmail.com>
Subject: CGI:Session & MS SQLServer
Message-Id: <1172084640.126627.241810@m58g2000cwm.googlegroups.com>

Hi All,

I've been running an application for some time that uses CGI::Session
and it's MySQL Driver.  However, I'd like to make the application
database portable and I'm unable to get it to work correctly with
SQLServer2005.

I have written a dummy driver called "mssql" based on the default DBI
driver.  It creates the session in the SQLServer2005 database, but I'm
never able to access that live session.

Any thoughts?  Anyone have a driver built for SQLServer?  Any success
at all?  Thanks in advance!



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

Date: 21 Feb 2007 08:38:30 -0800
From: "gf" <greg.ferguson@icrossing.com>
Subject: Re: Finding Background processes?
Message-Id: <1172075910.356196.56960@l53g2000cwa.googlegroups.com>

On Feb 20, 10:04 am, "pankaj_wolfhun...@yahoo.co.in"
<pankaj_wolfhun...@yahoo.co.in> wrote:
> Greetings,
>                I want to check whether a particular script (say
> test.txt) is already running in background or not?
> If it exists then I want to exit the code else proceed further.

Well, besides checking ps, you could do what a lot of apps do.

Define a flag file in your app's default directory.
Check to see if the file exists. Die if it does with a message saying
why you're dying.

If it doesn't exist then open the file and write the $$ variable to it
and continue on your way.
Delete the file when your app quits.

Something like this untested code.

#!/usr/bin/perl

use warnings;
use strict;

my $PID_FLAG = './_running_pid';
( -f $PID_FLAG ) and die "Another instance is running.\n";
open (my $pid_flag_file, '>', $PID_FLAG) or die "Can't create
$PID_FLAG ($!)\n";
print $pid_flag_file $$;
close $pid_flag_file;

 # do stuff

END {
unlink $PID_FLAG;
}

I put the unlink in an END{} block so there's a pretty good chance the
file will be removed automatically as the app exists.

This sort of approach is nice because the flag file contains the
process ID of the last running instance of the app. If something is
weird, like the app is run away or a zombie, you can cat the file and
know which ID to look for or to kill. After killing it, or if the app
won't launch correctly, then you kill the flag file and you're good
for another launch. And/or, if you want to keep your app from
launching, say because it's on a cron and it'd be a pain to kill the
cron entry, then touch the flag file to temporarily disable the run of
the app. You'll get the normal die message as a reminder the app is
trying to do its job.



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

Date: 21 Feb 2007 16:02:19 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: getOptions for object oriented Perl
Message-Id: <5438obF1uebilU1@mid.dfncis.de>

a <a@mail.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> Since some parameters from @ARGV are for the child method. I need to process
> some of these parameters in the method of the child class.  But the
> following code doesnt work.

"Doesn't work" is the most meaningless error description there is.
Please say what you expect it to do and what it does instead.  Otherwise
we're left to guesswork.

> The GetOptions do not process the ARGV for the
> parent class. How should I make it to work?

That's how GetOptions works.  It removes the keys and their values from
@ARGV for good.  If you want to parse them again, you can localize @ARGV
before the call.  However, GetOptions will then complain about the
options that are present in @ARGV, but are meant for the "other" call.
In the child class method:

    sub parseCommandLine {
        my $self = shift;
        {
            local @ARGV = @ARGV;
            GetOptions( \ %cmdLineArgs, "h","p=i", "k=s"");
        }
        $self->SUPER::parseCommandLine();
    }

I'm leaving it open where and how %cmdLineArgs is declared.

Normal practice is not to process @ARGV in a class (or module), but
do that in the main program.  Then call appropriate methods to spread
the news.

> In parentClass
> parseCommandLine(){
> GetOptions(\%cmdLineArgs, "h","p=i", "k=s"")
> }
> 
> In childClass
> parseCommandLine(){
> GetOptions(\%cmdLineArgs, "n=s", "t=i")
> $self->SUPER::parseCommandLine();
> }

Your code above is not valid Perl.  The "sub" keyword is missing before
the method definitions.  The prototype (that's the '()' after the method
name) is bogus and should go.  It is ignored with methods.  Blocks
should be indented.  Semicolons are missing between statements.  It
wouldn't compile.

Anno


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

Date: 21 Feb 2007 09:44:46 -0800
From: "HansHG" <hgehrts@gmail.com>
Subject: how to handle Multi Value Hash output?
Message-Id: <1172079886.809934.31710@m58g2000cwm.googlegroups.com>

Hi all!

I have a script that returns one SNMP OID from an SNMP Agent. It works
perfectly:
#!/usr/bin/perl -w
use strict;
use IO::Handle;
use Net::SNMP;
my $agentIdUniqueId = '.1.3.6.1.4.1.1977.1.1.2.1.0';
sub getuid {
      my ($session, $error) = Net::SNMP->session
      (
      -hostname  => shift || $_[0],
      -community => shift || $community,
      -port      => shift || $port
      );
     my %hash = ($session->hostname, $result->{$agentIdUniqueId});

while ( ($k, $v) = each %hash) {
    print "key $k value $v\n";
    }

this works. But what do I do, when I have more than one varbind in my
varbindlist? Like:
 my $result = $session->get_request(-varbindlist =>
[$agentIdUniqueId,$agentIdName,$agentBuildDescription,
$agentBuildVersion,$agentBuildNumber,$agentIdPlatformDescription]);

How do I need to change the script so that it returns all requested
OIDs? The query is done from perl. I can see the OIDs getting
requested in wireshark. But how do I return them?

please help
cheers
Hans



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

Date: 21 Feb 2007 07:31:45 -0800
From: "gf" <greg.ferguson@icrossing.com>
Subject: Re: how to use system command to launch a shell script ?
Message-Id: <1172071904.740380.26260@k78g2000cwa.googlegroups.com>

On Feb 21, 2:13 am, "gniagnia" <gniag...@gmail.com> wrote:
> Hi all,
>
> I've searched the www for hours but I still don't understand why this
> isn't working.
>
> I am writting a perl script (on a linux server) that needs to run a
> shell script (on the same linux server).
> So I tried the following :
>
> 1 - exec "/path/to/my/shell_script.sh";
>
> 2 - open EXIT, "/us/path/to/my/shell_script.sh |";
>
> 3 - system "/path/to/my/shell_script.sh";
>

Besides testing your return values and error codes, you might want to
do preflight tests to see if the script exists as you expect it, i.e.,
is it an executable file?

(-f "/path/to/my/shell_script.sh" && -x _) && exec "/path/to/my/
shell_script.sh"; ... or system() or `` or qx()

And don't forget the standard

use warnings;
use strict;

at the top of your code.



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

Date: Wed, 21 Feb 2007 10:54:45 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: how to use system command to launch a shell script ?
Message-Id: <xYudnYS9-7jmCEHYnZ2dnUVZ_oipnZ2d@comcast.com>

gniagnia wrote:

> Neither of these 3 attempts actually worked.....the shell script isnt
> launched by the linux server....

Server?   Is this a stealth CGI question?   You should say so.

'perldoc -q CGI' shows a pointer to: http://www.perl.org/CGI_MetaFAQ.html

I wouldn't be surprised if it was the case where a process running as
user 'nobody' does not have permission to access files owned by 'gniagnia'.
	-Joe


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

Date: Wed, 21 Feb 2007 09:26:20 -0500
From: RC <raymond.chui@nospam.noaa.gov>
Subject: Mystry CGI Perl from new Redhat server
Message-Id: <erhkqd$3ec$1@news.nems.noaa.gov>

I have a Perl CGI file working fine in past 5-6 years. Just upgraded
our new Redhat OS, then my program suddenly only print out half of
HTML file. The remaining half of HTML file are not printing.

Any help will be very appreciate!
Thanks!


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

Date: Wed, 21 Feb 2007 15:48:10 +0000
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Mystry CGI Perl from new Redhat server
Message-Id: <45dc69ba$0$2458$db0fefd9@news.zen.co.uk>

RC wrote:
> I have a Perl CGI file working fine in past 5-6 years. Just upgraded
> our new Redhat OS, then my program suddenly only print out half of
> HTML file. The remaining half of HTML file are not printing.
> 
> Any help will be very appreciate!

You should post code, otherwise all anyone can do is make random guesses.

Since you upgraded your server you probably got a newer version of perl 
and modules.

Maybe one of the modules your script relied on was a non-standard module?

Maybe your perl script contained an error but the old version of Perl 
didn't object whereas the new one does. Check the web-server error logs.

Try running the CGI script from the command line to see what error 
messages it produces.

Try modifying the CGI script so that error messages are sent to the browser
    use CGI::Carp qw(fatalsToBrowser);

Try telling perl to tell you what is going wrong
    use strict;
    us warnings;

And so on ad infinitum.

If you post short self-contained complete runnable example code that 
exhibits the problem, people will be able to help you fix it.


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

Date: Wed, 21 Feb 2007 10:35:36 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Mystry CGI Perl from new Redhat server
Message-Id: <COadnWeZFv1iDUHYnZ2dnUVZ_tadnZ2d@comcast.com>

RC wrote:
> I have a Perl CGI file working fine in past 5-6 years. Just upgraded
> our new Redhat OS, then my program suddenly only print out half of
> HTML file. The remaining half of HTML file are not printing.

Insufficient information.

1) You neglected to tell us which version of RedHat and perl.  `uname -a;perl -V`

2) Sounds like you haven't even bothered looking at the webserver's
    error log: /var/log/httpd/error_log


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

Date: 21 Feb 2007 08:08:48 -0800
From: "jesse" <jesse_hardy@premierinc.com>
Subject: Newlines and deprecations
Message-Id: <1172074128.429949.119050@k78g2000cwa.googlegroups.com>

I have a perl script that parses a file of backup failures.  I have it
print what failed and how many times it's failed. The log file lines
look like this:

c3devweb3 C:\\
c3devweb3 D:\\

This is the name of the server and what failed.  The scripts seems to
be working okay but there are some problems in the output.  Here is
the script.

#!/usr/bin/perl
#
use:strict;
use warnings;
my $file = "/export/home/jhardy/failed";
my %failures;

open(FAILED, "<", $file) or die "$!\n";
        while (<FAILED>) {
        s/#.*//;
        next if /^(\s)*$/;
my $failure = ( split,(/ /, $_) );
        $failures{$failure}++;
}
close(FAILED);
        foreach $failure ( keys %failures) {
        print "The backup of $failure has failed $failures{$failure}
times this month\n";
}

The output I get is this:

The backup of c3duoraint1-bkup /
 has failed 2 times this month
The backup of c3duoraint1-bkup /export/home
 has failed 2 times this month

The output needs to be on one line ie;
The backup of c3duoraint1-bkup / has failed 2 times this month.

Can someone tell me what I'm doing wrong.  I am also getting an error
on the split it says the way I'm using it is deprecated and I'm not
sure what I'm doing wrong there either.

Thanks,
Jesse



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

Date: 21 Feb 2007 08:50:41 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Newlines and deprecations
Message-Id: <1172076641.074704.189820@m58g2000cwm.googlegroups.com>

On Feb 21, 11:08 am, "jesse" <jesse_ha...@premierinc.com> wrote:
> I have a perl script that parses a file of backup failures.  I have it
> print what failed and how many times it's failed. The log file lines
> look like this:
>
> c3devweb3 C:\\
> c3devweb3 D:\\
>
> This is the name of the server and what failed.  The scripts seems to
> be working okay but there are some problems in the output.  Here is
> the script.
>
> #!/usr/bin/perl
> #
> use:strict;
> use warnings;
> my $file = "/export/home/jhardy/failed";
> my %failures;
>
> open(FAILED, "<", $file) or die "$!\n";
>         while (<FAILED>) {

You forgot to chomp.  That's why you have a newline in your output.

chomp;

>         s/#.*//;
>         next if /^(\s)*$/;
> my $failure = ( split,(/ /, $_) );

You have two different errors here that are working in conjunction to
produce almost-correct results.  For one, split should not have a
comma before its first argument.  For two, it's using split in a
depreciated context that's depreciated.  Fortunately, because you
erroneously put that comma there, you're not getting the return value
of split called in a scalar context stored into $failure.  Instead,
you're getting $_ itself - the whole line.  Now because you're not
complaining that you're getting the whole line of the file rather than
just the part after the spaces, I can only assume that you really have
no need to split at all.  So just assign $failure to $_:
my $failure = $_;

If you really did want to split the line and use just the last part of
it, then call split in a list context, and get the last element of the
returned list:

my $failure = (split / /, $_)[0];


Paul Lalli



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

Date: 21 Feb 2007 08:51:05 -0800
From: "marora@gmail.com" <marora@gmail.com>
Subject: Re: Newlines and deprecations
Message-Id: <1172076659.987700.53700@v45g2000cwv.googlegroups.com>

On Feb 21, 11:08 am, "jesse" <jesse_ha...@premierinc.com> wrote:
> I have a perl script that parses a file of backup failures.  I have it
> print what failed and how many times it's failed. The log file lines
> look like this:
>
> c3devweb3 C:\\
> c3devweb3 D:\\
>
> This is the name of the server and what failed.  The scripts seems to
> be working okay but there are some problems in the output.  Here is
> the script.
>
> #!/usr/bin/perl
> #
> use:strict;
> use warnings;
> my $file = "/export/home/jhardy/failed";
> my %failures;
>
> open(FAILED, "<", $file) or die "$!\n";
>         while (<FAILED>) {
>         s/#.*//;
>         next if /^(\s)*$/;
> my $failure = ( split,(/ /, $_) );
>         $failures{$failure}++;}
>
> close(FAILED);
>         foreach $failure ( keys %failures) {
          chomp($failure); # should do the trick
>         print "The backup of $failure has failed $failures{$failure}
> times this month\n";
>
> }
>
> The output I get is this:
>
> The backup of c3duoraint1-bkup /
>  has failed 2 times this month
> The backup of c3duoraint1-bkup /export/home
>  has failed 2 times this month
>
> The output needs to be on one line ie;
> The backup of c3duoraint1-bkup / has failed 2 times this month.
>
> Can someone tell me what I'm doing wrong.  I am also getting an error
> on the split it says the way I'm using it is deprecated and I'm not
> sure what I'm doing wrong there either.
>
> Thanks,
> Jesse




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

Date: Wed, 21 Feb 2007 09:13:31 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Newlines and deprecations
Message-Id: <210220070913319051%jgibson@mail.arc.nasa.gov>

In article <1172074128.429949.119050@k78g2000cwa.googlegroups.com>,
jesse <jesse_hardy@premierinc.com> wrote:

> I have a perl script that parses a file of backup failures.  I have it
> print what failed and how many times it's failed. The log file lines
> look like this:
> 
> c3devweb3 C:\\
> c3devweb3 D:\\
> 
> This is the name of the server and what failed.  The scripts seems to
> be working okay but there are some problems in the output.  Here is
> the script.
> 
> #!/usr/bin/perl
> #
> use:strict;
-----^  This should be a space.

> use warnings;
> my $file = "/export/home/jhardy/failed";
> my %failures;
> 
> open(FAILED, "<", $file) or die "$!\n";

Omit the \n if you want to know where your program died.

>         while (<FAILED>) {

$_ will have a newline at the end. You can remove it with:

  chomp;

>         s/#.*//;
>         next if /^(\s)*$/;

There is no need to capture the whitespace characters here: omit the
parentheses.

> my $failure = ( split,(/ /, $_) );
-----------------------^ 
The comma here is wrong and causes the warning message you are seeing.
You may want to be more explicit about what you are extracting, and you
can use the default split separator and argument:

  my( $system, $disk ) = split;

If you are counting system failures, use $system:

  $failures{$system}++;

If you are count system/disk failures, use the whole line and omit the
split:

  $failures{$_}++;

>         $failures{$failure}++;
> }
> close(FAILED);
>         foreach $failure ( keys %failures) {
>         print "The backup of $failure has failed $failures{$failure}
> times this month\n";
> }
> 
> The output I get is this:
> 
> The backup of c3duoraint1-bkup /
>  has failed 2 times this month
> The backup of c3duoraint1-bkup /export/home
>  has failed 2 times this month
> 
> The output needs to be on one line ie;
> The backup of c3duoraint1-bkup / has failed 2 times this month.

The chomp will remove the newline from the extracted data.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: 21 Feb 2007 09:55:56 -0800
From: "kens" <kenslaterpa@hotmail.com>
Subject: Re: Newlines and deprecations
Message-Id: <1172080556.330358.167520@j27g2000cwj.googlegroups.com>

On Feb 21, 11:50 am, "Paul Lalli" <mri...@gmail.com> wrote:
> On Feb 21, 11:08 am, "jesse" <jesse_ha...@premierinc.com> wrote:
>
>
>
> > I have a perl script that parses a file of backup failures.  I have it
> > print what failed and how many times it's failed. The log file lines
> > look like this:
>
> > c3devweb3 C:\\
> > c3devweb3 D:\\
>
> > This is the name of the server and what failed.  The scripts seems to
> > be working okay but there are some problems in the output.  Here is
> > the script.
>
> > #!/usr/bin/perl
> > #
> > use:strict;
> > use warnings;
> > my $file = "/export/home/jhardy/failed";
> > my %failures;
>
> > open(FAILED, "<", $file) or die "$!\n";
> >         while (<FAILED>) {
>
> You forgot to chomp.  That's why you have a newline in your output.
>
> chomp;
>
> >         s/#.*//;
> >         next if /^(\s)*$/;
> > my $failure = ( split,(/ /, $_) );
>
> You have two different errors here that are working in conjunction to
> produce almost-correct results.  For one, split should not have a
> comma before its first argument.  For two, it's using split in a
> depreciated context that's depreciated.  Fortunately, because you
> erroneously put that comma there, you're not getting the return value
> of split called in a scalar context stored into $failure.  Instead,
> you're getting $_ itself - the whole line.  Now because you're not
> complaining that you're getting the whole line of the file rather than
> just the part after the spaces, I can only assume that you really have
> no need to split at all.  So just assign $failure to $_:
> my $failure = $_;
>
> If you really did want to split the line and use just the last part of
> it, then call split in a list context, and get the last element of the
> returned list:
>
> my $failure = (split / /, $_)[0];
>
> Paul Lalli

Looks like a typo - that will get the first element.
The following would get the last:

my $failure = (split / /, $_)[-1];

Ken



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

Date: 21 Feb 2007 11:01:28 -0800
From: joakim.grahl@gmail.com
Subject: Passing an array of arrays to an external function
Message-Id: <1172084488.290263.143460@l53g2000cwa.googlegroups.com>

I need to pass a list of arrays to a function gnuplot() in the CPAN
module Chart-Graph-3.2, like in the example at the bottom (from
http://search.cpan.org/~caidaperl/Chart-Graph-3.2/Graph/Gnuplot.pm).

Say I wish to plot the following functions (as in the example):
@plots = ($data, $fnc1, $fnc2);

Then I can't do:
gnuplot(\%options, @plots);

which drives me crazy :)
How can I pass the array of arrays, @plots, to gnuplot(), without
explicitly saying $plots[0], $plots[2], ... etc
- I've also tried doing stuff like this:
gnuplot(\%options, join(", ", @plots);

Any help greatly appreciated!

- Joakim



SNIP:

   my %options = (
                   'title' => 'plot functions example',
                   'output file' => 'gnuplot5.png',
                 );

   my $data = [{ 'title' => 'data 1',
                 'style' => 'lines',
                 'type' => 'matrix',
               },
               [
                 [0,10],
                 [3,30],
                 [6,0],
                 [9,-10],
                 [12,-0],
               ]
              ];

   my $fnc1 = [{ 'title' => 'function 1',
                 'style' => 'lines',
                 'type' => 'function',
               },
               '10*sin(x)+2*cos(1.1 * x)+.5*tan(x)'
              ];

   my $fnc2 = [{ 'title' => 'function 2',
                 'style' => 'lines',
                 'type' => 'function',
               },
              '20*sin(sqrt(2**x))/sqrt(2**x)'
              ];

    gnuplot(\%options, $data, $fnc1, $fnc2);

/SNIP



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

Date: 21 Feb 2007 10:42:03 -0800
From: bearophileHUGS@lycos.com
Subject: Re: Performance project for the SigEx Foundry
Message-Id: <1172083323.373948.255220@v33g2000cwv.googlegroups.com>

Pablo:
> I am looking for articles/studies/benchmarks on the subject.

It's not easy to test that, you need to be equally expert on all the
languages to test them. This may be a starting point for you:
http://shootout.alioth.debian.org/

Bye,
bearophile



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

Date: 21 Feb 2007 10:21:19 -0800
From: "yary" <not.com@gmail.com>
Subject: printing all commands' return value in debugger
Message-Id: <1172082079.741943.302030@v45g2000cwv.googlegroups.com>

I'm often using the debugger as a scratchpad to try things out. I'd
like to see the return value of all commands I type, so I don't have
to start each line with "p"- that is, something like:

> perl -de 1
DB<1> $a=5
5
DB<2> $a
5
DB<3> print $a
5
1

I can't figure out how to twist the debugger commands/options around
to get this "auto-print" going! Any ideas?



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

Date: 21 Feb 2007 10:46:35 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: printing all commands' return value in debugger
Message-Id: <1172083595.752496.72240@a75g2000cwd.googlegroups.com>

On Feb 21, 11:21 am, "yary" <not....@gmail.com> wrote:
>
> I'm often using the debugger as a scratchpad to try things out. I'd
> like to see the return value of all commands I type, so I don't have
> to start each line with "p"- that is, something like:
>
> > perl -de 1
>
> DB<1> $a=5
> 5
> DB<2> $a
> 5
> DB<3> print $a
> 5
> 1
>
> I can't figure out how to twist the debugger commands/options around
> to get this "auto-print" going! Any ideas?


   I remember seeing someone's post a few years ago that addressed a
similar issue, but for the life of me I can't seem to locate it.

   Anyway, you could try the follwoing:

      perl -wne 'print eval, "$@\n> "'  # for UNIX
      perl -wne "print eval, qq/$@\n> /"  # for DOS

That way, you can type the following input and get the following
output:

> $a=5
5
> $a
5
> print $a
51

(Note that "51" shows up because you didn't print a newline after
printing $a.)

(Also note that, unlike the debugger, you can't exit by typing "q".
Instead, you exit by typing "exit".)

   This is pretty much what you wanted, right?  To be honest, I don't
really see what's so hard about using the regular perl debugger and
typing "p" or "x" before every statement (I would think that's easier
than typing out the full one-liner I gave above), but if you prefer it
that way, go ahead and use it.

   (Like you, I use the debugger as a scratchpad all the time, but I
don't consider typing "x" in front of statements to be a hassle.)

   I hope this helps, yary.

   -- Jean-Luc



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

Date: 21 Feb 2007 10:55:48 -0800
From: "yary" <not.com@gmail.com>
Subject: Re: printing all commands' return value in debugger
Message-Id: <1172084148.605109.71850@v45g2000cwv.googlegroups.com>

Thanks! That will work... it's not so much a hassle, it's more that I
forget, and if there are side-effects I may need to start all over
again when I do forget a critical p/x.



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

Date: 21 Feb 2007 14:58:49 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <543519F1ul8d7U1@mid.dfncis.de>

Shannon Jacobs <Shannon.Jacobs.nospam@gmail.com> wrote in comp.lang.perl.misc:
> On Feb 20, 8:47 pm, Ilya Zakharevich <nospam-ab...@ilyaz.org> wrote:
> > [A complimentary Cc of this posting was sent to
> > Shannon Jacobs
> > <Shannon.Jacobs.nos...@gmail.com>], who wrote in article
> <1171928007.342955.293...@v45g2000cwv.googlegroups.com>:
> >
> > > (I did test Ilya Zakharevich's proposed suggestion in the next post,
> > > and it worked more poorly, producing additional false matches. I'm
> > > eager to study the differences there, though his approach seems more
> > > complicated than yours.)
> >
> > The only difference *in semantic* is //x which I used (for clarity);
> > the possible difference I meant is in performance.
> >
> > If your hash contains spaces etc, you may need to modify it
> > accordingly (either remove //x and formatting, or wrap the hash in (?-x:)).
> >
> > Hope this helps,
> > Ilya
> 
> Looking at your version again, the problem is the same one that I had
> before with the first part being included in the match. For example,
> if the search target includes 1101, and the first fifty characters
> include 1101, then it produces a false match for that line. I tested
> it both with and without the x parameter, and it made no difference.
> (My ancient version of the camel book doesn't even 'translate' that
> "x" word in that context. From that perspective, my limited Japanese
> is superior to my fluency in Perl.) I couldn't understand your .50
> versus my .{50}, so I tried that, too. No joy.

/.50/ was a typo by Ilya.  (Apologies for presuming to speak for you,
Ilya.)  It matches any character followed by a literal "50" which
can't be what he meant.

> I did some more testing with Anno's version, and I feel like it is
> correct and that there is some other problem going on there. In
> particular, when I 'manually' forced a search on 1101 in isolation
> using Anno's version, it works correctly, but running in the normal
> context with other values, it produces a false match on the second
> line of the following data:
> 
> Algorithms + Data Structures = Programs 19760010021657        CS
> 
> Waking Up Just in Time                  1995001003210921101612PsPh
> 
> Boukyouhen: Hinotori No.6               19870010042111        SFJa
> 
> 
> So in my next round of experiments, I manually trimmed the search
> target to see what it was really matching on. This broke my mind...
> However, I think I found the minimal example of the problem. If I
> limit the search target to this:
> 
>  909|1101
> 
> It produces the false match of that second line. But as
> 
> 1101| 909
> 
> there is no problem. The problem is somehow apparently due to the
> leading space, since
> 
>  908|1101
> 
> also produces the false match (though the rest of the results are
> correct). Lisp and Japanese make more sense to me... If this was a
> contest, I would say that the laurels rest with Anno, and I think I'll
> just try to live with this slight peculiarity.

You should show us actual code that actually demonstrates the behavior.

Jumping back and forth between your postings, I tried to reconstruct
what you might have done from the bits of code you *did* post.  I
arrived at this:

    my %form_values = (
        a_SEARCH_VALUE => '(1121|1217|1256|2033)',
        another        => '( 909|1101)',
    );
    my @foo1 = <DATA>;

    my @foo2 = grep substr( $_, 50, 12 ) =~
        /^(?:\d{4}){0,2}$form_values{ another}/,
        @foo1;

    print for @foo2;

    __DATA__
    Algorithms + Data Structures = Programs 19760010021657        CS
    Waking Up Just in Time                  1995001003210921101612PsPh
    Boukyouhen: Hinotori No.6               19870010042111        SFJa

That doesn't show the spurious match you reported.  So, reduce your
program and data to a small set that demonstrates the problem.
There's no other way we could help you any further.

Anno


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

Date: Wed, 21 Feb 2007 18:50:28 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <eri49k$2irn$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Shannon Jacobs
<Shannon.Jacobs.nospam@gmail.com>], who wrote in article <1172037809.016755.225340@l53g2000cwa.googlegroups.com>:
> The actual code is a pretty large piece and has a very mottled and
> almost ancient history, too.

This is absolutely irrelevant.  You apply an m// operator at some
moment.  Just show us what is the regexp, and what is the value you
match agains.

Thanks,
Ilya




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

Date: Wed, 21 Feb 2007 11:33:42 -0600
From: Jeremy Henty <jeremy@chaos.org.uk>
Subject: Subclassing CGI::Pretty dies instantly in ->new , bug?
Message-Id: <slrnetp0ib.4er.jeremy@omphalos.onepoint>

I created a subclass of CGI::Pretty and it instantly dies:

    $ /data/www-jeremy/cgi-bin/cgi-jeremy
    Undefined subroutine Jeremy::CGI::delete
     at /data/www-jeremy/cgi-bin/cgi-jeremy line 9

Line 9 is:

    my $query = Jeremy::CGI->new;

If I modify the class to inherit from CGI then it works.

Is this a bug or a feature?

Is there a workaround?

Are there any other pitfalls if I inherit from CGI instead of
CGI::Pretty ?  (I plan to use object-oriented style exclusively.)


Details:

Perl 5.8.7 on Linux 2.6.17.14 , gcc 3.4.3 .

The CGI subclass (works as given but fails if I replace CGI with
CGI::Pretty):

    use strict;
    use warnings;

    package Jeremy::CGI;
    use CGI;
    our @ISA;
    @ISA = qw( CGI );

    1; # success 

The CGI script:

    #!/usr/bin/perl

    use strict;
    use warnings;

    use lib qw( /home/jeremy/Personal/Geeky/Perl/Lib );
    use Jeremy::CGI;

    my $query = Jeremy::CGI->new;

    print 
	$query->header, 
	$query->start_html("Hi!"),
	$query->p("boink"),
	$query->ul($query->li("foo"),
		   $query->li("bar"),);
	$query->end_html,
	;

Full output of "perl -V":

Summary of my perl5 (revision 5 version 8 subversion 7) configuration:
  Platform:
    osname=linux, osvers=2.6.9, archname=i686-linux
    uname='linux knoppix 2.6.9 #2 smp tue oct 19 23:51:10 cest 2004 i686 athlon-4 i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dpager=/bin/less -isR'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.4.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: USE_LARGE_FILES
  Built under linux
  Compiled at Dec  5 2005 05:39:47
  @INC:
    /usr/lib/perl5/5.8.7/i686-linux
    /usr/lib/perl5/5.8.7
    /usr/lib/perl5/site_perl/5.8.7/i686-linux
    /usr/lib/perl5/site_perl/5.8.7
    /usr/lib/perl5/site_perl
    .


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

Date: Wed, 21 Feb 2007 13:24:53 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Subclassing CGI::Pretty dies instantly in ->new , bug?
Message-Id: <x7y7mrmkqy.fsf@mail.sysarch.com>

>>>>> "JH" == Jeremy Henty <jeremy@chaos.org.uk> writes:

  JH> I created a subclass of CGI::Pretty and it instantly dies:
  JH>     $ /data/www-jeremy/cgi-bin/cgi-jeremy
  JH>     Undefined subroutine Jeremy::CGI::delete
  JH>      at /data/www-jeremy/cgi-bin/cgi-jeremy line 9

  JH> Line 9 is:

  JH>     my $query = Jeremy::CGI->new;

  JH> If I modify the class to inherit from CGI then it works.

you are contradicting yourself. you can't subclass without
inheriting. the namespace of a module HAS NOTHING to do with subclassing
or inheritance. it is an arbitrary namespace and you can call it Foo and
subclass Bar.

  JH> Is this a bug or a feature?

  JH> Is there a workaround?

you found the fix (not a workaround).

  JH> Are there any other pitfalls if I inherit from CGI instead of
  JH> CGI::Pretty ?  (I plan to use object-oriented style exclusively.)

  JH>     use CGI;
  JH>     our @ISA;
  JH>     @ISA = qw( CGI );

replace all that with:

	use base 'CGI' ;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

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


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