[25084] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7334 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 28 18:10:43 2004

Date: Thu, 28 Oct 2004 15:10:14 -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: 7334

Today's topics:
    Re: How to handle large variable <uguttman@athenahealth.com>
    Re: How to handle large variable ctcgag@hotmail.com
    Re: How to handle large variable ctcgag@hotmail.com
    Re: How to handle large variable <uguttman@athenahealth.com>
    Re: How to handle large variable <usenet@morrow.me.uk>
    Re: How's my logic? <bik.mido@tiscalinet.it>
    Re: How's my logic? <usenet@morrow.me.uk>
    Re: interpolation question: <c186282@yahoo.com>
    Re: Is this really legal? <bradd+news@szonye.com>
    Re: Is this really legal? <tadmc@augustmail.com>
    Re: Is this really legal? <bradd+news@szonye.com>
        Little question on regex. (NeoAsimov)
    Re: Little question on regex. <mritty@gmail.com>
        mail forwarding mygooglegroupsaccount@yahoo.com
    Re: mail forwarding <abigail@abigail.nl>
        modifying hash key (dispatch table) <jeff@spamalanadingong.com>
    Re: modifying hash key (dispatch table) <mritty@gmail.com>
    Re: modifying hash key (dispatch table) <tadmc@augustmail.com>
    Re: open-perl-ide qustion (Graham)
    Re: Parallel/ Multithreading /Forking? ctcgag@hotmail.com
        print FILE function() <cNaOlSePbA@MvPeLtEsAtSaEr.com>
    Re: removin \n from only part of a string <usenet@morrow.me.uk>
    Re: Should I use BEGIN, CHECK, or INIT? <abigail@abigail.nl>
    Re: Should I use BEGIN, CHECK, or INIT? <usenet@morrow.me.uk>
    Re: Should I use BEGIN, CHECK, or INIT? (Anno Siegel)
        Syslog replay script for centralized syslog host (leroy isaac)
        what is %process XX% (Amy)
    Re: what is %process XX% <tony_curtis32@yahoo.com>
    Re: what is %process XX% <noreply@gunnar.cc>
    Re: what is %process XX% <ebohlman@omsdev.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Oct 2004 14:06:56 -0400
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: How to handle large variable
Message-Id: <m33bzyyawv.fsf@linux.local>

>>>>> "L" == Laura  <lwt0301@bellsouth.net> writes:


  L> What is so great about this File::Slurp module anyway?  Does it
  L> deal with files on a byte level using buffers appropriately?  How
  L> is it that the built in way of doing it is less efficient?  If
  L> File::Slurp is so great, why is it not one of the modules included
  L> with Perl?

why don't you look at the module and see for yourself? why don't you
read the article that comes with it and was published on perl.com? 

  L> The problem with reading line by line is that you have to read
  L> ahead through the file to see where the lines start and end if you
  L> want random access or you are stuck going sequentially.  I propose
  L> that a user should be able to page through a file with random
  L> access ability, loading a specified sized chunk at a time.  You
  L> could also have the chunk auto-shrink or expand to the nearest
  L> line(s).  Or, you could create an index of lines saved to the same
  L> or a separate file so future accesses of lines will not take so
  L> long.

you are so clueless as to be laughable. file access is an OS issue and
not a programming language one. and some OS's support random access
lines (VMS for one) but most don't.

you are batting worse than the cardinals did in the series. perhaps you
should go to the T-ball level programming league.

uri


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

Date: 28 Oct 2004 18:57:06 GMT
From: ctcgag@hotmail.com
Subject: Re: How to handle large variable
Message-Id: <20041028145706.867$5O@newsreader.com>

Laura <lwt0301@bellsouth.net> wrote:
> A. Sinan Unur wrote:
>
> > "Shashidhar Vajramatti" <shashidhar.hv@in.bosch.com> wrote in
> > news:clqv7t$imb$1@ns2.fe.internet.bosch.com:
> >
> >> Following is the code which is used to handle the file contents
> >> through a single variable using regular expressions.
> >>
> >> #$file = join '',<IN>;
> >>
> >> @file = <IN>;
> >
> > I am surprised why no one has pointed out that this a bad, bad way to
> > slurp a file. File::Slurp is an excellent module:
>
> What is so great about this File::Slurp module anyway?

In my hands, not much.  I found it marginally slower than the old
fashioned way.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 28 Oct 2004 18:58:30 GMT
From: ctcgag@hotmail.com
Subject: Re: How to handle large variable
Message-Id: <20041028145830.500$VM@newsreader.com>

"Shashidhar Vajramatti" <shashidhar.hv@in.bosch.com> wrote:
> Hello,
>         As listed below in the snippet of code, I am trying to handle a
> file's contents by copying in to a single variable. It works fine for the
> files of lesser size( few MegaBytes). But when the size of the file is
> more than 16MB, it gives me an error message saying "System out of
> memory".

Well, how much memory does your system have?  What else is running on it?

>     But perl doesnot have any limits to the size of the variable. Then,
> what can be the reason for this problem?

Most likely, you have run out of memory.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 28 Oct 2004 15:01:13 -0400
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: How to handle large variable
Message-Id: <m3vfcuwtty.fsf@linux.local>

>>>>> "c" == ctcgag  <ctcgag@hotmail.com> writes:

  >> What is so great about this File::Slurp module anyway?

  c> In my hands, not much.  I found it marginally slower than the old
  c> fashioned way.

care to show some benchmarks? have you looked at the benchmark script
that comes in the tarball? and was that for line/record mode or scalar
mode? return by ref or by value?

just saying it is slower is like newbies saying it doesn't work :)

uri


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

Date: Thu, 28 Oct 2004 16:03:46 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How to handle large variable
Message-Id: <ibe752-0tf.ln1@osiris.mauzo.dyndns.org>


Quoth "Shashidhar Vajramatti" <shashidhar.hv@in.bosch.com>:
> Hello,
>         As listed below in the snippet of code, I am trying to handle a
> file's contents by copying in to a single variable. It works fine for the
> files of lesser size( few MegaBytes). But when the size of the file is more
> than 16MB, it gives me an error message saying "System out of memory".
> 
>     But perl doesnot have any limits to the size of the variable. Then, what
> can be the reason for this problem?

Err... that the system is out of memory? You probably want to work a
line at a time.

> Following is the code which is used to handle the file contents through a
> single variable using regular expressions.
> 
> #$file = join '',<IN>;

The usual idiom for this is

$file = do {local $/; <IN>};

; a better idiom is

use File::Slurp;

$file = read_file $filename;

> @file = <IN>;

Well, which? If you want the array, then you can use Tie::File instead.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Thu, 28 Oct 2004 21:07:09 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How's my logic?
Message-Id: <1s51o01utmv3tafho3rclffvvdtp51pvbv@4ax.com>

On Thu, 28 Oct 2004 08:45:48 +0200, Michele Dondi
<bik.mido@tiscalinet.it> wrote:

>>        $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

Also, you probably want the second print() to be a die() or a warn().


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 15:51:13 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How's my logic?
Message-Id: <1kd752-0tf.ln1@osiris.mauzo.dyndns.org>


Quoth ioneabu@yahoo.com:
> Here is a piece of code from a simple program I wrote to do some FTPing.  I
> was wondering if the form of my statement is acceptable with respect to the
> use of 'and' and 'or'.  I did it, hoping for the best, and it seems to
> 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.
> 
> 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 must say, I have always wanted a low-precedence version of ?:, perhaps 
'... then ... else ...', for just this situation. :)

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
                                                               ben@morrow.me.uk


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

Date: Thu, 28 Oct 2004 21:40:13 GMT
From: c186282 <c186282@yahoo.com>
Subject: Re: interpolation question:
Message-Id: <pan.2004.10.28.21.40.13.807739@yahoo.com>

O.K I'm embarrassed. The solution was simple and I searched with a poor
choice of words.




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

Date: Thu, 28 Oct 2004 19:06:38 GMT
From: "Bradd W. Szonye" <bradd+news@szonye.com>
Subject: Re: Is this really legal?
Message-Id: <slrnco2gpu.rfg.bradd+news@szonye.com>

wana noted the equivalence of these two expressions:
>> if (!defined $outfile) {$outfile = $infile;}
>> $outfile = $infile if not defined $outfile;

Michele Dondi <bik.mido@tiscalinet.it> wrote:
> [Were] we speaking Perl6 rather than Perl5,
> 
>   $outfile //= $infile;
> 
> would be *exactly* the same .... As of now C<?:> could be used
> instead, but then it'd be too verbose ....

I had trouble with a very similar construct:

    my $foo = 'stuff' if defined $bar;

It seemed to work most of the time, but failed horribly in loops. After
a long hunt, I found a small note (in the Perl FAQ, IIRC) explaining
that 'my' isn't well-defined when followed by a conditional modifier.
I had to change my idiom to one of these two patterns:

    my $foo = defined $bar ? 'stuff' : undef;
    my $foo; $foo = 'stuff' if defined $bar;

Unfortunately, at that point my system had grown quite large, so it was
some effort to track down and fix all occurrences of my flawed idiom.

Is this a well-known problem? I suspected what was wrong from the
symptoms, but it took me a long time to find the documentation that
supported my hypothosis.
-- 
Bradd W. Szonye
http://www.szonye.com/bradd


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

Date: Thu, 28 Oct 2004 15:28:29 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Is this really legal?
Message-Id: <slrnco2ljd.uea.tadmc@magna.augustmail.com>

Bradd W. Szonye <bradd+news@szonye.com> wrote:

> I had trouble with a very similar construct:
> 
>     my $foo = 'stuff' if defined $bar;


Me too, which is why I kicked myself when I found it clearly
documented, and why I can cite from memory the documentation
trail that would have saved me (and you).  :-)


> It seemed to work most of the time, but failed horribly in loops. After
> a long hunt, I found a small note (in the Perl FAQ, IIRC) explaining
> that 'my' isn't well-defined when followed by a conditional modifier.


> but it took me a long time to find the documentation that
> supported my hypothosis.


   perldoc -f my

says:

   See "Private Variables via my()" in perlsub for details,

then

   perldoc perlsub

says:

   B<NOTE:> The behaviour of a C<my> statement modified with a statement
   modifier conditional or loop construct (e.g. C<my $x if ...>) is
   B<undefined>.  The value of the C<my> variable may be C<undef>, any
   previously assigned value, or possibly anything else.  Don't rely on
   it.  Future versions of perl might do something different from the
   version of perl you try it out on.  Here be dragons.


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


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

Date: Thu, 28 Oct 2004 21:51:44 GMT
From: "Bradd W. Szonye" <bradd+news@szonye.com>
Subject: Re: Is this really legal?
Message-Id: <slrnco2qfg.rfg.bradd+news@szonye.com>

Bradd W. Szonye wrote:
>> I had trouble with a very similar construct:
>>     my $foo = 'stuff' if defined $bar;

Tad McClellan wrote:
> Me too, which is why I kicked myself when I found it clearly
> documented, and why I can cite from memory the documentation trail
> that would have saved me (and you).  :-)

I found it clearly documented too, but the documentation was in a locked
cabinet, guarded by a jaguar.

>    perldoc -f my [says]
>    See "Private Variables via my()" in perlsub for details,
>
>    perldoc perlsub [says]
>    B<NOTE:> The behaviour of a C<my> statement modified with a statement
>    modifier conditional or loop construct (e.g. C<my $x if ...>) is
>    B<undefined>.  The value of the C<my> variable may be C<undef>, any
>    previously assigned value, or possibly anything else.  Don't rely on
>    it.  Future versions of perl might do something different from the
>    version of perl you try it out on.  Here be dragons.

That's the warning I found, but it's not in perlfunc or perlsub in my
distribution (perl 5.8.3, Fedora Core 1 flavor). Instead, it's under
"Statement Modifiers" in perlsyn. (Which actually makes more sense than
putting it in perlfunc or perlsub, IMO.)

I beat my head against the docs for a long time, trying to find some
reference to this in the "my" rules, but it just wasn't there. Worse,
there are many irrelevant uses of the word "my" in the docs, so
grep-type searches were no help. Eventually, I thought to check rules
for modifiers, and bingo. It sounds like more recent docs duplicate the
warning in the "my" section.

I'm not sure how I could've avoided the problem in the first place,
though. This is a tricky trap: The usage is advanced enough that newbies
are likely to ignore the warning when they first learn how to use the
two features, but the two features are so basic that veterans are
unlikely to look up the fine points -- at least, not until something
goes wrong, at which point you've already sprinkled it throughout your
code like I did. Again, searching for relevant uses of "my" in perl
programs or docs is not fun!
-- 
Bradd W. Szonye
http://www.szonye.com/bradd


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

Date: 28 Oct 2004 12:28:13 -0700
From: neoasimov@hotmail.com (NeoAsimov)
Subject: Little question on regex.
Message-Id: <db56912c.0410281128.2737b1a2@posting.google.com>

Hello,

    I want to select specific lines of C++ source codes.


There is the pattern that I want to match:

    I want a line that have a "..." string in but not any "//" characters.

Exemple:

    public void Foo("test")                 [This one match]
//  public void Foo("test")                 [This one doesn't match]



I tested many things but none works....

there are some of my tests:

^([^//])*("[^"]*")$
^([^//]|[^"])* "[^"]*"
^([^//]*|[^"]*)*"[^"]*"
^([^//]*|[^"]*|$)("[^"]*")
^[ \t]*[^//]*("[^"]*")*$

Is this really possible to do what i want?




Thank alot for your help/hints,


Salutations,


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

Date: Thu, 28 Oct 2004 19:37:08 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Little question on regex.
Message-Id: <ETbgd.5338$9R4.398@trndny09>

"NeoAsimov" <neoasimov@hotmail.com> wrote in message
news:db56912c.0410281128.2737b1a2@posting.google.com...
> I want to select specific lines of C++ source codes.
>
> There is the pattern that I want to match:
>
>     I want a line that have a "..." string in but not any "//"
characters.
>
> Exemple:
>
>     public void Foo("test")                 [This one match]
> //  public void Foo("test")                 [This one doesn't match]

> I tested many things but none works....
>
> there are some of my tests:
>
> ^([^//])*("[^"]*")$
> ^([^//]|[^"])* "[^"]*"
> ^([^//]*|[^"]*)*"[^"]*"
> ^([^//]*|[^"]*|$)("[^"]*")
> ^[ \t]*[^//]*("[^"]*")*$

You seem to be using character classes where none are called for.  Have
you read
perldoc perlretut
and
perdoc perlre
?  Those are good places to start.

If all you're looking for is to match strings which do not contain //,
you can do so like this:

if ($string !~ m|//| ){
    print "No comment found!";
}

If you're looking for something more advanced (comments in particular
positions, for example), you need to give us a better description of
your problem.


> Is this really possible to do what i want?

I'm sure it is.  But you really haven't described well enough what it is
you want.





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

Date: 28 Oct 2004 13:17:20 -0700
From: mygooglegroupsaccount@yahoo.com
Subject: mail forwarding
Message-Id: <1098994640.414279.199990@z14g2000cwz.googlegroups.com>

I am running a website using Perl and MySQL that is based around a
member database setup.

I want to enable each userid the option of having mails sent to
[userid@mydomain.com] forwarded to their main email address, eq
[whatever@whatever.com].

Anyone done this, or can enlight as of what is required by my script
and webhost to achieve it?

Thanks



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

Date: 28 Oct 2004 20:41:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: mail forwarding
Message-Id: <slrnco2mch.3ac.abigail@alexandra.abigail.nl>

mygooglegroupsaccount@yahoo.com (mygooglegroupsaccount@yahoo.com) wrote
on MMMMLXXVI September MCMXCIII in <URL:news:1098994640.414279.199990@z14g2000cwz.googlegroups.com>:
??  I am running a website using Perl and MySQL that is based around a
??  member database setup.
??  
??  I want to enable each userid the option of having mails sent to
??  [userid@mydomain.com] forwarded to their main email address, eq
??  [whatever@whatever.com].
??  
??  Anyone done this, or can enlight as of what is required by my script
??  and webhost to achieve it?


If you are running qmail as your MTA, it could be as simple as:

    sub setup_forwarding {
        my ($userid, $forward_to) = @_;  # Assume the arguments have
                                         # been validated.
        $userid =~ y/./:/;
        open my $fh => ">", "/var/qmail/alias/.qmail-$userid" or die;
        print $fh $forward_to, "\n";
        close $fh or die;
    }


Abigail
-- 
   my $qr =  qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
      $qr =~  s/$qr//g;
print $qr, "\n";


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

Date: Thu, 28 Oct 2004 19:05:52 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: modifying hash key (dispatch table)
Message-Id: <kqbgd.11908$ta5.3303@newsread3.news.atl.earthlink.net>

   I'm calling a dispatch table:

my $hashref=\%SOME_HASH;

if(exists $DISPATCH{modify_hash_key}){
my $sub_ref=$DISPATCH{modify_hash_key};
&$sub_ref($hashref);
}

I'd like to add/modify a hash key but I'm unsure how to do that.

### In some external config file

$DISPATCH{modify_hash_key}=sub{
my $hashref=shift;

????

};

   Jeff



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

Date: Thu, 28 Oct 2004 19:33:42 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: modifying hash key (dispatch table)
Message-Id: <qQbgd.2570$803.1189@trndny04>

"Jeff Thies" <jeff@spamalanadingong.com> wrote in message
news:kqbgd.11908$ta5.3303@newsread3.news.atl.earthlink.net...
>    I'm calling a dispatch table:
>
> my $hashref=\%SOME_HASH;
>
> if(exists $DISPATCH{modify_hash_key}){
> my $sub_ref=$DISPATCH{modify_hash_key};
> &$sub_ref($hashref);
> }
>
> I'd like to add/modify a hash key but I'm unsure how to do that.
>
> ### In some external config file
>
> $DISPATCH{modify_hash_key}=sub{
> my $hashref=shift;
>
> ????
>
> };

What happened when you tried the above?

Paul Lalli




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

Date: Thu, 28 Oct 2004 15:34:42 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: modifying hash key (dispatch table)
Message-Id: <slrnco2lv2.uea.tadmc@magna.augustmail.com>

Jeff Thies <jeff@spamalanadingong.com> wrote:
>    I'm calling a dispatch table:
> 
> my $hashref=\%SOME_HASH;
> 
> if(exists $DISPATCH{modify_hash_key}){
> my $sub_ref=$DISPATCH{modify_hash_key};
> &$sub_ref($hashref);
> }
> 
> I'd like to add/modify a hash key but I'm unsure how to do that.
                  ^^^^^^^^^^^^^^^^^


You cannot modify a hash key.

The key is the identity, if it is different then you have 
a *different* hash element.

You can however, delete the element with the "old" key and 
add an element with a "new" key.


> ### In some external config file
> 
> $DISPATCH{modify_hash_key}=sub{
> my $hashref=shift;
> 
> ????
> 
> };


That code is not attempting to add/modify a hash key, it is
modifying a hash *value*.


What happened when you tried it?


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


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

Date: Thu, 28 Oct 2004 19:17:54 GMT
From: graham@nospam.steelworks.org.uk (Graham)
Subject: Re: open-perl-ide qustion
Message-Id: <417eb403.6233564@news.freenetname.co.uk>

I use and recommend Perl Open IDE. There are some bugettes, mostly
documented on the sourceforge.org web pages for Open IDE, but they are
an inconvenience rather than stopping your Perl from working. I use
mainly Perl for programming at home, because I find it the most
productive development language when used with Open IDE, and Perl is
well suited to the kind of tasks that I want to do at home.

Graham


On Sat, 23 Oct 2004 20:50:23 -0400, "daniel kaplan"
<nospam@nospam.com> wrote:

>can anyone recommend or NOT recommend this?

--
Graham Steel: graham@nospam.steelworks.org.uk
Web: http://www.steelworks.org.uk


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

Date: 28 Oct 2004 20:38:48 GMT
From: ctcgag@hotmail.com
Subject: Re: Parallel/ Multithreading /Forking?
Message-Id: <20041028163848.376$QL@newsreader.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>  <ctcgag@hotmail.com> wrote in comp.lang.perl.misc:
> > Prab_kar@hotmail.com (Prabh) wrote:
> > > Hi,
> > > My task involves searching a huge number of files on filesystem and
> > > based on the filetype perform some function. e.g. if file is ".java"
> > > perform a particular routine, if its ".pl" perform another.
> > >
> > > As the no. of files is quite huge, I thought it'd be most efficient
> > > if I used any parallel-processing techinique.
> >
> > The easiest way to parallel process directory tree is just to run
> > the program multiple times independently, each one operating from
> > a different root node.
> >
> > perl do_stuff.pl /opt/partition1/mystuff &
> > perl do_stuff.pl /opt/partition1/yourstuff &
> > perl do_stuff.pl /opt/partition2 &
> >
> > etc.
> >
> > But that doesn't do load balancing very well (if one program finishes
> > much ealier than the others, it will just exit, rather that start
> > working on whatever the slower ones haven't gotten to yet.)
>
> If there are symlinks criss-crossing the file system there is also
> the possibility that it does part of the tree repeatedly.

Well, that depends on the internal rules that do_stuff.pl uses for
traversing down from the top-level directories it is given.  The same
need for care arises in threader or forked situations, also.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 28 Oct 2004 15:56:54 -0600
From: Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com>
Subject: print FILE function()
Message-Id: <10o2qp5sbg6u284@corp.supernews.com>

Hi,

I've looked all over the 'net for an answer but can't find it.

Why is that I can't print a function's output to file?

my $path = "/home/atc/scripts/test.txt";
open (FILE, ">$path") or die "Unable to open file $!";
print FILE "PC: Status Inquiry ",curr_time(),"\n";
print FILE hdump($loc);
close (FILE) or die "Can't close file";


The first print line prints to file and not to screen (including the 
curr_time() func).
The second prints to screen and not to the file.

Here's the subroutines:
sub hdump {
     my $offset = 0;
     my(@array,$format);
     foreach my $data (unpack("a16"x(length($_[0])/16)."a*",$_[0])) {
         my($len)=length($data);
         if ($len == 16) {
             @array = unpack('N4', $data);
             $format="0x%08x (%05d)   %08x %08x %08x %08x   %s\n";
         } else {
             @array = unpack('C*', $data);
             $_ = sprintf "%2.2x", $_ for @array;
             push(@array, '  ') while $len++ < 16;
             $format="0x%08x (%05d)" .
                "   %s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s   %s\n";
         }
         $data =~ tr/\0-\37\177-\377/./;
         printf $format,$offset,$offset,@array,$data;
         $offset += 16;
     }
};

sub curr_time {
	my $curr_time = localtime();
}

TIA
Caleb


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

Date: Thu, 28 Oct 2004 15:58:24 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: removin \n from only part of a string
Message-Id: <g1e752-0tf.ln1@osiris.mauzo.dyndns.org>


Quoth roemerman@gmail.com (sroemerm):
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2uai68F28uim5U1@uni-berlin.de>...
> > sroemerm wrote:
> > > I have a rather large string wiht all kinds of valid \n(s) but I have
> > > some that I want to get rid of.
> > > 
> > > In the following example I want to get rid of only the new lines in
> > > between < and >
> > > 
> > > my $string = "I like this\n but <I dont like\n the\n ones\n in here>"
> > > I want the previous string to look like this
> > > "I like this\n but <I dont like the ones in here>"
> > > 
> > > I've tried a couple things but the bottom line is that I'm not good at
> > > expression parsing.   please help.
> > 
> >      $string =~ s/(<[^>]+>)/ ( my $tmp = $1 ) =~ s!\n!!g; $tmp /eg;
> 
> That works!  Thanks,  if you have time could you break that down and
> explain what is going on?

I've added /x to make things clearer.

$string =~              # over $string
    s/( < [^>]+ > )/    # extract < up to the nearest > and replace with
                        # the result of evaluating
        (my $tmp = $1)  # assign what we just grabbed (the <...>) to $tmp
        =~              # and apply the next s/// to it
        s! \n !!gx;     # which says 'replace newlines with nothing'
        $tmp            # return the new value, to be used as the
                        # replacement
    /exg;               # g => all matches, x => allow whitespace in
                        # pattern, e => treat replacement part as a Perl
                        # expression

Ben

-- 
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent? [Feynmann]     ben@morrow.me.uk


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

Date: 28 Oct 2004 20:26:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Should I use BEGIN, CHECK, or INIT?
Message-Id: <slrnco2lfe.3ac.abigail@alexandra.abigail.nl>

Brian McCauley (nobull@mail.com) wrote on MMMMLXXVI September MCMXCIII in
<URL:news:clr9kl$ia4$4@sun3.bham.ac.uk>:
--  
--  
--  Brian McCauley wrote:
--  
-- > 
-- > 
-- > Anno Siegel wrote:
--  
--  [snip most of Anno's message ]
--  
-- >> I have little to add to Tassilo's thorough discussion of the issue,
-- >> except still another alternative:
-- >>
-- >>      f) rename the init() function as import() (or call it from
-- >>         the import() function)
-- >>
-- >> That (import()) will be called after the last executable statement
-- >> of your module, but before "use" returns to the caller, so it is
-- >> basically equivalent to d).  The difference is that the user has
-- >> the choice to suppress the call to import() and call it on their
-- >> own.
--  
--  import() is called each time the module use use()d.  It is therefore 
--  inappropriate for initialisation that should happen once regardless of 
--  how many times the module is used.


    my $ping_a_pong;
    sub import {
        $ping_a_pong ++ or do {
            ... initialization code ...
        };
    }


I'd hesitate to use INIT in a module. From "man perlmod":

   "INIT" blocks are run just before the Perl runtime begins
    execution, in "first in, first out" (FIFO) order. For
    example, the code generators documented in perlcc make use
    of "INIT" blocks to initialize and resolve pointers to
    XSUBs.

It's not entirely clear to me when (or if) an INIT in a module is run.
Is that just before runtime of the main program, or just before runtime
of the module?


However, if I need to initialize something in a module, I wouldn't use
BEGIN, INIT, or CHECK, nor would I use import() or require an init()
function to be called.

I'd either put the initialization code in the main body of the module,
or just the call to init(). After all, a module, whether required or used,
*is* executed. Once. Right after it was compiled. Which sounds exactly 
what the OP wants.  (Sure, it would run multiple times if people use 
'do Module;', or much with '%INC'. But that's their problem.)


Abigail
-- 
#!/opt/perl/bin/perl   --   # Remove trailing newline!
BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
truncate$0,-1+-s$0;exec$0;}}//rekcaH_lreP_rehtona_tsuJ


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

Date: Thu, 28 Oct 2004 15:48:14 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Should I use BEGIN, CHECK, or INIT?
Message-Id: <eed752-0tf.ln1@osiris.mauzo.dyndns.org>


Quoth "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>:
> Also sprach J. Romano:
> 
> >    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

You should not put things in CHECK blocks, in general. They are hooks
for the (unimplemented) perl compiler.

> >    c) put the init() statement in an INIT block

I would say here is best, but it really makes no difference. Putting
init stuff in init blocks is necessary for any form of perl compiler to
work (including things I have tried to do in the past to make PAR's
module-detection mechanism more reliable in the face of modules which
use other modules for you, such as 'if' and 'all'); however, this
convention is so universally ignored that there is little point trying
to follow it.

> >      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.

As you're going to do this, I would recommend calling it from ->import.
Thn the user can choose (if necessary) not to call it with 

use Module ();

and then call it later when necessary.

Ben

-- 
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent? [Feynmann]     ben@morrow.me.uk


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

Date: 28 Oct 2004 21:58:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Should I use BEGIN, CHECK, or INIT?
Message-Id: <clrq1j$emi$1@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Brian McCauley (nobull@mail.com) wrote on MMMMLXXVI September MCMXCIII in
> <URL:news:clr9kl$ia4$4@sun3.bham.ac.uk>:
> --  
> --  
> --  Brian McCauley wrote:
> --  
> -- > 
> -- > 
> -- > Anno Siegel wrote:
> --  
> --  [snip most of Anno's message ]
> --  
> -- >> I have little to add to Tassilo's thorough discussion of the issue,
> -- >> except still another alternative:
> -- >>
> -- >>      f) rename the init() function as import() (or call it from
> -- >>         the import() function)
> -- >>
> -- >> That (import()) will be called after the last executable statement
> -- >> of your module, but before "use" returns to the caller, so it is
> -- >> basically equivalent to d).  The difference is that the user has
> -- >> the choice to suppress the call to import() and call it on their
> -- >> own.
> --  
> --  import() is called each time the module use use()d.  It is therefore 
> --  inappropriate for initialisation that should happen once regardless of 
> --  how many times the module is used.
> 
> 
>     my $ping_a_pong;
>     sub import {
>         $ping_a_pong ++ or do {
>             ... initialization code ...
>         };
>     }

Either that, or the initialization is prepared to be run more than once,
perhaps with different parameters, by different callers.  

> I'd hesitate to use INIT in a module. From "man perlmod":
> 
>    "INIT" blocks are run just before the Perl runtime begins
>     execution, in "first in, first out" (FIFO) order. For
>     example, the code generators documented in perlcc make use
>     of "INIT" blocks to initialize and resolve pointers to
>     XSUBs.
> 
> It's not entirely clear to me when (or if) an INIT in a module is run.
> Is that just before runtime of the main program, or just before runtime
> of the module?

I had always "known" that INIT runs before the first executable statement
of the main program.  Could be that I blithely assumed, but the assumption
is supported by the actual behavior of programs.

It would be a time to see which other modules are loaded and what
they are up to.  Modules that modify the behavior of other modules,
or of Perl as a whole, may have business that is best done at INIT
time.

> However, if I need to initialize something in a module, I wouldn't use
> BEGIN, INIT, or CHECK, nor would I use import() or require an init()
> function to be called.
> 
> I'd either put the initialization code in the main body of the module,
> or just the call to init(). After all, a module, whether required or used,
> *is* executed. Once. Right after it was compiled. Which sounds exactly 
> what the OP wants.  (Sure, it would run multiple times if people use 
> 'do Module;', or much with '%INC'. But that's their problem.)

That is, of course, the natural thing to do when there is no reason
to delay initialization.  Sometimes you want to adapt to a given
situation and may want to do that a late as possible.  For example,
sometimes class initialization is done the first time ->new is called,
even later than INIT.

Anno


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

Date: 28 Oct 2004 12:21:56 -0700
From: lisaac01@yahoo.com (leroy isaac)
Subject: Syslog replay script for centralized syslog host
Message-Id: <ead6ddc1.0410281121.62900510@posting.google.com>

I have a need to retrieve syslog data from various remote nodes, and
the smallest network link to the remote nodes is 19K. The syslog
traffic for the link
cannot exceed 9K. 

I plan to setup a configuration which generates new log files every 10
minutes. These files are then compressed, zipped, and transfered to a
centralized
loghost. 

The files are then unzipped, uncompressed, and the data is inserted
into the syslog data stream on a central syslog host.

Is there a perl script or module which will accomplish this task? If
not, then does any one have any suggestions on products which may
accomplish this same
task. 

LeRoy Isaac


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

Date: 28 Oct 2004 12:12:15 -0700
From: cs221239@yahoo.ca (Amy)
Subject: what is %process XX%
Message-Id: <53a1c7f5.0410281112.570b2c0a@posting.google.com>

Can somebody explain that what is %process organization% where
organiztion is a HTML templete. this code is from a redhat, appach
server.


Many thx


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

Date: Thu, 28 Oct 2004 14:15:54 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: what is %process XX%
Message-Id: <87sm7y64d1.fsf@limey.hpcc.uh.edu>

>> On 28 Oct 2004 12:12:15 -0700,
>> cs221239@yahoo.ca (Amy) said:

> Can somebody explain that what is %process organization%
> where organiztion is a HTML templete. this code is from a
> redhat, appach server.

nothing to do with Perl, try an HTML related group.

hth
t


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

Date: Thu, 28 Oct 2004 21:30:38 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: what is %process XX%
Message-Id: <2ud028F1sjnjlU1@uni-berlin.de>

Amy wrote:
> Can somebody explain that what is %process organization% where
> organiztion is a HTML templete. this code is from a redhat, appach
> server.

To maintain a Perl based web site, you'd better learn some Perl, and you 
won't do that by asking random question in a Usenet group.

Try http://learn.perl.org/

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


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

Date: 28 Oct 2004 19:53:49 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: what is %process XX%
Message-Id: <Xns9590988A2C111ebohlmanomsdevcom@130.133.1.4>

cs221239@yahoo.ca (Amy) wrote in 
news:53a1c7f5.0410281112.570b2c0a@posting.google.com:

> Can somebody explain that what is %process organization% where
> organiztion is a HTML templete. this code is from a redhat, appach
> server.

You asked this same question a day or two ago.  The answer is still the 
same as the one you got then: it's a "template variable" that gets replaced 
by some sort of template processor with an actual value.  Without knowing 
*what* template processor is being used (for all anybody knows, it might be 
something totally custom-written), *nobody* other the author of the code in 
question (who probably isn't reading this groupd) can tell you anything 
more.

If you can find the perl code that does the processing, look to see what 
modules it's using.  Then go over to <http://search.cpan.org> and look up 
what each of them does.  If one of them turns out to be a templating 
module, read its documentation.  If, on the other hand, the author of the 
code rolled his own templating system (unfortunately all too common) then 
your best bet is to contact the author.  If he can't be found or won't 
help, then you're pretty much going to have to pay a Perl programmer to 
look over the code and make whatever modifications you need; doing 
maintenance on production code really isn't the sort of thing most people 
are willing to do for free.  In that case I'd suggest going to 
<http://www.pm.org> and finding your closest chapter of the Perl Mongers 
user group; it will almost certainly have some members who would be willing 
to do the job for a reasonable cost.


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

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


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