[25142] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7391 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 11 06:05:29 2004

Date: Thu, 11 Nov 2004 03:05:06 -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, 11 Nov 2004     Volume: 10 Number: 7391

Today's topics:
    Re: Binary files in PERL? <do-not-use@invalid.net>
        FAQ 2.11: Perl Books <comdog@panix.com>
    Re: FAQ 9.16: How do I decode a CGI form? <spamtrap@dot-app.org>
    Re: FAQ 9.16: How do I decode a CGI form? <comdog@panix.com>
    Re: FAQ 9.16: How do I decode a CGI form? <ebohlman@omsdev.com>
    Re: FAQ 9.16: How do I decode a CGI form? <noreply@gunnar.cc>
    Re: Finding two strings with the same crc32 <dzluk8fsxsw0001@sneakemail.com>
    Re: How to save/restore a hash of hashes? <ebohlman@omsdev.com>
        human nature of perl (new operators etc) <iohihuh@INVALID.yahoo.com>
        Ignore undef elements for array count (David)
    Re: Ignore undef elements for array count <jurgenex@hotmail.com>
        Overloaded stringification lost (Eric)
    Re: Overloaded stringification lost (Anno Siegel)
    Re: regexp s// too greedy <lv@aol.com>
    Re: replace pattern including newline : perl version 5. <do-not-use@invalid.net>
    Re: warnings on non-text hash keys? (was Re: better way <tassilo.von.parseval@rwth-aachen.de>
        What about MD5? <ineverreadanythingsenttome@hotmail.com>
    Re: What about MD5? <sholden@flexal.cs.usyd.edu.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 11 Nov 2004 10:23:20 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Binary files in PERL?
Message-Id: <yzdvfcceo3b.fsf@invalid.net>


"Alan J. Flavell" <flavell@ph.gla.ac.uk> writes:
[about using and not using 'binmode']
> Indeed.  And of course it also makes software less portable to other 
> platforms - even in those older Perl versions.  Which might be what 
> the unix bigots were hoping - but that's hardly to be commended, in a 
> language like Perl which aims to be rather platform-neutral.

Were you feeling a little conspirational when you wrote the above?


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

Date: Thu, 11 Nov 2004 11:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 2.11: Perl Books
Message-Id: <cmvgt5$ct5$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

2.11: Perl Books

    A number of books on Perl and/or CGI programming are available. A few of
    these are good, some are OK, but many aren't worth your money. There is
    a list of these books, some with extensive reviews, at
    http://books.perl.org/ .

    The incontestably definitive reference book on Perl, written by the
    creator of Perl, is now (Sept 2004) in its third edition:

            Programming Perl (the "Camel Book"):
            by Larry Wall, Tom Christiansen, and Jon Orwant
            ISBN 0-596-00027-8  [3rd edition July 2000]
            http://www.oreilly.com/catalog/pperl3/
            (English, translations to several languages are also available)

    The companion volume to the Camel containing thousands of real-world
    examples, mini-tutorials, and complete programs is:

            The Perl Cookbook (the "Ram Book"):
            by Tom Christiansen and Nathan Torkington,
                with Foreword by Larry Wall
            ISBN 0-596-00313-7 [2nd Edition August 2003]
            http://www.oreilly.com/catalog/perlckbk2/

    If you're already a seasoned programmer, then the Camel Book might
    suffice for you to learn Perl from. If you're not, check out the Llama
    book:

            Learning Perl (the "Llama Book")
            by Randal L. Schwartz and Tom Phoenix
            ISBN 0-596-00132-0 [3rd edition July 2001]
            http://www.oreilly.com/catalog/lperl3/

    And for more advanced information on writing larger programs, presented
    in the same style as the Llama book, continue your education with the
    Alpaca book:

            Learning Perl Objects, References, and Modules (the "Alpaca Book")
            by Randal L. Schwartz, with Tom Phoenix (foreword by Damian Conway)
            ISBN 0-596-00478-8 [1st edition June 2003]
            http://www.oreilly.com/catalog/lrnperlorm/

    If you're not an accidental programmer, but a more serious and possibly
    even degreed computer scientist who doesn't need as much hand-holding as
    we try to provide in the Llama, please check out the delightful book

            Perl: The Programmer's Companion
            by Nigel Chapman
            ISBN 0-471-97563-X [1997, 3rd printing Spring 1998]
            http://www.wiley.com/compbooks/catalog/97563-X.htm
            http://www.wiley.com/compbooks/chapman/perl/perltpc.html (errata etc)

    If you are more at home in Windows the following is available (though
    unfortunately rather dated).

            Learning Perl on Win32 Systems (the "Gecko Book")
            by Randal L. Schwartz, Erik Olson, and Tom Christiansen,
                with foreword by Larry Wall
            ISBN 1-56592-324-3 [1st edition August 1997]
            http://www.oreilly.com/catalog/lperlwin/

    Addison-Wesley ( http://www.awlonline.com/ ) and Manning (
    http://www.manning.com/ ) are also publishers of some fine Perl books
    such as *Object Oriented Programming with Perl* by Damian Conway and
    *Network Programming with Perl* by Lincoln Stein.

    An excellent technical book discounter is Bookpool at
    http://www.bookpool.com/ where a 30% discount or more is not unusual.

    What follows is a list of the books that the FAQ authors found
    personally useful. Your mileage may (but, we hope, probably won't) vary.

    Recommended books on (or mostly on) Perl follow.

    References
                Programming Perl
                by Larry Wall, Tom Christiansen, and Jon Orwant
                ISBN 0-596-00027-8 [3rd edition July 2000]
                http://www.oreilly.com/catalog/pperl3/

                Perl 5 Pocket Reference
                by Johan Vromans
                ISBN 0-596-00032-4 [3rd edition May 2000]
                http://www.oreilly.com/catalog/perlpr3/

                Perl in a Nutshell
                by Ellen Siever, Stephan Spainhour, and Nathan Patwardhan
                ISBN 1-56592-286-7 [1st edition December 1998]
                http://www.oreilly.com/catalog/perlnut/

    Tutorials
                Elements of Programming with Perl
                by Andrew L. Johnson
                ISBN 1-884777-80-5 [1st edition October 1999]
                http://www.manning.com/Johnson/

                Learning Perl
                by Randal L. Schwartz and Tom Phoenix
                ISBN 0-596-00132-0 [3rd edition July 2001]
                http://www.oreilly.com/catalog/lperl3/

                Learning Perl Objects, References, and Modules
                by Randal L. Schwartz, with Tom Phoenix (foreword by Damian Conway)
                ISBN 0-596-00478-8 [1st edition June 2003]
                http://www.oreilly.com/catalog/lrnperlorm/

                Learning Perl on Win32 Systems
                by Randal L. Schwartz, Erik Olson, and Tom Christiansen,
                    with foreword by Larry Wall
                ISBN 1-56592-324-3 [1st edition August 1997]
                http://www.oreilly.com/catalog/lperlwin/

                Perl: The Programmer's Companion
                by Nigel Chapman
                ISBN 0-471-97563-X [1997, 3rd printing Spring 1998]
                http://www.wiley.com/compbooks/catalog/97563-X.htm
                http://www.wiley.com/compbooks/chapman/perl/perltpc.html (errata etc)

                Cross-Platform Perl
                by Eric Foster-Johnson
                ISBN 1-55851-483-X [2nd edition September 2000]
                http://www.pconline.com/~erc/perlbook.htm

                MacPerl: Power and Ease
                by Vicki Brown and Chris Nandor,
                    with foreword by Matthias Neeracher
                ISBN 1-881957-32-2 [1st edition May 1998]
                http://www.macperl.com/ptf_book/

    Task-Oriented
                The Perl Cookbook
                by Tom Christiansen and Nathan Torkington
                    with foreword by Larry Wall
                ISBN 1-56592-243-3 [1st edition August 1998]
                http://www.oreilly.com/catalog/cookbook/

                Effective Perl Programming
                by Joseph Hall
                ISBN 0-201-41975-0 [1st edition 1998]
                http://www.awl.com/

    Special Topics
                Mastering Regular Expressions
                by Jeffrey E. F. Friedl
                ISBN 0-596-00289-0 [2nd edition July 2002]
                http://www.oreilly.com/catalog/regex2/

            Network Programming with Perl
                by Lincoln Stein
                ISBN 0-201-61571-1 [1st edition 2001]
                http://www.awlonline.com/

            Object Oriented Perl
                Damian Conway
                    with foreword by Randal L. Schwartz
                ISBN 1-884777-79-1 [1st edition August 1999]
                http://www.manning.com/Conway/

            Data Munging with Perl
                Dave Cross
                ISBN 1-930110-00-6 [1st edition 2001]
                http://www.manning.com/cross

            Mastering Perl/Tk
                by Steve Lidie and Nancy Walsh
                ISBN 1-56592-716-8 [1st edition January 2002]
                http://www.oreilly.com/catalog/mastperltk/

                Extending and Embedding Perl
                by Tim Jenness and Simon Cozens
                ISBN 1-930110-82-0 [1st edition August 2002]
                http://www.manning.com/jenness

                Perl Debugger Pocket Reference
                by Richard Foley
                ISBN 0-596-00503-2 [1st edition January 2004]
                http://www.oreilly.com/catalog/perldebugpr/ 



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Thu, 11 Nov 2004 00:18:07 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <jqWdnVA3G-uaaw_cRVn-iw@adelphia.com>

PerlFAQ Server wrote:

>     Make sure you know whether to use a GET or a POST in your form. GETs
>     should only be used for something that doesn't update the server.
>     Otherwise you can get mangled databases and repeated feedback mail
>     messages. The fancy word for this is ``idempotency''. This simply means
>     that there should be no difference between making a GET request for a
>     particular URL once or multiple times. This is because the HTTP protocol
>     definition says that a GET request may be cached by the browser, or
>     server, or an intervening proxy. POST requests cannot be cached, because
>     each request is independent and matters. Typically, POST requests change
>     or depend on state on the server (query or update a database, send mail,
>     or purchase a computer).

It might also be worth mentioning here that the use of GET can have 
serious security implications. In a GET request form data is encoded as 
part of the URL, so it can appear in server logs, which are often world 
readable. This makes passing any kind of sensitive info via GET a Very 
Bad Idea.

sherm--

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


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

Date: Thu, 11 Nov 2004 01:39:32 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <111120040139321099%comdog@panix.com>

In article <jqWdnVA3G-uaaw_cRVn-iw@adelphia.com>, Sherm Pendley
<spamtrap@dot-app.org> wrote:

> PerlFAQ Server wrote:
> 
> >     Make sure you know whether to use a GET or a POST in your form. 

> It might also be worth mentioning here that the use of GET can have 
> serious security implications. 

We can't discuss everything in every answer. :)

-- 
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com


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

Date: 11 Nov 2004 09:45:27 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <Xns959E26D2A1A83ebohlmanomsdevcom@130.133.1.4>

PerlFAQ Server <comdog@panix.com> wrote in
news:cmurq6$82g$1@reader1.panix.com: 

> 9.16: How do I decode a CGI form?

[snip]
>     In short, they're bad hacks. Resist them at all costs. Please do
>     not be tempted to reinvent the wheel. Instead, use the CGI.pm or
>     CGI_Lite.pm (available from CPAN)

OK up to here.

> , or if you're trapped in the
>     module-free land of perl1 .. perl4, you might look into cgi-lib.pl
>     (available from http://cgi-lib.stanford.edu/cgi-lib/ ).

May I suggest that the latter clause no longer belongs in documentation for 
any recent version of Perl?


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

Date: Thu, 11 Nov 2004 11:54:40 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <2vgv25F2lgk92U1@uni-berlin.de>

PerlFAQ Server wrote:
>     You use a standard module, probably CGI.pm.

How about:

You use a module, probably the standard module CGI.pm. There are other, 
more specialised CPAN modules available, such as CGI::Lite, CGI::Fast 
and CGI::Minimal.

It's generally not advisable to use hand-written code, and please beware 
of uncritically copy one of the many code fragments for CGI parsing that 
are available on the web.

>     Under no circumstances should you attempt to do so by hand!
> 
>     You'll see a lot of CGI programs that blindly read from STDIN the number
>     of bytes equal to CONTENT_LENGTH for POSTs, or grab QUERY_STRING for
>     decoding GETs. These programs are very poorly written. They only work
>     sometimes. They typically forget to check the return value of the read()
>     system call, which is a cardinal sin. They don't handle HEAD requests.
>     They don't handle multipart forms used for file uploads. They don't deal
>     with GET/POST combinations where query fields are in more than one
>     place. They don't deal with keywords in the query string.
> 
>     In short, they're bad hacks. Resist them at all costs.

That diatribe is unprofessional, adversely affects the credibility of 
this FAQ entry, and should better be dropped. The above suggestion would 
be a sufficient replacement.

>     Please do not be
>     tempted to reinvent the wheel. Instead, use the CGI.pm or CGI_Lite.pm
>     (available from CPAN), or if you're trapped in the module-free land of
>     perl1 .. perl4, you might look into cgi-lib.pl (available from
>     http://cgi-lib.stanford.edu/cgi-lib/ ).

The above suggestion covers that part as well. It's not motivated to 
keep mentioning cgi-lib.pl.

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


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

Date: Thu, 11 Nov 2004 08:20:26 +0100
From: "Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com>
Subject: Re: Finding two strings with the same crc32
Message-Id: <cmv3rg$phv$1@news.island.liu.se>

"Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com> wrote in message
news:cmqd3k$7v6$1@news.island.liu.se...
> "Mark Shelor" <mshelor@cpan.dot.org> wrote :
> >
> > But, can you come up with an efficient Perl program that finds an input
> > string whose CRC value is 1756683253?
> >
> > Hint: I'd recommend writing it in C!  ;)
>
> Shall I write a Perl-program in C?
>
> I'm currently running this:
>
<snip code>

I've run through 2.6 billion lowercase letter combination without a hit. Is
it so that using only a subset of bytes (like 'a'-'z' == 97 - 122) I will
only have access to a subset of the CRC32 values? I thougt not. If there
still is no hit after the weekend I will start to think otherwise...

/jN

<Revised code - able to restart from last position>

use strict;
use integer;
use Digest::CRC qw(crc32);
my $string='a';
$|=1;
if (open(FILE,"<crc1756683253.log")) {
 $string=<FILE>;
 chomp($string);
 close(FILE);
}

my $t0=time();
while (1) {
 for (1..500000) {
  if (crc32($string)==1756683253) {
   my $timediff=(time()-$t0);
   print "After $timediff seconds I found this: $string\n";
   if (open(FILE,">>crc1756683253")) {
    print FILE "After $timediff seconds I found this: $string\n";
    close(FILE);
   }
  }
  $string++;
 }
 open(FILE,">crc1756683253.log") or die;
 print FILE "$string\n";
 my $number;
 my $mult=1;
 my $ex=26;
 no integer;
 for (reverse split //,$string) {
  $number+=(ord($_)-96)*$mult;
  $mult*=$ex;
 }
 $number--;
 print FILE "Now I checked $number strings!\n";
 close FILE;
 use integer;
}




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

Date: 11 Nov 2004 09:35:15 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: How to save/restore a hash of hashes?
Message-Id: <Xns959E2517DEF79ebohlmanomsdevcom@130.133.1.4>

Ben Morrow <usenet@morrow.me.uk> wrote in
news:d64762-sp5.ln1@osiris.mauzo.dyndns.org: 

> 
> Quoth "David Filmer" <ineverreadanythingsenttome@hotmail.com>:
>> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message 
>> news:cmq3sh$sf3$1@mamenchi.zrz.TU-Berlin.DE...
>> > Data::Dumper or Storable (standard modules).  FreezeThaw from CPAN.
>>
>> Awesome - thanks! A quick read-thru of Data::Dumper looks great but
>> Storable (and prehaps FreezeThaw - still figuring that one out) is
>> incredible and exactly what I need. I very much appreciate you
>> pointing me in this direction.
> 
> The only disadvantage of Storable is that it produces binary, rather
> than text, files. You did originally specify text, but may not have
> meant it.
> 
> If you decide you *do* need text files, I would recommend Data::Dump
> from CPAN rather than D:Dumper, as I find it easier to use.

And take at least a glance at YAML.


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

Date: Thu, 11 Nov 2004 10:37:10 GMT
From: "I H H" <iohihuh@INVALID.yahoo.com>
Subject: human nature of perl (new operators etc)
Message-Id: <qhHkd.29795$k4.578097@news1.nokia.com>

Hello,

perl's syntax is what it is (as I undertood correctly)  because it was
supposed to be like human languages.
Meaning a word or a phrase has context bind meaning. If context changes, the
meaning changes too.
Should there be more human nature properties in perl?

Could these be useful? At least might make scripting even more faster.

Division operator in string context would be like 'split':

@cols=split(/$expression/,$line); <=> @cols=$line/$expression;

---
open(F,$file);
@lines=<F>;
close(F);

  <=>

@lines<$file>\o /\n;

---
if($x>$y){do_something $arr[$x];}  <=>  $arr[(if($x>$y))]  cond returning
values that fill it.


---

anyone else having crazy ideas like these?




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

Date: 10 Nov 2004 22:25:42 -0800
From: davidol@hushmail.com (David)
Subject: Ignore undef elements for array count
Message-Id: <3bef037b.0411102225.618ec6cb@posting.google.com>

Dear all,

How does one get the number of non-empty elements in an array?  The
following snippet prints '3', I only want to count the non-empty
elements.

Thanks!

#!/usr/bin/perl

use strict;

local $\ = "\n";
my @arr = qw ( sissors paper undef );
print scalar @arr;


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

Date: Thu, 11 Nov 2004 06:35:42 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Ignore undef elements for array count
Message-Id: <2LDkd.5734$9u2.4985@trnddc01>

David wrote:
> How does one get the number of non-empty elements in an array?  The
> following snippet prints '3', I only want to count the non-empty
> elements.
>
> local $\ = "\n";
> my @arr = qw ( sissors paper undef );
> print scalar @arr;

But this array does not contain any undefined elements. The first element 
contains the text 'sissors', the second the text 'paper', and the third the 
text 'undef', all three of them well defined strings.

If you are talking about actual undefined values then just filter for 
defined values before counting them:

    print scalar grep defined, @arr;

jue 




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

Date: 11 Nov 2004 00:59:55 -0800
From: jain@gmx.net (Eric)
Subject: Overloaded stringification lost
Message-Id: <835c2e5d.0411110059.12febea4@posting.google.com>

It seems that if you define a custom stringification subroutine within
a package that has an AUTOLOAD subroutine, the stringification
subroutine is 'forgotten' after it has been called once (my
speculation). You can bless the object again to get the
stringification to work one more time...

The following code demonstrates the effect. Sorry for the length, I
did tried to simplify it as much as possible. I am running Perl 5.8.

use strict;
use warnings;

my $model = Model->new({type => { id => 'Foo' }});
print "1: ", $model->type, "\n"; # prints Foo
print "2: ", $model->type, "\n"; # prints Model=HASH(0x804c844)
my $type = $model->type;
bless $type, 'Model';
print "3: ", $type, "\n"; # prints Foo

package Model;

use overload '""' => \&_string;

sub new
{
	my ($class, $data) = @_;
	return bless $data,
		ref($class) || $class;
}

sub _string
{
	my ($self) = @_;
	return $self->id || '?';
}

sub AUTOLOAD
{
	(my $field = our $AUTOLOAD) =~ s/.*:://;
	no strict 'refs';
	*$field = sub { my ($self) = @_; return $self->_get($field) };
	goto &$field;
}

sub _get
{
	my ($self, $key) = @_;
	return $self->_get_scalar($self->{$key})
		if exists $self->{$key};
}

sub _get_scalar
{
		my ($self, $value) = @_;
		$value = $self->new($value)
			if (ref $value eq 'HASH');
		return $value;
}


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

Date: 11 Nov 2004 10:12:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Overloaded stringification lost
Message-Id: <cmvdup$sm3$1@mamenchi.zrz.TU-Berlin.DE>

Eric <jain@gmx.net> wrote in comp.lang.perl.misc:
> It seems that if you define a custom stringification subroutine within
> a package that has an AUTOLOAD subroutine, the stringification

No, AUTOLOAD isn't the culprit.

> subroutine is 'forgotten' after it has been called once (my
> speculation). You can bless the object again to get the
> stringification to work one more time...
> 
> The following code demonstrates the effect. Sorry for the length, I
> did tried to simplify it as much as possible. I am running Perl 5.8.

Your Model class is, frankly, a mess.  The accessors (autoloaded or
not), try to pull a hashref out of the object and *bless* that into
the same class the object is from.  That is, to put it mildly, an
unusual action for an accessor.  The purpose of an accessor is to
get at the components of an object, not to present you with new
objects of the same type.

Also, your implementation of ->new must be the most generic one
I have ever seen. It simply blesses any scalar you give it into
any class you give it.  A little sanity checking would be in order.

For the problem at hand, I haven't fully analyzed what's happening,
but the problem is not AUTOLOAD.

In the test code, OVERLOAD is activated twice, once to create the
accessor ->type, and another time (already in overload) to create
the accessor ->id.  To see that AUTOLOAD is not the source of your
problem, pre-define the two accessors the way AUTOLOAD would:

    sub type { $_[ 0]->_get( 'type') }
    sub id { $_[ 0]->_get( 'id') }

After that, your test code doesn't call AUTOLOAD (rename it to
AUTOLOAD_off to be sure), but the behavior is the same.

My advice:  Check the design of class Model, in particular the
action of your proposed accessors.  If you're sure they do what
you want them to do, implement and debug the class *without*
AUTOLOAD.  You'll need some scaffolding for that to pre-define
the accessors AUTOLOAD would otherwise create.  Introduce
AUTOLOAD only after you're sure everything works as intended.

Anno

[code for reference]

> use strict;
> use warnings;
> 
> my $model = Model->new({type => { id => 'Foo' }});
> print "1: ", $model->type, "\n"; # prints Foo
> print "2: ", $model->type, "\n"; # prints Model=HASH(0x804c844)
> my $type = $model->type;
> bless $type, 'Model';
> print "3: ", $type, "\n"; # prints Foo
> 
> package Model;
> 
> use overload '""' => \&_string;
> 
> sub new
> {
> 	my ($class, $data) = @_;
> 	return bless $data,
> 		ref($class) || $class;
> }
> 
> sub _string
> {
> 	my ($self) = @_;
> 	return $self->id || '?';
> }
> 
> sub AUTOLOAD
> {
> 	(my $field = our $AUTOLOAD) =~ s/.*:://;
> 	no strict 'refs';
> 	*$field = sub { my ($self) = @_; return $self->_get($field) };
> 	goto &$field;
> }
> 
> sub _get
> {
> 	my ($self, $key) = @_;
> 	return $self->_get_scalar($self->{$key})
> 		if exists $self->{$key};
> }
> 
> sub _get_scalar
> {
> 		my ($self, $value) = @_;
> 		$value = $self->new($value)
> 			if (ref $value eq 'HASH');
> 		return $value;
> }




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

Date: Wed, 10 Nov 2004 23:27:29 -0600
From: l v <lv@aol.com>
Subject: Re: regexp s// too greedy
Message-Id: <4192f5e7$1_5@127.0.0.1>

bettyann wrote:
> hi all,
> 
> can anyone help me limit the greediness of my substitution pattern?  i
> have a CSV file and i want to insert a new column of values after the
> 6th column.  but the new data to be inserted is dependent upon the
> value of the 6th column.
> 
> example original data:
> 2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1 
> 1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1 
> 5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1 
> 8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1 
> 
> i want to put "0" after the 6th column if the 6th column contains
> "hold.bmp".
> i want to put "-1" after the 6th column if the 6th column contains
> "NaN".
> 
> i thought i could do this with two substitutions commands:
> 
> s/^((.*?,){5}?(hold.bmp))/$1,0/
> s/^((.*?,){5}?(NaN))/$1,-1/
> 
> i cannot limit the matching of "hold.bmp" or "NaN".  i want this
> pattern to match *only* if "hold.bmp" or "NaN" immediately follows the
> 5th column.
> 
> my test code:
> #!/usr/local/bin/perl
> 
> use strict;
> use warnings;
> 
> my $input = <<EOF;
> 2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1
> 1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1
> 5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1
> 8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1
> EOF
> 
> my @oData = split( '\n', $input );
> my $line;
> my $cnt = 0;
> foreach $line ( @oData ) {
>    printf( "$cnt)  $line \n" );
>    $cnt++;
> }
> 
> my $prevCol = 5;
> my @txtList = ( "hold.bmp",   "NaN" );
> my @valList = ( "0",          "-1" );
> my ( $txt, $cmd, $i );
> $i = 0;
> foreach $txt ( @txtList ) {
>    $cmd = sprintf( '$line =~ s/^((.*?,){%d}?(%s))/$1,%s/;',
>       $prevCol, $txt, $valList[$i] );
>    printf( "\ncmd >>$cmd<< \n" );
>    foreach $line ( @oData ) {
>       printf( "orig line |$line| \n" );
>       eval $cmd;
>       printf( " new line |$line| \n---------------------\n" );
>    }
>    $i++;
> }
> 
> exit;
> 
> output:
> % test2.pl
> 0)  2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1 
> 1)  1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1 
> 2)  5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1 
> 3)  8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1 
> 
> cmd >>$line =~ s/^((.*?,){5}?(hold.bmp))/$1,0/;<< 
> orig line |2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
>  new line |2,NaN,NaN,NaN,64,hold.bmp,0,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
> ---------------------
> orig line |1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1|
>  new line |1,NaN,NaN,NaN,32,hold.bmp,0,1607488,NaN,NaN,NaN,hold.bmp,3,1|
> ---------------------
> orig line |5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1| 
>  new line |5,NaN,NaN,4,32,hold.bmp,0,1607503,NaN,NaN,8,go.bmp,NaN,1| 
> ---------------------
> orig line |8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1| 
>  new line |8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,0,NaN,1| 
> ---------------------
> 
> cmd >>$line =~ s/^((.*?,){5}?(NaN))/$1,-1/;<< 
> orig line |2,NaN,NaN,NaN,64,hold.bmp,0,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
>  new line |2,NaN,NaN,NaN,64,hold.bmp,0,1607444,NaN,-1,NaN,NaN,hold.bmp,NaN,1|
> ---------------------
> orig line |1,NaN,NaN,NaN,32,hold.bmp,0,1607488,NaN,NaN,NaN,hold.bmp,3,1|
>  new line |1,NaN,NaN,NaN,32,hold.bmp,0,1607488,NaN,-1,NaN,NaN,hold.bmp,3,1|
> ---------------------
> orig line |5,NaN,NaN,4,32,hold.bmp,0,1607503,NaN,NaN,8,go.bmp,NaN,1| 
>  new line |5,NaN,NaN,4,32,hold.bmp,0,1607503,NaN,-1,NaN,8,go.bmp,NaN,1|
> ---------------------
> orig line |8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,0,NaN,1| 
>  new line |8,NaN,NaN,4,32,NaN,-1,1607564,NaN,NaN,8,hold.bmp,0,NaN,1| 
> ---------------------
> 
> thanks,
> - bettyann

How about splitting the line on comma's, analyzing the 6th column, then 
joining the line back together?

like ....

#!/usr/local/bin/perl

use strict;
use warnings;

my $input = <<EOF;
2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1
1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1
5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1
8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1
EOF

my @oData = split( '\n', $input );
my $line;
my $cnt = 0;
foreach $line ( @oData ) {
    printf( "$cnt)  $line \n" );
    $cnt++;
}

foreach $line ( @oData ) {
   my @cols = split(',', $line);
   my $newCol = ($cols[5] =~ m/hold.bmp/) ? '0' : '-1';
   my $newLine = join(',', (@cols)[0..5], $newCol, (@cols)[6..$#cols]);
   printf( "orig line |$line| \n" );
   printf( " new line |$newLine| \n---------------------\n" );
}

exit;

output:
0)  2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1
1)  1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1
2)  5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1
3)  8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1
orig line |2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
  new line |2,NaN,NaN,NaN,64,hold.bmp,0,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
---------------------
orig line |1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1|
  new line |1,NaN,NaN,NaN,32,hold.bmp,0,1607488,NaN,NaN,NaN,hold.bmp,3,1|
---------------------
orig line |5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1|
  new line |5,NaN,NaN,4,32,hold.bmp,0,1607503,NaN,NaN,8,go.bmp,NaN,1|
---------------------
orig line |8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1|
  new line |8,NaN,NaN,4,32,NaN,-1,1607564,NaN,NaN,8,hold.bmp,NaN,1|
---------------------

Len


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: 11 Nov 2004 10:14:36 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: replace pattern including newline : perl version 5.8
Message-Id: <yzdzn1oeohv.fsf@invalid.net>


gsprince@gmail.com (Prince) writes:
> 
> The given solution works perfect. What does -073 option do?

Let 'perl' tell you:

        % perl -h

        Usage: perl [switches] [--] [programfile] [arguments]
          -0[octal]       specify record separator (\0, if no argument)

So let it tell us what character has the code 073:

        % perl -e 'print "(\073)\n"'

        (;)


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

Date: Thu, 11 Nov 2004 06:10:56 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: warnings on non-text hash keys? (was Re: better way using IO::Select and pool of non-blockig socks)
Message-Id: <slrncp5t30.qq.tassilo.von.parseval@localhost.localdomain>

Also sprach Stuart Moore:

> Stuart Moore wrote:
>
>> Andrew Tkachenko wrote:
>> 
>>> Sorry, mistaken a bit.
>>> I've meant:
>>>
>>>  %socks = ();
>>>  for (0 .. 10) {
>>>          my $sock = new IO::Socket::INET(..);
>>>          $socks{$sock} = $_;
>>>  }
>>>
>> 
>> Without Tie::RefHash, any hash keys are strings, so the key would be a 
>> stringified version of the reference to the socket. This might well seem 
>> to work for most stuff, if something else (IO::Select for example) is 
>> keeping a copy of the socket, but e.g. you won't be able to use the 
>> output of 'keys' as a reference to the socket.
>
> Just a thought, would attempting to use a reference as a hash key be a 
> suitable thing to mention when "use warnings;" is on? Neither warnings 
> nor diagnostics seems to do anything

And they better don't. It's perfectly ok to use a reference as a
hash-key. Andrew's suggestion does make quite a bit of sense and I used
a similar approach in a select-loop in one of my programs. I had the
reference both as key and value. When a filehandle became readable and
the program read a sign-off string from it, all I had to do was

    while (<$fh>) {
	...
	if (/^q$/) {
	    $select->remove($sockets{ $fh });
	    ...
	}
    }

Most of the time you need the key as a lookup-means. For that it doesn't
matter that you cannot really do anyting useful with the key itself. For
that you have the value. And your complain that you cannot use 'keys' to
get references to the handle is moot in this setup, too: You just use
'values' to achieve the same.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 11 Nov 2004 00:00:53 -0800
From: "David Filmer" <ineverreadanythingsenttome@hotmail.com>
Subject: What about MD5?
Message-Id: <JP-dnR_66sqOgA7cRVn-uw@comcast.com>

This is interesting. If I may follow up (though I realize it's getting OT; I 
beg your indulgence)...

What about MD5? I am of the opinion that it is infeaseable to find two 
strings that share the same MD5 digest (without taking a hundred million 
(billion? trillion?) years or so to do it). Would anyone in the group 
disagree?




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

Date: 11 Nov 2004 09:03:06 GMT
From: Sam Holden <sholden@flexal.cs.usyd.edu.au>
Subject: Re: What about MD5?
Message-Id: <slrncp6ama.7i5.sholden@flexal.cs.usyd.edu.au>

On Thu, 11 Nov 2004 00:00:53 -0800,
	David Filmer <ineverreadanythingsenttome@hotmail.com> wrote:
> This is interesting. If I may follow up (though I realize it's getting OT; I 
> beg your indulgence)...
>
> What about MD5? I am of the opinion that it is infeaseable to find two 
> strings that share the same MD5 digest (without taking a hundred million 
> (billion? trillion?) years or so to do it). Would anyone in the group 
> disagree?

Yes.

http://www.tcs.hut.fi/~mjos/md5/

-- 
Sam Holden


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

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


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