[25790] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8029 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 29 14:05:22 2005

Date: Fri, 29 Apr 2005 11:05:07 -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           Fri, 29 Apr 2005     Volume: 10 Number: 8029

Today's topics:
    Re: Can this be rewritten better? <hackeras@gmail.com>
    Re: Can this be rewritten better? <sbryce@scottbryce.com>
    Re: Can this be rewritten better? <hackeras@gmail.com>
    Re: Can this be rewritten better? <lawshouse.public@btconnect.com>
    Re: Can this be rewritten better? <jgibson@mail.arc.nasa.gov>
    Re: Can this be rewritten better? <hackeras@gmail.com>
    Re: Can this be rewritten better? <lawshouse.public@btconnect.com>
    Re: Can this be rewritten better? <lawshouse.public@btconnect.com>
    Re: Can this be rewritten better? <hackeras@gmail.com>
    Re: Can this be rewritten better? <hackeras@gmail.com>
    Re: Can this be rewritten better? <tim@vegeta.ath.cx>
    Re: Can this be rewritten better? <tim@vegeta.ath.cx>
    Re: Entirely new idea for a webpage <tadmc@augustmail.com>
    Re: LogReader.pl <no@email.com>
        Looking for Perl Grammar <khamis@wellcode.com>
    Re: Looking for Perl Grammar <apeiron+usenet@coitusmentis.info>
    Re: Multiple Inheritance: mixed base class refs (hash,  <a.newmane.remove@eastcoastcz.com>
    Re: multiples ifs <lawshouse.public@btconnect.com>
    Re: multiples ifs <hackeras@gmail.com>
    Re: multiples ifs <sbryce@scottbryce.com>
    Re: multiples ifs <hackeras@gmail.com>
        Perl windows to linux conversion (Master)
    Re: Perl windows to linux conversion <sbryce@scottbryce.com>
    Re: Perl windows to linux conversion <lawshouse.public@btconnect.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 29 Apr 2005 19:36:19 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Can this be rewritten better?
Message-Id: <d4tnq3$gav$1@nic.grnet.gr>

Nikos wrote:
> my $script = param('select') or "Áñ÷éêÞ Óåëßäá!";

Please help with this. its a precide question


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

Date: Fri, 29 Apr 2005 10:52:51 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Can this be rewritten better?
Message-Id: <NdCdnbm4bML---_fRVn-3g@comcast.com>

Nikos wrote:

> Nikos wrote:
> 
>> my $script = param('select') or "Áñ÷éêÞ Óåëßäá!";
> 
> 
> Please help with this. its a precide question

What do you expect this line to do? What is it doing that is different 
than you expect? Please write it into a short, but complete program that 
demonstrates the problem.

And read the posting guidelines for this group. It has got to be less 
reading that reading all of the posts that have tried to explain them to 
you.


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

Date: Fri, 29 Apr 2005 19:59:35 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Can this be rewritten better?
Message-Id: <d4tp5n$hdr$1@nic.grnet.gr>

Scott Bryce wrote:
> Nikos wrote:
> 
>> Nikos wrote:
>>
>>> my $script = param('select') or "Áñ÷éêÞ Óåëßäá!";

I meant [snip] the rest!

here is the code so far that i want to be rewritten in a better shorter way!

my $script = param('select') or "Áñ÷éêÞ Óåëßäá!";

$sth = $dbh->prepare( "SELECT host FROM guestlog" );
$sth->execute();

my $hostmatch;
while( $row = $sth->fetchrow_hashref ) {
     if( $host eq $row->{host} ) {
         $hostmatch = 1;
     }
}

my ($data, @data);
if( param('select') and param('select') !~ /\.\./ )
{
     open(FILE, "<../data/text/$script.txt") or die $!;
          @data = <FILE>;
     close(FILE);

     $data = join('', @data);

     $dbh->do( "UPDATE guestlog SET script='$script' WHERE host='$host'" 
) or die $dbh->errstr;
}
elsif( $hostmatch == 1 )
{
     $dbh->do( "UPDATE guestlog SET hostcount = hostcount + 1 WHERE 
host='$host'" ) or die $dbh->errstr;
     $sth = $dbh->prepare( "SELECT * FROM guestlog WHERE host='$host'" );
     $sth->execute();
     $row = $sth->fetchrow_hashref;

     $data = "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçí óåëßäá 
åíäéáöÝñïõóá!\n" .
             "Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò " 
 .$row->{date}. " !!\n" .
             "ÓýíïëéêÝò Þñèåò åäþ " .$row->{hostcount}. " öïñÝò!!!\n" .
             "Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{script}. " }\n" .
             "Ðïéü êåßìåíï èá ìåëåôÞóåòé áõôÞí ôçí öïñÜ !?";
}
elsif( $hostmatch != 1 )
{
    if ( $host ne "Íßêïò" )
    {
        $data = "ÃåéÜ óïõ " .$host. "!\n" .
                "¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
                "Åëðßæù íá âñåßò ôá êåßìåíá åíäéáöÝñïíôá :-)";

        $dbh->do( "INSERT INTO guestlog VALUES (null, '$host', '$date', 
'$script', 1, 1)" ) or die $dbh->errstr;
    }
    else
    {
        $data = "ÃåéÜ óïõ Íéêüëá, ôé ÷áìðÜñéá?! ¼ëá äåîéÜ íá óïõ ðÜíå 
ðÜíôá! ;-)";
    }
}

Please help me.
This is the best way i can write it.


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

Date: Fri, 29 Apr 2005 18:04:54 +0100
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: Can this be rewritten better?
Message-Id: <hap471hthpqo3bp0h75i795iuft2qnl809@4ax.com>

On Fri, 29 Apr 2005 17:25:38 +0300, Nikos <hackeras@gmail.com> wrote:

>my $script = param('select') or " !";

What happens if param fails for some reason?

>
>$sth = $dbh->prepare( "SELECT host FROM guestlog" );
>$sth->execute();
>while( $row = $sth->fetchrow_hashref ) {
>     if( $host eq $row->{host} ) {
>         my $hostmatch = 1;

The use of "my" here will localise $hostmatch to the braces of the
"if" statement.  It will be undef when you need it later.

>     }
>}
>
>if( param('select') and param('select') !~ /\.\./ )

I don't know what this is doing but it looks odd to me.  I can't
imagine what the two calls to "param" are returning which when anded
together could ever look like ".."

Oh, and code your left brace at the end of the line, as you've done
before

>{
>    open(FILE, "<../data/text/$script.txt") or die $!;
>         my @data = <FILE>;
>    close(FILE);

Can you be sure that $script.txt isn't too big to be loaded into
memory all at once?

>
>     my $data = join('', @data);
>
>     $dbh->do( "UPDATE guestlog SET script='$script' WHERE host='$host'" 
>) or die $dbh->errstr;
>}
>elsif( $hostmatch == 1 )

See comment on $hostmatch earlier

>{
>     $dbh->do( "UPDATE guestlog SET hostcount = hostcount + 1 WHERE 
>host='$host'" ) or die $dbh->errstr;
>     $sth = $dbh->prepare( "SELECT * FROM guestlog WHERE host='$host'" );
>     $sth->execute();
>     $row = $sth->fetchrow_hashref;
>
>     $data = "  " .$host. "!      
>!\n" .
>             "     " .$row->{host}. "  " 
>.$row->{date}. " !!\n" .
>             "   " .$row->{hostcount}. " !!!\n" .
>             "    { " .$row->{script}. " }\n" .
>             "       !?";
>}
>elsif( $hostmatch != 1 )

This is just a simple "else" construct; you've checked to see whether
$hostmatch is 1, so now it's not. 

>{
>    if ( $host ne "" )
>    {
>        $data = "  " .$host. "!\n" .
>                "  1   !!\n" .
>                "      :-)";
>
>        $dbh->do( "INSERT INTO guestlog VALUES (null, '$host', '$date', 
>'$script', 1, 1)" ) or die $dbh->errstr;
>    }
>    else
>    {
>        $data = "  ,  ?!      
>! ;-)";
>    }
>}
>
>ok with the above script iam trying to see if the current hostname of a 
>visitor exists in guestlog mysql database.
>
>If it does then i just update the existing record,
>if it does not i just welcome the user.

I have no idea about the logic.  Tell you what: you run it and see if
it does what you expect.  If it doesn't, try to figure out why.

>Please you asked me to ask specific questions and here i ask one:
>
>Is the above logic correct?

No idea.   That's not a Perl question.  It's a program design
question, which is better answered somewhere else (if you can find
somewhere). 

>Is there any betetr that i can write it?

I've marked a few things; I advise you just to make it work and don't
worry too much about the programming style as long as it is decently
laid out.

>ps. Sorry about the Greek folks but although i use UTF-8 it still being 
>displayed like shit. I hate seeing it myself too but i donw know how can 
>they be displayed correctly.

I'm not expert in that, but I don't think that changing your code page
will help; it's not going to map "beta" into b, or "rho" into r is it?

But if you'd make a SMALL, SELF-CONTAINED program - as it asks you to
in the posting guidelines - then you could use only a-z just for that
and the problem wouldn't arise.



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

Date: Fri, 29 Apr 2005 10:11:28 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Can this be rewritten better?
Message-Id: <290420051011281504%jgibson@mail.arc.nasa.gov>

In article <d4tg52$915$1@nic.grnet.gr>, Nikos <hackeras@gmail.com>
wrote:

> my $script = param('select') or "Áñ÷éêÞ Óåëßäá!";
> 
> $sth = $dbh->prepare( "SELECT host FROM guestlog" );
> $sth->execute();

You need to check whether or not the above two statements executed
properly.

Here you need:

my $hostmatch;

(see below).

> while( $row = $sth->fetchrow_hashref ) {
>      if( $host eq $row->{host} ) {

Where is $host set? You are not showing the entire program, for which
we are grateful, but you need to show all of the relevant parts. There
is also no need to fetch all of the host names in the guestlog table to
see if a particular host is present. You can use an SQL statement such
as "select host from guestlog where host = '$hostname'" as you do later
following an update, which here should fetch either one or zero rows.

>          my $hostmatch = 1;

Declaring $hostmatch with 'my' limits the scope of this variable to the
enclosing block. This is not what you want. You need to declare
$hostmatch at the same level as the statements that want to access it.
You need to declare it before this while loop as shown above.

>      }
> }


> 
> if( param('select') and param('select') !~ /\.\./ )

You have already fetched the value of param('select') (with a default
value) into $script above. Why not use that value here? If you are
testing to see if the value of select is '..', then use string
comparison, not a regular expression ( param('select') ne '..' ). Your
test will reject any value of param('select') that contains two
successive periods, such as 'abc..def', which may not be what you want.

> {
>     open(FILE, "<../data/text/$script.txt") or die $!;
>          my @data = <FILE>;
>     close(FILE);
> 
>      my $data = join('', @data);

There are better ways to read the contents of a file into a scalar
variable. Set the input record separator variable $/ to undef and read
directly into the scalar, and do it in a block to localize the change
of the $/ variable, but don't localize the data variable:

   my $data;
   {
      local $/;
      $data = <FILE>;
   }

or use the File::Slurp module.

> 
>      $dbh->do( "UPDATE guestlog SET script='$script' WHERE host='$host'" 
> ) or die $dbh->errstr;
> }
> elsif( $hostmatch == 1 )

This test will not be made if param('select') is defined and doesn't
contain '..' as tested above.

> {

[statements updating guestlog table snipped]

> }
> elsif( $hostmatch != 1 )

Ditto.

> {
>     if ( $host ne "Íßêïò" )
>     {
>         $data = "ÃåéÜ óïõ " .$host. "!\n" .
>                 "¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
>                 "Åëðßæù íá âñåßò ôá êåßìåíá
> åíäéáöÝñïíôá :-)";
> 
>         $dbh->do( "INSERT INTO guestlog VALUES (null, '$host', '$date', 
> '$script', 1, 1)" ) or die $dbh->errstr;
>     }
>     else
>     {
>         $data = "ÃåéÜ óïõ Íéêüëá, ôé ÷áìðÜñéá?! ¼ëá
> äåîéÜ íá óïõ ðÜíå 
> ðÜíôá! ;-)";
>     }
> }
> 
> ok with the above script iam trying to see if the current hostname of a 
> visitor exists in guestlog mysql database.
> 
> If it does then i just update the existing record,
> if it does not i just welcome the user.
> 
> 
> Please you asked me to ask specific questions and here i ask one:
> 
> Is the above logic correct?

No, because if param('select') is true and doesn't contain '..', the
guestlog table won't be updated regardless of whether or not it
contains an entry for $host.

> Is there any betetr that i can write it?

"Better" in what way? That is a subjective criteria that depends upon
your goals. Do you want it to be shorter, faster, less memory, easier
to maintain, or something else? Only you know what your criteria are.
At your stage of programming experience, I would advise to just
concentrate on getting it working. Worry about quality later.

> 
> ps. Sorry about the Greek folks but although i use UTF-8 it still being 
> displayed like shit. I hate seeing it myself too but i donw know how can 
> they be displayed correctly.

You should write a short test program that illustrates the problem you
are having. Don't post your complete program or parts of it, because we
don't have the time to inspect your program in its entirety. You will
increase your chances of getting helpful responses if you limit
yourself to the English language and post a program that anyone can
cut-and-paste and execute on their own system. For you, this means not
including the database parts of your program because none of us have
your database on our systems. 

Good luck!

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


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

Date: Fri, 29 Apr 2005 20:18:35 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Can this be rewritten better?
Message-Id: <d4tq9b$kp6$1@nic.grnet.gr>

Henry Law wrote:

The script is working ok now that i removes my as you correclty said but 
i think maybe it can be even better written


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

Date: Fri, 29 Apr 2005 18:29:19 +0100
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: Can this be rewritten better?
Message-Id: <5lr4715baht87tpiaphaeovmtb43aoh8ic@4ax.com>

On Fri, 29 Apr 2005 20:18:35 +0300, Nikos <hackeras@gmail.com> wrote:

>Henry Law wrote:

No, actually, I didn't.  You did.  

>The script is working ok now that i removes my as you correclty said but 
>i think maybe it can be even better written

My advice to you is not to bother about coding style; you have more
serious problems. 


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

Date: Fri, 29 Apr 2005 18:26:20 +0100
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: Can this be rewritten better?
Message-Id: <l2r471pbl70hcv4d4b8j8rv5hjssdf262q@4ax.com>

On Fri, 29 Apr 2005 19:59:35 +0300, Nikos <hackeras@gmail.com> wrote:

>Please help me.
>This is the best way i can write it.

Are you asking us to comment on your coding style or the logic of your
program?  I don't think anyone is going to debug your program for you.
Even if we were (and I did think of trying, just to be helpful) we
can't run it.  Look:

	F:\WIP>perl nikos.pl
	Undefined subroutine &main::param called at nikos.pl line 1.

	F:\WIP>

It compiles clean, of course, because it has no strict and warnings.
I added them and this happened, as expected:

F:\WIP>perl nikos.pl
Global symbol "$sth" requires explicit package name at nikos.pl line
6.
Global symbol "$dbh" requires explicit package name at nikos.pl line
6.
Global symbol "$sth" requires explicit package name at nikos.pl line
7.

 ... and so on and on.  That's because I haven't got the requisite DBI
module (I even coded "use DBI;" for you just in case.

Nikos, let me say this once more: we WILL NOT DEBUG YOUR PROGRAM LOGIC
FOR YOU.  That's not what this group is for.  

If your logic goes wrong because you've not understood how Perl works,
that we can help with.


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

Date: Fri, 29 Apr 2005 20:35:17 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Can this be rewritten better?
Message-Id: <d4tr8m$lqb$1@nic.grnet.gr>

Jim Gibson wrote:

By following almost all your sugegstions i convert it to:


===========================================================
my $script = param('select') or "Welcome Page!";

$sth = $dbh->prepare( "SELECT host FROM guestlog WHERE host='$host'" );
$sth->execute();

my ($data, @data);
if( param('select') and param('select') ne '..' )
{
     open(FILE, "<../data/text/$script.txt") or die $!;
          @data = <FILE>;
     close(FILE);

     $data = join('', @data);

     $dbh->do( "UPDATE guestlog SET script='$script' WHERE host='$host'" 
) or die $dbh->errstr;
}
elsif( $sth->rows )
{
     $dbh->do( "UPDATE guestlog SET hostcount = hostcount + 1 WHERE 	 
host='$host'" ) or die $dbh->errstr;
     $sth = $dbh->prepare( "SELECT * FROM guestlog WHERE host='$host'" );
     $sth->execute();
     $row = $sth->fetchrow_hashref;

     $data = "Never mind about that";
}
elsif( not $sth->rows )
{
    if ( $host ne "" ) {
	$data = "Never mind about that";

        $dbh->do( "INSERT INTO guestlog VALUES (null, '$host', '$date', 
'$script', 1, 1)" ) or die $dbh->errstr;
    }
    else {
        $data = "Never mind about that its greek";
    }
}
===========================================================


Dont worry about param('select') it gets its value.

I decided i dont really need hostmatch.

Can we make it even shorter and better written?


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

Date: Fri, 29 Apr 2005 20:36:30 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Can this be rewritten better?
Message-Id: <d4trau$lqb$2@nic.grnet.gr>

Henry Law wrote:
> On Fri, 29 Apr 2005 20:18:35 +0300, Nikos <hackeras@gmail.com> wrote:
> 
> 
>>Henry Law wrote:
> 
> 
> No, actually, I didn't.  You did.  
> 
> 
>>The script is working ok now that i removes my as you correclty said but 
>>i think maybe it can be even better written
> 
> 
> My advice to you is not to bother about coding style; you have more
> serious problems. 

The script is working but i want to write it as betetr as possible.
ima learnign this way.


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

Date: Fri, 29 Apr 2005 17:49:55 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Can this be rewritten better?
Message-Id: <slrnd74smv.6bc.tim@vegeta.saiyix>

Nikos <hackeras@gmail.com> wrote:
>  my $script = param('select') or " !";

If you want to set $script to " !" if param('select') is
empty, you'll probably want to use the || operator instead of "or".  As
it is, $script will either be set to param('select') or undef.

HTH,
Tim Hammerquist
-- 
A supercomputer is a device for converting
a CPU-bound problem into an I/O bound problem.
    -- Ken Batcher


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

Date: Fri, 29 Apr 2005 18:00:27 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Can this be rewritten better?
Message-Id: <slrnd74tan.6bc.tim@vegeta.saiyix>

Nikos <hackeras@gmail.com> wrote:
> Can we make it even shorter and better written?

You sure can.  You might want to read up on Perl some more.  The best
way to learn to program fast, efficient Perl code is study, practice,
and lurking in these here newsgroups.

Posting code and asking if there's a better way is not a good approach.

Yes, there's probably a better way to write it.  And for a standard fee,
many people here would be happy to show you.

Tim Hammerquist


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

Date: Fri, 29 Apr 2005 12:09:40 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Entirely new idea for a webpage
Message-Id: <slrnd74qik.dpq.tadmc@magna.augustmail.com>

Nikos <hackeras@gmail.com> wrote:

> Please watch your language.


Please watch your behavior.


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


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

Date: Fri, 29 Apr 2005 17:48:10 +0100
From: Brian Wakem <no@email.com>
Subject: Re: LogReader.pl
Message-Id: <3df6qbF6ci9ucU2@individual.net>

John Bokma wrote:

> Nikos wrote:
> 
>> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
>> &Clear;
>   ^
> 
> 
>> open (LOGFILE, $filename) or die $!;
>> 
>> while (<LOGFILE>) {
>>     ($user) = /^<([^>]*)>/;
>> 
>>     if (!$userhash{$user}) {
> 
> I would use something like:
> 
> unless ( exists $userhash{ $user } ) {
> 
> 
>>     DoPrint("$userhash{$user}");
>                ^
> Don't use funny characters like that.
> 
> 
>>     for $foo (split(//, $_)) {
>>        for(1..300000) {};
> 
>          ^^^^^ silly, I can even
> imagine Perl just drops that. Use sleep, or
> something related.
>


I remember using code like that for pauses in BASIC on an old Amstrad CPC464
when I was about 8!
 

-- 
Brian Wakem




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

Date: Fri, 29 Apr 2005 18:51:26 +0200
From: Khamis Abuelkomboz <khamis@wellcode.com>
Subject: Looking for Perl Grammar
Message-Id: <d4tomc$4fk$05$1@news.t-online.com>

Hi

I'm writing a Perl parser and I'm looking for a pure perl grammar. the documentation from perl is 
not a pure grammar, it's more a documentation of the perl language.

thanks in advance
-- 
Try Code-Navigator on http://www.codenav.com
a source code navigating, analysis and developing tool.
It supports following languages:
     * C/C++
     * Java
     * .NET (including CSharp, VB.Net and other .NET components)
     * Classic Visual Basic
     * PHP, HTML, XML, ASP, CSS
     * Tcl/Tk,
     * Perl
     * Python
     * SQL,
     * m4 Preprocessor
     * Cobol


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

Date: 29 Apr 2005 17:33:42 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: Looking for Perl Grammar
Message-Id: <slrnd74rvm.mkc.apeiron+usenet@prophecy.dyndns.org>

On 2005-04-29, Khamis Abuelkomboz scribbled these curious markings:
> I'm writing a Perl parser and I'm looking for a pure perl grammar. the
> documentation from perl is not a pure grammar, it's more a
> documentation of the perl language.

[Please wrap your lines at 70-72 characters. Thank you.]

First, a bit of folklore: "Only perl can parse Perl". What this means is
that only perl (the program) is capable of properly and completely
parsing Perl (the language). So why not have the existing Perl parser
(accessible at least via the command perl and possibly via a shared
library) do it for you? If you're doing this from C, you should start
with perldoc perlembed (assuming your documentation is installed, of
course; some Unix vendors think that it's bright to not ship
documentation by default).

Second, failing that, you can find the file perly.y in the perl source
kit which contains the grammar for the language.

Best Regards,
Christopher Nehren
-- 
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.


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

Date: Fri, 29 Apr 2005 09:31:21 -0700
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Multiple Inheritance: mixed base class refs (hash, array)
Message-Id: <3df5r1F6s9ef7U1@individual.net>

Mark Clements wrote:
> Tassilo v. Parseval wrote:
>> Also sprach Mark Clements:
>>
>>> Alfred Z. Newmane wrote:
>>
>> [...]
>>
>>>> I noticed that IO:Select actually uses an ARRAY ref (blessed),
>>>> rather than a HASH ref, to contain itself. Why is this?
>>
>> [...]
>>
>>> It's an array ref because it is a pseudohash (or pseudo-hash).
>>> Check out perldoc fields
>>
>> It isn't. It just happens to be a plain array-reference because it is
>> a fairly natural choice of data-structures when it comes to
>> maintaining a list of file-descriptors. It however mimics
>> pseudo-hashes to a certain extent in that IO::Select uses named
>> constants to access the first three fields of the array.
>
> Oops - I completely misread the output of Data::Dumper. I tend to use
> pseudo-hashes for my own classes, so I guess I have conditioned myself
> (badly) to see them even where they are not present :(

Thank you for those descriptions and sample code. I have only one 
remaining question, concerning the code you have shown in your previous 
post:

> This doesn't really work for multiple inheritance though.
>
> With composition, your class isn't a subclass, but contains references
> to the other classes.
>
>
> sub new {
> my $class = shift;
> my $argsForEvent = shift;
> my $argsForSelect = shift;
>
> my $self = {
> _event => MyEvent->new( @$argsForEvent ),
> _select => IO::Select->new( @$argsForSelect ) ,
> };
>
> return bless $self,$class;
> }

Yes I could of done it this way. but I was really wondering if it would 
be possible to accomplish this with inheritance, some how combine the 
two base classes into one big class. Would it be possible to "convert" 
(for lack of a better term) the "pseudo-hashes" returned by IO::Select 
into a more standard HASH (ref), *without* compromising the IO::Select 
class itself (meaning, can the values be fed into the $obj hashref and 
then still be able to use an inherited subs of IO::Select?)

Thank you again for you responses. 




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

Date: Fri, 29 Apr 2005 17:46:39 +0100
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: multiples ifs
Message-Id: <r2p471duibsb6ccokr500aj9jq7ivfs2j9@4ax.com>

On Fri, 29 Apr 2005 16:14:03 +0300, Nikos <hackeras@gmail.com> wrote:

>is there any better way to write this in Perl?
>
>    if( !$name )    { print font( {-size=>4, -color=>'Lime'},  ' 
>    !<p>' );       $i=1; }
>    if( !$pray )    { print font( {-size=>4, -color=>'Lime'},  ' 
>  !<p>' );                $i=1; }
>    if( !$remark )  { print font( {-size=>4, -color=>'Lime'},  '  
>     ?<p>' );  $i=1; }
>    if( !$email )   { print font( {-size=>4, -color=>'Lime'}, 
>'  email !<p>' );               $i=1; }
>    exit 0 if ($i!=0);

Oi, you lot.  This isn't a bad question at all and one or two of the
previous posters have been most unkind.  OK, that may be because Nikos
has got up people's noses a lot (really a lot) but maybe he's trying
to rehabilitate himself.

What he's trying to do is to make n tests for the non-true-evaluation
of n separate variables (he's presumably using that to infer their
zero-lengthness and therefore their non-existence), issue a customised
message for each one that is false, and then exit with a zero code if
there was at least one error.  It's a fair question and I for one
can't find a neater way of doing it.

Here's a traditional ASCII codepage version, which makes it easier to
see:

	# No strict, warnings - this is a fragment
	# Untested for the same reason
	# Probably crashes if $a or $b etc is undef

	my $fail=0;
	unless ($a) {
		print "Error message for missing \$a\n"; 
		$fail=1;
	}
	unless ($b) {
		print "Different error message for missing \$b\n";
		$fail=1;
	}
	# Etc for n different variables; his n=4
	#

	exit 0 if $fail;

	print "We succeeded - they were all there\n";

Looks pretty clunky to me.  Maybe some "eval" construct would help?
I'm not good enough to try it.


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

Date: Fri, 29 Apr 2005 20:06:50 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: multiples ifs
Message-Id: <d4tpja$inf$1@nic.grnet.gr>

Henry Law wrote:
> On Fri, 29 Apr 2005 16:14:03 +0300, Nikos <hackeras@gmail.com> wrote:
> 
> 
>>is there any better way to write this in Perl?
>>
>>   if( !$name )    { print font( {-size=>4, -color=>'Lime'},  ' 
>>    !<p>' );       $i=1; }
>>   if( !$pray )    { print font( {-size=>4, -color=>'Lime'},  ' 
>>  !<p>' );                $i=1; }
>>   if( !$remark )  { print font( {-size=>4, -color=>'Lime'},  '  
>>     ?<p>' );  $i=1; }
>>   if( !$email )   { print font( {-size=>4, -color=>'Lime'}, 
>>'  email !<p>' );               $i=1; }
>>   exit 0 if ($i!=0);
> 
> 
> Oi, you lot.  This isn't a bad question at all and one or two of the
> previous posters have been most unkind.  OK, that may be because Nikos
> has got up people's noses a lot (really a lot) but maybe he's trying
> to rehabilitate himself.

Iam glad someone understand that. Thank you Henry.
I ahev started asking specific questions.

> What he's trying to do is to make n tests for the non-true-evaluation
> of n separate variables (he's presumably using that to infer their
> zero-lengthness and therefore their non-existence), issue a customised
> message for each one that is false, and then exit with a zero code if
> there was at least one error.  It's a fair question and I for one
> can't find a neater way of doing it.

Exactly! :-)
Unfortunately ic ant express myself adequatly in English :(

> Here's a traditional ASCII codepage version, which makes it easier to
> see:
> 
> 	# No strict, warnings - this is a fragment
> 	# Untested for the same reason
> 	# Probably crashes if $a or $b etc is undef
> 
> 	my $fail=0;
> 	unless ($a) {
> 		print "Error message for missing \$a\n"; 
> 		$fail=1;
> 	}
> 	unless ($b) {
> 		print "Different error message for missing \$b\n";
> 		$fail=1;
> 	}
> 	# Etc for n different variables; his n=4
> 	#
> 
> 	exit 0 if $fail;
> 
> 	print "We succeeded - they were all there\n";
> 
> Looks pretty clunky to me.  Maybe some "eval" construct would help?
> I'm not good enough to try it.

Here is hwo i made it aget your suggestion:

    unless( $name )    { print font( {class=>'tip'},  '   
  !<p>' );       $i=1; }
    unless( $pray )    { print font( {class=>'tip'},  '   
!<p>' );                $i=1; }
    unless( $remark )  { print font( {class=>'tip'},  '    
   ?<p>' );  $i=1; }
    unless( $email )   { print font( {class=>'tip'},  '  
email !<p>' );               $i=1; }
    exit 0 if ($i!=0);

but still not good enouph.

I really dont liek the use of $i.
I think there must me a smarter way of writing this.


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

Date: Fri, 29 Apr 2005 11:32:42 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: multiples ifs
Message-Id: <8KWdnfmUTuMn8u_fRVn-iA@comcast.com>

Nikos wrote:

> Here is hwo i made it aget your suggestion:

<code snipped>

> but still not good enouph.

Why not? Does it do what you want it to do? If not, what is it doing 
that is different than what you expect?

> I really dont liek the use of $i.

I think your use if $i is fine. You need some way of knowing whether an 
error was encountered. $i serves that purpose. You may want to use a 
more descriptive name such as $error_found.

> I think there must me a smarter way of writing this.

I think it is fine. I would probably do something very similar if I 
wrote it.


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

Date: Fri, 29 Apr 2005 20:39:15 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: multiples ifs
Message-Id: <d4trg3$lqb$3@nic.grnet.gr>

Scott Bryce wrote:

>> I really dont liek the use of $i.
> 
> 
> I think your use if $i is fine. You need some way of knowing whether an 
> error was encountered. $i serves that purpose. You may want to use a 
> more descriptive name such as $error_found.
> 
>> I think there must me a smarter way of writing this.
> 
> 
> I think it is fine. I would probably do something very similar if I 
> wrote it.

ok if you say so! :-)


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

Date: 29 Apr 2005 09:15:18 -0700
From: bsvijayan@gmail.com (Master)
Subject: Perl windows to linux conversion
Message-Id: <df7ef1bc.0504290815.7a14eac@posting.google.com>

i want to convert my windows perl script code to linux.Please help me
in finding the links for the same
thanks
saravan


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

Date: Fri, 29 Apr 2005 10:34:28 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl windows to linux conversion
Message-Id: <DIqdnYaacsCJ_-_fRVn-oA@comcast.com>

Master wrote:

> i want to convert my windows perl script code to linux.Please help me
> in finding the links for the same

With little exception, Perl is cross-platform. What exactly are you 
having trouble with? Please post code. Have you read the posting 
guidelines for this group?

Try running your script in a linux box. If there are problems, isolate 
the problems in a short, but complete script that demonstrates the 
problem, then post the code and ask specific questions.


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

Date: Fri, 29 Apr 2005 18:10:36 +0100
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: Perl windows to linux conversion
Message-Id: <3bq4711579a7i0vcebd2hcof75qlb5kqhl@4ax.com>

On 29 Apr 2005 09:15:18 -0700, bsvijayan@gmail.com (Master) wrote:

>i want to convert my windows perl script code to linux.Please help me
>in finding the links for the same
>thanks
>saravan

Can I encourage you to think a bit more about this question?  The
elements of the Perl language work perfectly in any operating system;
try 

	print "Hello world\n";

But modules that do specific Windows-ish stuff won't give the same
results in Linux; in fact they'll probably crash.  Any of the
Win32::whatever modules, for example.

Other functions are different between Windows and Linux, so if your
Perl exploits them the results will be different.  There's a section
in the ActiveState help that details a lot of them.  "Windows
implementation quirks" is a good place to start.

Maybe someone is at this moment posting useful URLs for you to look
at; I hope so.  If not then you'd be better to take a simple Perl
program from your Windows machine and run it in Linux and see what
happens!  If you don't understand what happened, or can't work out how
to fix it, post again!


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

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


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