[25079] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7329 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 28 03:05:49 2004

Date: Thu, 28 Oct 2004 00: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           Thu, 28 Oct 2004     Volume: 10 Number: 7329

Today's topics:
    Re: A file open and close that doesnt modify a timestam <usenet@morrow.me.uk>
        Calling 32 bit libraries on an x86_64 in 64 bit mode <alan@fnordora.org>
    Re: Calling 32 bit libraries on an x86_64 in 64 bit mod <vilain@spamcop.net>
    Re: Compress::Zlib vs. external gzip call <kalinaubears@iinet.net.au>
        FAQ 3.7: How do I cross-reference my Perl programs? <comdog@panix.com>
    Re: Fast random string generation <bik.mido@tiscalinet.it>
    Re: How do I parse this Charactor? 2byte vs 1byte <nntp@rogers.com>
    Re: How's my logic? <bik.mido@tiscalinet.it>
    Re: MAIL recommendation <bik.mido@tiscalinet.it>
    Re: Newbie question on regex. <noreply@gunnar.cc>
    Re: Newbie question on regex. <eighner@io.com>
    Re: Newbie question on regex. <odyniec-usenet@odyniec.net>
    Re: Newbie question on regex. <usenet@morrow.me.uk>
    Re: Parallel/ Multithreading /Forking? <usenet@morrow.me.uk>
        serverside perl: process (Amy)
    Re: serverside perl: process <noreply@gunnar.cc>
    Re: serverside perl: process <matthew.garrish@sympatico.ca>
        Should I use BEGIN, CHECK, or INIT? (J. Romano)
    Re: Should I use BEGIN, CHECK, or INIT? <tassilo.von.parseval@rwth-aachen.de>
    Re: What are these extra spaces in my registry? <usenet@morrow.me.uk>
    Re: What are these extra spaces in my registry? (Harry)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Oct 2004 03:23:17 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: A file open and close that doesnt modify a timestamp
Message-Id: <lp1652-g5b.ln1@osiris.mauzo.dyndns.org>


Quoth Jim Gibson <jgibson@mail.arc.nasa.gov>:
> In article <878baabf.0410271214.698835e7@posting.google.com>, gumby
> <georgeziv@hotmail.com> wrote:
> 
> > I need to be able to open a file, read a file, then close a file with
> > out perl rewriting the TimeStamp on the file.  I was able to do this
> > in C++ but not perl, and currently we are rewriting our old C code to
> > perl.
> 
> What operating system and version of Perl are you using? On my system
> (Mac OS 10.3, perl 5.8.5), opening and reading a file changes none of
> the file times atime, mtime, nor ctime.

A read of more than zero bytes ought to update the atime. Many systems
do not perform this update as a optimisation (under Linux, for example,
it is a mount-time option on most filesystems).

If the OP wants a last-mod-time he (?) wants to use the mtime. On
non-Unix OSen the meanings of the various times are different, and they
may be updated under different circumstances; the perlfoo (e.g.
perlwin32) page for your OS should say what they mean.

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: Wed, 27 Oct 2004 20:44:53 -0700
From: Alan <alan@fnordora.org>
Subject: Calling 32 bit libraries on an x86_64 in 64 bit mode
Message-Id: <pan.2004.10.28.03.44.48.936286@fnordora.org>


I have a set of proprietary libraries that are i386 compiled code under
Linux.  They are called from a perl module.

This worked fine until we moved to a dual AMD64 system.  Now it is choking
in DynamicLoader.pm.

Is there a clean way to call a 32 bit shared library from a 64 bit version
of Perl?  Is there some sort of option to get XS to emulate a 32 bit mode
or is it just bjorken?



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

Date: Wed, 27 Oct 2004 23:15:25 -0700
From: "Michael Vilain <vilain@spamcop.net>"
Subject: Re: Calling 32 bit libraries on an x86_64 in 64 bit mode
Message-Id: <vilain-CD484B.23152527102004@news.giganews.com>

In article <pan.2004.10.28.03.44.48.936286@fnordora.org>,
 Alan <alan@fnordora.org> wrote:

> I have a set of proprietary libraries that are i386 compiled code under
> Linux.  They are called from a perl module.
> 
> This worked fine until we moved to a dual AMD64 system.  Now it is choking
> in DynamicLoader.pm.
> 
> Is there a clean way to call a 32 bit shared library from a 64 bit version
> of Perl?  Is there some sort of option to get XS to emulate a 32 bit mode
> or is it just bjorken?

No, there isn't.  Leastways, this is a restriction on Solaris.  You have 
to compile the libraries in 64-bit mode or build perl as a 32-bit 
application to get compatibility.

Mixing the modes probably won't work.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...





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

Date: Thu, 28 Oct 2004 12:36:26 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Compress::Zlib vs. external gzip call
Message-Id: <41805c6f$0$13768$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

odigity wrote:

> sub ext_gzip
> {
>   my $fh = IO::File->new( "gzip -cd $file |" ) or die( "could not gzip
> -cd '$file' for reading: $!" );
>   my $lines = 0;
>   while ( defined(my $line = $fh->getline()) ) {
>     $lines++;
>   }
>   $fh->close();
>   print "ext_gzip: $lines lines\n";
> }
> 
> 
> sub compress_zlib
> {
>   my $gz = gzopen( $file, 'rb' ) or die( "could not gzopen '$file' for
> reading: $!" );
>   my $line;
>   my $lines = 0;
>   while ( ( my $bytes = $gz->gzreadline( $line ) ) > 0 ) {

The next line is a waste of time. If $bytes is -1 then the code inside 
the loop will not be executed. Also this is one test that the other 
subroutine doesn't have to do. I don't think, however, that it will 
account for the entire time difference .... remove it and see.

I also wonder whether there is more overhead in determining whether 
$bytes>0 than there is determining whether $line is defined.

And I don't know how 'getline()' and 'gzreadline()' compare - both in 
terms of what they actually do, and in terms of how fast they do it.

>     die( $gz->gzerror ) if ( $bytes == -1 );
>     $lines++;
>   }
>   $gz->gzclose();
>   print "compress_zlib: $lines lines\n";
> }
> 

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Thu, 28 Oct 2004 04:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.7: How do I cross-reference my Perl programs?
Message-Id: <clpr1l$2nn$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.

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

3.7: How do I cross-reference my Perl programs?

    The B::Xref module can be used to generate cross-reference reports for
    Perl programs.

        perl -MO=Xref[,OPTIONS] scriptname.plx



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

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: Thu, 28 Oct 2004 08:45:46 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Fast random string generation
Message-Id: <st70o0p4lvf7ptuet7oukm36njrb6vl4a2@4ax.com>

On 24 Oct 2004 08:00:46 -0700, merlyn@stonehenge.com (Randal L.
Schwartz) wrote:

>Peter>     my $str = "\000" x 20_000;
>Peter>     my @chr = map { chr $_ } 0 .. 255;
>Peter>     substr $str, $_, 1, $chr[rand 256] for 1 .. 20_000;

>maybe:
>
>        pack "C*", map rand 256 for 1 .. 20_000;

If you read my other posts in this thread (those with the benchmarks)
you'll notice that this solution doesn't perform well if compared to a
naive loop of the kind of that used by the OP. But a pack() solution
wins if we pack at four[*] bytes at a time (and in the meanwhile we
discovered that this depends on the RANDBITS compile option).

However it also resulted that map()-versions of the naive loop
solutions were, reasonably, slower than these. So I wondered wether a
solution like 'Loop3' below could perform even better. For ease of
reading I'll repeat my complete test here:


  #!/usr/bin/perl
  
  use strict;
  use warnings;
  
  use Benchmark qw/:all/;
  
  # For 'Dev2'
  open my $fh, '<', '/dev/urandom' or
    die "Can't access `/dev/urandom': $!\n";
  
  cmpthese 500, {
      Loop1 => \&Loop1,
      Loop2 => \&Loop2,
      # Map1 => \&Map1,
      # Map2 => \&Map2,
      # Subst => \&Subst,
      Vec => \&Vec,
      Pack1 => \&Pack1,
      Pack2 => \&Pack2,
      # S => \&S,
      Dev1 => \&Dev1,
      Dev2 => \&Dev2,
      Loop3 => \&Loop3 };
  
  
  sub Loop1 {
      my $str = '';
      $str .= chr int rand 256 for 1..20_000;
      $str;
  }
  
  sub Loop2 {
      my @chrs = map chr, 0..255;
      my $str = '';
      $str .= $chrs[rand 256] for 1..20_000;
      $str;
  }
  
  sub Map1 {
      join '', map { chr int rand 256 } 1..20_000;
  }
  
  sub Map2 {
      my @chrs = map chr, 0..255;
      join '', map $chrs[rand 256], 1..20_000;
  }
  
  sub Subst {
      my $str = "\000" x 20_000;
      my @chrs = map chr, 0..255;
      substr $str, $_, 1, $chrs[rand 256] for 0..19_999;
      $str;
  }
  
  sub Vec {
      my $str = ' ' x 20000;
      vec($str, $_, 8) = rand 256 for 0..19_999;
      $str;
  }
  
  sub Pack1 {
      pack 'C*', map int rand 256, 1..20_000;
  }
  
  sub Pack2 {
      # Is this OK, BTW?
      pack 'L*', map rand ~0, 1..5_000;
  }
  
  sub S {
      local $_ = ' ' x 20_000;
      s/ /chr int rand 256/ge;
      $_;
  }
  
  sub Dev1 {
      open my $fh, '<', '/dev/urandom' or
        die "Can't access `/dev/urandom': $!\n";
      local $/ = \20_000;
      scalar <$fh>;
  }
  
  sub Dev2 {
      local $/ = \20_000;
      scalar <$fh>;
  }
  
  sub Loop3 {
      my $str = '';
      $str .= pack 'L*', rand 2**32 for 1..5_000;
      $str;
  }
  
  __END__


Results:

          Rate   Vec Pack1 Loop1 Loop2 Loop3  Dev1  Dev2 Pack2
  Vec   74.7/s    --   -5%  -12%  -16%  -70%  -71%  -72%  -77%
  Pack1 78.7/s    5%    --   -7%  -11%  -68%  -70%  -71%  -75%
  Loop1 84.7/s   13%    8%    --   -4%  -65%  -67%  -68%  -74%
  Loop2 88.5/s   18%   12%    4%    --  -64%  -66%  -67%  -72%
  Loop3  245/s  228%  211%  189%  177%    --   -6%   -8%  -24%
  Dev1   260/s  248%  231%  207%  194%    6%    --   -3%  -19%
  Dev2   267/s  258%  240%  216%  202%    9%    3%    --  -17%
  Pack2  321/s  329%  307%  278%  262%   31%   23%   20%    --


So: no, it wasn't a good idea...


[*] Eight on 64-bit CPUs?


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: Wed, 27 Oct 2004 23:38:29 -0400
From: "nntp" <nntp@rogers.com>
Subject: Re: How do I parse this Charactor? 2byte vs 1byte
Message-Id: <htmdnbEx1qhJ9B3cRVn-rA@rogers.com>


"Karel Kubat" <karel@e-tunity.com> ????
news:417fdccf$0$142$e4fe514c@dreader19.news.xs4all.nl...
> Hi,
>
> > I found the bug, and could not fix it. It is related to OS related
bytes.
> >
> > Under dos, it looks like this
> > valign="top">¨¢</td>
> > In Unix, it looks like this
> > valign="top">| </td>
> > In my Textpad (in Chinese OS), it looks like this
> > valign="top">?/td>
> >
> > I asked experts about this. They told me that the charactor is missed
> > combined with the next charactor to become one charactor.
> > How do I make sure my perl can parse this correctly? Can perl tell 2
byte
> > word and 1 byte word?
>
> This is not a Perl issue per se, and neither an OS-related issue. You're
> dealing with multibyte encodings of characters.
>
> You need to look at the encoding of the original document first. Off the
top
> of my head, in an XML document, it would say something like <?xml
> version="1.0" encoding="....."?>. When the encoding specifier is missing,
> then UTF-8 is the default I think.
>
> Your problem however probably refers to an HTML page, not to an XML
> document. In that case the encoding might be in one of the HTTP headers
> that are sent when a server outputs a page -- that will depend on the
> server configuration.
>
> And regarding encodings or character sets:  _yes_, Perl can be told to
> regard 2-byte sequences as 1 character (or even more than 2 bytes,
> actually). Try "perldoc -f multibyte" and then play around with the
Unicode
> modules.
>
> What _is_ the problem you're describing anyway? It might be helpful to
> know..
>
> Cheers,

The first several lines:
<HTML XMLNS:IE>
<head>
<mainD5>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
URL of the page is www.ebay.com
I see charset=ISO-8859-1. Isn't that regular 1 byte encoding?

Can I do
s/\W//gs  or s/[^\w]//gs
to remove everything that is not an English charactor or number or < _ . -!
/\?

I read perldoc -q multebytes.




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

Date: Thu, 28 Oct 2004 08:45:48 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How's my logic?
Message-Id: <4g40o0968ndpqffu0jq24gdr1suup7qns9@4ax.com>

On Wed, 27 Oct 2004 15:55:00 -0400, wana <ioneabu@yahoo.com> wrote:

>work.  I am always shaky on rules of precedence and usually use lots of
>()'s to make sure I get it right, but I am trying to wean myself off of
>them.

Well, you can always check for yourself with

  perl -MO=Deparse,-p <your_script_here>

>if ($user and $pass)
>{
>        $ftp->login($user, $pass)
>        and print "successfully logged on to $server as $user\n"
>        or print "problem logging on to $server as $user\n";
>}

I don't know what the return value of $ftp->login() is, but as far as
only C<and> and C<or> are concerned, I'd say that it is ok. BTW: you
know that the info you need is at the very top of 'perldoc perlop',
don't you?


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: Thu, 28 Oct 2004 08:45:48 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: MAIL recommendation
Message-Id: <vu70o05l9b35krvu0jurcpr1s0cth65hoh@4ax.com>

On Wed, 27 Oct 2004 13:17:56 -0400, "daniel kaplan"
<nospam@nospam.com> wrote:

>> Then you *are* looking for people agreeing with you... on what a
>> newsgroup is really for.
>
>well to quote you previously, about the OP not getting bashed on "what's a
>good book?"...to me is the same as "any pref's to an IDE?"

So... dingalingaling!! Doesn't this suggest that there may be
something wrong in *your* attitude?

However the two subjects are indeed similar, but not just the same,
and the differences *can* justify the different treatments.


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: Thu, 28 Oct 2004 02:54:11 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie question on regex.
Message-Id: <2uava5F27h9f3U1@uni-berlin.de>

SomeDeveloper wrote:
> I'm unable to understand the following statement from
> http://search.cpan.org/dist/perl/pod/perlretut.pod.
> 
>     "Because, for example, \d and \w are sets of characters, it is
> incorrect to think of [^\d\w] as [\D\W];"
> 
> Of course, being subsumed by \w, \d is clearly redundant. But
> redundancy aside, aren't [^\d\w] and [\D\W] still mathematically
> equivalent?

No. Since \d is a subset of \w, [^\d\w] is the same as [^\w] which in 
turn is the same as \W.

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


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

Date: Wed, 27 Oct 2004 20:13:11 -0500
From: Lars Eighner <eighner@io.com>
Subject: Re: Newbie question on regex.
Message-Id: <slrnco0hma.1854.eighner@goodwill.io.com>

In our last episode, 
<f530002d.0410271631.3337c7b@posting.google.com>, 
the lovely and talented SomeDeveloper 
broadcast on comp.lang.perl.misc:

> I'm unable to understand the following statement from
> http://search.cpan.org/dist/perl/pod/perlretut.pod.

>     "Because, for example, \d and \w are sets of characters, it is
> incorrect to think of [^\d\w] as [\D\W];"

> Of course, being subsumed by \w, \d is clearly redundant. But
> redundancy aside, aren't [^\d\w] and [\D\W] still mathematically
> equivalent?

No, they are not mathematically equivalent (much less "still").

[\D\W] is all the characters which are not digits plus all the
characters which are not alphanumeric. Thus [\D\W] are all the
characters except digits (i.e. [^\d] which is the same as [\D]).

[^\d\w], as you seem to understand, amounts to [^\w] which is
the same as [\W].

> Tia (for responding to my possible ignorance),
> Some Developer.
-- 
Lars Eighner -finger for geek code-  eighner@io.com http://www.io.com/~eighner/
      If it wasn't for muscle spasms, I wouldn't get any exercise at all.


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

Date: Thu, 28 Oct 2004 03:58:22 +0200
From: Michal Wojciechowski <odyniec-usenet@odyniec.net>
Subject: Re: Newbie question on regex.
Message-Id: <87sm7zk3i9.fsf@orion.odyniec.net>

Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

[...]

>> Of course, being subsumed by \w, \d is clearly redundant. But
>> redundancy aside, aren't [^\d\w] and [\D\W] still mathematically
>> equivalent?
>
> No. Since \d is a subset of \w, [^\d\w] is the same as [^\w] which in
> turn is the same as \W.

And for a mathematical explanation, De Morgan's laws apply. For two
sets A and B:

  (A u B)' = A' n B'   (*)

Assuming \d is A and \w is B:

  [\d\w]  is equivalent to  A u B
  [^\d\w] is equivalent to  (A u B)'
  [\D\W]  is equivalent to  A' u B'

Therefore, [^\d\w] = [\D\W] implies (A u B)' = A' u B', and that is
contrary to (*).

-- 
Michal Wojciechowski : for(<>){/\s/,$l{$m=$`}=$'}$_ : 10 PRINT "Yet another"
odyniec()odyniec;net : =$l{$c},/O\s/?$c=$'-1:y/"//d : 20 PRINT "Perl hacker"
 http://odyniec.net  : ,/T\s/?print$':0while$c++<$m : 30 GOTO 10


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

Date: Thu, 28 Oct 2004 03:28:39 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Newbie question on regex.
Message-Id: <n32652-g5b.ln1@osiris.mauzo.dyndns.org>


Quoth somedeveloper@hotmail.com (SomeDeveloper):
> I'm unable to understand the following statement from
> http://search.cpan.org/dist/perl/pod/perlretut.pod.
> 
>     "Because, for example, \d and \w are sets of characters, it is
> incorrect to think of [^\d\w] as [\D\W];"
> 
> Of course, being subsumed by \w, \d is clearly redundant. But
> redundancy aside, aren't [^\d\w] and [\D\W] still mathematically
> equivalent?

You are being confused by the fact that \d is a subset of \w. In general
(say, \w and \s) [\S\W] means 'not a space OR not a wordchar' (and will
match everything) whereas [^\s\d] means 'not a space AND not a
wordchar'. As you have (half-)realised, in the case where \d is a
subset of \w these two are equivalent (and also equivalent to simply
'not a wordchar').

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Thu, 28 Oct 2004 03:01:59 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Parallel/ Multithreading /Forking?
Message-Id: <nh0652-g5b.ln1@osiris.mauzo.dyndns.org>


Quoth ctcgag@hotmail.com:
> 
> In very, very brief and lying more than a little: in Perl forking is
> usually for unix/linux and threading is usually for Windows.  For more
> honest and accurate descriptions, see "perldoc perlfork" and "perldoc
> perlthrtut"

I know you know this, but probably the OP doesn't: atm perl's threading
implementation is not worth using on Unix if you can use fork instead,
and perl will use threads to emulate fork on Win32 (though IME perl5.8
and WinNT are required for it to work well). So the best solution
usually is to just pretend you're on Unix and use fork, and that will do
whatever is possible on your platform. If you're on win9x, I wouldn't
hold out much hope for any performance gain by multitasking, as the
win9x scheduler is *awful*.

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: 27 Oct 2004 19:49:35 -0700
From: cs221239@yahoo.ca (Amy)
Subject: serverside perl: process
Message-Id: <53a1c7f5.0410271849.222b6d85@posting.google.com>

I am maintaining a website where the index file has extension .pl. The
page is divided into templetes, in the header (very first) templete,
there is:
%process organization%, where organization is another templete. There
are several organization templetes followed a unique number.

Please help to know what is the code inbetween %, and how do I know
which templete it is applying.

Many thanks


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

Date: Thu, 28 Oct 2004 04:41:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: serverside perl: process
Message-Id: <2ub5lqF276fj4U1@uni-berlin.de>

Amy wrote:
> I am maintaining a website where the index file has extension .pl.
> The page is divided into templetes, in the header (very first)
> templete, there is:
> %process organization%, where organization is another templete. There
> are several organization templetes followed a unique number.
> 
> Please help to know what is the code inbetween %, and how do I know
> which templete it is applying.

If I understand it correctly, %process organization% is a template
variable. I suppose you'd better include a Perl program in index.pl that
reads all the template files that are needed to compose the page,
replaces the template variables in the first template with the content
of respective sub-template, and prints the resulting content to STDOUT.

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


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

Date: Wed, 27 Oct 2004 23:13:16 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: serverside perl: process
Message-Id: <etZfd.15924$Qs6.1352908@news20.bellglobal.com>


"Amy" <cs221239@yahoo.ca> wrote in message 
news:53a1c7f5.0410271849.222b6d85@posting.google.com...
>I am maintaining a website where the index file has extension .pl. The
> page is divided into templetes, in the header (very first) templete,
> there is:
> %process organization%, where organization is another templete. There
> are several organization templetes followed a unique number.
>
> Please help to know what is the code inbetween %, and how do I know
> which templete it is applying.
>

I believe you mean template, not "templete". At any rate, from your 
description it sounds like the author of the script has either implemented 
their own templating system or is using one of the modules available for 
this task (impossible to say for sure which without seeing what modules are 
being used).

The "%text%" markers that you see in the template indicate where variables 
(normally containing html code) will be interpolated when the page is 
created by the script. What those variables are and how they're created is 
obviously unanswerable without seeing the code. Please do not post the 
entire script here in the hopes that someone will explain it all to you, 
though. I would suggest instead that you contact the author of the script.

Matt 




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

Date: 27 Oct 2004 19:32:51 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Should I use BEGIN, CHECK, or INIT?
Message-Id: <b893f5d4.0410271832.1a3667bf@posting.google.com>

Greetings,

   I have a couple of questions and I would like to know the opinions
of the Perl community.

   I while ago, I wrote a Perl module which is now practically
finished.  Its exact contents aren't important for my questions,
except for the fact that it is a package and its functions are called
like:

   use MyPackage;
   MyPackage::init();
   MyPackage::f1();
   MyPackage::f2($var1, $var2);

   The first function that must be called is an initialization
function (MyPackage::init()).  It must be called before any other
function in the package and should only be called once.  This fact is
well-documented in the perldoc documentation, so any Perl programmer
who bothers to check this module's documentation should be aware of
it.

   However, recently I've been thinking:  If the init() function has
to be called before any other function and should only be called once,
why not put the initialization call in a BEGIN block inside the module
itself?  That way, the programmer who uses my module doesn't even have
to call the init() function; it will be done automatically at the "use
MyPackage;" statement.

   My first question is:  Is putting the initialization function
inside a BEGIN (or CHECK or INIT) block a good idea, or is there some
pontential problem that I'm not aware of?  If the initialization
function fails, I want it to stop the program from running at all.  Of
course, if I do put the init() function in a BEGIN block, I'll remove
all mention of it from the perldoc so the programmer won't be tempted
to use it.

   And my second question:  If it is a good idea to automatically call
the init() function for the programmer, should I:

   a) put the init() statement in a BEGIN block
   b) put the init() statement in a CHECK block
   c) put the init() statement in an INIT block
   d) put the init() statement as the last statement executed
      in the module
     or
   e) it's not a good idea, so just let the programmer who uses
      my module call it in his/her own code

   The only difference I see between BEGIN, CHECK, and INIT (besides
the facts that BEGIN statments happen before CHECK statements which
happen before INIT statements and that CHECK statements happen in
"First In, Last Out" order) is that if I put the init() function in a
BEGIN or CHECK block and the init() function fails, then it is
discovered at compile time.  In other words, if the init() function
fails, then the statement:

      perl -c myscript.pl

will fail as well, as long as the init() function call is placed
inside a BEGIN block or a CHECK block.

   This sounds appealing in that "use MyPackage;" will fail if the
init() function fails, bringing it right away to the attention of the
programmer.  However, it's possible that I might not see an obvious
problem with this approach, and so I would like any advice or comments
from anyone who might have had experience with something similar.

   To sum up my questions:  Should I put the init() call in a BEGIN,
CHECK, or INIT block, or should I just let the programmer who uses my
module do it automatically (and document it thoroughly in the
perldoc)?

   Thanks in advance for any advice.

   -- Jean-Luc


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

Date: Thu, 28 Oct 2004 06:53:30 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Should I use BEGIN, CHECK, or INIT?
Message-Id: <slrnco0uqa.qv.tassilo.von.parseval@localhost.localdomain>

Also sprach J. Romano:

>    I while ago, I wrote a Perl module which is now practically
> finished.  Its exact contents aren't important for my questions,
> except for the fact that it is a package and its functions are called
> like:

[...]

>    The first function that must be called is an initialization
> function (MyPackage::init()).  It must be called before any other
> function in the package and should only be called once.  This fact is
> well-documented in the perldoc documentation, so any Perl programmer
> who bothers to check this module's documentation should be aware of
> it.
>
>    However, recently I've been thinking:  If the init() function has
> to be called before any other function and should only be called once,
> why not put the initialization call in a BEGIN block inside the module
> itself?  That way, the programmer who uses my module doesn't even have
> to call the init() function; it will be done automatically at the "use
> MyPackage;" statement.
>
>    My first question is:  Is putting the initialization function
> inside a BEGIN (or CHECK or INIT) block a good idea, or is there some
> pontential problem that I'm not aware of?  If the initialization
> function fails, I want it to stop the program from running at all.  Of
> course, if I do put the init() function in a BEGIN block, I'll remove
> all mention of it from the perldoc so the programmer won't be tempted
> to use it.

That appears to be good idea. 

>    And my second question:  If it is a good idea to automatically call
> the init() function for the programmer, should I:
>
>    a) put the init() statement in a BEGIN block
>    b) put the init() statement in a CHECK block
>    c) put the init() statement in an INIT block
>    d) put the init() statement as the last statement executed
>       in the module

There's really not much difference between any of those alternatives.
Putting it in a BEGIN block means that it is executed very early, even
before the rest of the module is compiled. Since the module cannot be
used without successfully calling YourModule::init() anyway, there is no
need to finish compilation of it so it doesn't harm to die very early.

>      or
>    e) it's not a good idea, so just let the programmer who uses
>       my module call it in his/her own code

You should at least give him the opportunity to call it manually even
when it usually must not be done. I had a problem lately with one of my
modules where I called an init function in a BOOT-section of the XS
portion [which is roughly equivalent to d) in the above list]. I
received reports that the module didn't work in processes that had been
forked off. And indeed, it turned out that the underlying C-library
required this initialization to happen in each process.

So call init() in a BEGIN block but also document that it must be called
manually when using the module's functionality in child processes.

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: Thu, 28 Oct 2004 03:10:50 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: What are these extra spaces in my registry?
Message-Id: <a21652-g5b.ln1@osiris.mauzo.dyndns.org>


Quoth joez3@yahoo.com (joe):
> Hi all,
> I am writting a perl script to check my windows 2000 registry to make
> sure some keys were added after I installed some software. In my
> script I use:
> system "regedit \e ....
> To dump the registry to a file,

There are at least two registry modules, which you may find easier to
use.

> I then open this file and do following
> to see if
> my key is in the file:
>        while (<fhTestFile>) {

Use lexical FHs instead. See 'Indirect Filehandles' in perlopentut.

> 		if (index ($_, $testValue) > -1) {

I would use a regex for this (I'd bet it's as fast, though I haven't
tested it and it almost certainly doesn't matter anyway; it's certainly
clearer to someone who knows Perl)

if (/\Q$testvalue/) {

> 			close (fhTestFile);

If you use lexical FHs they close themselves.

> 			return ("TRUE");

This is in general a bad idea: it's better to use 1 for true and '' or
undef for false (which is what Perl itself uses).

> 		}
> 	}
> 
> The problem I have is that the registry file looks like there are
> space between
> each char in it. So I maybe looking for:
> LOCAL_MACHINE_SOFTWARE
> The file contains:
> L O C C L _ M A C H I N E _ S O F T W A R E
> So my match does not work, also I don't thing the blank spaces are
> just extra spaces. Because I added spaces to $testValue and it still
> didn't match. Does anyone have any idea what this extra char is? And
> how I can get ride of it?

The file is in UTF16, M$'s preferred format for text nowadays. Under
perl5.8, you can use

open my $TESTFILE, '<:encoding(utf16)', $filename or die ...;

to have it decoded for you; under earlier Perl versions you can use
Unicode::String or you may be able to get away with knowing that the
'spaces' are in fact null bytes "\000".

> I already tried addind chomp $_ before the if and that didn't help.

Im am slightly puzzled as to why you thought it might... does perldoc -f
chomp suggest *anywhere* that it touches the middle of a string?

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: Thu, 28 Oct 2004 03:40:51 GMT
From: harryooopotter@hotmail.co_ (Harry)
Subject: Re: What are these extra spaces in my registry?
Message-Id: <7TZfd.12082$VA5.9825@clgrps13>

joe wrote...

>The problem I have is that the registry file looks like there are
>space between
>each char in it. So I maybe looking for:
>LOCAL_MACHINE_SOFTWARE
>The file contains:
>L O C C L _ M A C H I N E _ S O F T W A R E

The "space" characters are \000, as seen by hex dump.

$ cat xx.reg
ÿ_H K E Y _ L O C A L _ M A C H I N E

$ od -bc < xx.reg
0000000 377 376 110 000 113 000 105 000 131 000 137 000 114 000 117 000
        377 376   H  \0   K  \0   E  \0   Y  \0   _  \0   L  \0   O  \0
0000020 103 000 101 000 114 000 137 000 115 000 101 000 103 000 110 000
          C  \0   A  \0   L  \0   _  \0   M  \0   A  \0   C  \0   H  \0
0000040 111 000 116 000 105 000 015 000 012 000 015 000 012 000
          I  \0   N  \0   E  \0  \r  \0  \n  \0  \r  \0  \n  \0

You can get rid of those \0 characters by tr.

$ tr -d '\0' < xx.reg
ÿ_HKEY_LOCAL_MACHINE





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

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


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