[23241] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5462 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 8 09:05:53 2003

Date: Mon, 8 Sep 2003 06:05:09 -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, 8 Sep 2003     Volume: 10 Number: 5462

Today's topics:
    Re: Appending at various locations. <REMOVEsdnCAPS@comcast.net>
    Re: Can Perl do this? (Helgi Briem)
    Re: emulating @+ and @- <tassilo.parseval@rwth-aachen.de>
    Re: emulating @+ and @- <nospam-abuse@ilyaz.org>
    Re: emulating @+ and @- <tassilo.parseval@rwth-aachen.de>
    Re: Help configuring Perl with Apache 2 (Jon Bell)
    Re: Help configuring Perl with Apache 2 (Anno Siegel)
    Re: How do I count blocks of characters in a string var (Anno Siegel)
        how to do a simple check <vervoom@hotmail.com>
    Re: how to do a simple check <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: how to do a simple check <noreply@gunnar.cc>
    Re: how to do a simple check <vervoom@hotmail.com>
    Re: how to do a simple check <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: how to do a simple check <tore@aursand.no>
    Re: how to do a simple check (Helgi Briem)
    Re: how to do a simple check <noreply@gunnar.cc>
    Re: illegal seek <dave.nospam@ntlworld.com>
        Image::Magick perl: constitute.c:2015: ReadImage: Asser (Rob Bell)
    Re: Problem with simple contact script. (Tom)
        question about 'bless' <kju@ajou.ac.kr>
    Re: question about 'bless' <nobull@mail.com>
    Re: question about 'bless' (Anno Siegel)
    Re: simple regex problem <vervoom@hotmail.com>
    Re: simple regex problem <REMOVEsdnCAPS@comcast.net>
    Re: splitting an array <tassilo.parseval@rwth-aachen.de>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 08 Sep 2003 05:27:36 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Appending at various locations.
Message-Id: <Xns93F041E20C49Esdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

tabletdesktop@yahoo.com (MJS) wrote in
news:f0171209.0309071012.606a61bd@posting.google.com: 

> I have to ask the user to input any two digits e.g input= 3,5 (their
> value can be upto 300-whole numbers only). These two numbers have to
> be associated with multiple strings. As an example, 3 is associated 
 ...

Didn't you post this about a month ago?

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP1xZ0GPeouIeTNHoEQJZvgCg8Y60jVSZeUxbTGt3NxDgAy4RX18AoKGl
gKqzdoSxqxYrn85FjrjCRVPU
=y0Ca
-----END PGP SIGNATURE-----


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

Date: Mon, 08 Sep 2003 10:11:28 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: Can Perl do this?
Message-Id: <3f5c548b.238949781@News.CIS.DFN.DE>

On Mon, 08 Sep 2003 01:23:09 GMT, CountryLover
<crazygonuts@pcgeek.invalid> wrote:

>A project that I am working on requires the following steps:
>
>1. Parse a directory containing text files, potentially thousands 

perldoc perlrun
perldoc warnings
perldoc strict
perldoc -f opendir
perldoc -f grep
perldoc -f readdir
perldoc -f die
perldoc perlvar  ($!)
perldoc File::Find  (if there are subdirectories)

>2. Open each text file and read in the first 25 lines or so

perldoc -f open
perldoc perlvar  ( $. ) 
perldoc perlsyn (while)

>3. Write these lines to a temporary file

perldoc -f open
perldoc -f print
perldoc -f close

>4. Delete each original file & replace with the temp file, using same filename

perldoc -f unlink

>5. Parse the truncated files and find a specific keyword

perldoc perlre  (or perldoc perlrequick)

>6. Create directories based on the value of the keywords found

perldoc -f mkdir

>7. Move the truncated files to their respective directories.

perldoc -f rename

>8. Optionally, create a log file of all operations

perldoc -f open
perldoc -f print

>Is this something that Perl could be persuaded to do?

Of course.  What have you tried so far?



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

Date: 8 Sep 2003 10:42:59 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: emulating @+ and @-
Message-Id: <bjhmfj$d9l$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Ilya Zakharevich:

><tassilo.parseval@post.rwth-aachen.de>], who wrote in article <bjhh5k$3ib$1@nets3.rz.RWTH-Aachen.DE>:
>>         push @-, index($string, $1);
>>         push @+, pos($string);
> 
>>         $code->(@- > 1 ? () : substr($string, $-[0], $+[0] - $-[0]),
>>                 map substr($string, $-[$_], $+[$_] - $-[$_]), 1 .. $#-);
> 
> ???  What is the point of finding indices, then calling substr?  Why
> not use $$_ directly?

Copy and paste. I have the ordinary function scan() and the backward
compatible one scan5005003() and I do a 

    if ($] < 5.006) {
        *scan = \&scan500503;
    }

to replace the version not suitable for this perl. So the
backward-compatible ones are just a copy of the ordinary functions plus
the population of @- and @+.

Maybe I am going to reimplement it later by directly using $$digit, but
that's quite a bit of work since I have around five or six of these
duplicate functions. But I am not yet sure whether I should do that
because then a user cannot use @- and @+ in his code references (as he
could now).

>> Specifically, can $2 be undefined but $3 still contain a submatch?
> 
> Of course:
> 
>   (a)?(b)
> 
> Hope this helps,

It does, thank you. It means I have to find a different way to
figure out how many submatches exist. :-(

What about perl_get_sv? My code is 90% XS anyway, so I can just as
easily add more of it. Would this be reliable?

    int
    num_submatches ()
        PREINIT:
            int i = 0;
            char *digit;
            int len = 1;
        CODE:
            New(0, digit, 2, char);
            digit = "2";
            while (1) {
                if (!sv_get(digit, FALSE))
                    break;
                /* next() already exists elsewhere and 
                 * increments/grows the string accordingly */
                next(&digit, &len);
                i++;
            }
            RETVAL = i;
        OUTPUT:
            RETVAL

It assumes that $4 does not exist when $3 was the last succesful submatch.
But I don't know whether perl really destroys all the digit variables
that are larger than the highest submatch.

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: Mon, 8 Sep 2003 12:36:40 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: emulating @+ and @-
Message-Id: <bjht4o$v97$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Tassilo v. Parseval
<tassilo.parseval@post.rwth-aachen.de>], who wrote in article <bjhmfj$d9l$1@nets3.rz.RWTH-Aachen.DE>:
> What about perl_get_sv? My code is 90% XS anyway, so I can just as
> easily add more of it. Would this be reliable?

>     int
>     num_submatches ()

Just copy the code used for access to @-/@+.  Lemme see...  mg.c:

    case '+':
        if (PL_curpm && (rx = PM_GETRE(PL_curpm))) {
            paren = rx->lastparen;
            if (paren)
                goto getparen;
        }
        sv_setsv(sv,&PL_sv_undef);
        break;

Check with older Perl sources, but I think that PM_GETRE should be
something like identity macro on older perls...

Yours,
Ilya


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

Date: 8 Sep 2003 12:56:35 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: emulating @+ and @-
Message-Id: <bjhua3$kkv$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Ilya Zakharevich:

><tassilo.parseval@post.rwth-aachen.de>], who wrote in article <bjhmfj$d9l$1@nets3.rz.RWTH-Aachen.DE>:
>> What about perl_get_sv? My code is 90% XS anyway, so I can just as
>> easily add more of it. Would this be reliable?
> 
>>     int
>>     num_submatches ()
> 
> Just copy the code used for access to @-/@+.  Lemme see...  mg.c:
> 
>     case '+':
>         if (PL_curpm && (rx = PM_GETRE(PL_curpm))) {
>             paren = rx->lastparen;
>             if (paren)
>                 goto getparen;
>         }
>         sv_setsv(sv,&PL_sv_undef);
>         break;
> 
> Check with older Perl sources, but I think that PM_GETRE should be
> something like identity macro on older perls...

That's smart. I think that this will make it easy to solve my problem.
'struct regexp' (among others) holds

	U32 nparens;		/* number of parentheses */
	U32 lastparen;		/* last paren matched */
	U32 lastcloseparen;	/* last paren matched */

One of those (or even all of them) is probably what I am looking for.

Thanks for your help!
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: Mon, 8 Sep 2003 11:10:58 +0000 (UTC)
From: jtbellq2f@presby.edu (Jon Bell)
Subject: Re: Help configuring Perl with Apache 2
Message-Id: <bjho42$3m3$1@jtbell.presby.edu>

In article <bjh22i$ck0$2@grapevine.wam.umd.edu>,
Cyde Weys  <cyde@umd.edu> wrote:
>Jon Bell wrote:
>> 
>> How do you know you wouldn't have been more likely to get an answer in 
>> comp.infosystems.www.servers.* or comp.infosystems.www.authoring.cgi?  I 
>> don't see any postings from you in those groups.
>
>Because on my newsgroup server, c.l.p.misc has 3000 posts, while 
>c.i.w.s.misc, c.i.w.s.unix, and c.i.w.a.cgi have only 17, 281, and 68 
>posts, respectively.
>
>If you want an answer quickly, do you ask a few people or a whole crowd? 

You'll probably find even more postings in rec.photo.digital.  Does that
make it a better place to ask about configuring Web servers?  Surely there
are some people there who know something about Web servers.

-- 
Jon Bell <jtbellap8@presby.edu>                     Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA


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

Date: 8 Sep 2003 11:50:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help configuring Perl with Apache 2
Message-Id: <bjhqel$bgm$1@mamenchi.zrz.TU-Berlin.DE>

Cyde Weys  <cyde@umd.edu> wrote in comp.lang.perl.misc:
> Jon Bell wrote:
> 
> >>Because I believed this question was more likely to be answered in the 
> >>Perl newsgroup (which I was right about).  
> > 
> > 
> > How do you know you wouldn't have been more likely to get an answer in 
> > comp.infosystems.www.servers.* or comp.infosystems.www.authoring.cgi?  I 
> > don't see any postings from you in those groups.
> > 
> 
> Because on my newsgroup server, c.l.p.misc has 3000 posts, while 
> c.i.w.s.misc, c.i.w.s.unix, and c.i.w.a.cgi have only 17, 281, and 68 
> posts, respectively.

Of those 3000 posts on clpm, 1500 are questions, 1000 are answers
already provided by the 10-12 active regulars here and 500 are off
topic or replies explaining that they are.  How very thoughtful of
you to throw another off-topic posting in the mix.

> If you want an answer quickly, do you ask a few people or a whole crowd? 

So you do what (you think) gets you an answer most quickly without
regard if your question is welcome?  How selfish.

BTW, most of the crowd have as little Perl experience as you.

> And while some may have pointed out that my question was slightly 
> off-topic in this newsgroup, it's still relevant.  And it also generated 
> all sorts of discussions and follow-up questions that definitely were 
> relevant to Perl.

None that I've seen.

Anno


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

Date: 8 Sep 2003 12:53:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How do I count blocks of characters in a string variable?
Message-Id: <bjhu41$eed$1@mamenchi.zrz.TU-Berlin.DE>

Greg <gdsafford@hotmail.com> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message
> news:<bjdong$hp5o9$1@ID-184292.news.uni-berlin.de>...
> > Researcher wrote:
> > > I'm trying to create a code to count a certain character in a 
> > > string, lets say that I want to know how many letters "o" there are
> > > in the text "The book is yellow",
> > 
> > <snip>
> > 
> > > what if I want to count a block of characters instead of one only
> > > (e.g. how many "el" there are in $text)?
> > 
> > This method works with both single characters and strings:
> > 
> >      $text = "The book is yellow";
> >      $count++ while $text =~ /o/g;
> > 
> > Btw, you asked a FAQ. This is where you should have looked up the
> > answer:
> > 
> >      perldoc -q count
> 
> Just as an alternative to the regex methods, a common way in some
> languages of counting all the character types in a string would be to
> use the character code as an array index:

Those must be languages without a hash data type.

> my $text = "The book is yellow";
> my @a;
> 
> $a[ord(lc $_)]++ for split(//, $text);
> 
> print $a[ord('o')], $/;

In Perl, there is no need to decode the characters first:

    my %a;
    $a{ $_}++ for split //, $text;

    print "$a{ o}\n";

Re-introduce the lc() if wanted.

Anno


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

Date: Mon, 08 Sep 2003 12:21:44 +0100
From: JS <vervoom@hotmail.com>
Subject: how to do a simple check
Message-Id: <bjhopn$eri$1@cspc1n11.baplc.com>

I have a program called depstats.pl

which takes some files as input so I run it like:

 ./deptstats file1 file2 file3

and then loop through all those files using the construct:

while(<>)

How do I check if any files were supplied? Because if I just do :

 ./depstats.pl

the programs never ends until I CTRL-C it.

Thanks for the help.

JS.



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

Date: Mon, 8 Sep 2003 11:27:10 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: how to do a simple check
Message-Id: <Xns93F088C5D9DF6elhber1lidotechnet@62.89.127.66>

JS wrote:

> I have a program called depstats.pl
> 
> which takes some files as input so I run it like:
> 
> ./deptstats file1 file2 file3
> 
> and then loop through all those files using the construct:
> 
> while(<>)
> 
> How do I check if any files were supplied? Because if I just do :
> 
> ./depstats.pl


All of the script's arguments are stored in the special array @ARGV, so you 
can simply make sure it's not empty. For more


   perldoc perlvar

 .


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Mon, 08 Sep 2003 13:35:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to do a simple check
Message-Id: <bjhphc$j7nju$1@ID-184292.news.uni-berlin.de>

Bernard El-Hagin wrote:
> JS wrote:
>> I have a program called depstats.pl
>> 
>> which takes some files as input so I run it like:
>> 
>> ./deptstats file1 file2 file3
>> 
>> and then loop through all those files using the construct:
>> 
>> while(<>)
>> 
>> How do I check if any files were supplied?
> 
> All of the script's arguments are stored in the special array
> @ARGV, so you can simply make sure it's not empty.

Or maybe:

     if (-e $ARGV[0])

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



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

Date: Mon, 08 Sep 2003 12:41:04 +0100
From: JS <vervoom@hotmail.com>
Subject: Re: how to do a simple check
Message-Id: <bjhptv$poe$1@cspc1n11.baplc.com>

Gunnar Hjalmarsson wrote:
> Bernard El-Hagin wrote:
> 
>> JS wrote:
>>
>>> I have a program called depstats.pl
>>>
>>> which takes some files as input so I run it like:
>>>
>>> ./deptstats file1 file2 file3
>>>
>>> and then loop through all those files using the construct:
>>>
>>> while(<>)
>>>
>>> How do I check if any files were supplied?
>>
>>
>> All of the script's arguments are stored in the special array
>> @ARGV, so you can simply make sure it's not empty.
> 
> 
> Or maybe:
> 
>     if (-e $ARGV[0])
> 

Thanks for your help,

This worked:

usage() if ! $ARGV[0] ;



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

Date: Mon, 8 Sep 2003 12:03:21 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: how to do a simple check
Message-Id: <Xns93F08EE87B7C5elhber1lidotechnet@62.89.127.66>

JS wrote:


[...]


> Thanks for your help,
> 
> This worked:
> 
> usage() if ! $ARGV[0] ;


Or


  usage() unless @ARGV;


which seems a bit easier on the eye.


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Mon, 08 Sep 2003 14:19:43 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: how to do a simple check
Message-Id: <pan.2003.09.08.12.19.38.287829@aursand.no>

On Mon, 08 Sep 2003 12:41:04 +0100, JS wrote:
> This worked:
> 
> usage() if ! $ARGV[0] ;

There's always more than one way to do it, but please write

  usage() unless ( $ARGV[0] );

instead.  That 'if !' is ugly, IMO.


-- 
Tore Aursand <tore@extend.no>

"Whenever I see an old lady slip and fall on a wet sidewalk, my first
 instinct is to laugh. But then I think, what if I was an ant, and she
 fell on me. Then it wouldn't seem quite so funny." -- Jack Handey


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

Date: Mon, 08 Sep 2003 12:22:07 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: how to do a simple check
Message-Id: <3f5c7403.247005895@News.CIS.DFN.DE>

On Mon, 8 Sep 2003 12:03:21 +0000 (UTC), "Bernard El-Hagin"
<bernard.el-hagin@DODGE_THISlido-tech.net> wrote:


>> Thanks for your help,
>> This worked:
>> usage() if ! $ARGV[0] ;
>
>Or
>
>  usage() unless @ARGV;
>
>which seems a bit easier on the eye.

I use:

die $usage if not @ARGV;

but in the end it's a matter of taste.



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

Date: Mon, 08 Sep 2003 14:42:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to do a simple check
Message-Id: <bjhtgq$j0vsn$1@ID-184292.news.uni-berlin.de>

JS wrote:
> Gunnar Hjalmarsson wrote:
>>
>>     if (-e $ARGV[0])
> 
> Thanks for your help,
> 
> This worked:
> 
> usage() if ! $ARGV[0] ;

Okay. Note that my suggestion includes a check of the file path. Only 
you know if such a check would be useful.

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



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

Date: Mon, 08 Sep 2003 14:02:36 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: illegal seek
Message-Id: <qnirfnivyyragyjbeyqpbz.hkwq4c5.pminews@text.news.ntlworld.com>

On Mon, 8 Sep 2003 10:01:43 +0100, news@roaima.freeserve.co.uk wrote:

>Dave Saville <dave.nospam@ntlworld.com> wrote:
>> What printed out was "Illegal Seek" - looking backwards I found a "seek
>> HANDLE,0,0
>
>The error value is only set on an error: it's never implicitly reset. So,
>can you be sure that this is the relevant seek that generated the
>error? What happened when you /did/ check the return value from it?
>

Because it was just before - I have not got around to changing anything
before I fully understood what was going on.

>> The actual code is as follows:
>
>> open LIST, "<$clean_username" or die "$clean_username $!";
>
>The "<" is implicit, and so can be omitted. This leaves a quoted simple
>variable, so the quotes can now also be stripped:
>
>	open LIST, $clean_username or die "can't open $clean_username: $!";
>
>> flock LIST, $LOCK_EX;
>
>Depending on the underlying implementation of flock and your cross
>platform requirements, you cannot /guarantee/ an exclusive lock with
>read-only file access. (Mostly it will work, but just be aware...)

I am now *really* confused - I do not understand  about flock and read
only - surely the use of a lock is to protect from concurrent usage - I
am taking an exclusive lock because it is entirely possible that
another program could be updating the same file when I want to read it
- and of course I need to process it in a consistent state. 

I was taking an exclusive lock on reading <$file and writing - either
>$file or >>$file 

So how *should* I be doing it?

Regards

Dave Saville

NB switch saville for nospam in address




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

Date: 8 Sep 2003 03:38:05 -0700
From: robbelljr@aol.com (Rob Bell)
Subject: Image::Magick perl: constitute.c:2015: ReadImage: Assertion `image_info->signature == 0xabacadab' failed
Message-Id: <b3c4dce1.0309080238.1e7e5ca2@posting.google.com>

Hello,

perl: constitute.c:2015: ReadImage: Assertion `image_info->signature
== 0xabacadab' failed

If anyone here has encountered the error above when using the
Image::Magick module please share how you adapted your scripts to
avoid or work around it.

Thank you,

Rob

PS: This request for help was posted in Modules with no response for two days.


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

Date: 8 Sep 2003 04:49:52 -0700
From: tom@ztml.com (Tom)
Subject: Re: Problem with simple contact script.
Message-Id: <59b4279a.0309080349.3c592fbb@posting.google.com>

mortgageloan2003@aol.com (Mortgageloan2003) wrote in message news:<20030908023513.10815.00000560@mb-m29.aol.com>...
> I have a form below - I put a radio button for the person to select who they
> want to email to instead of "hardcoding" this into the form.  (thus the
> spammers can't get my email addresses) the email addresses are set in the
> script via an if elsif test. I run this on my Windows XP port of perl with the
> -w and it simply can't find the path. I get an error 500 on the webserver.  I
 .
 .
> open(SM,"|/usr/sbin/sendmail -oi -t");
 .
 .

Try this...

open(SM,">/usr/sbin/sendmail") or die $!;

Tom
ztml.com


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

Date: Mon, 08 Sep 2003 11:53:32 GMT
From: Kim Jonguk <kju@ajou.ac.kr>
Subject: question about 'bless'
Message-Id: <pan.2003.09.08.11.53.24.70124@ajou.ac.kr>

Hi.

i'm reading a book about OOP with perl.
in constructor, for example

sub new
{
	my ($class, %args) = @_;
	...
	bless { ... }, ref($class) || $class;
}

i'm wondering this. "ref($class) || $class".
i cannot understand this phrase.
plz, explain to me.

thanks for reading. :)



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

Date: 08 Sep 2003 13:07:25 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: question about 'bless'
Message-Id: <u9vfs3zdoi.fsf@wcl-l.bham.ac.uk>

Kim Jonguk <kju@ajou.ac.kr> writes:

> i'm reading a book about OOP with perl.
> in constructor, for example
> 
> sub new
> {
> 	my ($class, %args) = @_;
> 	...
> 	bless { ... }, ref($class) || $class;
> }
> 
> i'm wondering this. "ref($class) || $class".
> i cannot understand this phrase.

Can you tell us what parts (if any) of the reference manual
descriptions of the bless() funtion, ref() function and the ||
operator you can't understand?

Without this information we are just likely to repeat what the manual
says and you'll be no better off. 

I shall, therefore, proceded on the assumuption that you've read and
understood those manual entries.

The first argument passed to a subroutine being called as a method is
an object reference for an instance method call and a string
containing the class name for a class method call.

A constructor is usually called as a class method.

The variable $class, in this case, therefore contains the class name.

However the author of the above code obviously wanted to allow new to
be callable as an instance method too.  In that case $class would
contain an object reference and ref($class) would return the class
name.

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


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

Date: 8 Sep 2003 12:16:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: question about 'bless'
Message-Id: <bjhruk$dg0$1@mamenchi.zrz.TU-Berlin.DE>

Kim Jonguk  <kju@ajou.ac.kr> wrote in comp.lang.perl.misc:
> Hi.
> 
> i'm reading a book about OOP with perl.
> in constructor, for example
> 
> sub new
> {
> 	my ($class, %args) = @_;
> 	...
> 	bless { ... }, ref($class) || $class;
> }
> 
> i'm wondering this. "ref($class) || $class".
> i cannot understand this phrase.
> plz, explain to me.

It's an idiom that makes the new() method usable as both an object
method and a class method.  In a class-method call, (the normal way
to call new()), $class contains a string with a class name.  In that
case, "ref( $class)" is "" (a false value), and the result of "ref( $class)
|| $class" is $class itself.  If you call new() through an object,
$class will contain that object.  Then, "ref( $class)" is the name
of the object's class.  In both cases, bless() is called with a
class name, as it should be.

That said, in my opinion, using new() as an object method is not a
good idea.  If "$object->new( ...)" creates an entirely independent
object, the presence of "$object" in the call is confusing, since it has
no consequences.  If "$object->new( ...)" creates a clone of object,
then call the method "clone" or "copy", but not "new".

So, while the construct works and gives the new() method a spurious
universality, I'd just replace ""ref($class) || $class" with "$class".

Anno


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

Date: Mon, 08 Sep 2003 11:11:08 +0100
From: JS <vervoom@hotmail.com>
Subject: Re: simple regex problem
Message-Id: <bjhklb$er2$1@cspc1n11.baplc.com>

Gunnar Hjalmarsson wrote:
> John W. Krahn wrote:
> 
>> JS wrote:
>>
>>> I'm trying to build a regex to put the department name into a
>>> variable $dept and the rest of the line into another variable
>>> $stats:
>>>
>>> E-Test                  3       -       4       -
>>> Health and Safety       -       1       1       -
>>> Finance                 -       3       -       -
>>
>>
>> my ( $dept, $stats ) = unpack 'A24 A*', $_;
> 
> 
> That doesn't work for the E-Test line. How about:
> 
>     my ($dept, $stats) = /(.+[a-z])\s+(.*)/;
> 

Thank Gunnar,

That works if I do:

my ($dept, $stats) = /(.+[a-zA-Z])\s+(.*)/;



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

Date: Mon, 08 Sep 2003 05:38:44 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: simple regex problem
Message-Id: <Xns93F043C50A963sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

JS <vervoom@hotmail.com> wrote in news:bjhihj$nsq$1@cspc1n11.baplc.com:

> Hi,
> 
> I'm trying to build a regex to put the department name into a variable 
> $dept and the rest of the line into another variable $stats:
> 
> E-Test               3     -     4     -
> Health and Safety       -       1       1     -
> Finance                 -       3       -       -
> 
> This is my regex:
> 
> ($dept,$stats)=/^(.[^\s-|\d]*)\s+(.*)/;
> 
> but it doesn't work because of the \s- is not actually handled as a 
> string, but individual charaters.
> 
> Can anyone fix this for me please?

Not until you explain how you can tell where the department name ends and 
the "rest of the line" begins.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP1xcbWPeouIeTNHoEQLAeQCgufJlY2+TqrfKseQRoKzuJwmmSa8An0yB
JwDum1lkjJ/0GP4V/PI9z6uX
=E/iX
-----END PGP SIGNATURE-----


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

Date: 8 Sep 2003 10:51:51 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: splitting an array
Message-Id: <bjhn07$drd$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Philip Lees:

> On Sat, 06 Sep 2003 23:05:29 GMT, tiltonj@erols.com (Jay Tilton)
> wrote:
> 
>>Kinda fun.  I remember seeing variations on this problem solved before on
>>clpm, but I couldn't hit on the right Google Groups search terms.  Any
>>pointers?
> 
> Wasn't it one of MJDs quizzes of the week?

Yes, it was some time ago. The related archive of discussions can
probably be found somewhere at <http://perl.plover.com/qotw/>.

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: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5462
***************************************


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