[22072] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4294 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 20 00:10:44 2002

Date: Thu, 19 Dec 2002 21:10:19 -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           Thu, 19 Dec 2002     Volume: 10 Number: 4294

Today's topics:
    Re: Installing an event handler with use / require? <goldbb2@earthlink.net>
    Re: map and s/// on @list <stremitz@consultant.com>
    Re: map and s/// on @list <uri@stemsystems.com>
    Re: map and s/// on @list <stremitz@consultant.com>
    Re: Negation inside a pattern match <mgjv@tradingpost.com.au>
    Re: search and replace text in many files <bwalton@rochester.rr.com>
    Re: search and replace text in many files <jurgenex@hotmail.com>
    Re: SSH: remote protocol version not found (David Efflandt)
        telnet not waiting for command to finish (Ponzie B. Pogie)
    Re: Test please ignore (Tad McClellan)
    Re: Tied Filehandles <ahamm@mail.com>
    Re: Why doesn't this foreach SMTP loop work? <goldbb2@earthlink.net>
    Re: xmlgrep <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 19 Dec 2002 20:44:31 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Installing an event handler with use / require?
Message-Id: <3E0275FF.D58DBB50@earthlink.net>

Paul Cody Johnston wrote:
> 
> I would like to receive notification when a particular Module is fully
> loaded.  This would look something like:
> 
> my $sub = { print "My::Module loaded!\n; };
> add_loader_listener("My::Module", $sub);
> 
> Later at some unpredictable time during program execution, if
> "My::Module" is dynamically loaded, $sub would be invoked.
> 
> Any way to do this?

Overload CORE::GLOBAL::require, perhaps?

my %handlers;
sub Devel::Onload::add_load_listener {
   my ($mod, $coderef) = @_;
   (my $file = $mod) =~ s,::,/,g;
   push @{ $handlers{"$file.pm"} }, $coderef;
}
sub CORE::GLOBAL::require($) {
   my $file = shift;
   my $ok = CORE::require($file);
   if( $ok and my $h = $handlers{$file} ) {
      $_->("$file") for @$h;
   }
   $ok;
}

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Thu, 19 Dec 2002 22:25:06 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Re: map and s/// on @list
Message-Id: <3E028D92.6040909@consultant.com>

>
>
>you shouldn't be using map as map returns a list of values and s/// does
>not return the modified string.
>
Actually I came up with map as this is what the diagnostics output 
recommended.
 
   (W misc) The pattern match (//), substitution (s///), and
    transliteration (tr///) operators work on scalar values.  If you apply
    one of them to an array or a hash, it will convert the array or hash to
    a scalar value -- the length of an array, or the population info of a
    hash -- and then work on that scalar value.  This is probably not what
    you meant to do.  See perlfunc/grep and perlfunc/map for
    alternatives.

>
>
>  AS> -- 
>
>don't put code BELOW your signature. 
>
Still trying to learn all the rules here. Will do better next time.

>diagnostics will slow down your program as it is a large module. i think
>you probably meant to use warnings
>
Actually meant to use diagnostics as it gives you all the nice 
information beginners need.

>
>  AS> open (TEST, "<conf/upd_db.in") || die "problem";
>
>you should print the file and and $! in die
>
This was just a little test script I wrote, but thanks for the hint.

>
>
>
>well, have you read perldoc perlop on =~? it works on a scalar and not a
>list.
>
I knew that, but could not come up with a proper alternative.

>  AS> __DATA__
>
>you don't use your DATA so why show it?
>
I thought this was the proper way of posing the contents of  the file 
referenced in the program.

Thanks for all your help.



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

Date: Fri, 20 Dec 2002 03:59:24 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: map and s/// on @list
Message-Id: <x7isxpjq78.fsf@mail.sysarch.com>

>>>>> "AS" == Alexander Stremitzer <stremitz@consultant.com> writes:

  >> you shouldn't be using map as map returns a list of values and s/// does
  >> not return the modified string.
  >> 
  AS> Actually I came up with map as this is what the diagnostics output
  AS> recommended.
  AS>   (W misc) The pattern match (//), substitution (s///), and
  AS>     transliteration (tr///) operators work on scalar values.  If you apply
  AS>     one of them to an array or a hash, it will convert the array or hash to
  AS>     a scalar value -- the length of an array, or the population info of a
  AS>     hash -- and then work on that scalar value.  This is probably not what
  AS>     you meant to do.  See perlfunc/grep and perlfunc/map for
  AS>     alternatives.

hmm, that should be changed. i bet it was written pre 5.005 when the for
modifier was added. modifiying the values in map/grep is not considered
good coding by most perl hackers. their purpose is to generate lists and
not do side effects on their input data. other side effects are ok if
they are limited.

  >> diagnostics will slow down your program as it is a large module. i think
  >> you probably meant to use warnings
  >> 
  AS> Actually meant to use diagnostics as it gives you all the nice
  AS> information beginners need.

that is wise. add use warnings too. and remove diagnostics when you stop
needing the extra help.

  AS> I knew that, but could not come up with a proper alternative.

  AS> __DATA__
  >> 
  >> you don't use your DATA so why show it?
  >> 
  AS> I thought this was the proper way of posing the contents of  the file
  AS> referenced in the program.

well, you could have read it in the code and it would have made
sense. not doing that, it made little sense without any comments to say
it was the data. we can't read minds without using the PSI::ESP module.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 19 Dec 2002 23:23:13 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Re: map and s/// on @list
Message-Id: <3E029B31.1060309@consultant.com>


--------------030105020609090003040509
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit



Uri Guttman wrote:

>>>>>>"AS" == Alexander Stremitzer <stremitz@consultant.com> writes:
>>>>>>            
>>>>>>
>
>  >> diagnostics will slow down your program as it is a large module. i think
>  >> you probably meant to use warnings
>  >> 
>  AS> Actually meant to use diagnostics as it gives you all the nice
>  AS> information beginners need.
>
>that is wise. add use warnings too. and remove diagnostics when you stop
>needing the extra help.
>
>
>  
>
I tried to study this newsgroup now for a while. One of the posters 
pointed out that some settings are redundant.
perl -w
use warnings
use diagnostics
The poster explained that you should only use one of the three (which I 
did). This is why I only used diagnostics since I thought it implicitly 
inludes the other two.

--------------030105020609090003040509
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body>
<br>
<br>
Uri Guttman wrote:<br>
<blockquote type="cite" cite="midx7isxpjq78.fsf@mail.sysarch.com">
  <blockquote type="cite">
    <blockquote type="cite">
      <blockquote type="cite">
        <blockquote type="cite">
          <blockquote type="cite">
            <pre wrap="">"AS" == Alexander Stremitzer <a class="moz-txt-link-rfc2396E" href="mailto:stremitz@consultant.com">&lt;stremitz@consultant.com&gt;</a> writes:
            </pre>
          </blockquote>
        </blockquote>
      </blockquote>
    </blockquote>
  </blockquote>
  <pre wrap=""><!---->
  &gt;&gt; diagnostics will slow down your program as it is a large module. i think
  &gt;&gt; you probably meant to use warnings
  &gt;&gt; 
  AS&gt; Actually meant to use diagnostics as it gives you all the nice
  AS&gt; information beginners need.

that is wise. add use warnings too. and remove diagnostics when you stop
needing the extra help.


  </pre>
</blockquote>
I tried to study this newsgroup now for a while. One of the posters pointed
out that some settings are redundant.<br>
perl -w<br>
use warnings<br>
use diagnostics<br>
The poster explained that you should only use one of the three (which I did).
This is why I only used diagnostics since I thought it implicitly inludes
the other two.<br>
</body>
</html>

--------------030105020609090003040509--



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

Date: Thu, 19 Dec 2002 23:18:05 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Negation inside a pattern match
Message-Id: <slrnb04l15.865.mgjv@verbruggen.comdyn.com.au>

On Wed, 18 Dec 2002 13:44:15 +0000 (UTC),
	Sami Leino <sl58554@uta.fi> wrote:
> 
> If I would like to reject all messages that are coming from "bogus.com",
> the filter entry would be something like this:
> 
> /^From: (.*)bogus.com$/ REJECT

\begin{offtopic}

It is not entirely clear what you are trying to achieve [1], and how tight
you need it to be, but I think that what you are really looking for is
smtpd_recipient_restrictions (which by default probably is set
correctly) with a decent setting of $mynetworks.

If I were you, I would ask this question in a place where people are
likely to know the ins and outs of postfix, and explain what it is you
are trying to do at a higher level.

[1] Could it be that you're trying to stop people "outside" of your
network to connect? If so, limiting by From: field will not be very
reliable. The From: field is easily settable by clients, and in fact,
I almost always set it explicitly. many spam messages that we get
through our gateway here have a From: field that has been set to look
like it came from our domain.

\end{offtopic}

Martien
-- 
                        | 
Martien Verbruggen      | Little girls, like butterflies, need no
Trading Post Australia  | excuse - Lazarus Long
                        | 


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

Date: Fri, 20 Dec 2002 02:57:02 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: search and replace text in many files
Message-Id: <3E0286E8.1020701@rochester.rr.com>

BobbyD wrote:

 ...
> It's been a few months since I've been tasked to do some text editing.
>  I'm sure something simple out there exists.  I would like to create a
> perl script to be used in an alias on a Unix platform that will search
> and replace one or more strings in every file down a tree.  Couldn't I
> create an alias that begins with "find ." and then run the perl script
> on each file it finds.  Since find is recursive, it should search down
> the tree.  In most cases the string will be just one word, not that it
> matters.  I'm thinking that the alias call will look like:
> 
> SRtext oldtext newtext
> 
> And the alias definition would be:
> alias SRtext 'find . -type -f | xargs perlscriptname "$1" "$2"'
 ...
> BobbyD


You could check out the File::Find module for an all-Perl solution

which is not platform dependent.  And won't involve firing off a
process for each file.


-- 
Bob Walton



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

Date: Fri, 20 Dec 2002 03:03:51 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: search and replace text in many files
Message-Id: <rMvM9.52198$_S2.29825@nwrddc01.gnilink.net>

BobbyD wrote:
> It's been a few months since I've been tasked to do some text editing.
>  I'm sure something simple out there exists.  I would like to create a
> perl script to be used in an alias on a Unix platform that will search
> and replace one or more strings in every file down a tree.  Couldn't I

What about just using File::Find to walk the tree and then the advice given
in "perldoc -q insert" to do the manipulation per file?

jue




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

Date: Fri, 20 Dec 2002 02:23:09 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: SSH: remote protocol version not found
Message-Id: <slrnb04vod.875.efflandt@typhoon.xnet.com>

On 19 Dec 2002 14:07:36 -0800, Leaffoot <leaffoot@hotmail.com> wrote:
> I am new to SSH so I hope someone can tell me what this means.
> I'm on a Win XP box, Perl 5.6.1
> 
> When I try to connect using SSH, I get this message:
> "rlouden: Remote protocol version ., remote software version  "
> 
> So it seems to be unable to find the remote version of anything.
> It also reports:
> rlouden: Net::SSH::Perl Version 1.23_01, protocol version 1.5.
> rlouden: No compat match: .
> Your vendor has not defined Fcntl macro F_SETFL, used at
> C:/Perl/site/lib/Net/SSH/Perl.pm line 218.
> 
> I have noted that there is an F_SETFL.h file available when one
> installs C++; but that's all I know about it.
> Here's the code I use:
> 
> use Net::SSH::Perl;
> 
> my $host = 'myhost.com';
> my $user = 'mylogin';
> my $pwd = 'mypassword';
> my $ssh_params = ['debug',1];
> 
> #for SSH
> my %sshhash = ('debug'=>1,
>                'port'=>21,
>                'protocol'=>"2,1",
>                'interactive'=>1); 

ssh is port 22 unless the server has sshd listening on non-standard port 
21 (normally used for ftp).  Could that be why no ssh version is found?

> my $ssh = Net::SSH::Perl->new($host,%sshhash);
> 
> $ssh->login($user, $pwd);
> 
> The script never actually makes it to the login line.
> Thanks for any help!
> Becka Louden


-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 19 Dec 2002 18:40:17 -0800
From: ponzie_b_pogie@hotmail.com (Ponzie B. Pogie)
Subject: telnet not waiting for command to finish
Message-Id: <cf0dac6.0212191840.73d2e36d@posting.google.com>

I've got a problem using the Net::Telnet module. Here's some parts of
my code. The following works in my program:

$t->cmd("cd $dir");
$t->cmd("gunzip *.gz");
print "Finished uncompressing files.\n";

The following doesn't work within the same program:

$t->cmd("$some_perl_script");
print "Finished $some_perl_script.\n";

When it executes the gunzip program through telnet, it will actually
wait for gunzip to complete before executing the next line. But with
$some_perl_script, it doesn't wait for it before going to the next
line. Actually, when I check the host it telnets to, $some_perl_script
isn't even running. I even tried putting in the line:

$t->waitfor('/%/');

after but it still doesn't work. Anyone know how to fix this? Thanks
in advance.


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

Date: Thu, 19 Dec 2002 22:02:19 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Test please ignore
Message-Id: <slrnb055ib.20f.tadmc@magna.augustmail.com>

Mangesh <mangeshp16@hotmail.com> wrote:

> this is test question. please ignore


Too late.

I've already made use of the information you have provided.

Thanks for lightening my load.


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


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

Date: Fri, 20 Dec 2002 11:57:40 +1100
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: Tied Filehandles
Message-Id: <attpur$2r9oq$1@ID-79573.news.dfncis.de>

Uri Guttman wrote:
>
> well, you can easily write some of those to call the others. so you
> only need the timestamp logic in one sub. also you don't need to
> write the subs EOF, SEEK, etc if this is going to be a write only
> filehandle. anyone calling those will just get a fatal error.
>

OK - that's what I thought might be the case. Ahh well. I was thinking perl
might be capable of something similar to the complicated smarts that it gets
upto with operator overloading for assignment operators.

I'm thinking it might be best to sub-class IO::File for the work. I'm fairly
happy with my garnishing algorithm (it's as simple as you might expect) but
I can't test it because at the moment I can't even seem to get my class
called instead of IO::File methods.

Stripped to the bare essentials, I'm trying:

<code>
package My::IO::FileTS;

use strict;
use warnings;

use base qw(IO::File);

our @EXPORT = @IO::File::EXPORT;
our @EXPORT_OK = @IO::File::EXPORT_OK;
our $VERSION = 0.01;

sub garnish {
    print STDERR "garnish\n";
}   # garnish

sub write  { &garnish; IO::File::write(@_) }
sub print  { &garnish; IO::File::print(@_) }
sub printf { &garnish; IO::File::printf(@_) }

1;
</code>

<test>
use lib "mylib";

use Data::Dumper;
use My::IO::FileTS;

my $fd = new My::IO::FileTS;
$fd->open('output', '>');

print STDERR "I see:\n", Dumper($fd);

print $fd "This is the first line\n";
print $fd "This is the second line\n";

$fd->close;
</test>

<stdout>
I see:
$VAR1 = bless( \*Symbol::GEN0, 'IO::FileTS' );
</stdout>

<output file>
This is the first line.
This is the second line.
</output>

So clearly I'm not getting this override working properly. What am I
missing? Something Duhhhh I expect.

> she never ventures into any area beyond script kiddie level cgi
> crap. her recent foray into sorting was a major laugh for all of
> us. sorting array refs that happened to work because of the data is
> proof it works. :)

I've just seen the tail end of that. Frankly I've been away from these ngs
for several months now because I just get infuriated. I can kill-file her
easily enough, but how do you block the replies from other people who are
annoyed at her and deluded that they can convince her of the error of her
ways? Blocking the threads would miss out on useful stuff from useful
people.

Sigh. That's one of the disadvantages of the lawlessness of the Internet.
It's a pity strong authorisation wasn't built into so many Internet
protocols right from the start. Then we wouldn't have spam or trolls.




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

Date: Thu, 19 Dec 2002 18:28:58 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Why doesn't this foreach SMTP loop work?
Message-Id: <3E02563A.6F593E1A@earthlink.net>

Me wrote:
[snip]
> $smtp->to( '$Email' );        # recipient's address

Your recipient's address is the literal string '$Email'?  How strange!

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Thu, 19 Dec 2002 21:57:01 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: xmlgrep
Message-Id: <3E0286FD.8842F6F0@earthlink.net>

bill schaller wrote:

No 'use strict'?  No 'use warnings'

> while ($_=pop(@ARGV)) {

Why are you removing arguments from the *end* of @ARGV, instead of from
the beginning?  Unless you want the syntax to be:

   xmlgrep files -options
Instead of a more normal:
   xmlgrep -options files

[snip]
>     } elsif (/^-root:(.*)/) {

Any reason why you're not using GetOpts::<something> for this?

Further... why are you not using one of the XML:: or SAX:: parsers for
processing the XML?

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

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.  

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


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