[26826] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8856 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 16 09:06:36 2006

Date: Mon, 16 Jan 2006 06:05:04 -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           Mon, 16 Jan 2006     Volume: 10 Number: 8856

Today's topics:
    Re: create a hierarchical list from a text file <tadmc@augustmail.com>
    Re: ExpatXS: 'Can't call method "read" on an undefined  <ebohlman@omsdev.com>
        Netiquette aspect <noreply@gunnar.cc>
    Re: Netiquette aspect <matthew.garrish@sympatico.ca>
    Re: Strategy about browser cache and generated pages <.@.>
        while ( )  and  until ( ) <j.mapson.nurick@dial.pipex.com>
    Re: while ( )  and  until ( ) <tassilo.von.parseval@rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 16 Jan 2006 07:20:26 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: create a hierarchical list from a text file
Message-Id: <slrndsn7cp.hlf.tadmc@magna.augustmail.com>

Michael Friendly <friendly@yorku.ca> wrote:


> sub read_items {
>      $file = shift;


You should not use global variables without a good reason.

   my $file = shift;


>      open(IN, $file) || die("cant open $file\n");


You should include the *reason* why the open() failed in your message:

    open(IN, $file) || die("cant open '$file'  $!");


>      undef @items;


If you weren't using a global variable there, then you wouldn't
need to clear it out each time.

You should have

   use strict;

in all of your Perl programs, then declare each variable at its first use:

   my @items;



>          $line  =~ s/(\t*)//;
>          $level = length($1);      # level in tree


You should never use the dollar-digit variables unless you
have ensured that the match *succeeded*, otherwise there
will be a stale, left-over value from some previous match.


   my $level = length($1) if $line  =~ s/(\t*)//;


But you don't even need regular expressions at all:

   my $level = $line =~ tr/\t//d;



>          $item = {
>              level => $level,
>              title => $title,
>              url => $url,
>              desc => $desc,
>              };
>          push @items, $item;


You don't need the $item temporary variable if you just us
an anonymous hash constructor in the first place:

   push @items, {
              level => $level,
              title => $title,
              url => $url,
              desc => $desc,
              };


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


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

Date: 16 Jan 2006 08:53:05 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: ExpatXS: 'Can't call method "read" on an undefined value' after ca. 500 XML files
Message-Id: <Xns974D1D44CC816ebohlmanomsdevcom@130.133.1.4>

Arvin Portlock <nomail@sorry.com> wrote in
news:dqehgs$auv$1@agate.berkeley.edu: 

> The line in question in ExpatXS is this:
> 
> $result = $args->{ParseFunc}->($args->{Parser},
>    $args->{ParseFuncParam});
> 
> In some context that's:
> 
> sub _parse_systemid {
>      my $self = shift;
>      my $fh = IO::File->new(shift);

It appears that the author of the module has committed a classic error of 
the sort that posters here are admonished for: opening a file without 
checking whether it actually opened.  If it didn't, then $fh will be undef 
and attempting to call any methods on it will give an error.

>      $self->{ParseOptions}->{ParseFunc} = \&ParseStream;
>      $self->{ParseOptions}->{ParseFuncParam} = $fh;
>      $self->_parse;
> }


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

Date: Mon, 16 Jan 2006 10:56:37 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Netiquette aspect
Message-Id: <4318qoF1kg12tU1@individual.net>

The netiquette bids us to read the whole thread before posting a reply, 
obviously to avoid that the same thing is said repeatedly.[1] That 
aspect of the netiquette could be better adhered to, giving us a less 
noisy and more to the point clpmisc.

[1] I know that there may be delays in propagating a message to other 
Usenet servers, but I have a feeling that unnecessary repetitions are 
only in exceptional cases explained by such delays.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 16 Jan 2006 07:53:53 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Netiquette aspect
Message-Id: <yHMyf.6774$xk1.129613@news20.bellglobal.com>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message 
news:4318qoF1kg12tU1@individual.net...
> The netiquette bids us to read the whole thread before posting a reply, 
> obviously to avoid that the same thing is said repeatedly.[1] That aspect 
> of the netiquette could be better adhered to, giving us a less noisy and 
> more to the point clpmisc.
>

What was this born of? You may get four or five identical answers to a 
question because four or five people started typing them up at the same 
time, but I can't say that I see all that many multi-branch threads where 
the exact same advice is being repeated over and over in each branch.

Matt 




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

Date: Mon, 16 Jan 2006 12:34:43 +0100
From: BlinKol <.@.>
Subject: Re: Strategy about browser cache and generated pages
Message-Id: <MPG.1e35a343ca45161f98974e@news.tiscali.fr>

In article <430nl4F1jrs5vU1@individual.net>, noreply@gunnar.cc says...
> Did you notice the instructions at 
> http://www.thinkspot.net/ciwac/howtopost.html
> 

Not at all. Now, I'm aware of. Thank you, Gunnar.


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

Date: Mon, 16 Jan 2006 07:49:34 +0000
From: John Nurick <j.mapson.nurick@dial.pipex.com>
Subject: while ( )  and  until ( )
Message-Id: <kqims1l8ilcmfirsdapa8m8dg132s7j7tn@4ax.com>

I'm trying to understand why 'while ()' behaves like 'while (1)', but
'until ()' doesn't behave like 'until (1)'. So far - maybe because of
clumsiness with perldoc - I can't find it documented.  

This compiles and runs without warnings:

  > perl -e "use warnings; while () {$x++; print $x; last if $x==9; }"
  123456789

while this won't compile:

  > perl -e "use warnings; until () {$x++; print $x; last if $x==9; }"
  syntax error at -e line 1, near "() "
  syntax error at -e line 1, near "; }"
  Execution of -e aborted due to compilation errors.

Could someone please point me to an explanation?

TIA
John 



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

Date: Mon, 16 Jan 2006 10:20:54 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: while ( )  and  until ( )
Message-Id: <4316rpF1lepv5U1@news.dfncis.de>

Also sprach John Nurick:

> I'm trying to understand why 'while ()' behaves like 'while (1)', but
> 'until ()' doesn't behave like 'until (1)'. So far - maybe because of
> clumsiness with perldoc - I can't find it documented.  
>
> This compiles and runs without warnings:
>
>  > perl -e "use warnings; while () {$x++; print $x; last if $x==9; }"
>   123456789
>
> while this won't compile:
>
>  > perl -e "use warnings; until () {$x++; print $x; last if $x==9; }"
>   syntax error at -e line 1, near "() "
>   syntax error at -e line 1, near "; }"
>   Execution of -e aborted due to compilation errors.
>
> Could someone please point me to an explanation?

It's a subtle difference in Perl's grammar:

/* Loops: while, until, for, and a bare block */
loop	:	label WHILE '(' remember texpr ')' mintro mblock cont
			{ ... }
	|	label UNTIL '(' remember iexpr ')' mintro mblock cont
			{ ... } 

Note the distinction into 'texpr' and 'iexpr', the difference being that
'texpr' is an expression where empty means true so 'while ()' is the
same as 'while (1)'.

I am quite sure this has been done on purpose because 'until () { ... }'
would then be the same as 'until (1) { ... }', meaning: the body of the
loop is never executed.

Still, it would be nice to turn 'until ()' into 'until (0)' so a
bug-report (see 'perldoc perlbug') might still be in order here.

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

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


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