[24109] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6303 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 26 03:05:49 2004

Date: Fri, 26 Mar 2004 00:05:07 -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           Fri, 26 Mar 2004     Volume: 10 Number: 6303

Today's topics:
        [ANN] Archive::Zip v1.10 uploaded to CPAN <ned@bike-nomad.com>
    Re: Amulating post back to a .net server (benny s.)
    Re: Amulating post back to a .net server <spamtrap@dot-app.org>
        data types anuradha.k.r@sify.com
    Re: data types <uri@stemsystems.com>
        demystifying UTF-8 and quotelike (valued customer)
    Re: dollar sign and spaces from a string <mr@sandman.net>
    Re: How to interpolate string containing a variable <matthew.garrish@sympatico.ca>
    Re: I want to scanf, dammit! <uri.guttman@fmr.com>
    Re: match pattern with $ failed <1usa@llenroc.ude>
    Re: match pattern with $ failed <tadmc@augustmail.com>
    Re: Parsing <td> tags with HTML::Parser after a certain (Myron Turner)
    Re: q: regex: parse <length><value>? <go@away.spam.invalid>
    Re: SCALAR(0x82dea94) <noreply@gunnar.cc>
    Re: SCALAR(0x82dea94) <tadmc@augustmail.com>
        Signal handling in objects.  Good idea?  Best practices (Carlton Brown)
    Re: Signal handling in objects.  Good idea?  Best pract <1usa@llenroc.ude>
    Re: Signal handling in objects.  Good idea?  Best pract <1usa@llenroc.ude>
    Re: Signal handling in objects.  Good idea?  Best pract <tadmc@augustmail.com>
    Re: Signal handling in objects.  Good idea?  Best pract <tadmc@augustmail.com>
    Re: Signal handling in objects.  Good idea?  Best pract <mgjv@tradingpost.com.au>
    Re: The "value" of a block in 'map' <bernie@fantasyfarm.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 25 Mar 2004 14:41:25 GMT
From: Ned Konz <ned@bike-nomad.com>
Subject: [ANN] Archive::Zip v1.10 uploaded to CPAN
Message-Id: <Hv5ox5.MLD@zorch.sf-bay.org>

Archive::Zip v1.10 has been released.

The changes since v. 1.09 of November 26 2003 are:
  - Fixed documentation of setErrorHandler()
  - Fixed link to Japanese translation of docs
  - Added Compress::Zlib Bufsize patch from Yeasah Pell that was supposed to
    have been added in 1.02
  - Fixed problems with backup filenames for zips with no extension
  - Fixed problems with undef volume names in _asLocalName()

>From the README:

The Archive::Zip module allows a Perl program to create, manipulate,
read, and write Zip archive files.

Zip archives can be created, or you can read from existing zip files
or strings (using IO::Scalar). Once created, they can be written to
files, streams, or strings.

Members can be added, removed, extracted, replaced, rearranged, and
enumerated.  They can also be renamed or have their dates, comments, or
other attributes queried or modified.  Their data can be compressed or
uncompressed as needed.  Members can be created from members in existing
Zip files, or from existing directories, files, or strings.
Directory trees can be added or extracted simply using special tree
routines.

This module uses the Compress::Zlib library to read and write the
compressed streams inside the files. Note that versions of Compress::Zlib
prior to 1.06 truncate data and should not be used.

Compress::Zlib prior to 1.08 caused crashes on some Windows systems.

Examples and helper libraries are given to show how:
  * zip files can be read and written to strings
  * zip files can be written in chunks to arbitrary functions

CHANGES SINCE v1.00:

1.10 Thu Mar 25 06:24:17 PST 2004
  - Fixed documentation of setErrorHandler()
  - Fixed link to Japanese translation of docs
  - Added Compress::Zlib Bufsize patch from Yeasah Pell that was supposed to
    have been added in 1.02
  - Fixed problems with backup filenames for zips with no extension
  - Fixed problems with undef volume names in _asLocalName()

1.09 Wed Nov 26 17:43:49 PST 2003
  - Fixed handling of inserted garbage (as from viruses)
  - Always check for local header signatures before using them
  - Added updateMember() and updateTree() functions
  - Added examples/mailZip.pl
  - Added examples/updateTree.pl
  - Fixed some potential but unreported bugs with function parameters like
'0'
  - Removed stray warn() call
  - Caught undef second arg to replaceMember()

1.08 Tue Oct 21 07:01:29 PDT 2003
  - test noise fix from Michael Schwern (ticket 4174)
  - FAQ NAME fix from Michael Schwern (ticket 4175)

1.07 Mon Oct 20 06:48:41 PDT 2003
  - Added file attribute code by Maurice Aubrey
  - Added FAQ about RedHat 9 build errors
  - Added check for empty filenames

1.06 Thu Jul 17 11:06:18 PDT 2003
  - Fixed seek use with IO::Scalar and IO::String
  - Fixed use of binmode with pseudo-file handles
  - Removed qr{} form for older Perl versions
  - Changed rel2abs logic in _asLocalName() if there is a volume
  - Fixed errors with making directories in extractMember() when none
provided
  - Return AZ_OK in extractMemberWithoutPaths() if member is a directory
  - Fixed problem in extractTree with blank directory becoming "." prefix
  - Added examples/writeScalar2.pl to show how to use IO::String as
destination of Zip write
  - Edited docs and FAQ to recommend against using absolute path names in
zip files.

1.05 Wed Sep 11 12:31:20 PDT 2002
  - fixed untaint from 1.04

1.04 Wed Sep 11 07:22:04 PDT 2002
  - added untaint of lastModFileDateTime

1.03 Mon Sep  2 20:42:43 PDT 2002
  - Removed dependency on IO::Scalar
  - Set required version of File::Spec to 0.8
  - Removed tests of examples that needed IO::Scalar
  - Added binmode() call to read/writeScalar examples
  - Fixed addTree() for 5.005 compatibility (still untested with 5.004)
  - Fixed mkdir() calls for 5.005
  - Clarified documentation of tree operations

1.02 Fri Aug 23 17:07:22 PDT 2002
  - Many changes for cross-platform use (use File::Spec everywhere)
  - Separated POD from Perl
  - Moved Archive::Zip::Tree contents into Archive::Zip
    A::Z::Tree is now deprecated and will warn with -w
  - Reorganized docs
  - Added FAQ
  - Added chunkSize() call to report current chunk size
    and added C::Z BufSize patch from Yeasah Pell.
  - Added fileName() to report last read zip file name
  - Added capability to prepend data, like for SFX files
  - Added examples/selfex.pl for self-extracting archives creation
  - Added examples/zipcheck.pl for validity testing
  - Made extractToFileNamed() set access/modification times
  - Added t/testTree.t to test A::Z::Tree
  - Fix/speed up memberNamed()
  - Added Archive::Zip::MemberRead by Sreeji K. Das
  - Added tempFile(), tempName()
  - Added overwrite() and overwriteAs() to allow read/modify/write of zip
  - added examples/updateZip.pl to show how to read/modify/write

1.01 Tue Apr 30 10:34:44 PDT 2002
  - Changed mkpath call for directories to work with BSD/OS
  - Changed tests to work with BSD/OS

COPYRIGHT:

Copyright (c) 2000-2004 Ned Konz. All rights reserved.  This program is free
software; you can redistribute it and/or modify it under the same terms
as Perl itself.

AVAILABILITY:

>From CPAN, in directory
  http://www.cpan.org/modules/by-authors/id/N/NE/NEDKONZ/
or
  ftp://ftp.cpan.org/pub/CPAN/modules/by-authors/id/N/NE/NEDKONZ/
as Archive-Zip-1.10.tar.gz




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

Date: 25 Mar 2004 17:52:01 -0800
From: tvfw@hotmail.com (benny s.)
Subject: Re: Amulating post back to a .net server
Message-Id: <1ffea2a.0403251752.30f80833@posting.google.com>

Roel van der Steen <roel-perl@st2x.net> wrote in message news:<slrnc5jrdv.ev.roel-perl@localhost.localdomain>...
> On Thu, 18 Mar 2004 at 17:43 GMT, benny s. <tvfw@hotmail.com> wrote:
> > For example I have an html file with a form one of the hidden fields
> > is
> ><input type="hidden" name="thisPage" value="1">
> 
> Are you sure you're on the right newsgroup? This one is
> about Perl.

I am using perl with user agent as a browser that make a post request
to a .net server. the first request is ok and I get a success result
but then I need to resubmit the answer the server has givven me back
to the server with a change to one of the fields

any ideas?


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

Date: Fri, 26 Mar 2004 00:56:47 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Amulating post back to a .net server
Message-Id: <P-adnYhIG4a9W_7dRVn-sQ@adelphia.com>

benny s. wrote:

> I am using perl with user agent as a browser that make a post request
> to a .net server. the first request is ok and I get a success result
> but then I need to resubmit the answer the server has givven me back
> to the server with a change to one of the fields

You're not giving a whole lot of information to work with here, but I'm
guessing that the values sent in the first request aren't being read from
an HTML form. Am I right?

It sounds like what you want to do is parse the HTML form that's sent back
as a response to the first request, extract the form elements that you're
interested in, and then send a second request.

Have a look at HTML::Parser or something similar.

sherm--

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


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

Date: 25 Mar 2004 22:03:54 -0800
From: anuradha.k.r@sify.com
Subject: data types
Message-Id: <57efaf35.0403252203.2af624bc@posting.google.com>

hi,
I have pl/1 program which I am porting to perl.My problem is 
I have a file which I read into a BIT array(in pl/1) and later use the
bits as
required in the program.My question here is since I don't have a data
type
representation for BIT,CHAR etc in perl, how will I handle it in
perl?What I
meant is if my input file has any type of data,when I read the data
(internally it reads as bits only)
and assign it to a BIT array,I actually get the bit represenattion of
the character in the file
into my BIT variable(in pl/1).Does perl have any provision like
that?If I have get 1s and 0s
after reading from a file in perl,isn't it required that my data in my
file is also of that type ie 1s and 0s?
thanx,
AKR.


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

Date: Fri, 26 Mar 2004 06:54:03 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: data types
Message-Id: <x7d670yu7w.fsf@mail.sysarch.com>

>>>>> "akr" == anuradha k r <anuradha.k.r@sify.com> writes:

  akr> I have pl/1 program which I am porting to perl.My problem is I
  akr> have a file which I read into a BIT array(in pl/1) and later use
  akr> the bits as required in the program.My question here is since I
  akr> don't have a data type representation for BIT,CHAR etc in perl,
  akr> how will I handle it in perl?What I meant is if my input file has
  akr> any type of data,when I read the data (internally it reads as
  akr> bits only) and assign it to a BIT array,I actually get the bit
  akr> represenattion of the character in the file into my BIT
  akr> variable(in pl/1).Does perl have any provision like that?If I
  akr> have get 1s and 0s after reading from a file in perl,isn't it
  akr> required that my data in my file is also of that type ie 1s and
  akr> 0s?

you need to be clearer about the exact format of the data in the
file. perl can read and process binary data with the pack/unpack
functions. also the bit::vector module can do most anything with bit
data. you mention CHAR type in pl/1 but perl handles chars with no
trouble. the biggest issue is how were the bits written out. ar ethey
fixed bit strings or varying? if varying, do you know the exact binary
format? if fixed, are they padded to 8 bits or bit aligned? you haven't
provided enough information for me to give you any more help. and i am
one of those odd perl hackers who knew pl/1 very well as i wrote/manage
development for the entire runtime lib of pl/1 including bit strings.

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: 25 Mar 2004 19:28:50 -0800
From: scooterm@hotmail.com (valued customer)
Subject: demystifying UTF-8 and quotelike
Message-Id: <1b347673.0403251928.2340a7e1@posting.google.com>

### PROBLEM

As you already know, the perl 'quotelike' operator is a useful and
quite unique feature of perl for specifying arbitrary strings in
your code. It helps you to avoid the need to add a lot of cumbersome
'escape' characters.

The problem is this, Unicode messes up the operation of the 
'quotelike' operator! If you have a text editor that allows
you to save a file as UTF-8 instead of ASCII, the following
demonstration code illustrates this point:

    print q^"Jump!" said Jack^; ### <-- works as expected
    print ("\n-----------------------------------\n");

    print q@"Jump!" said Jack@; ### <-- works as expected
    print ("\n-----------------------------------\n");

    print q§"Jump!" said Jack§;  ## <-- FAILS in utf-8, works in ASCII
    print ("\n-----------------------------------\n");

### QUESTIONS
Why does this not work as expected? Is this a bug, feature, or
misuse of the quotelike operator? Is there a non-baffling 
explaination of what UTF-8 does to mess things up?


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

Date: Fri, 26 Mar 2004 08:56:38 +0100
From: Sandman <mr@sandman.net>
Subject: Re: dollar sign and spaces from a string
Message-Id: <mr-BF802F.08563826032004@news.fu-berlin.de>

In article <78qdnfB-srBR_v7dRVn-gg@comcast.com>, "MrReallyVeryNice"
<MrReallyVeryNice.NOVIRUS@NoSpam.yahoo.com> wrote:

> Therefore no matter the type of response that this post might
> generate, I will keep quiet.

Then there is no point for me to do anything. Roger.

-- 
Sandman[.net]


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

Date: Thu, 25 Mar 2004 20:11:29 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: How to interpolate string containing a variable
Message-Id: <1rL8c.25248$A_2.1288033@news20.bellglobal.com>


"Mark Gaber" <mark.gaber@obs.unige.ch> wrote in message
news:40635605.C81F56B4@obs.unige.ch...
> Hello,
>
> I have a string variable which contains a command to be executed using
> backticks ``.  The command involves variables and so has to be
> interpolated.  For example, the following does a touch of /tmp/zzTest:
>
> #!/usr/bin/perl
>
> $filename = "/tmp/zzTest";
> $strCmd   = "`touch \$filename`";
>

You aren't interpolating the variable into the string. You're escaping the
dollar sign, so you wind up with `touch $filename` as your string. If you
want string interpolation, don't use a slash:

$strCmd = "`touch $filename`";

>
> eval ${\ $strCmd };
>

What on earth is this eval? Is the following what you are after?

eval "$strCmd";


Matt




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

Date: 25 Mar 2004 15:11:23 -0500
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: I want to scanf, dammit!
Message-Id: <sisc1xngit5g.fsf@tripoli.fmr.com>

>>>>> "PL" == Paul Lalli <ittyspam@yahoo.com> writes:

  PL> my ($i, $word);
  PL> while ($word = <$fs>){
  PL> 	last if ++$i == 500;
  PL> }

couldn't that be just

	<$fs> for 1 .. 500 ;

for provides void context so it will read one record at a time as
defined by $/.

it could be off by 1 so that might be 1 .. 499.

uri


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

Date: 25 Mar 2004 23:20:56 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: match pattern with $ failed
Message-Id: <Xns94B7BAA7B4E50asu1cornelledu@132.236.56.8>

nickelstat@sbcglobal.net (nickelstat) wrote in 
news:21160ba4.0403251451.43c2584@posting.google.com:

> Here is an example that failed.
> ==================================
> $s1 = $s2 = '$abc'; # identical value with $ in it
> 
> if ($s1 eq $s2) {
>         print qq%"$s1" (s1) EQUALS "$s2" (s2)\n%;
> } else {
>         print qq%"$s1" (s1)  NOT = "$s2" (s2)\n%;
> }
> 
> #if ($s1 =~ /$s2/) {    # same bad result
> if ($s1 =~ m'$s2') {    # how do I tell Perl to not expand $s2?

Try:

if ($s1 =~ /\Q$s2\E/) {

instead. (See perldoc perlop).

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: Thu, 25 Mar 2004 22:10:42 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: match pattern with $ failed
Message-Id: <slrnc67ba2.mh9.tadmc@magna.augustmail.com>

nickelstat <nickelstat@sbcglobal.net> wrote:


> $s1 = $s2 = '$abc'; # identical value with $ in it

> if ($s1 =~ m'$s2') {    # how do I tell Perl to not expand $s2?
              ^   ^
              ^   ^

The way you did it right there.  :-)

But you _want_ $s2 to be interpolated, so that the regex engine
will see the 4-char string "$abc".

The match fails because $s1 does not have the 3-char string "abc"
following the end of the string.


> How do I make it recognize that '$abc' is in $s1?


I think you wanted to ask:

   How do I make the $ in '$abc' not mean "end of string"?

instead?


   if ($s1 =~ m/\Q$s2/) {


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


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

Date: Fri, 26 Mar 2004 03:14:47 GMT
From: mturner@ms.umanitoba.ca (Myron Turner)
Subject: Re: Parsing <td> tags with HTML::Parser after a certain event
Message-Id: <40639ea0.1900467798@news.wp.shawcable.net>

On Wed, 10 Mar 2004 11:38:00 -0700, Ravi Parimi
<parimi@nowhere.none.com> wrote:

>Hi,
>	I have been trying to extract the text enclosed within the <td>
>tags in a HTML page only after finding a previous <a href=...> line.
>
>The format of the HTML is as:
>
><td><a href="/?services&KeyConfig_select=test1">Key1</a></td>
><td>UserName</td>
>
>I have been able to extract test1 and Key1. What I want to do next is to
>extract UserName.
>
>Main parts of my code doing the parsing are as below:
>
>I am not sure how to add a handler for extracting the text within <td>
>following the <a href...> line. Can someone show me how to do this?
>
>Thanks in advance,
>--ravi
>
I took some time to work this out, since I'm also interested in
familiarizing myself with HTML::Parser and have used it before.  It
doesn't always work as expected.  You don't seem to be able to add
handlers for the same event, for instance, so that you can select
among handlers as needed.  And, in your code, you pass the text
handler arguments which don't get defined when the handler is called,
for instance 'tagname' -- which means you have to figure out a way to
tell the text handler what to expect.  Anyway, I tried this code on a
simple html file:

<html><head><title>Test</title><body>
<Table><td><a href="/?services&KeyConfig_select=test1">Key1</a></td>
<td>UserName Jack</td>
<td>
Something Else
</td>
<td><a href="/?services&KeyConfig_select=test2">Key2</a></td>
<td>UserName john</td>
</table></body></html>



use HTML::Parser;	
use strict;
my @data = ();
my $count = 0;


my $p = HTML::Parser->new(
           api_version => 3,
           start_h     => [\&start, "tagname, attr, attrseq, text"],
           text_h     => [\&text, "text"]
         );

$p->report_tags('a', 'td');
open(F, "test.html") || die;
$p->parse_file(*F);
$p->eof;

print "\n";
for (my $i=0; $i < scalar @data; $i++) {
  next if !$data[$i]->{href};
  foreach my $entry (keys %{$data[$i]}) {
        print "$entry: $data[$i]->{$entry}\n";
  }              
    print "\n\n";
}





sub start {
my ($tag, $attr, $attrseq, $origtext) = @_;      
return unless $tag =~/^a$/ || $tag =~/^td$/;				
$data[$count] = {};
$data[$count]->{tag} = $tag;
foreach my $at (@$attrseq) {                         
 $data[$count]->{href} =  $attr->{$at} if $at =~/^href$/;

}
}



sub text {
  my ($origtext) = @_;      

return unless $data[$count]->{tag} =~/^a$/ || $data[$count]->{tag}
=~/^td$/;
$origtext =~ s/^\s+//;
$origtext =~ s/\s+$//;
$data[$count - 1]->{username} = $origtext if $count && exists
$data[$count - 1]->{href};
$count++; 
}


Myron Turner
Myron Turner
www.room535.org


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

Date: Fri, 26 Mar 2004 03:29:14 GMT
From: LaDainian Tomlinson <go@away.spam.invalid>
Subject: Re: q: regex: parse <length><value>?
Message-Id: <esN8c.20604$Rr5.1107173@twister.southeast.rr.com>

On 2004-03-25, 'dbwood at acm dot org' <> wrote in comp.lang.perl.misc:
> Tassilo v. Parseval wrote:
>> Also sprach dbwood at acm dot org:
>> 
>> 
>>>Is there a regular expression that will extract a field value when the 
>>>field has a length indicator describing how many characters are in the 
>>>field?  e.g. 7abcd123 refers to the value abcd123 and 3abcd123 refers to abc
>>>
>>>I know that unpack() is probably a better way, but the only regular 
>>>expression we can figure out is to use something like the extended 
>>>regular espression (??{ code }) as in (concept only):
>>>
>>>qr/(\d+)(??{ qr/.{$1}/ } )/
>>>
>>>and I think using unpack() twice is faster.
>> 
>> 
>> Why using it twice? This can be done with one unpack:
>> 
>>     my $field = unpack "A/A", "3abcd123";
>> 
>> Tassilo
>
> Thanks!  Exactly.  How about a regular expression?
>
> Dave

If you're really determined to use a regexp:

  s/^(\d+)(.*)/substr($2, 0, $1)/e for my @newdata = @data;

That protects the values in @data, so if you aren't worried about that, you
can lose @newdata.  Otherwise, that's where the fields end up.

Brandan L.
-- 
bclennox \at eos \dot ncsu \dot edu


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

Date: Fri, 26 Mar 2004 00:42:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: SCALAR(0x82dea94)
Message-Id: <c3vqno$2c0vu3$1@ID-184292.news.uni-berlin.de>

Todd Anderson wrote:
> I posted this before and respondents wanted more code to help
> decipher it. So I'm posting again with code below.

First the OP posted just this message to comp.lang.perl, and I
suggested him to post here instead.

He did.

I also suggested him to enable strictures and warnings, and post a
smaller program in order to illustrate his problem.

As you have noticed, he did not follow the latter advices.

Todd: Did Anno's and Sinan's responses surprise you? Hope not.

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



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

Date: Thu, 25 Mar 2004 21:19:27 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: SCALAR(0x82dea94)
Message-Id: <slrnc6789v.m6i.tadmc@magna.augustmail.com>

A. Sinan Unur <1usa@llenroc.ude> wrote:
> Todd Anderson <todd@asgweb.net> wrote in news:40633639.5608CDF8@asgweb.net:

> Your code is pretty hard to read. Have you tried indenting it properly? 


I made that same suggestion in December 2000.

I guess it didn't take...


>> day free trial. Sometimes it puts this... SCALAR(0x82dea94)
                                             ^^^^^^^^^^^^^^^^^

That is a "stringified reference".


>> $e_number = "-1";
> 
> huh? Is $e_number a global variable? If not, scope it properly using my. 


I made that same suggestion in January 2004.

I guess it didn't take...


> And why quote it?


I made that same suggestion in January 2004.

I guess it didn't take...


>>   open (USERS, "$user_file") || &billerror
                  ^          ^
                  ^          ^

       What's wrong with always quoting "$vars"?

As was pointed out in January. Did you read that FAQ?

Even just the first sentence of it?

      The problem is that those double-quotes force stringification--
      coercing numbers and references into strings--even when you
      don't want them to be strings.


Quoting vars can cause refereneces to become stringified.

You have a stringified reference.

This could well be the cause of your problem!

Why post if you are going to ignore the responses anyway?


>>             flock(USERS, 2);


I made that same suggestion (import the constants)in January 2004.

I guess it didn't take...


>>   while (<USERS>)
>>     {
>>     $line = $_;


If you want it in $line, then put it into $line straightaway:

   while ( my $line = <USERS> )

Same as January when we reviewed this code before...


> sooo ... $e_number is numeric after all.
>  
>> if (($start eq "$e_number")..($end eq "$e_number")){


You are _still_ using the wrong operator, as was also pointed
out a couple of months ago.


Todd, do you read the followups to your posts?

Or were those followups just "rectal discharge"?


> I am lost ... I give up.


Having advice repeatedly ignored tends to make you want to
just stop giving advice.

I give up too.


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


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

Date: 25 Mar 2004 15:45:01 -0800
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Signal handling in objects.  Good idea?  Best practices?
Message-Id: <aa611a32.0403251545.2c484b80@posting.google.com>

Is it "right" to try to define signal handlers in a class, or should
this be handled elsewhere such as the implementation code?  How should
I be thinking about this problem?

I am trying to write a class where instances will execute a "cleanup"
method in response to a SIGINT.  (At this point the method is just a
single print statement).  It won't work regardless of whether I define
the handler as class data or instance data.  The signal gets caught as
evidenced by ^C not breaking the execution.  However, the cleanup
method never gets executed on the INT... stranglely, it executes once
at startup. (i have it stripped down to a single print statement). 
This is confusing, I'd figure it would either work or throw a compile
error about the subroutine not being defined.

The lack of newsgroup activity on this subject suggests that this may
be the Wrong Strategy but I thought I'd check first.

# Implementation code
#!/usr/local/bin/perl
push(@INC,".");
use Booger;
$myBoog = new Booger;
while (true) {
	print ".";
	sleep 1;
}

# Class module
package Booger;

BEGIN {
    use Exporter();
    $VERSION  = 1.00;
    @ISA      = qw(Exporter);
    @EXPORT   = qw(new gripe);
}

sub new($) {
	my $classname = shift;
	my $self = {};
	bless($self, $classname);
	warn "Created object of type $classname";
	$SIG{'INT'} = $self->gripe();
	return $self;
}

sub gripe($) {
	my $self = shift;
	print "What do you want?\n";
}
return 1;


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

Date: 26 Mar 2004 01:11:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Signal handling in objects.  Good idea?  Best practices?
Message-Id: <Xns94B7CD57C4365asu1cornelledu@132.236.56.8>

carltonbrown@hotmail.com (Carlton Brown) wrote in 
news:aa611a32.0403251545.2c484b80@posting.google.com:

> Is it "right" to try to define signal handlers in a class, or should
> this be handled elsewhere such as the implementation code?  How should
> I be thinking about this problem?

 ...

> method never gets executed on the INT... stranglely, it executes once
> at startup. 

See below. It is not that strange.

> # Implementation code
> #!/usr/local/bin/perl
> push(@INC,".");
> use Booger;
> $myBoog = new Booger;
> while (true) {
>      print ".";
>      sleep 1;
> }
> 
> # Class module
> package Booger;
> 
> BEGIN {
>     use Exporter();
>     $VERSION  = 1.00;
>     @ISA      = qw(Exporter);
>     @EXPORT   = qw(new gripe);
> }
> 
> sub new($) {
>      my $classname = shift;
>      my $self = {};
>      bless($self, $classname);
>      warn "Created object of type $classname";
>      $SIG{'INT'} = $self->gripe();

Here you assign to $SIG{'INT'} the return value of the $self->gripe() 
method call. That is why you see the statement printed once at object 
creation time.

>      return $self;
> }
> 
> sub gripe($) {
>      my $self = shift;
>      print "What do you want?\n";
> }
> return 1;

I am not going to be able to speak to design issues except to note that I 
would find it odd to have 10 different signal handlers for the same 
signal.

I also do not know the correct syntax for obtaining to references to 
methods of on object and too lazy right now to look it up. 

However, the following might help:

sub gripe {
     my $self = shift;
     return sub {
         print "What do you want?\n";
     }
}

Also, if you want to see those dots, make sure to turn autoflush on for 
STDOUT.

$| = 1;

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: 26 Mar 2004 01:21:54 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Signal handling in objects.  Good idea?  Best practices?
Message-Id: <Xns94B7CF2A53FD7asu1cornelledu@132.236.56.8>

carltonbrown@hotmail.com (Carlton Brown) wrote in 
news:aa611a32.0403251545.2c484b80@posting.google.com:

> # Implementation code
> #!/usr/local/bin/perl
> push(@INC,".");
> use Booger;
> $myBoog = new Booger;
> while (true) {

What is this?


-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: Thu, 25 Mar 2004 22:20:32 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Signal handling in objects.  Good idea?  Best practices?
Message-Id: <slrnc67bsg.mh9.tadmc@magna.augustmail.com>

A. Sinan Unur <1usa@llenroc.ude> wrote:
> carltonbrown@hotmail.com (Carlton Brown) wrote in 
> news:aa611a32.0403251545.2c484b80@posting.google.com:

>> while (true) {
> 
> What is this?


An infinite loop.



What I want to know is why "use strict" doesn't complain about it?


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


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

Date: Thu, 25 Mar 2004 22:38:50 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Signal handling in objects.  Good idea?  Best practices?
Message-Id: <slrnc67cuq.mh9.tadmc@magna.augustmail.com>

Carlton Brown <carltonbrown@hotmail.com> wrote:

> #!/usr/local/bin/perl


You should ask for all the help you can get:

   use strict;
   use warnings;


> push(@INC,".");


That happens at runtime.


> use Booger;


That happens at compile-time.

If perl needs the cwd to find Booger.pm, that isn't going to work.

   perldoc -q include

      How do I add a directory to my include path at runtime?


> while (true) {


Strings should *look like* strings, ie. with quotes.


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


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

Date: 26 Mar 2004 05:14:48 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Signal handling in objects.  Good idea?  Best practices?
Message-Id: <slrnc67f26.644.mgjv@verbruggen.comdyn.com.au>

On Thu, 25 Mar 2004 22:20:32 -0600,
	Tad McClellan <tadmc@augustmail.com> wrote:
> A. Sinan Unur <1usa@llenroc.ude> wrote:
>> carltonbrown@hotmail.com (Carlton Brown) wrote in 
>> news:aa611a32.0403251545.2c484b80@posting.google.com:
> 
>>> while (true) {
>> 
>> What is this?
> 
> 
> An infinite loop.
> 
> 
> 
> What I want to know is why "use strict" doesn't complain about it?

I believe it has something to do with constant folding and
optimisation, and strict checks happening after that. I just vaguely
recall something about that being brought up on p5p at some point in
the past.

This croaks:

use strict;
while($a = true) { }

This doesn't:

use strict;
while(true) { }


Also:

$ perl -MO=Deparse -Mstrict -e 'while ($a = true) {}'
Bareword "true" not allowed while "strict subs" in use at -e line 1.
-e had compilation errors.
while ($a = 'true') {
    ();
}

and

$ perl -MO=Deparse -Mstrict -e 'while (true) {}'
for (;;) {
    ();
}
-e syntax OK


As you can see, Perl compiles the two in totally different manners,
having removed the "constant true value" without side effects from the
statement.

Martien
-- 
                        | 
Martien Verbruggen      | +++ Out of Cheese Error +++ Reinstall
Trading Post Australia  | Universe and Reboot +++
                        | 


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

Date: Thu, 25 Mar 2004 21:47:23 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: The "value" of a block in 'map'
Message-Id: <7s57609p2604ni72o73dotnnce7r8vcbhb@library.airnews.net>

Tad McClellan <tadmc@augustmail.com> wrote:

} Bernie Cosell <bernie@fantasyfarm.com> wrote:

} >>>>            open(FOO) ? 'hi mom' : die "Can't open $FOO: $!";
} >>>>                                # a bit exotic, that last one
} >>>> 
} > 
} > Isn't "that last one" not only exotic, but incorrect???  
} 
} 
} No.
} 
} > [in fact, won't it
} > *always* 'die' regardless of whether the open works or not?]

 [...]

} Do you know how the ?: operator works?

Yes, in fact I do: but as it turns out, of all of the languages [and there
are several] that have this ternary operator, *ONLY*PERL* short-circuits
it.  In every other language I've used it in, it always acts as an
expression operator, rather than as a mini-flow-of-control one.

It is pretty cool that Perl is careful enough even to short-circuit ?:
although I'll mention that it doesn't actually *say* that in the docs - it
doesn't say it *evaluates* the arg it is choosing, but *returns* it, which
leaves moot whether the args were already evaluated or not -- for ||, for
example, it explicitly says "performs a short-circuit logical OR operation"
and given the absence of a mention of short-circuit in the description of
?: AND that its description is virtually char-for-char the way it is
described in languages that *DON'T* short-circuit it... I got mislead [and
when I did a broken test-case misinterpreted].  Mea culpa...

  /Bernie\

-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

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


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