[24184] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6376 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 8 14:06:04 2004

Date: Thu, 8 Apr 2004 11:05:08 -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, 8 Apr 2004     Volume: 10 Number: 6376

Today's topics:
        Alternative to AUTOLOAD <jkrugman@yahbitoo.com>
    Re: Alternative to AUTOLOAD <nobull@mail.com>
    Re: arrays of parameters in CGI.pm <ittyspam@yahoo.com>
    Re: Cygwin and path question (Ken MacFarlane)
    Re: Cygwin and path question <warSPAMrenME@NOT.etr-usa.com>
        Detecting Local Admin for Win32 (AgnosticPope)
    Re: display Excel file in browser? <bdu@iastate.edu>
        File::Tail just...stops. (Don W.)
    Re: Initializing an anonymous hash (repost) <uri@stemsystems.com>
    Re: Object oriented gui with Perl/Tk ... how can I make (Nataku)
    Re: Object oriented gui with Perl/Tk ... how can I make <uri@stemsystems.com>
    Re: Perl neq Python <peter@semantico.com>
    Re: Perl neq Python <tore@aursand.no>
    Re: Perl neq Python <jtc@shell.dimensional.com>
    Re: Perl Version Issue? <mail@mail.com>
    Re: print given character range. (Kevin Collins)
    Re: problem with HangUP (GreenLight)
    Re: problem with HangUP <aolblowz@yahoo.com>
    Re: problem with HangUP <aolblowz@yahoo.com>
    Re: problem with HangUP <aolblowz@yahoo.com>
    Re: real, simple sample OOP intro text??!! <dha@panix.com>
    Re: Regular expression question <remorse@partners.org>
    Re: scoping, sig handlers, and labels <pinyaj@rpi.edu>
    Re: subroutine only returns non zero sums <gnari@simnet.is>
        what i am doing wrong here ..  getting  LDAP_STRONG_AUT (Durairaj Avasi)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 8 Apr 2004 16:05:50 +0000 (UTC)
From: J Krugman <jkrugman@yahbitoo.com>
Subject: Alternative to AUTOLOAD
Message-Id: <c53t8u$2ec$1@reader1.panix.com>





I've just come across this sort of code (from the CPAN module
SOAP::Lite):

sub BEGIN {
  no strict 'refs';
  for my $method (qw(ids hrefs parts parser base xmlschemas xmlschema)) {
    my $field = '_' . $method;
    *$method = sub {
      my $self = shift->new;
      @_ ? ($self->{$field} = shift, return $self) : return $self->{$field};
    }
  }
}

(SOAP::Lite comprises many packages; practically every one of them
has a BEGIN block in which methods are defined using this technique.)

This seems to me like an alternative to AUTOLOAD for defining
generic accessor methods.  Any ideas about why this technique would
be preferable to using AUTOLOAD?

Thanks!

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: 08 Apr 2004 18:29:36 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Alternative to AUTOLOAD
Message-Id: <u9y8p6gyyn.fsf@wcl-l.bham.ac.uk>

J Krugman <jkrugman@yahbitoo.com> writes:

> I've just come across this sort of code (from the CPAN module
> SOAP::Lite):
> 
> sub BEGIN {
>   no strict 'refs';
>   for my $method (qw(ids hrefs parts parser base xmlschemas xmlschema)) {
>     my $field = '_' . $method;
>     *$method = sub {
>       my $self = shift->new;
>       @_ ? ($self->{$field} = shift, return $self) : return $self->{$field};
>     }
>   }
> }
> 
> (SOAP::Lite comprises many packages; practically every one of them
> has a BEGIN block in which methods are defined using this technique.)
> 
> This seems to me like an alternative to AUTOLOAD for defining
> generic accessor methods.  Any ideas about why this technique would
> be preferable to using AUTOLOAD?

If a package can be subclassed then all it's autoloadable methods have
to be stubbed so that Perl knows to call the AUTOLOAD in your class
not in the subclass.

The choice beween using stubs and AUTOLOAD or just defining the whole
lot in a loop is largely a matter of personal preference.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 8 Apr 2004 10:16:47 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: arrays of parameters in CGI.pm
Message-Id: <20040408101427.B14622@dishwasher.cs.rpi.edu>

On Thu, 8 Apr 2004, Steve (another one) wrote:

> Dave Weaver wrote:
> > On Wed, 07 Apr 2004 13:04:56 +0100, Steve (another one)
> > 				    <y66y@56yu4b6.com> wrote:
> >
> >
> >>       (@{$myparams{$_}}=$q->param($_))=~ s/[^a..z,A..Z]/_/g;
> >
> >
> >                                               ^^^^^^^^^^^^
> > I suspect that doesn't do what you expected.
> > You want to replace anything that's not 'a' '.' 'z' ',' 'A' or 'Z' with
> > an underscore?
> >
> > You possibly meant:     s/[^a-zA-Z]/_/g;
> > or better:              tr/a-zA-Z/_/c;
> >
> > Run "perldoc perlop" and "perldoc perlre" for more info.
> >
> Urrm yes you are right. I wrecked this while hacking it down from a more
> complex regex to illustrate what was happening to my params as they came
> in.  However as you point out it shouldn't let anything but those chars
> through, but it does so I am obviously doing the assignment wrong. Any
> thoughts ?
>
> my @param_names = $q->param;
> my %myparams;
> foreach (@param_names){
>       (@{$myparams{$_}}=$q->param($_))=~ s/[^A-Za-z]/_/g;
> # this is not doing what I expect,
> # but now I can't see why it should !

the =~ operator takes a scalar on the left, not an array or list.  Don't
try to combine these two steps.

foreach (@param_names) {
	@{$myparams{$_}} = $q->param($_);
	tr/a-zA-Z/_/c for @{$myparams{$_}};
}

Paul Lalli


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

Date: 8 Apr 2004 07:08:33 -0700
From: kenneth_s_macfarlane@bankone.com (Ken MacFarlane)
Subject: Re: Cygwin and path question
Message-Id: <607f021d.0404080608.240c003b@posting.google.com>

G. Randall wrote:
> 1.  Are there any advantages (from an administrative point of view) to 
> using Cygwin's perl vs. ActiveState's?  My gut feeling is that Cygwin 
> would require more work to maintain.

If by "maintenance" you mean CPAN modules, ActiveState's ppm is a bit
easier.  If you're used to the command line module installs (perl
-MCPAN, etc. or building "by hand"), there's little-to-no difference
between Cygwin Perl and any other (espcially on Linux/Unix).

-Ken


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

Date: Thu, 08 Apr 2004 08:26:30 -0600
From: Warren Young <warSPAMrenME@NOT.etr-usa.com>
Subject: Re: Cygwin and path question
Message-Id: <iiddc.7$mZ5.18607@news.uswest.net>

G. Randall wrote:

> 1.  Are there any advantages (from an administrative point of view) to 
> using Cygwin's perl vs. ActiveState's?  My gut feeling is that Cygwin 
> would require more work to maintain.

Cygwin perl is updated automatically when you re-run Cygwin's setup.exe. 
  Once it's installed, you don't have to do anything special to keep it 
updated.  ActiveState perl you have to go and download from their web 
site periodically.

As for CPAN vs. ppm, I prefer CPAN simply because I'm used to it.  It 
works just like on *ix.

Also, if you need Perl to interact with the Cygwin mount scheme and 
other filesystem magic Cygwin provides (e.g. /proc), you'll need to use 
Cygwin Perl.

> 2.  If I were to use ActiveState's perl, will renaming Cygwin's perl.exe 
> suffice for the moment?  

Re-run Cygwin's setup.exe and tell it to uninstall Perl.  That will get 
rid of everything.

> It seems to do the trick, but I'm wondering 
> whether there's something else related I'm not aware of.

Perl is set up to allow multiple installations of Perl on a single 
machine.  Each Perl binary knows where to find its related files.  As 
long as each is set to use a different directory for modules and such, 
they can work side by side.

> 3.  If I place a script foo.pl somewhere in my path, I can execute it 
> elsewhere using the Windows 2000 cmd interpreter by typing "foo.pl".  In 
> Bash, I can type "cmd /C foo.pl".  What I don't understand is why under 
> Bash "perl foo.pl" doesn't work unless I run it from where foo.pl is 
> actually located.

$ chmod +x /path/to/foo.pl
$ foo.pl


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

Date: 8 Apr 2004 09:06:34 -0700
From: agnosticpope@comcast.net (AgnosticPope)
Subject: Detecting Local Admin for Win32
Message-Id: <cb4da905.0404080806.390ba7ff@posting.google.com>

I need to check and see if the current user has admin rights on a
system (different from rights on the domain.  It's possible for a user
to be a local admin with no admin rights on the domain).  I'm
attempting to write a function to do this, but I'm having trouble. 
Here's what I have so far.
##################

sub IsAdmin {

use Win32::NetAdmin qw(UserGetAttributes);
$domain = Win32::DomainName();
$machine = Win32::NodeName;
$_ = Win32::LoginName; # grab the name of the current user
UserGetAttributes($machine, $_, $pwd, $passwordAge, $privilege,
                        $homeDir, $comment, $flags, $scriptPath)
                or die "UserGetAttributes() failed: $^E";
return ($privilege==USER_PRIV_ADMIN);
}

#################
This obviously doesn't work.  Changing $machine to $domain works, but
doesn't give me what I'm look for.  Anyone out there help?


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

Date: Thu, 08 Apr 2004 10:24:21 -0500
From: Bing Du <bdu@iastate.edu>
Subject: Re: display Excel file in browser?
Message-Id: <c53qrb$bv8$1@news.iastate.edu>

Thanks so much, folks, for the heads-up.  The clues you all provided are 
very important and helpful to me.

Bing

John McNamara wrote:

> Bing Du <bdu@iastate.edu> wrote:
> 
> 
>>I've used Spreadsheet::WriteExcel to generate a spreadsheet.  Now I
>>need this spreadsheet to be viewable in web browsers.
>>...
>>
>>If I use the following code to load my.xls into $bindata, how can
>>I display $bindata in its original spreadsheet format on the web?
> 
> 
> 
> In the examples directory of the Spreadsheet::WriteExcel distro there
> is a program called cgi.pl that shows how to stream an Excel file to a
> browser.
> 
> The Content-type/Content-Disposition headers in the program will also
> work if you wish to stream an existing file.
> 
> John.
> --



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

Date: 8 Apr 2004 09:01:16 -0700
From: google@agentsix.net (Don W.)
Subject: File::Tail just...stops.
Message-Id: <d4013293.0404080801.6322d6db@posting.google.com>

I wrote a program that would continuously dump the output of a file to
syslog, using File::Tail and Tie::Syslog.  Problem is, after about two
days of operation, the program just stops tailing -- it's still
running, and if I strace it, I can see that the file is being
stat()ed, but no data is being sent across the wire to the syslog
server.  If I restart the program, it starts tailing again.

Any clues?  This is what I'm using for the File::Tail constructor:

my $tail = File::Tail->new(
        'name' => $file,
        'maxinterval' => '1'
    );

I can't find anything in the man page that would explain this
behaviour, but it wouldn't be the first time I've RTFM and missed
something.

Thanks-in-advance!


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

Date: Thu, 08 Apr 2004 14:24:19 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Initializing an anonymous hash (repost)
Message-Id: <x73c7emtt8.fsf@mail.sysarch.com>

>>>>> "NS" == Neil Shadrach <neil.shadrach@corryn.com> writes:

  NS> If I have 2 arrays @k and @v I can initialize a hash %h with
  NS> @h{@k}=@v;
  NS> If my next step is
  NS> push @a,\%h;
  NS> is there a neat way to skip creating %h and initialize an anonymous
  NS> hash for use in a line like
  NS> push @a, {};

besides the other two answers, i have done this. it works if you can
allow destruction of one of the arrays:

	push( @a, { map { shift @k, $_ } @v } ) ;

you can destroy @v instead of @k:

	push( @a, { map { $_, shift @v } @k } ) ;

either way should be faster then the others but benchmark to be sure.

uri

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


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

Date: 8 Apr 2004 06:11:53 -0700
From: Crapnut566@yahoo.com (Nataku)
Subject: Re: Object oriented gui with Perl/Tk ... how can I make this work?
Message-Id: <7e48fc99.0404080511.55b74076@posting.google.com>

Interesting ... now why didnt I think of that? :)

Thanks for the suggestion - Ill go try that out tonight and see what
kind of success I have.

I wouldn't say perl has better OO than Java, I just enjoy writing Perl
code much more than Java.  Java's strictness does allow for some
pretty nice development tools, but Perl is just so much more fun to
write.

Uri Guttman <uri@stemsystems.com> wrote in message news:<x7lll8o017.fsf@mail.sysarch.com>...
> >>>>> "N" == Nataku  <Crapnut566@yahoo.com> writes:
> 
>   N> Sometime recently I really got into Java because of an OOP class I
>   N> was taking at the university, and I have been attempting to apply
>   N> what I have learned to a Perl project I have been working on.
> 
> glad you realize that perl has better OO than java! :)
> 
>   N> My problem arises when I get to assigning the command to the
>   N> BrowseEntry widget using the browsecmd hashkey/variable.  I can only
>   N> assign a package function call to it, and as such - it kind of defeats
>   N> the whole OO aspect of it, since I cant keep multiple instances of it
>   N> around.  The piece of code that follows should help to illustrate my
>   N> plight.
> 
>   N> ***************
> 
>   N> sub Populate {
>   N>   my ($self, $args) = @_;
>   N>   $self->SUPER::Populate($args);
> 
>   N>   my $browseEntry = $cardLabFrame->BrowseEntry( -variable =>
>   N> \$currentSet,
>   N>                                                 -browsecmd =>
>   N> \&refreshList )->pack( -side => 'top' );
>   N> }
> 
> use a closure for the callback and close on $self.
> 
> <untested>
> 
> 	my $callback = sub { my $widget = shift ;
> 				 $self->whatever(
> 				$widget ) } ;
> 
> do that inside Populate and use it for the -browsecmd value. then call
> whatever method you want in the same class as Populate. it has both the
> widget passed in @_ and the Populate object closed on $self.
> 
> note: this could creates a data loop (the closure has $self which could
> have  $browseEntry which has $self!). so you need to be careful or you
> may leak memory. you have explicitly break that loop to properly garbage
> collect it. you can do that by clearing the values in $browseEntry
> (maybe some tk destroy method?) and then deleting $browseEntry.
> 
>   N> So I appeal to the community at large.  Can any of you think of a way
>   N> out of this without hacking the language?
> 
> get the book object oriented perl which covers using closures with
> objects for callbacks.
> 
> uri


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

Date: Thu, 08 Apr 2004 14:20:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Object oriented gui with Perl/Tk ... how can I make this work?
Message-Id: <x765camu0e.fsf@mail.sysarch.com>

>>>>> "N" == Nataku  <Crapnut566@yahoo.com> writes:

<don't top post. read the group guidelines which are posted regularly>

  N> Interesting ... now why didnt I think of that? :)

because java doesn't have closures and perl does? :)

  N> I wouldn't say perl has better OO than Java, I just enjoy writing
  N> Perl code much more than Java.  Java's strictness does allow for
  N> some pretty nice development tools, but Perl is just so much more
  N> fun to write.

read the book object oriented perl and then try to tell me that
again. perl can run circles around java's OO. perl OO can be stricter or
looser, have many ways to create objects and call methods on them, do
late binding, multimethods and more. java is very narrow in focus and
has little OO flexibility.

uri

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


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

Date: Thu, 08 Apr 2004 15:16:26 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: Perl neq Python
Message-Id: <40755ebe$0$3814$afc38c87@news.easynet.co.uk>

Berk Birand wrote:
> Under what circumstances should I use Perl, Python or straight shell
> scripting?

Perl
----
Perl is useful if you intend to earn money and is a sort of defacto 
sysadmin tool. If only because many of the tools a sysadmin will use are 
written in perl - especially with web sites. So Perl is a usefull skill 
to have to get work.

Perl has CPAN, your problem might already have been solved and posted to 
CPAN. For a quick solution the ability to download 50%-90% of the code 
from CPAN is a real boon.

Python
------
I use it for fun, like a lot of languages I use. However it can be used 
in all the places you can use Perl, its just finding an employer who 
actually wants Python skills. Also wxWindows is better developed in 
Python than in Perl. If I want a cross platform GUI I go for Python and 
wxWindows (unless I feel like a challenge and go for tcl/tk). This alone 
is a very big plus for Python, it is the only portable language (I'm not 
counting C/C++ here - dont flame) with a portable GUI, other than Java 
but lets not go there.

Shell scripts
-------------
If your Perl/Python scripts end up being just a bunch of system calls 
then you should probably have used a shell script. Actually the ability 
to write shell scripts should be a given if you are getting into a 
programming, just like knowing how to use vi, cvs, sed and awk - tools 
of the trade.

Most of the time, when the problem seems simple, I start with a shell 
script and promote to Perl or Python as it gets either bigger or critical.

Summary
-------
Perl and Python, get to know both and see which feels like your sort of 
language. Shell scripts, you should be able to do these regardless of 
what language you use.


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

Date: Thu, 08 Apr 2004 16:35:26 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Perl neq Python
Message-Id: <pan.2004.04.08.14.32.20.623887@aursand.no>

On Thu, 08 Apr 2004 08:50:49 +0000, Joe Smith wrote:
> [...]
> A good exercise is to find an interesting task, then implement it in all
> three languages.  Take notes of how long it takes to write, then
> benchmark how fast each one is.  Repeat a couple dozen times.

 ...and when you're done, don't be surprised if your boss - or even the
customer for whom you're creating the application - haven't heard about
the language of your choice and insists that you write it in a language
which everyone has heard about, but that's not really suitable for the
problem. :)


-- 
Tore Aursand <tore@aursand.no>
"Omit needless words. Vigorous writing is concise. A sentence should
 contain no unnecessary words, a paragraph no unnecessary sentences,
 for the same reason that a drawing should have no unnecessary lines
 and a machine no unnecessary parts." -- William Strunk Jr.


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

Date: 8 Apr 2004 11:21:20 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: Perl neq Python
Message-Id: <slrnc7b2gg.b4i.jtc@shell.dimensional.com>

In article <40755ebe$0$3814$afc38c87@news.easynet.co.uk>, Peter Hickman wrote:
> Berk Birand wrote:
>> Under what circumstances should I use Perl, Python or straight shell
>> scripting?
> 
> Perl
> ----
> Perl is useful if you intend to earn money and is a sort of defacto 
> sysadmin tool. If only because many of the tools a sysadmin will use are 
> written in perl - especially with web sites. So Perl is a usefull skill 
> to have to get work.
> 
> Perl has CPAN, your problem might already have been solved and posted to 
> CPAN. For a quick solution the ability to download 50%-90% of the code 
> from CPAN is a real boon.
> 
> Python
> ------
> I use it for fun, like a lot of languages I use. However it can be used 
> in all the places you can use Perl, its just finding an employer who 
> actually wants Python skills. Also wxWindows is better developed in 
> Python than in Perl. If I want a cross platform GUI I go for Python and 
> wxWindows (unless I feel like a challenge and go for tcl/tk). This alone 
> is a very big plus for Python, it is the only portable language (I'm not 
> counting C/C++ here - dont flame) with a portable GUI, other than Java 
> but lets not go there.

Sorry to introduce an off-topic response, but I think a correction is
needed to the above statement.  Eiffel is a portable language, and Eiffel
Software's compiler includes a portable GUI library (EiffelVision2).
Now if you amend the statement to something like: "it is the only portable
language (I'm not counting C/C++ here - dont flame) with a portable,
well-known, open-source or freely available GUI, other than Java but lets
not go there", then it might be true.  However, I'm still not sure if this
is true - what about Perl?  And don't some of the functional languages
(e.g., scheme, Haskell) have a portable GUI library available?

-- 
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]


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

Date: Thu, 8 Apr 2004 16:09:10 +0100
From: "bob" <mail@mail.com>
Subject: Re: Perl Version Issue?
Message-Id: <_-2cnbwgFfLm9ujdSa8jmw@karoo.co.uk>

5.80 was known to have a few bugs in it, hence we now have 5.8.3.
"Jason Crowther" <jason@purplewire.com> wrote in message
news:37a16639.0404060757.7a31d78d@posting.google.com...
> I've stumbled across a little strangeness when we had to do an
> emergency upgrade from perl 5.6.0 to perl 5.8.0.
>
> I have some code that works fine under 5.6.0 but goes down in flames
> in 5.8.0.  the error I'm getting is "Can't find label...".
>
> I can replicate this issue with two simple files:
>
>
> test.pl:
> #!/usr/bin/perl
> print "test 1\n";
> goto SKIP;
> print "test 2\n";
> SKIP:
> print "test 3\n";
> 1;
>
> caller.pl:
> #!/usr/bin/perl
> require 'test.pl';
> exit 0;
>
>
> here's what you get when you run these on 5.6.0:
>
> $ ./test.pl
> test 1
> test 3
> $ ./caller.pl
> test 1
> test 3
>
> here's what happens on 5.8.0:
>
> $ ./test.pl
> test 1
> test 3
> $ ./caller.pl
> test 1
> Can't find label SKIP at test.pl line 5.
> Compilation failed in require at ./caller.pl line 2.
>
>
> I'm not sure what could be causing the problem.  is this a bug or new
> default perl behavior?  I couldn't find any relavent previous posts.
>
> thanks for any help!
>
> ps. I know that goto's are evil to begin with!  I'm slowly but surely
> working the goto's out this historical code...  ;-)




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

Date: 8 Apr 2004 09:45:03 -0700
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: print given character range.
Message-Id: <a6882f32.0404080845.3cf0786@posting.google.com>

Jayaprakash Rudraraju <prakash@ece.arizona.edu> wrote in message news:<Pine.GSO.4.50.0404051459490.2957-100000@ece2.ece.arizona.edu>...
> Most of the files in bioinformatics save their sequences in fasta
> format. Fasta format files contain header lines followed by dna
> sequence. I have been using the following short-cut to get sequence
> given the range in the sequence.
> 
> perl -ne 'chomp; next if />/; print' FASTA.TXT | cut -c3450-3470
> 
> Is there is a better and convinient way to do it.

Try this:

   perl -ne 'chomp; print substr($_, 3449, 20) unless (/^>/);'

The "^" assumes (as you mentioned in another reply) that the header
starts with '>' - otherwise you can leave it out. However, if the
lines do start with '>', it is much faster (especially for the long
records) for the regexp engine if you anchor the RE with '^'.

This single perl command should always be faster that 'perl | cut'...

Kevin


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

Date: 8 Apr 2004 07:00:10 -0700
From: google@milbaugh.com (GreenLight)
Subject: Re: problem with HangUP
Message-Id: <c4b60ce1.0404080600.32936440@posting.google.com>

lucas <aolblowz@yahoo.com> wrote in message news:<hMCdnbvlp9s7Dend4p2dnA@golden.net>...
> 
> sub LoadFiles {
>    my $adfilterfile = shift;
> 
>    #load ad filter strings into memory
>    print "$$: Loading in Ad Filters from $adfilterfile..." if($debug);
>    open(FILE,"$adfilterfile") || die "Error opening $adfilterfile: $!\n";
>    @filters = <FILE>;
>    close(FILE);
>    for($_=0;$_<@filters;$_++) {
>       @filters[$_] =~ s/[\r|\n]//g;   #Rid of \r \n!
>       if (@filters[$_] eq '') { pop(@filters); $_--; next; } #skip entry if
> it's empty
>       print ">@filters[$_]\n" if ($debug);
>    }
>  print "$$: ", $_ = @filters," Strings Loaded\n" if($debug);
> }

lucas:
I don't know about your actual problem, but I am wondering if you had
ever considered writing your code like this:

sub LoadFiles {
	my $adfilterfile = shift;

	#load ad filter strings into memory
	print "$$: Loading in Ad Filters from $adfilterfile..." if($debug);
	open(FILE,"$adfilterfile") || die "Error opening $adfilterfile:
$!\n";
	while (<FILE>) {
		chomp;
		next if //;
		push @filters, $_;
		print ">$_\n" if ($debug);
	}
	close(FILE);
	print "$$: ", $_ = @filters," Strings Loaded\n" if($debug);
}

It is a bit cleaner-looking amd more "conventional".
Mind you, I'm not saying that this is "the way" to go, but you might
consider it.

Also, one thing that I often do to reduce the "if ($debug)"-type
statements is to define a sub called "chatter":

sub chatter {
	if ($debug) {print shift;}
}

This way, I can code it like this:

chatter("$$: ", $_ = @filters," Strings Loaded\n");


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

Date: Thu, 08 Apr 2004 13:28:39 -0400
From: lucas <aolblowz@yahoo.com>
Subject: Re: problem with HangUP
Message-Id: <24ydnU6AX75bFujdRVn-hA@golden.net>

GreenLight wrote:

> lucas:
> I don't know about your actual problem, but I am wondering if you had
> ever considered writing your code like this:
> 
> sub LoadFiles {
> my $adfilterfile = shift;
> 
> #load ad filter strings into memory
> print "$$: Loading in Ad Filters from $adfilterfile..." if($debug);
> open(FILE,"$adfilterfile") || die "Error opening $adfilterfile:
> $!\n";
> while (<FILE>) {
> chomp;
> next if //;
> push @filters, $_;
> print ">$_\n" if ($debug);
> }
> close(FILE);
> print "$$: ", $_ = @filters," Strings Loaded\n" if($debug);
> }
> 
> It is a bit cleaner-looking amd more "conventional".
> Mind you, I'm not saying that this is "the way" to go, but you might
> consider it.
> 
> Also, one thing that I often do to reduce the "if ($debug)"-type
> statements is to define a sub called "chatter":
> 
> sub chatter {
> if ($debug) {print shift;}
> }
> 
> This way, I can code it like this:
> 
> chatter("$$: ", $_ = @filters," Strings Loaded\n");

Thanks for the code, it is nicer looking.  I've never consider using push
when reading from a text file.  Think i'll give it a try

Thanks again,
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Thu, 08 Apr 2004 13:32:21 -0400
From: lucas <aolblowz@yahoo.com>
Subject: Re: problem with HangUP
Message-Id: <24ydnUmAX744EejdRVn-hA@golden.net>

Anno Siegel wrote:

> lucas  <aolblowz@yahoo.com> wrote in comp.lang.perl.misc:
> 
> Don't top-post please.  You're not exactly new to this group, aren't you?
> 
>> Anno Siegel wrote:
>> 
>> > No.
>> > 
>> > The code you show doesn't exit.  If it exits for you, that happens in
>> > the
>> > code you don't show.  We can't correct code we don't get to see.
>> > 
>> 
>> the sub routine doesn't exit either.  i know this because i run it at the
>> start of the program.
> 
> Where?  The code you show doesn't call "the sub" (I suppose LoadFiles()).
> 
>>                        And i know that the $SIG(HUP) shouldn't exit, but
>>                        it
>> does.  i put a 'print "DONE LOADING\N"; ' in the $SIG, as you can see,
>> and it is printed to screen, so the LoadFiles() returns properly.
> 
> The code below is incomplete, and it doesn't run under strict and
> warnings. To run it, people must make all kinds of amendments, which also
> means making assumptions about the content of variables and files that you
> don't
> show.  So we still don't know what code you ran.
> 
> Show a complete, runnable piece of code, tell us what you expect it to
> do and explain how what it does is different.
> 
> I have annotated your code and pointed out some mistakes.  I don't know
> if these have anything to do with your perceived problem.
> 
>> $SIG{HUP}   = sub { print STDERR "$$: HUP Caught\n";
>> LoadFiles($adfilterfile); print "DONE LOADING\n"; };
> 
> What is $adfilterfile?  A global variable?  It is nowhere declared, nor
> does it have a value.
> 
>> sub LoadFiles {
>>    my $adfilterfile = shift;
> 
> This variable "$adfilterfile" is lexically scoped to the sub block.  It
> has nothing to do with "$adfilterfile" outside the sub.  Apparently you
> expect them to be the same, since you never do anything with
> "$adfilterfile"
> in the rest of the routine.  Maybe that's your error, but who knows.
> 
> If so, LoadFiles should return the array at the end, and the call should
> catch it.
> 
>>    #load ad filter strings into memory
>>    print "$$: Loading in Ad Filters from $adfilterfile..." if($debug);
> 
> What is "$debug"?  It is nowhere declared, nor does it have a value.
> Is it supposed to be true or false during the runs you mention?
> 
>>    open(FILE,"$adfilterfile") || die "Error opening $adfilterfile: $!\n";
>>    @filters = <FILE>;
> 
> "@filters" is undeclared.
> 
>>    close(FILE);
>>    for($_=0;$_<@filters;$_++) {
> 
> Why the C-style indexed loop?  It is rarely needed and only encumbers
> your code.
> 
>>       @filters[$_] =~ s/[\r|\n]//g;   #Rid of \r \n!
> 
> "@filters[ $_]" is a one-element array slice.  That is better written as
> "$filters[ $_]", and "warnings" would have told you so.  The same applies
> to two more uses of "@filters[ $_]".
> 
> "s/[\r|\n]//g" doesn't do what you think it does.  It kills "|" besides
> "\r" and "\n", and it kills the first appearance of any of those, not
> the one at the end of the line.
> 
> What you mean is (untested) "s/[\r\n]$//" or "s/(?:\r|\n)$//", but
> usually "chomp" does that job.  Why do you think it doesn't in your
> case?
> 
>>       if (@filters[$_] eq '') { pop(@filters); $_--; next; } #skip entry
>>       if
>> it's empty
> 
> Ugh.  Just say "@filters = grep /./, @filters"  in any convenient place
> before the loop.
> 
>>       print ">@filters[$_]\n" if ($debug);
>>    }
>>    print "$$: ", $_ = @filters," Strings Loaded\n" if($debug);
>> }
> 
> So this is what LoadFiles should look like (untested, and minus debugging
> statements):
> 
>     sub LoadFiles {
>         open(FILE,"$adfilterfile") || die "Error opening $adfilterfile:
>         $!\n"; chomp( my @filters = grep /./, <FILE>);
>         print "$_\n" for @filters;
>         $adfilterfile;
>     }
> 
> ...and call it as
> 
>     $adfilterfile = LoadFiles;
> 
> This is just a translation of what you have into more reasonable Perl. It
> still doesn't make much sense.  In particular, the array @filters is
> only used to print the values, it's gone after the sub returns.
> 
> From your treatment LoadFiles it is apparent that you have no clear grasp
> of the workings of sub arguments and return values.  You still seem to
> reach for global variables when these should be used.  After three years
> of Perl programming you should know better.
> 
> Anno


thanks for the heads up on cleaning up my code.  s/[\r\n]$// was actually
given to me by somebody else, it's not my own
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Thu, 08 Apr 2004 13:34:41 -0400
From: lucas <aolblowz@yahoo.com>
Subject: Re: problem with HangUP
Message-Id: <24ydnUiAX76sEOjdRVn-hA@golden.net>

lucas wrote:

> $SIG{HUP}   = sub { print STDERR "$$: HUP Caught\n";
> LoadFiles($adfilterfile); };   #Catch HanUPs, and reread all loaded files
> 
> All I want this to do is catch a HangUP signal, run the LoadFiles()
> routine
> and return to what it was doing.  However this exits the program.  It
> doesn't die, it just exits.  Any idea on how I can stop this from exiting?
> 
> thx


I finally found the problem I was having.  This program listens on a port,
and what was happening was when a HangUP was receieved, and the sub routine
finished, the script was returning true to $new_sock = $socket->accept();
(i think), and obviously $new_sock would be undefined, and the script died.

Thanks for all your posts,
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Thu, 8 Apr 2004 17:44:52 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: real, simple sample OOP intro text??!!
Message-Id: <slrnc7b3sk.s24.dha@panix2.panix.com>

In article <c47a701u2o9iu0p9vq53nnq1ntj2761usv@4ax.com>, Bart Lateur wrote:
> Geoff Cox wrote:
> 
>>wouldn't dream of suggesting you are personally responsible for this!!
>>if a book costs say $30 in the US and £30 here - does it really cost
>>£10 to get it into a shop the UK?? 
> 
> Don't forget about shipping. It's a long way from the USA to the UK...

Also, there are probably some kind of import taxes involved.

Is anyone around who actually works with a publisher know the details?

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
If you don't know where you're going, any road'll take you there.
	- George Harrison


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

Date: Thu, 08 Apr 2004 12:32:10 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: Regular expression question
Message-Id: <remorse-6921F0.12321008042004@plato.harvard.edu>

In article <slrnc78v18.6ll.tadmc@magna.augustmail.com>,
 Tad McClellan <tadmc@augustmail.com> wrote:

> Richard Morse <remorse@partners.org> wrote:
> >    # if you're going to lexicalize global variables, always do
>                           ^^^^^^^^^^
> 
> Eh?
> 
> I guess you meant "if you're going to change a built-in
> variable's value" instead?

I'm sorry, I've been reading too much about lexical variables lately.  I 
meant, of course, 'localize', not 'lexicalize'.

This may still be the wrong terminology, but at least it's the right 
wrong.

> >    # so in a code block.  Or save and restore their original
> >    # values
> >    open(my $in, "<", 'e:/mycode/perl/brace.txt')
> >       or die("could not open file: $!");
> >    local $/ = undef;
> >    $data = <$in>;
> >    close($in);
> > }
> 
> 
> If I'm going to make my own scope anyways, then I usually let
> Perl handle all that file opening/closing stuff for me:
> 
>    {
>       local $/;   # enable slurp mode
>       local @ARGV = 'e:/mycode/perl/brace.txt';
>       $data = <>;
>    }

How does it handle the 'or die' clause?

Ricky

-- 
Pukku


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

Date: Thu, 8 Apr 2004 09:48:21 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: scoping, sig handlers, and labels
Message-Id: <Pine.SGI.3.96.1040408094744.1076912A-100000@vcmr-64.server.rpi.edu>

On Wed, 7 Apr 2004, Bill wrote:

>#!/usr/bin/perl
>use strict;
>use warnings;
>
>my $rdo = sub { goto REDO; };
>
>REDO:
>foreach(1...1000) {
>   print "$_ ... ";
>   $SIG{ALRM}= $rdo->();

THIS calls &$rdo, which does 'goto REDO'.  You just called the function
here, which was your mistake.

>   alarm 10;
>   system "sleep $_"; # don't use builtin sleep, just in case.
>   alarm 0;
>   print "$_\n";
>}

-- 
Jeff Pinyan             RPI Acacia Brother #734             2004 IT Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Thu, 8 Apr 2004 16:28:59 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: subroutine only returns non zero sums
Message-Id: <c53uho$hkh$1@news.simnet.is>

"Brian McCauley" <nobull@mail.com> wrote in message
news:u9k70qj463.fsf@wcl-l.bham.ac.uk...
> Richard Morse <remorse@partners.org> writes:
>
> >    my $total += $_ foreach @_;
>
> AFAIK the behaviour of a my() declaration with a statement qualifier
> is explicitly undefined.  So the above may happen do what you want
> today but may not in future.

and in fact, it probably does NOT happen to do what
you want today.

gnari







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

Date: 8 Apr 2004 10:51:54 -0700
From: dash@webdurai.com (Durairaj Avasi)
Subject: what i am doing wrong here ..  getting  LDAP_STRONG_AUTH_NOT_SUPPORTED
Message-Id: <2f872516.0404080951.4675df14@posting.google.com>

When i bind like the following code.. i am getting
LDAP_STRONG_AUTH_NOT_SUPPORTED

if i connect with normal bind without Authen::SASL and $sasl i am
getting LDAP_STRONG_AUTH_REQUIRED error..

what i am doing wrong here... why this drives so grazy... 

ldap gurus... help me out.

use Net::LDAP qw(LDAP_SUCCESS LDAP_PROTOCOL_ERROR);
use Authen::SASL;
use Net::LDAP::Util qw(ldap_error_name ldap_error_text);

sub lConnect {
	my $server = shift;
	print " the server name is $server\n";
	my $ldap = Net::LDAP->new($server, port=> 389, version => 3);
	print "=== The error is $@ <====\n";
	return($ldap);
}

my $ldap = &lConnect('$myserver');
my $sasl = Authen::SASL->new(mechanism => 'CRAM-MD5',password =>
'Abcd1234$');
my $isBinded = $ldap->bind ('CN=Durairaj
Avasi,OU=ITDEV2,DC=webdurai,DC=com', sasl => $sasl, version => 3);
print "ERROR detected: -> ", ldap_error_name($isBinded->code), " ",
ldap_error_text($isBinded->code) if($isBinded->code);


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

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


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