[28206] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9570 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 7 09:05:54 2006

Date: Mon, 7 Aug 2006 06: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           Mon, 7 Aug 2006     Volume: 10 Number: 9570

Today's topics:
        About Object-Oriented Perl <zhushenli@gmail.com>
    Re: About Object-Oriented Perl anno4000@radom.zrz.tu-berlin.de
    Re: About Object-Oriented Perl usenet@DavidFilmer.com
    Re: foreach aliasing, my variables, and visibility in s anno4000@radom.zrz.tu-berlin.de
    Re: how to "anonymize" Perl script before publishing it <nobody@dizum.com>
    Re: How to "convert" a string into a variable name? <mritty@gmail.com>
        How to use OO and package? <zhushenli@gmail.com>
    Re: How to use OO and package? <john@castleamber.com>
    Re: How to use OO and package? anno4000@radom.zrz.tu-berlin.de
    Re: How to use OO and package? <zhushenli@gmail.com>
    Re: How to use OO and package? anno4000@radom.zrz.tu-berlin.de
    Re: How to use OO and package? <bik.mido@tiscalinet.it>
    Re: How to use OO and package? <zhushenli@gmail.com>
    Re: How to use OO and package? (Marc Espie)
    Re: perl regular expression help anno4000@radom.zrz.tu-berlin.de
    Re: perl regular expression help uttamhoode@gmail.com
    Re: Perl script does nt parses d entire excel file plea <zen13097@zen.co.uk>
    Re: Perl script does nt parses d entire excel file plea <suvratj@gmail.com>
    Re: Printing "" and $iIN <scobloke2@infotop.co.uk>
        Public/Private Data/Funcion in Perl OO? <zhushenli@gmail.com>
    Re: Public/Private Data/Funcion in Perl OO? anno4000@radom.zrz.tu-berlin.de
    Re: Simple file list in directory to array <rprp@gmx.net>
    Re: Simple file list in directory to array <bik.mido@tiscalinet.it>
    Re: Simple file list in directory to array <jue@monster-berlin.de>
    Re: Using s///g to remove carriage returns <josef.moellers@fujitsu-siemens.com>
    Re: Using s///g to remove carriage returns <a24061@yahoo.com>
        What bless() do actually? <zhushenli@gmail.com>
    Re: What bless() do actually? anno4000@radom.zrz.tu-berlin.de
    Re: What bless() do actually? <bik.mido@tiscalinet.it>
    Re: What bless() do actually? <David.Squire@no.spam.from.here.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 7 Aug 2006 01:02:58 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: About Object-Oriented Perl
Message-Id: <1154937778.694235.235430@p79g2000cwp.googlegroups.com>

Hi all,

I am a Perl newbie and familiar with subroutine and reference. And I
want to use Perl's OO feature to encapsulate the private data and
private function. I just need the encapsulation and don't need
inheritance.
And I read perlboot and perltoot, but it is too complex for me. Is
there any simple but complete tutorial and example on encapsulation
feature of Perl's OO?

Thanks!
Davy



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

Date: 7 Aug 2006 08:28:16 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: About Object-Oriented Perl
Message-Id: <4jobt0F8jiu1U1@news.dfncis.de>

Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:
> Hi all,
> 
> I am a Perl newbie and familiar with subroutine and reference. And I
> want to use Perl's OO feature to encapsulate the private data and
> private function. I just need the encapsulation and don't need
> inheritance.
> And I read perlboot and perltoot, but it is too complex for me. Is
> there any simple but complete tutorial and example on encapsulation
> feature of Perl's OO?

There's a lot more literature on Perl OO, but it doesn't get less
complex than perltoot.  Build the Person class described in it and
play with it.

For a comprehensive treatment see _Object Oriented Perl_ by Damian
Conway.

Anno


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

Date: 7 Aug 2006 01:52:00 -0700
From: usenet@DavidFilmer.com
Subject: Re: About Object-Oriented Perl
Message-Id: <1154940720.729126.22860@h48g2000cwc.googlegroups.com>

Davy wrote:
> And I read perlboot and perltoot, but it is too complex for me.

I also did not find these tutorials very helpful.  Others have, but not
everybody benefits equally from the same material.  There's more than
one way to explain it.

I think you might benefit (as did I) from Chapter 11 of Simon Cozens'
book, "Beginning Perl" which you may read online for free (legally) in
Acrobat format at

   http://www.perl.org/books/beginning-perl

When I read this, the whole OO thing finally 'clicked' for me.  You
might find other chapters informative as well.

Welcome to Perl - you won't regret learning it.

-- 
David Filmer (http://DavidFilmer.com)



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

Date: 7 Aug 2006 11:42:05 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: foreach aliasing, my variables, and visibility in sub
Message-Id: <4jon8dF91s0vU1@news.dfncis.de>

Stephan Titard  <sgt19DELCAPS@tidNOSPAM.es> wrote in comp.lang.perl.misc:
> Ben Morrow escribió:
> > Quoth sgt19DELCAPS@tidNOSPAM.es:

[...]

> compare
> 
> my $sub = sub {...};
> my *glob = \&$sub;

"*glob" can't be a lexical, "my" has got to go.

Otherwise, "*glob = \&$sub" is exactly the same as "*glob = $sub", you're
just de-referencing and taking a new reference.

Okay, $sub could be overloading "&{}", in which case it would make a
difference.

> vs
> 
> *glob = sub {...};
> 
> Besides the fact it is not a useful closure do you see actually
> something wrong in using that...I have been using this for years
> without any negative side-effect so far...

Both do the same thing, except for the overload-exception.

Anno


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

Date: Mon,  7 Aug 2006 14:10:06 +0200 (CEST)
From: Nomen Nescio <nobody@dizum.com>
Subject: Re: how to "anonymize" Perl script before publishing it?
Message-Id: <e1c2e8e28240852b6b71803e82b87c28@dizum.com>

allenjo5@mail.northgrum.com wrote:

> You might also want to look at B::Deparse:
> 
>   perl -MO=Deparse yourprogram.pl
> 
> It reads the bytecode perl produces and creates a perl program out of
> it.

Yes, thanks!




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

Date: 7 Aug 2006 05:29:15 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How to "convert" a string into a variable name?
Message-Id: <1154953755.498912.323220@p79g2000cwp.googlegroups.com>

perlistpaul wrote:
> I give suggestion, but not mean I adhesive with it.

I have *no* idea what that means.  Clearly, English is not your first
language, and that's fine.  But the above is gibberish.  "Adhesive"
means sticky, as in tape or glue.


> Symbolic reference is considered dangerous

Yes.

> Alternative is soft reference

Uh.  No.  "Soft reference" is a synonym for "symbolic reference".  Two
different terms for the same thing.

Paul Lalli



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

Date: 7 Aug 2006 01:55:25 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: How to use OO and package?
Message-Id: <1154940925.413313.198460@p79g2000cwp.googlegroups.com>

Hi all,

I have write a simple program of OO and package.
But Cow-speak; seems not work right? Thanks!

#-----test.pl---
#! /usr/local/bin/perl
use strict;
use warnings;

use Cow ();
Cow->speak;

#-----Cow.pm---
#! /usr/local/bin/perl
use strict;
use warnings;

{
   package Cow;
   sub sound {"My god"}
   sub speak {
       my $class = shift;
       print"a $class say hello\n", $class->sound,"\n";
   }
}



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

Date: 7 Aug 2006 09:02:11 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How to use OO and package?
Message-Id: <Xns9818290E86680castleamber@130.133.1.4>

"Davy" <zhushenli@gmail.com> wrote:

> Hi all,
> 
> I have write a simple program of OO and package.
> But Cow-speak; seems not work right?

Describe what "not work right" means. Do you get an error/warning? Copy 
paste it.


-- 
John Bokma          Freelance software developer
                                &
                    Experienced Perl programmer: http://castleamber.com/


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

Date: 7 Aug 2006 09:09:18 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How to use OO and package?
Message-Id: <4joe9uF913tcU1@news.dfncis.de>

Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:
> Hi all,
> 
> I have write a simple program of OO and package.
> But Cow-speak; seems not work right? Thanks!

Cow->speak isn't even called, your script fails at compile time
at "use Cow;".

You only need "use" when the module is in a different file.  The
Cow class is defined inside your file, so scratch "use".  Cow->speak
works as well as can be expected.

Anno

> 
> #-----test.pl---
> #! /usr/local/bin/perl
> use strict;
> use warnings;
> 
> use Cow ();
> Cow->speak;
> 
> #-----Cow.pm---
> #! /usr/local/bin/perl
> use strict;
> use warnings;
> 
> {
>    package Cow;
>    sub sound {"My god"}
>    sub speak {
>        my $class = shift;
>        print"a $class say hello\n", $class->sound,"\n";
>    }
> }
> 




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

Date: 7 Aug 2006 02:45:37 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: Re: How to use OO and package?
Message-Id: <1154943937.504378.302020@75g2000cwc.googlegroups.com>

Hi,

I seperate the Cow.pm file and the calling test.pl file. For I want the
pm file not changed by other programmer.
The error is
Cow.pm did not return a true value at test.pl line 5.
BEGIN failed--compilation aborted at test.pl line 5.

Thanks!
Davy

anno4000@radom.zrz.tu-berlin.de wrote:
> Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:
> > Hi all,
> >
> > I have write a simple program of OO and package.
> > But Cow-speak; seems not work right? Thanks!
>
> Cow->speak isn't even called, your script fails at compile time
> at "use Cow;".
>
> You only need "use" when the module is in a different file.  The
> Cow class is defined inside your file, so scratch "use".  Cow->speak
> works as well as can be expected.
>
> Anno
>
> >
> > #-----test.pl---
> > #! /usr/local/bin/perl
> > use strict;
> > use warnings;
> >
> > use Cow ();
> > Cow->speak;
> >
> > #-----Cow.pm---
> > #! /usr/local/bin/perl
> > use strict;
> > use warnings;
> >
> > {
> >    package Cow;
> >    sub sound {"My god"}
> >    sub speak {
> >        my $class = shift;
> >        print"a $class say hello\n", $class->sound,"\n";
> >    }
> > }
> >



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

Date: 7 Aug 2006 09:54:57 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How to use OO and package?
Message-Id: <4jogvhF8p65hU1@news.dfncis.de>

Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:

[Please don't top-post.  I put your reply in context]

> anno4000@radom.zrz.tu-berlin.de wrote:
> > Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:
> > > Hi all,
> > >
> > > I have write a simple program of OO and package.
> > > But Cow-speak; seems not work right? Thanks!
> >
> > Cow->speak isn't even called, your script fails at compile time
> > at "use Cow;".
> >
> > You only need "use" when the module is in a different file.  The
> > Cow class is defined inside your file, so scratch "use".  Cow->speak
> > works as well as can be expected.
>
> Hi,
> 
> I seperate the Cow.pm file and the calling test.pl file. For I want the
> pm file not changed by other programmer.
> The error is
> Cow.pm did not return a true value at test.pl line 5.
> BEGIN failed--compilation aborted at test.pl line 5.

If you get a Perl message you don't understand, put "use diagnostics"
near the beginning of your program.  It will add explanations to the
messages.

Anno


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

Date: 7 Aug 2006 12:13:27 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How to use OO and package?
Message-Id: <bf4ed2148o6k5tgam0j3j5babalt5e5lkl@4ax.com>

On 7 Aug 2006 01:55:25 -0700, "Davy" <zhushenli@gmail.com> wrote:

>#-----Cow.pm---
>#! /usr/local/bin/perl
>use strict;
>use warnings;
>
>{
>   package Cow;
>   sub sound {"My god"}
>   sub speak {
>       my $class = shift;
>       print"a $class say hello\n", $class->sound,"\n";
>   }
>}

Since you put your package in a separate module, you should return a
true value, i.e. customarily

  1;

at the end for the use() statement to succeed.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 7 Aug 2006 03:44:18 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: Re: How to use OO and package?
Message-Id: <1154947458.235974.226090@b28g2000cwb.googlegroups.com>

Hi,

Thanks! But why the program need a return value, what's the function
means??

Davy

Michele Dondi wrote:
> On 7 Aug 2006 01:55:25 -0700, "Davy" <zhushenli@gmail.com> wrote:
>
> >#-----Cow.pm---
> >#! /usr/local/bin/perl
> >use strict;
> >use warnings;
> >
> >{
> >   package Cow;
> >   sub sound {"My god"}
> >   sub speak {
> >       my $class = shift;
> >       print"a $class say hello\n", $class->sound,"\n";
> >   }
> >}
>
> Since you put your package in a separate module, you should return a
> true value, i.e. customarily
>
>   1;
>
> at the end for the use() statement to succeed.
>
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,



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

Date: Mon, 7 Aug 2006 11:51:04 +0000 (UTC)
From: espie@lain.home (Marc Espie)
Subject: Re: How to use OO and package?
Message-Id: <eb79f8$c47$1@biggoron.nerim.net>

In article <1154947458.235974.226090@b28g2000cwb.googlegroups.com>,
Davy <zhushenli@gmail.com> wrote:
>Hi,
>
>Thanks! But why the program need a return value, what's the function
>means??

Because packages may do stuff besides defining methods, and they need
a way to report success/failure.

That's the API that was chosen, a .pm file must return a true value
if it's successful.


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

Date: 7 Aug 2006 07:17:46 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: perl regular expression help
Message-Id: <4jo7oqF8rfr0U1@news.dfncis.de>

 <uttamhoode@gmail.com> wrote in comp.lang.perl.misc:
> hi all,
>    i have around 100 perl CGI scripts in which i want to delete some
> string.
> 
> String is  $abc::message{M001}   i want to remove $abc::message{ } so
> that the string becomes M001.
> 
> if i get regular expression for the above i will change the files using
> PERL command line

So what have you tried and how does it fail to do what you want?

Anno


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

Date: 7 Aug 2006 01:25:34 -0700
From: uttamhoode@gmail.com
Subject: Re: perl regular expression help
Message-Id: <1154939134.744766.277400@m73g2000cwd.googlegroups.com>

got the solution

perl -pi -w -e 's/\$abc::message{(\D\d\d\d)}/$1/g;' *.cgi

this will replace all $abc::message{xxx} to xx

before it didnt work because i gave escape sequence to some special
charatcers

 ....like this

perl -pi -w -e 's/\$abc\:\:message\{(\D\d\d\d)\}/$1/g;' *.cgi

Regards,
uttam hoode


anno4000@radom.zrz.tu-berlin.de wrote:

> <uttamhoode@gmail.com> wrote in comp.lang.perl.misc:
> > hi all,
> >    i have around 100 perl CGI scripts in which i want to delete some
> > string.
> >
> > String is  $abc::message{M001}   i want to remove $abc::message{ } so
> > that the string becomes M001.
> >
> > if i get regular expression for the above i will change the files using
> > PERL command line
>
> So what have you tried and how does it fail to do what you want?
> 
> Anno



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

Date: 07 Aug 2006 08:36:59 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: Perl script does nt parses d entire excel file please help
Message-Id: <44d6fbab$0$15050$db0fefd9@news.zen.co.uk>

On 4 Aug 2006 01:42:17 -0700, neo <suvratj@gmail.com> wrote:
 ...
>      for($i=1;$i<=$oWkS->{MaxRow};$i++)
 ...
>              for($j=0;$i<=$oWkS->{MaxRow};$i++)

Apart from the fact that the 2nd statement should probably be using $j
instead of $i (as someone else pointed out), did you mean to start the
one loop from 1, and the other from 0?  Looks a little odd to me.

This sort of thing is better written:

	for my $i (1 .. $oWkS->{MaxRow}) 
	    ...



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

Date: 7 Aug 2006 04:50:21 -0700
From: "neo" <suvratj@gmail.com>
Subject: Re: Perl script does nt parses d entire excel file please help
Message-Id: <1154951421.662805.271610@75g2000cwc.googlegroups.com>

Thank you guys for all the inputs but now it i working fine.




Dave Weaver wrote:
> On 4 Aug 2006 01:42:17 -0700, neo <suvratj@gmail.com> wrote:
> ...
> >      for($i=1;$i<=$oWkS->{MaxRow};$i++)
> ...
> >              for($j=0;$i<=$oWkS->{MaxRow};$i++)
>
> Apart from the fact that the 2nd statement should probably be using $j
> instead of $i (as someone else pointed out), did you mean to start the
> one loop from 1, and the other from 0?  Looks a little odd to me.
>
> This sort of thing is better written:
> 
> 	for my $i (1 .. $oWkS->{MaxRow}) 
> 	    ...



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

Date: Mon, 07 Aug 2006 11:48:13 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Printing "" and $iIN
Message-Id: <kPGdndWLwb_zh0rZRVny3g@bt.com>

vedpsingh@gmail.com wrote:
<snip>
> For this I have written the code given below:
> --------------------------------------------------------
> 
> use strict; # important pragma
> use warnings; # another important pragma

When I'm learning a new language, I tend to deliberately over-comment as 
  reminder to myself of elementary concepts. This seems to be what you 
are doing. When posting to a newsgroup I'd consider whether that level 
of commenting is appropriate to my audience.

I'd also aim for something a bit more informative.
   use strict; # Restrict unsafe constructs

> 
> print "Enter value of instantiations ? "; # print out the question
> 
> my $i;        # \declare" the variable

I'd get into the habit of explaining the *purpose* of the variable not 
simply restating the statement in English. I find that choosing 
descriptive variable names can be more helpful than adding comments.

<snip>


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

Date: 7 Aug 2006 03:40:33 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: Public/Private Data/Funcion in Perl OO?
Message-Id: <1154947233.194037.208430@b28g2000cwb.googlegroups.com>

Hi all,

I am a C++ programmer and new to Perl.
Is there some equal idea like Public/Private Data/Funcion in Perl OO?
I found the tutorial provided by Perldoc show all the Data is public??

Thanks!
Davy



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

Date: 7 Aug 2006 10:50:34 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Public/Private Data/Funcion in Perl OO?
Message-Id: <4jok7qF8spemU2@news.dfncis.de>

Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:
> Hi all,
> 
> I am a C++ programmer and new to Perl.
> Is there some equal idea like Public/Private Data/Funcion in Perl OO?
> I found the tutorial provided by Perldoc show all the Data is public??

Right about methods (and subs in general).  There is only the convention
to let the names of private methods begin with an underscore (_private).
That doesn't stop anyone from using them, but at least they'll know they
are doing something wrong.

Data stored in lexical variables are inaccessible from outside their scope
so they are truly private.  This is not true for package variables.

Anno


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

Date: Mon, 07 Aug 2006 09:51:07 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Simple file list in directory to array
Message-Id: <44d6f0ec$0$15793$14726298@news.sunsite.dk>

darkmoo wrote:
> Thanks to all that have helped with my previous question.  
> 
> Now one more question. I've completely forgetten how to grab a list of all
> files in a directory and load it up into an array. 
> 
> Im not a full time perl programmer so always returning back to te learning
> curve on the same topics :( 
> 
> Any help would be greatly appreciated.

Look at opendir,readdir,closedir or use the module File::Find (have to
fill the array _manualy_).

regards,
Reinhard


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

Date: 7 Aug 2006 10:02:15 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Simple file list in directory to array
Message-Id: <qrsdd29h8dd6s3dnbi9kcjhvvhdrk1va40@4ax.com>

On Mon, 07 Aug 2006 16:01:10 +1000, in comp.lang.perl.misc you wrote:

>Thanks to all that have helped with my previous question.  
>
>Now one more question. I've completely forgetten how to grab a list of all
>files in a directory and load it up into an array. 

  perldoc -f opendir
  perldoc -f readdir

and perhaps

  perldoc -f glob

which may be appropriate for your case.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 7 Aug 2006 01:02:55 -0700
From: "Thomas J." <jue@monster-berlin.de>
Subject: Re: Simple file list in directory to array
Message-Id: <1154937775.607410.44560@b28g2000cwb.googlegroups.com>

darkmoo schrieb:

>
> Now one more question. I've completely forgetten how to grab a list of all
> files in a directory and load it up into an array.
>

perl -e 'opendir($d,".");print join "\n", grep -f,readdir($d); close
$d;'

> Im not a full time perl programmer so always returning back to te learning
> curve on the same topics :(
>

There is a great way where you can start to get information about
perlfunctions:

perldoc perlfunc

the functions are arranged according to topics

Thomas



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

Date: Mon, 07 Aug 2006 10:33:16 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Using s///g to remove carriage returns
Message-Id: <eb6u0l$f04$1@nntp.fujitsu-siemens.com>

Jason wrote:
> I've gone through about a dozen options, and none of them work
> correctly! This is driving me nuts.
>=20
> The request is pretty simple: I have a form with a textarea field, and
> I want to remove any opening or trailing carriage returns from it
> (while leaving any return in the middle). This is the code I tried most=

> recently, and was certain would work:
>=20
> $comment =3D~ s/^\r\n+|^\r+|^\n+|\r\n+$|\r+$|\n+$//g;
>=20
> But, it doesn't seem to have any impact at all! Correct me if I'm
> wrong, but I thought that this broke down like:

> Do you guys see what I'm overlooking?

In a nutshell: the precedence of operators (concatenation is an=20
operator) in regular expressions.

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Mon, 7 Aug 2006 10:36:59 +0100
From: Adam Funk <a24061@yahoo.com>
Subject: Re: Using s///g to remove carriage returns
Message-Id: <r6ejq3-rdu.ln1@news.ducksburg.com>

On 2006-08-05, Jason <jwcarlton@gmail.com> wrote:

> The request is pretty simple: I have a form with a textarea field, and
> I want to remove any opening or trailing carriage returns from it
> (while leaving any return in the middle). This is the code I tried most
> recently, and was certain would work:
>
> $comment =~ s/^\r\n+|^\r+|^\n+|\r\n+$|\r+$|\n+$//g;

I think the easiest way to do this is in two steps:

  $comment =~ s/^[\r\n]+//;
  $comment =~ s/[\r\n]+$//;

I'm assuming that you want to delete all "carriage returns" and
"newlines" from the beginning and end, without distinguishing between
the two things.


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

Date: 7 Aug 2006 02:53:03 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: What bless() do actually?
Message-Id: <1154944382.802093.9860@h48g2000cwc.googlegroups.com>

Hi all,

I am new to Perl OO.

I found I have to bless($self) in new subroutine. If not do that, there
is a error: "can't call method on unblessed methods".

I guess if it is before bless($self), only private data pointer to
$self; and after bless($self), method pointer to $self. Is it right? If
not, please give me some intuitive explaination on bless, thanks!

Davy



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

Date: 7 Aug 2006 10:07:53 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: What bless() do actually?
Message-Id: <4johnpF8spemU1@news.dfncis.de>

Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:
> Hi all,
> 
> I am new to Perl OO.
> 
> I found I have to bless($self) in new subroutine. If not do that, there
> is a error: "can't call method on unblessed methods".
> 
> I guess if it is before bless($self), only private data pointer to
> $self; and after bless($self), method pointer to $self. Is it right?

It is neither right nor wrong, it's nonsense.  You are making up
the terms "private data pointer" and "method pointer" to explain
things, but these terms have no common meaning and explain nothing.

> If
> not, please give me some intuitive explaination on bless, thanks!

Bless() associates a reference (actually the thing referenced) with
the given class, making the thing an object.  When Perl later sees a
reference to the object it can retrieve the class.  This is used in
method calls to find the method for a given name and object.

Anno


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

Date: 7 Aug 2006 12:10:10 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: What bless() do actually?
Message-Id: <764ed2hjl90sjgkj87e4770tn98f6v3so7@4ax.com>

On 7 Aug 2006 02:53:03 -0700, "Davy" <zhushenli@gmail.com> wrote:

>I guess if it is before bless($self), only private data pointer to
>$self; and after bless($self), method pointer to $self. Is it right? If
>not, please give me some intuitive explaination on bless, thanks!

bless() just adds a 'tag'.

  $ perl -le 'print \$r; print bless \$r, "foo"'
  SCALAR(0x814fe04)
  foo=SCALAR(0x814fe04)

Afterwards perl will know what to do with the bless()ed reference.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Mon, 07 Aug 2006 11:11:04 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: What bless() do actually?
Message-Id: <eb73jo$h50$1@gemini.csx.cam.ac.uk>

Davy wrote:
> Hi all,
> 
> I am new to Perl OO.
> 
> I found I have to bless($self) in new subroutine. If not do that, there
> is a error: "can't call method on unblessed methods".
> 
> I guess if it is before bless($self), only private data pointer to
> $self; and after bless($self), method pointer to $self. Is it right? If
> not, please give me some intuitive explaination on bless, thanks!

bless $ref, $classname;

tells the thing referred to by $ref (most commonly a hash) that it is 
now an object of class $classname. This means that when it is used 
later, $objectref knows which package to look in for its methods etc.

See perldoc -f bless


DS

PS. Perl references are not pointers as in C/C++.


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

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


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