[25238] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7483 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 4 09:05:37 2004

Date: Sat, 4 Dec 2004 06:05:09 -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           Sat, 4 Dec 2004     Volume: 10 Number: 7483

Today's topics:
    Re: An efficient way to make a large directory tree? <joe@inwap.com>
        FAQ 1.1: What is Perl? <comdog@panix.com>
    Re: FAQ 7.26: How can I comment out a large block of pe (Erik Wasser)
    Re: how I can get more error info from virtual machine? <nobull@mail.com>
    Re: Obtaining length of binary string <nobull@mail.com>
    Re: Obtaining length of binary string <joe@inwap.com>
    Re: Obtaining length of binary string <shawn.corey@sympatico.ca>
    Re: Obtaining length of binary string <jurgenex@hotmail.com>
    Re: Obtaining length of binary string <usenet@morrow.me.uk>
    Re: parse hash by array element  seems to run slow <joe@inwap.com>
    Re: parse hash by array element  seems to run slow <bik.mido@tiscalinet.it>
    Re: parse hash by array element  seems to run slow <bik.mido@tiscalinet.it>
    Re: Perl Books <bik.mido@tiscalinet.it>
    Re: Perl classes NOT in separate files <nobull@mail.com>
    Re: Perl classes NOT in separate files <usenet@morrow.me.uk>
    Re: Perl crashes <james@emarch.net>
    Re: Perl crashes <matternc@comcast.net>
    Re: Pipe input from a Text-File <joe@inwap.com>
    Re: print FILE truncating input <joe@inwap.com>
    Re: RegEx Help Needed <spamtrap@dot-app.org>
    Re: RegEx Help Needed <joe@inwap.com>
    Re: RegEx Help Needed <tassilo.von.parseval@rwth-aachen.de>
    Re: RegEx Help Needed <flavell@ph.gla.ac.uk>
    Re: RegEx Help Needed <jurgenex@hotmail.com>
    Re: testing for existence of an inline file with Inline <usenet@morrow.me.uk>
        Trying to install module with CPAN <two@telia.com>
    Re: write error message to a log file while processing  <nobull@mail.com>
    Re: write error message to a log file while processing  <joe@inwap.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 04 Dec 2004 11:01:03 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: An efficient way to make a large directory tree?
Message-Id: <KNgsd.132594$V41.128521@attbi_s52>

Richard Gration wrote:
> reverse sort { $a=~s#/#/#g <=> $b=~s#/#/#g }

           sort { $b=~tr#/#/# <=> $a=~tr#/#/# }

   -Joe


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

Date: Sat, 4 Dec 2004 11:03:00 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 1.1: What is Perl?
Message-Id: <cos5h4$120$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

1.1: What is Perl?

    Perl is a high-level programming language with an eclectic heritage
    written by Larry Wall and a cast of thousands. It derives from the
    ubiquitous C programming language and to a lesser extent from sed, awk,
    the Unix shell, and at least a dozen other tools and languages. Perl's
    process, file, and text manipulation facilities make it particularly
    well-suited for tasks involving quick prototyping, system utilities,
    software tools, system management tasks, database access, graphical
    programming, networking, and world wide web programming. These strengths
    make it especially popular with system administrators and CGI script
    authors, but mathematicians, geneticists, journalists, and even managers
    also use Perl. Maybe you should, too.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Fri, 3 Dec 2004 17:44:13 +0100
From: fuzz@uni-paderborn.de (Erik Wasser)
Subject: Re: FAQ 7.26: How can I comment out a large block of perl code?
Message-Id: <tnh682-bln.ln1@wasser-7359.user.cis.dfn.de>

PerlFAQ Server <comdog@panix.com> wrote:

> 7.26: How can I comment out a large block of perl code?

How can I comment out a large block of perl code so that it will not 
appear in the POD doc? Sometimes I want to write some comments about the 
internal data structures that won't fit into the public man page
of this module.

% cat foo.pl
#!/usr/bin/perl -w

=head1 DESCRIPTION

bla... bla... bla...

=cut

# program is here

=for nobody

all of this stuff here will be ignored by everyone

=cut

# program continues
% pod2man <foo.pl | nroff -man
<STANDARD INPUT>(1) User Contributed Perl Documentation  <STANDARD INPUT>(1)

DESCRIPTION
       bla... bla... bla...

       all of this stuff here will be ignored by everyone

perl v5.8.4                       2004-12-03             <STANDARD INPUT>(1)
% perl -v
This is perl, v5.8.4 built for i686-linux
[...]

There there a way to drop some parts of the pod?

-- 
So long... Fuzz


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

Date: Sat, 04 Dec 2004 08:39:19 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: how I can get more error info from virtual machine?
Message-Id: <corsqk$36s$2@sun3.bham.ac.uk>



Alont wrote:

> My CGI script can running correctly on my own IIS machine, but when I
> execute it from remote virtual machine(support Perl CGI script), it
> can't work correctly(it be executed, but the result isn't correct),
> and it don't give me any error infomation.
> I've use:
> use CGI::Carp qw(fatalsToBrowser);
> 
> but it still haven't any error information, how I can get more
> infomation?

Look in the error log.  (Where this is and how you get access to it has 
nothing to do with your choice of programming language).



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

Date: Sat, 04 Dec 2004 08:36:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Obtaining length of binary string
Message-Id: <corsm2$36s$1@sun3.bham.ac.uk>



Perl User wrote:

> I read encrypted data from a server and save it in a variable. Now, I 
> need to send this back to the server along with a number that tells how 
> many bytes long the binary data is.
> 
> I've tried
> $x = read_data_from_server($args);
> $y = length $x;
> send_data_to_server($x,$y);
>
> I am not sure if the length function is the right way to count the 
> number of bytes in the string $x.

It is right since you say it's a binary string.  If it were a text 
string then length() would return the number of characters.

If you want to force length() to count bytes even in text strings:

use bytes;



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

Date: Sat, 04 Dec 2004 10:50:40 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: Obtaining length of binary string
Message-Id: <4Egsd.712026$8_6.609930@attbi_s04>

Perl User wrote:

> I am not sure if the length function is the right way to count the 
> number of bytes in the string $x.

The length() function returns the number of characters in the string.
If you're not using Unicode, the number of bytes is the same as
the number of characters.
	-Joe


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

Date: Sat, 04 Dec 2004 07:25:49 -0500
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: Obtaining length of binary string
Message-Id: <W0isd.29842$Ad3.2186144@news20.bellglobal.com>

Joe Smith wrote:
> The length() function returns the number of characters in the string.
> If you're not using Unicode, the number of bytes is the same as
> the number of characters.
>     -Joe

If you are using Perl 5.8+ and the string is is_utf8 (see perldoc 
Encode) the length returns the number of characters, not the number of 
bytes.

    --- Shawn

#!/usr/bin/perl

use strict;
use warnings;

my $s = "\x{2022}"; # Unicode for a bullet character

print length($s), "\n";

__END__


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

Date: Sat, 04 Dec 2004 12:44:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Obtaining length of binary string
Message-Id: <Diisd.1048$wa3.97@trnddc02>

Joe Smith wrote:
> Perl User wrote:
>
>> I am not sure if the length function is the right way to count the
>> number of bytes in the string $x.
>
> The length() function returns the number of characters in the string.
> If you're not using Unicode, the number of bytes is the same as
> the number of characters.

That's wrong. Any MBCS or DBCS uses more than one byte for a single 
character.

jue 




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

Date: Fri, 3 Dec 2004 21:45:29 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Obtaining length of binary string
Message-Id: <pc3782-d56.ln1@osiris.mauzo.dyndns.org>


Quoth Perl User <ravi@none.nowhere.com>:
> Hi,
>  	Here's my problem:
> 
> I read encrypted data from a server and save it in a variable. Now, I need 
> to send this back to the server along with a number that tells how many 
> bytes long the binary data is.
> 
> I've tried
> $x = read_data_from_server($args);
> $y = length $x;
> send_data_to_server($x,$y);
> 
> I am not sure if the length function is the right way to count the number 
> of bytes in the string $x. Can someone please show me how to do this?

It is, provided you've told perl that your data is binary not textual.
Make sure you use binmode on the socket filehandle.

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk                                    The Levellers, 'Believers'


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

Date: Sat, 04 Dec 2004 10:36:21 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: parse hash by array element  seems to run slow
Message-Id: <Fqgsd.189437$HA.125340@attbi_s01>

JRoot wrote:

> while(<TC>){
> 	$line = $_;
> 	++$lineCnt;
> 	if($lineCnt > 9){

      if ($. > 9) {     # Use $. when reading file line by line

> foreach $sortedNet (keys %count) {
> 	($key, $val) = ($sortedNet, $count{$sortedNet});
> 	$list{$key} = $val;
> }

     %list = %count;		# Copy entire hash.  But why?

> foreach $tpList (@tpList) {
> 	$found = "no";
> 	++$cnt;
> 	foreach $key (keys %list) {
>     		if ($key eq $tpList) {

   foreach my $tp (@tp_list) {
      if (exists $count{$tp}) {
         push @one_arr,"$tp = $count{$tp}\n" if $count{$tp} == 1;
         push @ver_arr,"$tp = $count{$tp}\n" if $count{$tp} > 1;
      } else {
         push @zer_arr,$tp;
      }
   }

That loop with 'keys %list' was killing your performance.
	-Joe


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

Date: Sat, 04 Dec 2004 12:59:42 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: parse hash by array element  seems to run slow
Message-Id: <nm63r09g167l6hou8g7slci7lctgagtc9u@4ax.com>

On 3 Dec 2004 19:23:34 -0800, awkster@yahoo.com (JRoot) wrote:

>BEGIN { push(@INC, "/app/util/perl5.6.1/lib/5.6.1") }

Uri already showed you a better way to do this. Why do you do it
anyway? It don't see what use it could serve...

>use strict;
[snip rest]

From the description of your purpose and the part of the code I
actually read (the "big" loop was overly clumsy and complex for me to
try to understand what it did) I think that this *may* be what you're
after:


  #!/app/util/perl/bin/perl -l
  
  use strict;
  use warnings;
  
  warn "$0: Working...\n\n";
  
  chomp(my @tp_list=do {
      open my $tl, 'tp_list' or 
        die "$0: Can't open `tp_list' for reading: $!\n";
      <$tl> });
  
  my @nets;
  {
      open my $tc, 'testpoint_chart' or 
        die "$0: Can't open `testpoint_chart' for reading: $!\n";
  
      while (<$tc>) {
  	next unless $. > 10;
  	my ($net_name, $side)=(split)[2,3];
  	push @nets, $net_name 
  	  if $side eq 'Top' or $side eq 'Bottom';
      }
  }
  
  my %count;
  $count{$_}++ for @nets;
  
  my @result;
  for (@tp_list) {
      my $c=$count{$_} || 0;
      push @{ $result[$c<2 ? $c : 2] }, $_
  }
  
  my @msg=qw/ZERO ONES VERIFY/;
  for my $i (1,2,0) {
      my $head="==== $msg[$i] ====";
      print for '', $head, '-' x length $head;
      print "$msg[$i]: $_" for @{ $result[$i] };
  }
  
  __END__


Hmmm, now that I think of it, since you're concerned about efficiency,
if chances are that 'testpoint_chart' be huge, then you may gain
something by skipping the first ten lines *before* the main cycle.
Also, you may avoid the C<for @nets> loop in unnecessary, just like
@nets itself. All in all this should be faster:


  my %count;
  {
      open my $tc, '<', 'testpoint_chart' or 
        die "$0: Can't open `testpoint_chart' for reading: $!\n";
  
      <$tc> for 1..10;
      while (<$tc>) {
  	my ($net_name, $side)=(split)[2,3];
  	$count{$net_name}++
  	  if $side eq 'Top' or $side eq 'Bottom'
      }
  }


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sat, 04 Dec 2004 13:04:36 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: parse hash by array element  seems to run slow
Message-Id: <7t93r0dobgptpdna9n35uqe79uo15o62ss@4ax.com>

On Sat, 04 Dec 2004 10:36:21 GMT, Joe Smith <joe@inwap.com> wrote:

>> 	++$lineCnt;
>> 	if($lineCnt > 9){
>
>      if ($. > 9) {     # Use $. when reading file line by line

s/9/10/; # or not?

>     %list = %count;		# Copy entire hash.  But why?

Indeed!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sat, 04 Dec 2004 09:24:27 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl Books
Message-Id: <ofn1r0hpso1sbob0sm8cfncqgvc0idp09n@4ax.com>

On 3 Dec 2004 12:47:29 -0800, binnyva@hotmail.com (Binny V A) wrote:

>point of view also. I have written a tutorial DON'T mean that 
>I have completed the tutorial. A lot of polishing has to be 

"I have written a tutorial" DOESN'T mean "I have completed the
tutorial".

"I have written a tutorial" ne "I have completed the tutorial".
(perlish)

The fact that I have written a tutorial DOESN'T mean that I have
completed it.


Not a native English speaker either,
Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sat, 04 Dec 2004 10:42:46 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl classes NOT in separate files
Message-Id: <cos424$6fc$1@sun3.bham.ac.uk>



Andy Glew wrote:

>>>[Me, Andy Glew --- news@patten-glew.net]
>>>print "Code befre interleaved package/classes\n";
>>>{
>>>   package A;
>>>   sub new { bless {}; }
>>>   sub bar { print "A"; }
>>>}
>>>print "Code between interleaved package/classes\n";
>>>{
>>>   package B;
>>>   sub new { bless {}; }
>>>   sub bar { print "B"; }
>>>}
> 
> 
>>>I've tried putting package more than once
>>>in a file, with no luck. E.g. how do you
>>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> 
>>What's the problem?  "No luck" is right there with "doesn't work".
> 
> 
> 
> Sorry.  The last time I tried this (multiple packages per file) was
> many years ago (circa 1996-2000) on a much earlier version of Perl.  I
> only vaguely remember that, but I think I did
> 
>       package A;
>       ...
>       package B;
>       ...
> 
> instead of 
> 
>       {
>          package A;
>          ...
>       }
>       {
>          package B;
>          ...
>       }
> 
> Whatever I did back then, I could not get it to work.
> 
> 
> I realized, as I was writing the post, that embedding the package in
> curly braces works.  It may even work without the curly braces,
> but I prefer the curly block because it allows me to embed
> the package right in the code - see below.

What you mean is you don't need to explicitly set the package back to 
main. Both will of course work.

> So, is this the best way to embed packages in a file?

I don't think either is universally better.

>  To my surprise

>                 package foo {
>                         ...
>                 }

> seems to work.

No it does not.

> Follow-on question: what about nested packages
> within the same file?  Or, nested packages period.
> 
> {
>    package A;
>    ...
>    {
>       package B;
>       ...
>    }
> }
> 
> did *NOT* do what I, well, didn't really expect
> but might have hoped for.
> 
> Even though nested like this, package B is defined
> in the global scope.  I had been hoping that it
> might be defined as A::B, i.e. nested.

No all package names in Perl are absolute

> I was hoping that I could use this so that 
> I did not have to worry as much about namespace collisions.

Yes, I've often wished there was a simple way to specify relative 
package names in Perl.



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

Date: Fri, 3 Dec 2004 21:57:03 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl classes NOT in separate files
Message-Id: <f24782-d56.ln1@osiris.mauzo.dyndns.org>


Quoth Andy Glew <andy.glew@intel.com>:
> > > [Me, Andy Glew --- news@patten-glew.net]
> > > print "Code befre interleaved package/classes\n";
> > > {
> > >    package A;
> > >    sub new { bless {}; }
> > >    sub bar { print "A"; }
> > > }
> > > print "Code between interleaved package/classes\n";
> > > {
> > >    package B;
> > >    sub new { bless {}; }
> > >    sub bar { print "B"; }
> > > }
> 
> > > I've tried putting package more than once
> > > in a file, with no luck. E.g. how do you
> > 
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> > What's the problem?  "No luck" is right there with "doesn't work".
> 
> 
> Sorry.  The last time I tried this (multiple packages per file) was
> many years ago (circa 1996-2000) on a much earlier version of Perl.  I
> only vaguely remember that, but I think I did
> 
>       package A;
>       ...
>       package B;
>       ...

This will work correctly.

<snip>
> So, is this the best way to embed packages in a file?
> 
>       {
>          package A;
>          ...
>       }
>       {
>          package B;
>          ...
>       }

It's certainly what I would do, modulo making those blocks BEGIN blocks
if necessary. (Actually, following a post of (IIRC) Anno's a while back,
I'd format it like

{{

package A;

 ...;

}}

{{

package B;

}}

just to stop the nesting getting too deep.)

> By the way, I like using the curly block because it allows me to place 
> a package in the middle of code.  To my surprise
> 
>         sub bar {
>                 my $arg = shift;
> 
>                 package foo {
>                         ...
>                 }
> 
>                 ...
>         }
> 
> seems to work.

No it doesn't.

~% perl -le'package foo { 1; }'
syntax error at -e line 1, near "package foo { "
Execution of -e aborted due to compilation errors.

> Follow-on question: what about nested packages
> within the same file?  Or, nested packages period.
> 
> {
>    package A;
>    ...
>    {
>       package B;
>       ...
>    }
> }
> 
> did *NOT* do what I, well, didn't really expect
> but might have hoped for.
> 
> Even though nested like this, package B is defined
> in the global scope.  I had been hoping that it
> might be defined as A::B, i.e. nested.

Yes. A package statement is lexically scoped, but the packages
themselves are global. Note that the package A::B is in no sense (at the
Perl level, anyway) inside package A. It is just a package that happens
to have a :: in the middle of it's name.

> I was hoping that I could use this so that 
> I did not have to worry as much about namespace collisions.
> 
> E.g. 
> { 
>     package A;
>     { 
> 	package helper; 
> 	sub hello { print "A...helper\n";}
>     }
> }
> helper::hello();

If this has done what you expect this statement would have produced an
'undefined subroutine' error. It would have needed to be inside the
block.

> { 
>     package B;
>     { 
> 	package helper; 
> 	sub hello { print "B...helper\n";}
>     }
> }
> helper::hello();
> 
> Produces 
> B...helper
> B...helper
> 
> I.e. A's helper is defined over.  That is unfortunate.

I agree it's unfortunate. It is doubly unfortunate that there appears to
be no workaround (at least, not without using XS; with XS it's trivial,
so there may even be a module on CPAN to do it).

Note also that all top-level packages beginning with a lower-case letter
are reserved for future pragmas, so you shouldn't use them.

Ben

-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]         ben@morrow.me.uk


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

Date: Sat, 04 Dec 2004 12:00:35 GMT
From: "James Tolley" <james@emarch.net>
Subject: Re: Perl crashes
Message-Id: <DFhsd.433$gF5.376@trndny01>

> #!/usr/bin/perl -w
> use strict;
>
> sub &total {
>     my $sum;
>     foreach (@_){
>         sum+=$_;
> }

This just needs a little editing:

#!/usr/bin/perl -w
use strict;

sub total {
    my $sum;
    foreach (@_){
        $sum+=$_;
    }
    $sum;
}

print total(1,2,3); # 6
__END__

hth,

James




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

Date: Sat, 04 Dec 2004 07:23:58 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Perl crashes
Message-Id: <O4udnTFgidX9MSzcRVn-gQ@comcast.com>

Steve Butler wrote:

> Hi all,
> 
> I have not posted here before. I am compelled to ask about this code
> snipet crashing perl.exe when attempting a perl -c:
> 
> #!/usr/bin/perl -w
> use strict;
> 
> sub &total {
>     my $sum;
>     foreach (@_){
>         sum+=$_;
> }
> 
> Basically I know the code is bad, but I never expected perl to crash on a
> syntax check. Should I send this bug somewhere or just not write bad code?
> 
> Thanks!
> Steve

Doesn't crash perl 5.8.4 on my Debian Linux machine (standard sarge build):

syscjm@ayato:~$ perl -c perltest.pl
Illegal declaration of anonymous subroutine at perltest.pl line 4.
syscjm@ayato:~$

Doesn't crash perl 5.8.5 on my SPARC Solaris 9 machine (sunfreeware, I
think...):

$ perl -c perltest.pl
Illegal declaration of anonymous subroutine at perltest.pl line 4.
$

Doesn't crash perl 5.6.1 on the Solaris box (shipped with Solaris):

$ /usr/perl5/5.6.1/bin/perl -c perltest.pl
syntax error at perltest.pl line 4, near "sub &total"
Can't use global @_ in "my" at perltest.pl line 6, near "(@_"
Missing right curly or square bracket at perltest.pl line 8, at end of line
Bareword "sum" not allowed while "strict subs" in use at perltest.pl line 7.
perltest.pl had compilation errors.
$

Doesn't crash perl 5.005_03 on the Solaris box (also shipped with Solaris):

$ /usr/perl5/5.00503/bin/perl -c perltest.pl
syntax error at perltest.pl line 4, near "sub &total"
Can't use global @_ in "my" at perltest.pl line 6.
$

I could look over at a couple of AIX boxes I have access to, but that's
probably enough...

Perhaps it's just a problem with your build (something around 5.6, maybe,
I think I saw somebody else reporting this bug in a 5.6.x build...)

However, for future reference, no program should ever crash; it 
should report the error (whatever it was) and handle it gracefully 
in the most appropriate manner.  A program crash is *always* a bug,
although it may not be a fixable one (for example, it is very 
difficult to keep a program from crashing if you run your computer 
out of memory to the point where the program can no longer 
successfully do a malloc(); unless the program itself is doing the
memory chomping, this is not really fixable).
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Sat, 04 Dec 2004 11:13:07 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: Pipe input from a Text-File
Message-Id: <2Zgsd.508427$D%.39042@attbi_s51>

Tore Aursand wrote:

>>12 2
>>2 4
>>5 7
>   my $sum = 0;
>   while ( <STDIN> ) {
>       chomp;
>       last unless ( defined && /\d/ );
>       $sum += $_;
>   }
>   print "$sum\n";

I interpret the problem as needing to produce three lines of output.
14
6
12

    # Command-line argument = name of input file(s), '-' for STDIN.
    while (<>) {
       my $sum = 0;
       $sum += $_ foreach split;
       print "$sum\n";
    }

	-Joe


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

Date: Sat, 04 Dec 2004 10:40:56 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: print FILE truncating input
Message-Id: <Yugsd.141909$5K2.114136@attbi_s03>

Spin wrote:

> print "Result Type: ".$result_type."\n";
> print FILE get_lab_header($loc),"\n";

Change that to

   print FILE "Result Type: $result_type\n",get_labheader($loc),"\n";

and make sure that get_labheader() uses sprintf (and not printf).
	-Joe


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

Date: Sat, 04 Dec 2004 03:40:08 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: RegEx Help Needed
Message-Id: <2I-dnbxqAZl16izcRVn-hg@adelphia.com>

DeepDiver wrote:

> 1. I'm not programming in Perl.
>
> 2. I'm writing the current routine in C#.

This is a Perl group. The C# group is down the hall to the left. Don't 
let the door hit you on the way out.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Sat, 04 Dec 2004 09:58:34 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: RegEx Help Needed
Message-Id: <eTfsd.608967$mD.417869@attbi_s02>

DeepDiver wrote:

> 1. I came here because I believe
> that Perl programmers are generally the most proficient with regular
> expressions.

Regular expressions as implemented in other languages are not the same.

Using just a regular expression won't cut it; correct parsing usually
requires program logic as well.
	-Joe


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

Date: Sat, 4 Dec 2004 11:00:53 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: RegEx Help Needed
Message-Id: <slrncr32ml.pp.tassilo.von.parseval@localhost.localdomain>

Also sprach DeepDiver:

> "David H. Adler" <dha@panix.com> wrote in message
> news:slrncr2pos.j2i.dha@panix2.panix.com...
>> On 2004-12-04, DeepDiver <no-spam@sonic.net> wrote:
>> > "Sherm Pendley" <spamtrap@dot-app.org> wrote in message
>> > news:SOydnYD65MRH0izcRVn-tg@adelphia.com...
>> >>
>> >> Have a look at HTML::Parser on CPAN.
>> >>
>> >
>> > Thanks, but I'm in need of a pure RegEx solution.
>>
>> This of course raises the question: Why?
>
>
> A few reasons:
>
> 1. I'm not programming in Perl. In fact, my experience with Perl was a long
> time ago (and not very extensive even then). I came here because I believe
> that Perl programmers are generally the most proficient with regular
> expressions.

This nonetheless makes your posting rather off-topic in this group. Perl
did not invent regular expressions. Also, Perl regular expressions are
likely to be more powerful than regular expressions found in other
languages. This means you probably couldn't use a regex solution
from this group in your program.

> 2. I'm writing the current routine in C#. But I would still prefer a "pure"
> RegEx solution so that I have something that is concise and (higher-level)
> language independent.

I have my doubts as to the conciseness of a pure regex solution.
Classical reguar expressions aren't even remotely powerful enough to
parse HTML (and there's not much to argue about: It can be proven with
the famous Pumping lemma). Perl's regular expressions might be powerful
enough as they have some non-regular extensions (they allow
back-references, they can be recursive etc.). Still, a regex solution
could hardly be robust. Let alone the fact that .NET regular expressions
lack many of the Perl features.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 4 Dec 2004 11:51:17 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: RegEx Help Needed
Message-Id: <Pine.LNX.4.61.0412041143580.3674@ppepc56.ph.gla.ac.uk>

On Sat, 4 Dec 2004, Tassilo v. Parseval wrote:

> Perl regular expressions are likely to be more powerful than regular 
> expressions found in other languages.

Would this be a moment to mention PCRE, http://www.pcre.org/  ?

"Perl Compatible Regular Expressions" library.

I often use its diagnostic command, "pcretest", to explore the 
behaviour of some complex regex that I'm working with, when fed with 
various data.  Whether the regex is meant for Perl or, indeed, when 
writing ACLs for the same author's excellent MTA, exim.

(Of course, that has nothing to do with attempting to use regexes for
parsing arbitrary HTML - which is ultimately hopeless.)


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

Date: Sat, 04 Dec 2004 12:49:36 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: RegEx Help Needed
Message-Id: <Anisd.1077$wa3.403@trnddc02>

DeepDiver wrote:
[About parsing HTML]
> "Sherm Pendley" <spamtrap@dot-app.org> wrote in message
> news:SOydnYD65MRH0izcRVn-tg@adelphia.com...
>>
>> Have a look at HTML::Parser on CPAN.
>>
>
> Thanks, but I'm in need of a pure RegEx solution.

Forget it. Nobody with a sane mind would try parsing HTML using pure REs. 
Contrary to popular believe parsing HTML is non-trivial and while it is not 
decided yet if Perl's advanced REs are powerful enough to do it, most 
certainly it would be _way_ too complex to be of any real use.
As this has been discussed many times before please see the FAQ and Google 
for further details .

jue 




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

Date: Fri, 3 Dec 2004 21:44:00 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: testing for existence of an inline file with Inline::Files
Message-Id: <0a3782-d56.ln1@osiris.mauzo.dyndns.org>


[please wrap your articles, including the attribution, at 76 characters]

Quoth swolf2@yahoo.com (Sven Wolf):
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<copo7j$6o5$2@mamenchi.zrz.TU-Berlin.DE>...
> > Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> > > Sven Wolf <swolf2@yahoo.com> wrote:
> > > > 
> > > > I'm using Inline::Files, which allows me to put data after __FOO__ in
> > > > a file and then to read it with "while (<FOO>) {...}" or @lines =
> > > ><FOO>;
> > > 
> > > > I get a read-from-unopened-filehandle error if there is no section
> > > > __MYCANDIDATE__ in the script.
> > > > 
> > > > Can someone suggest a test to apply before attempting to read?
> > 
> > More generally, fileno( HANDLE) will be defined if and only of HANDLE
> > is an open filehandle.  In particular,
> > 
> >     defined fileno( DATA)
> > 
> > will tell if there is an available __DATA__ or __END__ section.  I
> > suppose that's how $MYCANDIDATE is set internally.
> 
> Thanks.  I'm getting an exception when trying this with a virtual
> file.

Try Scalar::Util::openhandle.

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Sat, 04 Dec 2004 11:27:04 GMT
From: simon <two@telia.com>
Subject: Trying to install module with CPAN
Message-Id: <cahsd.123406$dP1.436627@newsc.telia.net>

Hi
I am trying to install MIME::Base64 and MIME::QuotedPrint using CPAN on 
Suse 9.1. Suse comes with Perl v5.8.3 already installed.

The error message I receive is as follows:

MOOSE:/usr/local/cpanSGH # perl -MCPAN -e "install 'MIME::Base64'"
CPAN: Storable loaded ok
Going to read /usr/local/cpanSGH/Metadata
   Database was generated on Sat, 04 Dec 2004 02:50:14 GMT
Running install for module MIME::Base64
Running make for G/GA/GAAS/MIME-Base64-3.05.tar.gz
CPAN: Digest::MD5 loaded ok
Checksum for 
/usr/local/cpanSGH/sources/authors/id/G/GA/GAAS/MIME-Base64-3.05.tar.gz ok
Scanning cache /usr/local/cpanSGH/build for sizes
MIME-Base64-3.05/
MIME-Base64-3.05/t/
MIME-Base64-3.05/t/warn.t
MIME-Base64-3.05/t/bad-sv.t
MIME-Base64-3.05/t/unicode.t
MIME-Base64-3.05/t/quoted-print.t
MIME-Base64-3.05/t/base64.t
MIME-Base64-3.05/README
MIME-Base64-3.05/QuotedPrint.pm
MIME-Base64-3.05/MANIFEST
MIME-Base64-3.05/decode-qp
MIME-Base64-3.05/encode-base64
MIME-Base64-3.05/encode-qp
MIME-Base64-3.05/Base64.pm
MIME-Base64-3.05/Changes
MIME-Base64-3.05/Makefile.PL
MIME-Base64-3.05/decode-base64
MIME-Base64-3.05/Base64.xs
Removing previously used /usr/local/cpanSGH/build/MIME-Base64-3.05


Here's the contents of the Config.pm file:


cpan> o conf
CPAN::Config options from /usr/lib/perl5/5.8.3/CPAN/Config.pm:
     commit             Commit changes to disk
     defaults           Reload defaults from disk
     init               Interactive setting of all options

     build_cache        10
     build_dir          /usr/local/cpanSGH/build
     cache_metadata     1
     cpan_home          /usr/local/cpanSGH
     dontload_hash
     ftp                /usr/bin/ftp
     ftp_proxy
     getcwd             cwd
     gpg                /usr/bin/gpg
     gzip               /usr/bin/gzip
     histfile           /usr/local/cpanSGH/histfile
     histsize           100
     http_proxy
     inactivity_timeout 0
     index_expire       1
     inhibit_startup_message 0
     keep_source_where  /usr/local/cpanSGH/sources
     lynx
     make
     make_arg
     make_install_arg
     makepl_arg
     ncftp
     ncftpget
     no_proxy           localhost
     pager              less
     prerequisites_policy ask
     scan_cache         atstart
     shell              /bin/bash
     tar                /bin/tar
     term_is_latin      1
     unzip              /usr/bin/unzip
     urllist
         ftp://ftp.du.se/pub/CPAN/
     wget               /usr/bin/wget
cpan>




Any help would be greatly appreciated. I just looked to see if there 
were any environment variables in 'profile'. No referens to Perl 
anywhere. Hmm, seems a bit strange. How can I check the Perl variable?

//Simon


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

Date: Sat, 04 Dec 2004 08:56:07 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: write error message to a log file while processing the ftp command
Message-Id: <cortq4$3o0$1@sun3.bham.ac.uk>



Jing wrote:

> The system admin. has a problem to configure the Makefile.pl for
> Net::FTP module. my program need to ftp a local files to a remote
> server. Since i can't use Net::FTP, i try to use ftp command instead.
> I got trouble to write error message to a log file while processing
> the ftp command.

I'm not sure what you are asking but I suspect it may be FAQ: "How can I 
open a pipe both to and from a command?".

Personally I think that FAQ answer is incomplete.

It should say first "You may be able to avoid the problem by rediecting 
one to/from a temparary file" (for details see my post about this last 
week).



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

Date: Sat, 04 Dec 2004 10:05:33 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: write error message to a log file while processing the ftp command
Message-Id: <NZfsd.141610$5K2.63970@attbi_s03>

Jing wrote:

> I got trouble to write error message to a log file
> while processing the ftp command.

So, you want to send commands to ftp's STDIN and be able to
capture the error messages it sends to STDERR, right?
Use the IPC::Open3 module for that.
	-Joe


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

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


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