[24827] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6978 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 9 06:06:27 2004

Date: Thu, 9 Sep 2004 03:05:08 -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, 9 Sep 2004     Volume: 10 Number: 6978

Today's topics:
        Antwort: Re: POD-Templates Bastian.Zacher@aspect-online.de
        Antwort: Using Perl in slashboxes in slashcode (how to  Bastian.Zacher@aspect-online.de
    Re: Antwort: Using Perl in slashboxes in slashcode (how <cyde@umd.edu>
    Re: Antwort: Using Perl in slashboxes in slashcode (how <cyde@umd.edu>
    Re: DBD::ODBC,SQL Server,brackets - escape? <mb@uq.net.au.invalid>
    Re: Executing cmd from perl script <tadmc@augustmail.com>
    Re: Executing cmd from perl script <tore@aursand.no>
    Re: Network Scanner (Anno Siegel)
    Re: Object Oriented Perl : Query (Bryan Castillo)
    Re: Object Oriented Perl : Query (Peter J. Acklam)
    Re: parsing XML using a regular expression <ceo@nospam.on.net>
    Re: parsing XML using a regular expression <leifwessman@hotmail.com>
    Re: parsing XML using a regular expression <tintin@invalid.invalid>
        Perl and Inheritance strangeness. <news@ant-roy.co.uk>
    Re: Perl and Inheritance strangeness. (Anno Siegel)
    Re: Perl flow/code diagramming tools? <mark.clements@kcl.ac.uk>
    Re: Perl inconsistency <tadmc@augustmail.com>
    Re: Perl inconsistency <wherrera@lynxview.com>
    Re: Perl inconsistency <wherrera@lynxview.com>
    Re: Perl inconsistency (Anno Siegel)
    Re: Perl inconsistency <bik.mido@tiscalinet.it>
        Plotting into XML pages <Stephen.Jeffrey@maths.uq.edu.au>
        Setting the LWP::Parallel::UserAgent chunk size in the  <leifwessman@hotmail.com>
    Re: Socket holding pattern (Gordon)
    Re: Sybase DBI Returned data query <tadmc@augustmail.com>
    Re: Sybase DBI Returned data query (Michael Peppler)
        Using Perl in slashboxes in slashcode (how to force ref <cyde@umd.edu>
        web services... <prasad.gadgil@gmail.com>
    Re: what's wrong with @$ip? <abdank@gmx.de>
    Re: Xah Lee's Unixism <steveo@eircom.net>
    Re: Xah Lee's Unixism <reynirhs@mi.is>
    Re: Xah Lee's Unixism <reynirhs@mi.is>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 9 Sep 2004 06:10:05 +0000 (UTC)
From: Bastian.Zacher@aspect-online.de
Subject: Antwort: Re: POD-Templates
Message-Id: <chos3t$2ocr$1@news.f.de.plusline.net>

><Bastian.Zacher@aspect-online.de> wrote in message
news:chn7rv$rfl$1@news.f.de.plusline.net...
>> I'm actually exploring the perl-documentation via POD. It's  nice and
easy
>> to improve the code. While exploring
>> and writing own PODs, I just want to know if it's possible to work
with
>> templates.
>> The design of most PODs is the same and my doc's should also be
identical.
>> But I don't want to write the framework
>> over and over again.
>>
>> The easiest way, I think, is to write a text-pod and  pipe it into the
>> source. Maybe there's a "pod"-buildin?
>>
>
>
>Are you trying to write a POD for your own new module?  If that's the
>case, allow me to suggest Randal Schwartz's _Learning Perl Objects,
>References, and Modules_.  I just finished re-reading it a week ago, so
>the material is relatively fresh on my mind - which made your post jump
>out a bit.  The last 2 or 3 chapters of the book all deal with writing
>your own modules, documenting them, and testing them.  Within these
>chapters, it is suggested to use the program h2xs which comes with a
>standard Perl installation.  Running this command will give you the
>directories and templates for all files needed to create a distribution.
>This includes the skeleton POD included within the .pm file.  This
>serves as a basic template.
>
>If this is not what you're looking for, carry on. :-)
>
>Paul Lalli
>

Yes - I heard about h2xs. Hmmm, it's time to explore this feature...

But I'm not writing modules, just perlscripts. Comments with beginning "#"
is not what I'm looking for, cause others don't want to search the whole
script for descriptions.

Maybe the best way is to create an own template and using it while 
starting
a new script.

Thanks,

Bastian


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

Date: Thu, 9 Sep 2004 06:29:36 +0000 (UTC)
From: Bastian.Zacher@aspect-online.de
Subject: Antwort: Using Perl in slashboxes in slashcode (how to force refresh)
Message-Id: <chot8g$2ocr$2@news.f.de.plusline.net>

>                Okay, I know this is kind of offtopic, but there really 
isn't a 
>slashcode newsgroup, so this is the closest I could come.  I'm trying to 
>put a slashbox on my webpage that looks at the current system clock and 
>says stuff based on that (i.e., "It's 9:39pm, the Sun has just gone 
down", 
>or whatever).  I know the Perl to do this; the problem is, the slashboxes 

>are only updated once in a while and then their output cached.  I need to 

>force this Perl code to run every time the page is viewed and the 
slashbox 
>is displayed.  Anyone know how to accomplish that?  Thanks.
>
>-- 
>~ Cyde Weys ~
>Bite my shiny metal ass.
>
>
Cyde,

I assume this is not a perl problem, either the html has to configured not
to cache the site. There are some html-META-Tags to use:

<META HTTP-EQUIV="Cache-Control" content="no-cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Refresh" CONTENT="60">

The first tells the browser not to cache the site, the last will initiate 
to
load the site every 60 seconds. Maybe also useful.

Refer html guides...

bastian



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

Date: Thu, 9 Sep 2004 08:21:37 +0000 (UTC)
From: Cyde Weys <cyde@umd.edu>
Subject: Re: Antwort: Using Perl in slashboxes in slashcode (how to force refresh)
Message-Id: <Xns955F2C5B33BB72galopagosterrapincy@128.8.10.18>

Thanks for the help, but I guess I didn't make the problem clear.  
Slashcode itself is what caches the page, not the browser.  To get a 
slashbox to refresh its contents I have to restart the slashd process - not 
very useful.  I'm looking for a way to directly execute some Perl code on 
each page view.


-- 
~ Cyde Weys ~
Bite my shiny metal ass.


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

Date: Thu, 9 Sep 2004 08:32:09 +0000 (UTC)
From: Cyde Weys <cyde@umd.edu>
Subject: Re: Antwort: Using Perl in slashboxes in slashcode (how to force refresh)
Message-Id: <Xns955F2E24531B02galopagosterrapincy@128.8.10.18>

I need some sort of a way to directly execute code like how it's done in 
the templates - but instead, in the slashbox.  Anyone got an idea?



-- 
~ Cyde Weys ~
Bite my shiny metal ass.


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

Date: Thu, 09 Sep 2004 14:30:44 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: DBD::ODBC,SQL Server,brackets - escape?
Message-Id: <chom9l$k6f$1@bunyip.cc.uq.edu.au>

Derf wrote:

> I have inheritied a database where they decided to put the column names 
> of the tables in brackets (i.e. [Machine Serial No],[Machine Model No], 
> etc). I've never worked with this before and somehow my SQL query is not 
> sending the brackets:
> 
> update MachineData
> set [Machine Model No] = '$model'
> 
> DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver][SQL 
> Server]Line 2: Incorrect syntax near 'Machine Model No'.
> 
> I tried:
> 
> update MachineData
> set \[Machine Model No\] = '$model'
> 
> and got the same error, so I'm wondering if there is a different escape 
> or some other simple helper I'm missing?
> 
> Thanks for the help
> 
> Derf
> 

DBD::ODBC is good to see in there - I take it you're using DBI.

DBI extensions should include the functions quote and quote_identifier. 
Hopefully these will do what you want:

$dbh->do('UPDATE MachineData SET ' .
          $dbh->quote_identifier('Machine Model No') .
          ' = ' . $dbh->quote($model));

As long as DBD::ODBC has been written properly it should do whatever is 
necessary to make 'Machine Model No' be acceptable.

You can use placeholders instead of quote as well (but not quote_identifier).

Oh the evils of DBMS that let you have any old character in column names :)

MB


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

Date: Wed, 8 Sep 2004 23:16:03 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Executing cmd from perl script
Message-Id: <slrncjvm83.40j.tadmc@magna.augustmail.com>

yusufdestina <joericochuyt@msn.com> wrote:

> I want to do simple mysql guery execution from

> -u username -p database
                 ^^^^^^^^

   perldoc -q database

       How do I use an SQL database?


> password
  ^^^^^^^^

   perldoc -q password

       How do I ask the user for a password?


> I'm realy new to this!


Please check the Perl FAQ *before* posting to the Perl newsgroup.

Have you seen the Posting Guidelines that are posted here frequently?


> but how can i send commands to mysql from perl?
                     ^^^^^^^

   perldoc -q command

       Why can't I get the output of a command with system()?

       How can I capture STDERR from an external command?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 09 Sep 2004 08:46:26 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Executing cmd from perl script
Message-Id: <pan.2004.09.09.06.46.25.555046@aursand.no>

On Wed, 08 Sep 2004 20:49:06 -0400, yusufdestina wrote:
> I can't get this working... I want to do simple mysql guery execution
> from my Perl/Tk appl.

There are modules for this;

  perldoc DBI
  perldoc DBD::mysql

If you don't have them installed, download them from CPAN;

  <http://www.cpan.org/>


-- 
Tore Aursand <tore@aursand.no>
"The purpose of all war is ultimately peace." (Saint Augustine)


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

Date: 9 Sep 2004 08:46:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Network Scanner
Message-Id: <chp59q$kin$2@mamenchi.zrz.TU-Berlin.DE>

Chad Brown <chad@wononline.net> wrote in comp.lang.perl.misc:
> I cant figure this one out... I initialized the variable and it still
> brings up the warning.
> 
> Use of uninitialized value in pack at
> G:\PHASIC\PROJECTS\NETSCAN\netsweep.pl line 136.
> 
> this is the line thats causing it...
> my $this = pack($sockaddr,$AF_INET,0,my $thisaddr);
                                       ^^^^^^^^^^^^

Apart from other possibilities, "my $thisaddr" is guaranteed to
be undefined.  What's the mystery?

Anno


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

Date: 8 Sep 2004 22:41:17 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Object Oriented Perl : Query
Message-Id: <1bff1830.0409082141.55799464@posting.google.com>

Thens <thens@NOSPAMti.com> wrote in message news:<20040906175436.32d95abf@asiclindt001>...
> I have a base class called as Weapon  and I have derived classes 'Gun'
> and 'RocketLauncher'.  I   need to instantiate  Gun  or RocketLauncher
> based on a parameter say distance from  the target. If the distance is
> less  than 20m  I  need  a  gun  and  if it is   more I   will  need a
> RocketLauncher. 
> 
> This is my attempt  at a Perl code  that does this.  Is this the right
> way to do this. Any pointers will be of help.
> 

I added some comments and code to your code.  There was a problem with
the new methods in your child classes, they would have actually
returned you the wrong class type.  All of the new methods would have
given you plain Weapon objects.
You don't show any code about how to create a class depending on the
conditions of distance as your statements above led me to belive the
code would try to do.  Was your question more along the lines of "Did
I create me classes properly to use inheritance?"

Or pehaps you were trying to find out how to have a class
automatically change its type in the fire method?  So when you invoke
fire it checks the target distance and then calls fire on the proper
weapon.  Here is a class below
which will act like a weapon, but delegate out to other weapons in the
fire
method depending on the distance.

package SmartWeapon;
use strict;
use base 'Weapon';

sub new {
    my $self = Weapon::new(@_);
    $self->{rocket} = RocketLauncher->new();
    $self->{gun} = Gun->new();
}

sub fire {
    my ($self, $target) = @_;
    if ($target->getDistance() < 20) {
        $self->{gun}->fire($target);
    }
    else {
        $self->{rocket}->fire($target);
    }
}

> #! /usr/local/bin/perl -w
> 
> package Weapon;
> 
> use strict;
> 
> sub new {
>   my ( $self ) = @_;
>   my $class = ref($self) || $self;
>   return  bless {  }, $class;
> }
> 
> sub hitPoints {
>   my ( $self ) = @_;
>   return $self->{hitpoints};
> }
> 
> sub fire { 
>   my ( $self, $target ) = @_;
>   print "Destroyed the target !! ", $self->hitPoints;
>   #$target->hurt($self->hitPoints);
> }
> 
> package Gun;
> use strict;
> use base 'Weapon';
> 
> sub new {

    # you could allow your parent class to intialize everything
    # it needs to like this.
    my $self = Weapon::new(@_);

    # Don't need this stuff
>   # my ( $self ) = @_;
>   # my $class = ref($self) || $self;
>   # $self = new Weapon();
>   

    # now you can initialize the variables needed for the child class
>   $self->{type} = 'GUN';
>   $self->{hitpoints} = 10;
>   
>   return $self;
> }
> 
> 
> package RocketLauncher;
> use strict;
> use base 'Weapon';
> 
> sub new {

    my $self = Weapon::new(@_);

    # don't need this stuff
>   #my ( $self ) = @_;
>   #my $class = ref($self) || $self;
>   #$self = new Weapon();
>   
>   $self->{type} = 'ROCKET';
>   $self->{hitpoints} = 100;
>   return $self;
>   
> }
> 
> 1;


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

Date: 9 Sep 2004 02:30:17 -0700
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Object Oriented Perl : Query
Message-Id: <fe4612a5.0409090130.3b86ba36@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> The shortcut of calling ->new as an object method is
> inherently unclear.  Unless there are massive advantages
> in allowing it (there aren't in most classes), I think it
> is better to leave it out.  Its use as a matter of course
> smacks of cargo cult.

The "$class = ref($obj) || $obj;" construction is used many
places in the Perl docs and the Perl standard modules, so
its not strange that people choose to use it.

Anyway, if it's use is disallowed an appropriate error
message should be given.  Maybe something like this:

    sub new {
      my $class = shift;
      croak "new(): not an instance method" if ref $class;
      ...
    }

Peter


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

Date: Thu, 09 Sep 2004 06:25:08 GMT
From: ChrisO <ceo@nospam.on.net>
Subject: Re: parsing XML using a regular expression
Message-Id: <8HS%c.1058$BC5.136@newssvr16.news.prodigy.com>

Jeremy Bowers wrote:
> On Thu, 09 Sep 2004 01:11:40 +0000, ChrisO wrote:
> 
>>But he's not allowed to use a module because his professor has 
>>specifically indicated that that is not an option for his assignment. 
>>Seems pretty clear to me... ;-)
> 
> 
> Are you serious, or joking?
> 

I can't think of any other reason why someone would want to parse XML 
and specifically state that they "didn't want" to use the XML modules... 
(twice)?  It seems to me to say loudly that this is a class room 
assignment.  I've seen worse requirements handed out...

-ceo


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

Date: 9 Sep 2004 00:44:18 -0700
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Re: parsing XML using a regular expression
Message-Id: <chp1ki$rpa@odbk17.prod.google.com>


Hi!

I was trying to find a general solution to parsing both HTML and
xml-files. And I didn't know that regular expressions was such a bad
idea when parsing XML. Now I know, and now I will build a solution
using regular expressions for HTML and an XML-parser for the XML-files.

THANKS for all your input!!

Leif


ChrisO wrote:
> Jeremy Bowers wrote:
> > On Thu, 09 Sep 2004 01:11:40 +0000, ChrisO wrote:
> >
> >>But he's not allowed to use a module because his professor has
> >>specifically indicated that that is not an option for his
assignment.
> >>Seems pretty clear to me... ;-)
> >
> >
> > Are you serious, or joking?
> >
>
> I can't think of any other reason why someone would want to parse XML

> and specifically state that they "didn't want" to use the XML
modules...
> (twice)?  It seems to me to say loudly that this is a class room
> assignment.  I've seen worse requirements handed out...
> 
> -ceo



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

Date: Thu, 9 Sep 2004 20:55:21 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: parsing XML using a regular expression
Message-Id: <2qak2oFtl5coU1@uni-berlin.de>


"Leif Wessman" <leifwessman@hotmail.com> wrote in message
news:chp1ki$rpa@odbk17.prod.google.com...
>
> Hi!
>
> I was trying to find a general solution to parsing both HTML and
> xml-files. And I didn't know that regular expressions was such a bad
> idea when parsing XML. Now I know, and now I will build a solution
> using regular expressions for HTML and an XML-parser for the XML-files.

Que?

That's like saying "I know that heating my room with a jet engine is a bad
idea, but I'm going to do it anyway."

Good luck.




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

Date: Thu, 09 Sep 2004 08:50:18 +0100
From: Anthony Roy <news@ant-roy.co.uk>
Subject: Perl and Inheritance strangeness.
Message-Id: <chp1vp$kv4$2@south.jnrs.ja.net>

Hi all,

I am trying to solve a problem to do with inheritance which I just
cannot fathom. Four example files are at the bottom of this email which
I think are a pretty much minimal example of the problem.

I'm basically trying to inherit some methods from a super class. Parent
defines two methods, new and getClass. The file Inheritence.pl basically
creates an instance of each of two subclasses of Parent, printing out
the value returned by the getClass() method after each is created, and
then prints out the value returned by getClass on the first object
again. These are the results:

A: ChildA
B: ChildB
A: ChildB

even though I haven't explicitly changed any values in A. Surely the
first and third lines should be identical? What am I missing here, or am
I just better off avoiding inheritance in perl?

Note I am using ActiveState perl v5.8.1 on a Windows XP box.

Thanks,

Anthony Roy.

-------------------------------------------------------------
#Parent.pm
package Parent;

sub new {
     my $class = shift;
     my $self = {};

     $self{Class} = $class;

     bless $self, $class;
}

sub getClass{
     my $self = shift;
     $self{Class};
}
1;
-------------------------------------------------------------
#ChildA.pm
package ChildA;

use Parent;
@ISA = (Parent);

1;
-------------------------------------------------------------
#ChildB.pm
package ChildB;

use Parent;
@ISA = (Parent);

1;
-------------------------------------------------------------
#Inheritence.pl
use ChildA;
use ChildB;

my $childA = ChildA->new();

print "A: " . $childA->getClass() . "\n";

my $childB = ChildB->new();

print "B: " . $childB->getClass() . "\n";
print "A: " . $childA->getClass() . "\n";





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

Date: 9 Sep 2004 08:41:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl and Inheritance strangeness.
Message-Id: <chp4vv$kin$1@mamenchi.zrz.TU-Berlin.DE>

Anthony Roy  <news@ant-roy.co.uk> wrote in comp.lang.perl.misc:
> Hi all,
> 
> I am trying to solve a problem to do with inheritance which I just
> cannot fathom. Four example files are at the bottom of this email which
> I think are a pretty much minimal example of the problem.
> 
> I'm basically trying to inherit some methods from a super class. Parent
> defines two methods, new and getClass. The file Inheritence.pl basically
> creates an instance of each of two subclasses of Parent, printing out
> the value returned by the getClass() method after each is created, and
> then prints out the value returned by getClass on the first object
> again. These are the results:
> 
> A: ChildA
> B: ChildB
> A: ChildB
> 
> even though I haven't explicitly changed any values in A. Surely the
> first and third lines should be identical? What am I missing here, or am
> I just better off avoiding inheritance in perl?

You're better off using strict (and warnings).  Introduce them in
your code and try again.  Also, use Data::Dumper to see what your
objects actually contain.

See the problem now?

Inheritance in Perl does have its issues, but on the level you're
acting here it works just fine.  Your code is in error, in several
places.  Strict will point them out.

Anno

> -------------------------------------------------------------
> #Parent.pm
> package Parent;
> 
> sub new {
>      my $class = shift;
>      my $self = {};
> 
>      $self{Class} = $class;
>      bless $self, $class;
> }
> 
> sub getClass{
>      my $self = shift;
>      $self{Class};
> }
> 1;
> -------------------------------------------------------------
> #ChildA.pm
> package ChildA;
> 
> use Parent;
> @ISA = (Parent);
> 
> 1;
> -------------------------------------------------------------
> #ChildB.pm
> package ChildB;
> 
> use Parent;
> @ISA = (Parent);
> 
> 1;
> -------------------------------------------------------------
> #Inheritence.pl
> use ChildA;
> use ChildB;
> 
> my $childA = ChildA->new();
> 
> print "A: " . $childA->getClass() . "\n";
> 
> my $childB = ChildB->new();
> 
> print "B: " . $childB->getClass() . "\n";
> print "A: " . $childA->getClass() . "\n";
> 
> 
> 




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

Date: Thu, 09 Sep 2004 11:01:40 +0200
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Perl flow/code diagramming tools?
Message-Id: <41401bf4$1@news.kcl.ac.uk>

ixtahdoom wrote:
> I'm charged with the task of understanding a large amount of perl
> code, mostly very large .pl files (10k+ lines!).  Is there any
> software that indexes perl code, making a table of contents for all
> functions and variables, as well as function flow diagrams (who calls
> what and where)?  I don't even know what the technical term is to
> google for (diagramming perl code returns graphing modules!).

you could take a look at AutoDia - http://droogs.org/autodia/

regards,

Mark


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

Date: Wed, 8 Sep 2004 23:29:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl inconsistency
Message-Id: <slrncjvn1a.47j.tadmc@magna.augustmail.com>

Bill <wherrera@lynxview.com> wrote:
> Mike Mimic wrote:


>> open(FILE, '<file.txt');


You should always, yes *always*, check the return value from open():

   open(FILE, '<file.txt') or die "could not open 'file.txt'  $!";


>> while (<FILE>) {

> IMO the second (<FILE>) looks line an array 
                          ^^^^^         ^^^^^

Where is the at-sign then?

An "array" and a "list" are NOT the same thing. There is a FAQ about this...

(but there is no "list" there either.)


> with one element containing 
> 0 to Perl. It only becomes a scalar later. 


If it exists, as in "element", then it has _already_ become a scalar value.


> This is bacause <FILE> is 
> preferred to be an array of lines to Perl.


No it isn't. Where did you get that idea?



Your "O" is way off.

Invoking opinion when discussing machines is the exception 
rather than the rule.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 09 Sep 2004 00:08:07 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: Perl inconsistency
Message-Id: <6emdnb7vTuzabqLcRVn-tw@adelphia.com>

Tad McClellan wrote:
> Bill <wherrera@lynxview.com> wrote:
> 
>>Mike Mimic wrote:
> 
> 
> 
>>>open(FILE, '<file.txt');
> 
> 
> 
> You should always, yes *always*, check the return value from open():
> 
>    open(FILE, '<file.txt') or die "could not open 'file.txt'  $!";
> 
> 
> 
>>>while (<FILE>) {
> 
> 
>>IMO the second (<FILE>) looks line an array 
> 
>                           ^^^^^         ^^^^^
> 
> Where is the at-sign then?
> 
> An "array" and a "list" are NOT the same thing. There is a FAQ about this...
> 
> (but there is no "list" there either.)
> 
> 
> 
>>with one element containing 
>>0 to Perl. It only becomes a scalar later. 
> 
> 
> 
> If it exists, as in "element", then it has _already_ become a scalar value.
> 
> 
> 
>>This is bacause <FILE> is 
>>preferred to be an array of lines to Perl.
> 
> 
> 
> No it isn't. Where did you get that idea?
> 
> 
> 
> Your "O" is way off.
> 
> Invoking opinion when discussing machines is the exception 
> rather than the rule.
> 
> 
Sorry, my bad. The "scalar" transform is of a boolean not an array. I 
canceled the message after a minute, but the thing slipped through 
anyway :(.


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

Date: Thu, 09 Sep 2004 00:34:11 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: Perl inconsistency
Message-Id: <UuWdnXS6kI7-ZKLcRVn-tQ@adelphia.com>

Bob Walton wrote:
> Mike Mimic wrote:
> 
>> Hi!
>>
>> I think that I found some inconsistency in Perl.
>>
>> Let us suppose we have a file named "file.txt" that contains
>> only one byte which is '0' (ASCII character for number 0).
>>
>> And we execute this code:
>>
>> open(FILE, '<file.txt');
>> if (<FILE>) {
>>     print "OK\n";
>> }
>> close(FILE);
>>
>> And code does not output anything. What is correct as "0" is
>> false in Perl.
>>
>> But then we try this:
>>
>> open(FILE, '<file.txt');
>> while (<FILE>) {
>>     print "OK\n";
>> }
>> close(FILE);
>>
>> And code do output "OK". What is strange. Becasue "0" is still
>> false. In "Programming Perl" it is written:
> 
> 
> The while loop with a <FH> operator is special, at least in recent 
> versions of Perl.  It is actually interpreted as something like:
> 
>    while(defined($_=<FH>)){
>      #...
>    }
> 
> See:
> 
>    perldoc perlop
> 
> particularly the section titled "I/O Operators".
> 
>>
>> The while statement repeatedly executes the block as long as EXPR is 
>> true.
> 
> 
> So it actually executes as long as the result is *defined*, not true. 
> <FH> gives undefined upon end of file, and is defined otherwise.  Note 
> that this behavior is only true of the while loop (and "for(;<FH>;)" if 
> you want to be persnickety).  It does not apply to other uses of the 
> <FH> operator.  That feature (hack?) was put in to avoid having to code 
> the call to defined() over and over again to avoid the situation with 
> reading lines which evaluate to false which you mention.  That makes 
> sense, as one almost never wants to stop reading when a false line 
> occurs, but rather when end of file occurs.
> 
>>
>> But "0" is false.
>>
>> So what is going on?
>>
>>
>> Mike
> 
> 
> 

Yes, that's perlop. But what about the below? There is some interpretive 
DWIM magic here with context that is a bit beyond what can be expressed 
in mere Perl code in the perldocs, I think :).

#!/usr/bin/perl

use strict;
use warnings;

# 'file.txt' contains just the character 0

open(FILE, '<file.txt');
while (<FILE>) {
     print "OK 1\n";
}
close(FILE);

open(FILE, '<file.txt');
while (scalar <FILE>) {
     print "OK 2\n";
}
close(FILE);

open(FILE, '<file.txt');
while( defined($_= <FILE>) ) {
     print "OK 3\n";
}
close(FILE);

open(FILE, '<file.txt');
while (scalar defined($_= <FILE>)) {
     print "OK 4\n";
}
close(FILE);

==========
prints:
OK 1
OK 3
OK 4



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

Date: 9 Sep 2004 08:03:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl inconsistency
Message-Id: <chp2od$j2f$1@mamenchi.zrz.TU-Berlin.DE>

Bill  <wherrera@lynxview.com> wrote in comp.lang.perl.misc:
> Bob Walton wrote:
> > Mike Mimic wrote:

["while ( <FH> )" is interpreted as "while( defined($_=<FH>) )"]

> Yes, that's perlop. But what about the below? There is some interpretive 
> DWIM magic here with context that is a bit beyond what can be expressed 
> in mere Perl code in the perldocs, I think :).

What's the big surprise?  The behavior you show below is completely
and precisely predictable from the doc.

[The file is supposed to contain only one "0" (no linefeed)]

> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> # 'file.txt' contains just the character 0
> 
> open(FILE, '<file.txt');
> while (<FILE>) {
>      print "OK 1\n";
> }
> close(FILE);

The standard case.  Implicitly, defined() is applied, so this prints.


> open(FILE, '<file.txt');
> while (scalar <FILE>) {
>      print "OK 2\n";
> }
> close(FILE);

Not the standard case.  No implicit application of defined() so no print.


> open(FILE, '<file.txt');
> while( defined($_= <FILE>) ) {
>      print "OK 3\n";
> }
> close(FILE);

This is explicitly what Perl does implicitly in the first case.  Same
behavior, so it prints.


> open(FILE, '<file.txt');
> while (scalar defined($_= <FILE>)) {
>      print "OK 4\n";
> }

"scalar defined(...)" is bogus.  The defined() function is not context-
sensitive, it returns the same thing in any context.  Besides, the
content of a while-condition is already in scalar context.  So the
behavior is like the last one, it prints.


> ==========
> prints:
> OK 1
> OK 3
> OK 4

Sure.  What did you expect?

Anno


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

Date: Thu, 09 Sep 2004 10:29:57 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl inconsistency
Message-Id: <im40k01ta7uimte6cei4cs3k8ihfqfc47e@4ax.com>

On Thu, 09 Sep 2004 04:19:30 +0200, Mike Mimic <ppagee@yahoo.com>
wrote:

>I think that I found some inconsistency in Perl.

And who said Perl is supposed to be consistent? Others have explained
you precisely what's going on: the point is that dwimmeries are
thought to be friendly to you in the vast majority of cases. Though
the drawback is that you should be aware of them or either be prepared
to get burnt in the minority of cases in which they won't DWYM...

BTW: this is one of the reasons why Perl6 is being designed to be more
consistent (and IMHO *slightly* less magic).


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Thu, 09 Sep 2004 19:59:32 +1000
From: Stephen Jeffrey <Stephen.Jeffrey@maths.uq.edu.au>
Subject: Plotting into XML pages
Message-Id: <chp9i5$ubh$1@bunyip.cc.uq.edu.au>

Hi,

I have a CGI script that uses GnuPlot to
dynamically graph data. It works when the
page calling the CGI script is HTML, but
not XML.

Does anyone have any example code that
shows how to plot data using gnuplot
into an XML page?

The following fragment works when graphing
to HTML:

----------------------------------------------------------------
$GNUPLOT = '/usr/bin/gnuplot';

$|=1;                                 # Prevent buffering problems
print "Content-type: image/png\n\n";  # required header

open (GRAPH,"| $GNUPLOT") || die;
print GRAPH <<END;
     set term png color small
     set output
     plot sin(x)
END

close GRAPH;
----------------------------------------------------------------

cheers
steve



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

Date: 9 Sep 2004 02:23:05 -0700
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Setting the LWP::Parallel::UserAgent chunk size in the callback method
Message-Id: <chp7dp$t54@odak26.prod.google.com>


Hi!

I want to use LWP::Parallel::UserAgent to handle each request when it
has returned.

I've tried the wait() method. The problem with the wait() method is
that I can parse each response first when all the other requests are
finished.

My second try was to use a callback function. Since I want to handle
the whole response data at the same time, I've set the chunk size to be
very large (100 MB). I was thinking that this would make each chunk to
be the whole page. However, that didn't work. Each cunk becomes about
1460 bytes anyway.

My third try was to use a callback function and put the chunks for a
certain request in a buffer. So that when the whole page is loaded, I
can parse it. However - I can't figure out how to know when the page is
fully loaded. As staded in the docs, the length($content) == 0 doesn't
mean the connection is closed.

Is the some other way to handle each request when it has returned?
Leif



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

Date: 9 Sep 2004 02:20:57 -0700
From: clemmons@gmail.com (Gordon)
Subject: Re: Socket holding pattern
Message-Id: <cd939529.0409090120.53581985@posting.google.com>

> If the duration of each connection is limited, an "overlapping restart"
> is a possibility.
> 
> On a signal (or something), the server forks and execs a new copy.
> It also ceases to accept new connections, but continues serving
> the old ones.  When the last connection is gone, it dies.  All
> new requests are served by the new process.
> 
> If you have unlimited connection time, and can't afford to break
> long-lasting ones, this simple scheme won't work.  Sketchy as it
> is, it may well not work for other reasons.
> 
> Anno

Thanks for the message, it's actually for unlimited connections
though.  It's a mud / online game server.

-gordon


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

Date: Wed, 8 Sep 2004 21:02:26 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Sybase DBI Returned data query
Message-Id: <slrncjvedi.40j.tadmc@magna.augustmail.com>

Rob.Buxton@wcc.govt.nz <Rob.Buxton@wcc.govt.nz> wrote:


> I've been struggling with this for a while so I'm hoping there'll will
> be someone who knows what I'm doing wrong.


You may be mis-partitioning the problem...


> It's driven from a Web Page (IIS 6.0)

> change the password via the sp_password stored procedure.

> The problem is the sp_password generates a message:


So then, one solution would be to figure out how to get sp_password
to stop doing that?

That would be a Sybase question.


> If I run the script locally, it works fine. 


(I assume that "locally" means "from the command line", 
 ie. not in a CGI environment.
)

If it works from the command line, but not as a CGI program, then
the answer is nearly always a server-configuration or environment
problem rather than a programming language problem.




Have you seen the relevant Perl FAQs yet?

   perldoc -q CGI

       My CGI script runs from the command line but not the browser.  
       (500 Server Error)

       How can I get better error messages from a CGI program?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 8 Sep 2004 23:37:18 -0700
From: michael.peppler@gmail.com (Michael Peppler)
Subject: Re: Sybase DBI Returned data query
Message-Id: <54ec902e.0409082237.5d2dd688@posting.google.com>

Rob.Buxton@wcc.govt.nz wrote in message news:<6stuj0p9uu257impt3tddevi6usmh924i3@4ax.com>...

> The database connection works fine and the actual sth->execute does
> change the password via the sp_password stored procedure.
> Snippet of code below.
> 
> my $query="execute sp_password '$PASSWORD', '$pass', '$name'"; 
> my $sth = $dbh->prepare(${query});
> $sth->execute;
> 
> The problem is the sp_password generates a message:
> "Password correctly set." which seems to upset the Web Page as all I
> get is a CGI Error

Take a look at the syb_err_handler attribute. The problem is that the
sp_password proc generates a PRINT statement, which is sent to stdout
by default.

By using an ad-hoc error handler you can redirect that message to the 
server error log, or ignore it completely.
A PRINT statement is sent back to the client's error handler with an
error message number of 0, so you can test on that condition.

Michael


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

Date: Thu, 9 Sep 2004 05:57:50 +0000 (UTC)
From: Cyde Weys <cyde@umd.edu>
Subject: Using Perl in slashboxes in slashcode (how to force refresh)
Message-Id: <Xns955F13FAA9AC72galopagosterrapincy@128.8.10.18>

    	Okay, I know this is kind of offtopic, but there really isn't a 
slashcode newsgroup, so this is the closest I could come.  I'm trying to 
put a slashbox on my webpage that looks at the current system clock and 
says stuff based on that (i.e., "It's 9:39pm, the Sun has just gone down", 
or whatever).  I know the Perl to do this; the problem is, the slashboxes 
are only updated once in a while and then their output cached.  I need to 
force this Perl code to run every time the page is viewed and the slashbox 
is displayed.  Anyone know how to accomplish that?  Thanks.

-- 
~ Cyde Weys ~
Bite my shiny metal ass.


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

Date: 8 Sep 2004 23:22:51 -0700
From: "Prasad  Gadgil" <prasad.gadgil@gmail.com>
Subject: web services...
Message-Id: <chosrr$ieb@odbk17.prod.google.com>

hi,

Web services is very interesting. How does one code this using perl?
Any famous examples ?

regards,
prasad



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

Date: Thu, 09 Sep 2004 09:32:45 +0200
From: **** <abdank@gmx.de>
Subject: Re: what's wrong with @$ip?
Message-Id: <chp0v8$nt6$1@achot.icm.edu.pl>

**** wrote:

> use NetAddr::IP;
> my $ip = new NetAddr::IP('10.0.0.0/30');
> print join(' ', @$ip), "\n";
> 
> prints: Not an ARRAY reference

problem is perl version (5.005)
thank you


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

Date: Wed, 8 Sep 2004 19:29:13 +0100
From: Steve O'Hara-Smith <steveo@eircom.net>
Subject: Re: Xah Lee's Unixism
Message-Id: <20040908192913.67c07e7d.steveo@eircom.net>

On Wed, 08 Sep 04 11:48:36 GMT
jmfbahciv@aol.com wrote:

> In article <p9qdnTnxTYDJR6PcRVn-pw@speakeasy.net>,
>    rpw3@rpw3.org (Rob Warnock) wrote:

> >*Only* a month?!?  Here's the uptime for one of my FreeBSD boxes
> >[an old, slow '486]:
> >
> >    %  uptime
> >     2:44AM  up 630 days, 21:14, 1 user, load averages: 0.06, 0.02, 0.00
> >    % 
> >
> >That's over *20* months!!
> 
> I bet we can measure the youngster's age by the uptimes he boasts.

	The Yahoo! server farm ran to very long uptimes last time I had
any details. The reason being that they commission a machine, add it to
the farm and leave it running until it is replaced two or three years
later.

-- 
C:>WIN                                      |   Directable Mirror Arrays
The computer obeys and wins.                | A better way to focus the sun
You lose and Bill collects.                 |    licences available see
                                            |    http://www.sohara.org/


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

Date: Thu, 09 Sep 2004 04:05:28 +0000
From: Reynir Stefánsson <reynirhs@mi.is>
Subject: Re: Xah Lee's Unixism
Message-Id: <tblvj0psc16vbequddlca1s6cf97pa8a9f@4ax.com>

So spake CBFalconer:

>There is no need, nor cause, to impute Bush & Co. with
>intrinsically evil intentions.

Merely remember Occam's and Hanlon's Razors.
-- 
Reynir Stefánsson (reynirhs@mi.is)


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

Date: Thu, 09 Sep 2004 04:05:31 +0000
From: Reynir Stefánsson <reynirhs@mi.is>
Subject: Re: Xah Lee's Unixism
Message-Id: <2tjvj0ttc99io295ecg2l86lc2h4tug1jc@4ax.com>

So spake Anne & Lynn Wheeler:

>OSI can support x.25 packet switching and/or even the arpanet packet
>switching from the 60s & 70s .... but it precludes internetworking
>protocol. internetworking protocol (aka internet for short) is a
>(non-existant) layer in an OSI protocol stack between
>layer3/networking and layer4/transport. misc. osi (& other) comments
>http://www.garlic.com/~lynn/subnetwork.html#xtphsp

Wasn't the idea behind ISO/OSI that there should be One Network for
everybody, instead of today's lot of interconnected nets?
-- 
Reynir Stefánsson (reynirhs@mi.is)


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

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 V10 Issue 6978
***************************************


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