[23998] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6199 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 18:05:44 2004

Date: Mon, 1 Mar 2004 15:05:10 -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           Mon, 1 Mar 2004     Volume: 10 Number: 6199

Today's topics:
        (newbie) How do I group a string for repetition count?  (Ray)
    Re: (newbie) How do I group a string for repetition cou <usenet@morrow.me.uk>
    Re: (newbie) How do I group a string for repetition cou <gnari@simnet.is>
    Re: (newbie) How do I group a string for repetition cou <gnari@simnet.is>
        Efficiency and scoping 'my' variables <david@emology.com>
    Re: Efficiency and scoping 'my' variables (Anno Siegel)
    Re: Efficiency and scoping 'my' variables <david@emology.com>
        Equivalent of CPAN for regular expressions? (Ray)
    Re: Equivalent of CPAN for regular expressions? (Anno Siegel)
    Re: finding common words (Anno Siegel)
    Re: finding common words <noreply@gunnar.cc>
    Re: Getting status/response codes in Perl <pkent77tea@yahoo.com.tea>
    Re: Getting status/response codes in Perl <gnari@simnet.is>
    Re: how die in AUTOLOAD <yshtil@cisco.com>
    Re: how die in AUTOLOAD <tassilo.parseval@rwth-aachen.de>
    Re: how die in AUTOLOAD <yshtil@cisco.com>
    Re: how die in AUTOLOAD <tadmc@augustmail.com>
    Re: how die in AUTOLOAD <nospam-abuse@ilyaz.org>
    Re: how die in AUTOLOAD <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: how die in AUTOLOAD <yshtil@cisco.com>
    Re: how die in AUTOLOAD (Jay Tilton)
    Re: how die in AUTOLOAD <yshtil@cisco.com>
        how do I choose between an explicit file and standard i <lkirsh@cs.ubc.ca>
    Re: how do I choose between an explicit file and standa (Anno Siegel)
    Re: how do I choose between an explicit file and standa <gnari@simnet.is>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 1 Mar 2004 12:26:55 -0800
From: rayling@spiderchase.com (Ray)
Subject: (newbie) How do I group a string for repetition count?  {m,n}
Message-Id: <4370311c.0403011226.17145d9e@posting.google.com>

Hello,

I'm trying the following to get the 2nd, and only the 2nd occurrence
of the phrase "turkey shoot", in a string with a lot more than 2
occurrences of the phrase:

(turkey shoot){2}

It does't match anything.

How do I structure this properly?

Thanks.


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

Date: Mon, 1 Mar 2004 20:32:04 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: (newbie) How do I group a string for repetition count?  {m,n}
Message-Id: <c206k4$9vr$1@wisteria.csv.warwick.ac.uk>


rayling@spiderchase.com (Ray) wrote:
> I'm trying the following to get the 2nd, and only the 2nd occurrence
> of the phrase "turkey shoot", in a string with a lot more than 2
> occurrences of the phrase:
> 
> (turkey shoot){2}
> 
> It does't match anything.

It does. It matches, among other things, "turkey shootturkey shoot".

> How do I structure this properly?

/^.*?turkey shoot.*?(turkey shoot)/

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces molit animos, tristesque mentes erigit.    |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: Mon, 1 Mar 2004 20:46:10 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: (newbie) How do I group a string for repetition count?  {m,n}
Message-Id: <c207cm$fpn$1@news.simnet.is>

"Ray" <rayling@spiderchase.com> wrote in message
news:4370311c.0403011226.17145d9e@posting.google.com...
> Hello,
>
> I'm trying the following to get the 2nd, and only the 2nd occurrence
> of the phrase "turkey shoot", in a string with a lot more than 2
> occurrences of the phrase:
>
> (turkey shoot){2}
>
> It does't match anything.
>
> How do I structure this properly?

it depends really on what you want to do with it
are you talking about /turkey shoot.*(turkey shoot)/ ?

or maybe you want to read perldoc perlre
in particular the bit about  zero-width positive look-behind assertions.
something like / (?<=turkey shoot).*(turkey shoot)/

gnari






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

Date: Mon, 1 Mar 2004 20:56:01 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: (newbie) How do I group a string for repetition count?  {m,n}
Message-Id: <c207uu$fre$1@news.simnet.is>

"gnari" <gnari@simnet.is> wrote in message
news:c207cm$fpn$1@news.simnet.is...
> "Ray" <rayling@spiderchase.com> wrote in message
> news:4370311c.0403011226.17145d9e@posting.google.com...
> > Hello,
> >
> > I'm trying the following to get the 2nd, and only the 2nd occurrence
> > of the phrase "turkey shoot", in a string with a lot more than 2
> > occurrences of the phrase:
> >
> > (turkey shoot){2}
> >
> > It does't match anything.
> >
> > How do I structure this properly?
>
> it depends really on what you want to do with it
> are you talking about /turkey shoot.*(turkey shoot)/ ?
/turkey shoot.*?(turkey shoot)/  of course

>
> or maybe you want to read perldoc perlre
> in particular the bit about  zero-width positive look-behind assertions.
> something like / (?<=turkey shoot).*(turkey shoot)/

ditto here: / (?<=turkey shoot).*?(turkey shoot)/

gnari






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

Date: Mon, 01 Mar 2004 21:49:40 +0000
From: david scholefield <david@emology.com>
Subject: Efficiency and scoping 'my' variables
Message-Id: <BC696074.9D0E%david@emology.com>

Not easily being able to look into the perl interpreter code, does anyone
have any idea on whether or not declaring a new _my_ variable is more
efficient when declared inside a loop (creating a new instance every
time), or declared outside the loop, or whether there is no great
difference. 

By efficiency I mean both
space, and speed (though as the loop body completes each iteration I assume
the variable reference count reduces to zero and it is destroyed anyway, so
I guess space isn't a issue?)

e.g.
{
    my $someVal;
    while ($loopcontrol)
    {
        ... use $someval in some way
    }
}

is more efficient than (?)

while ($loopcontrol)
{
    my $someVal;
    ... use $someval as before
}

I realise that there is a functional difference in that by declaring inside
the loop, any old value is over-written, but assuming that isn't an issue...

david
emology.com



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

Date: 1 Mar 2004 22:23:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Efficiency and scoping 'my' variables
Message-Id: <c20d4k$es7$1@mamenchi.zrz.TU-Berlin.DE>

david scholefield  <david@emology.com> wrote in comp.lang.perl.misc:
> Not easily being able to look into the perl interpreter code, does anyone
> have any idea on whether or not declaring a new _my_ variable is more
> efficient when declared inside a loop (creating a new instance every
> time), or declared outside the loop, or whether there is no great
> difference. 

In deciding the scope of a variable, efficiency stays out of the
consideration.  The rule is to put the variable in the smallest
possible scope.

> By efficiency I mean both
> space, and speed (though as the loop body completes each iteration I assume
> the variable reference count reduces to zero and it is destroyed anyway, so
> I guess space isn't a issue?)

Both space and time aren't issues here.  You start thinking about
efficiency when your program is too slow.  In that case, shuffling
loop variables around won't bring the breakthrough you need.

[code with variable declared inside/outside while-loop]

> I realise that there is a functional difference in that by declaring inside
> the loop, any old value is over-written, but assuming that isn't an issue...

It's always an issue.  If functionality doesn't demand the variable outside
the loop, put it inside.

Theoretically, the point is clear.  The space requirement is the same,
as you observed.  Obviously, the run-time effect of "my" happens more
often when the variable is declared inside the loop.  The difference
is small (use Benchmark to measure it on your machine, if you can).

Consider it the cost of correct scoping.  It's one of the last things you
want to trade for efficiency.

Anno


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

Date: Mon, 01 Mar 2004 22:33:41 +0000
From: david scholefield <david@emology.com>
Subject: Re: Efficiency and scoping 'my' variables
Message-Id: <BC696AC5.9D58%david@emology.com>

On 1/3/04 10:23 pm, in article c20d4k$es7$1@mamenchi.zrz.TU-Berlin.DE, "Anno
Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote:

> In deciding the scope of a variable, efficiency stays out of the
> consideration.  The rule is to put the variable in the smallest
> possible scope.
> 
Good advice, generally...

> Both space and time aren't issues here.  You start thinking about
> efficiency when your program is too slow.  In that case, shuffling
> loop variables around won't bring the breakthrough you need.
> 

that's what I was asking... thanks for the answer... I guess that
variable declaration isn't a time-intensive activity at run-time

thanks
david



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

Date: 1 Mar 2004 13:40:43 -0800
From: rayling@spiderchase.com (Ray)
Subject: Equivalent of CPAN for regular expressions?
Message-Id: <4370311c.0403011340.415a6dbb@posting.google.com>

Is their a web site that specializes in having various regular
expressions cataloged by desired usage?  Sort of like CPAN is to Perl,
except focusing strictly on regular expressions?

Thanks.


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

Date: 1 Mar 2004 21:57:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Equivalent of CPAN for regular expressions?
Message-Id: <c20bk6$clp$3@mamenchi.zrz.TU-Berlin.DE>

Ray <rayling@spiderchase.com> wrote in comp.lang.perl.misc:
> Is their a web site that specializes in having various regular
> expressions cataloged by desired usage?  Sort of like CPAN is to Perl,
> except focusing strictly on regular expressions?

Ugh, no.  There are too many dialects of regular expressions for such a
thing to be feasible.

There is a repository of Perl regular expressions *on* CPAN, Regex::Common,
as well as other regex-related modules.

Anno


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

Date: 1 Mar 2004 21:15:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: finding common words
Message-Id: <c2094o$clp$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> viv2k wrote:

[...]

> > Example:
> > ListA
> > Apple 4, Boy 3, Cat 5
> > ListB
> > Apple 1.0, Baby 2.1, Cat 3.3
> > ListC
> > Apple 99, Beef 100, Cow   101
> > 
> > Should give me as result:
> > ListA      ListB       ListC
> > Apple 4    Apple 1.0   Apple 99
> > Cat   5    Cat   3.3   Cat   0
> > 
> > Right now, my code looks like below but I don't know how to give
> > this default value. Any help is much appreciated.
> 
> Well, you need to somehow count the number of occurrences of each
> word, right? Below find a suggestion that does just that.

[setup of %ListA, %ListB and %listC]

>      my %count;
>      $count{$_}++ for keys %ListA, keys %ListB, keys %ListC;
> 
>      for (keys %count) {
>          if ($count{$_} > 1) {
>              $ListA{$_} ||= 0;
>              $ListB{$_} ||= 0;
>              $ListC{$_} ||= 0;
>          }
>      }
> 
> > print "ListA \n";
> > print "$_\t$ListA{$_}\n" for sort keys %ListA;
> > print "\n";
> > print "ListB \n";
> > print "$_\t$ListB{$_}\n" for sort keys %ListB;
> > print "\n";
> > print "ListC \n";
> > print "$_\t$ListC{$_}\n" for sort keys %ListC;
> 
> Even if this solution gets the job done, there are likely more
> efficient ways to do it.

I don't know about efficiency, it doesn't seem to be an issue here.

I'd make the individual %ListA .. %ListC an array of hashes, and write
the code so that it works for an arbitrary number of them.  At the same
time, the code gets more compact (if that is an advantage).  Also,
avoid tabs like the plague.  The meaning of tabs is too ill-defined for
them to be of practical use.  Use (s)printf for formating, or use
Text::Table.  Thirdly, Perl's default value for numbers *is* 0.  The
idiom " ... || 0" (soon " ... // 0", yay) has its place, but isn't
needed here.

Assume "@lists = \ ( %ListA, %ListB, %ListC)" to connect to previous
code.  One would read the data directly into @lists.

    my %count;
    $count{ $_} ++ for map keys %$_, @lists;

    for my $item ( sort grep $count{ $_} >= 2, keys %count ) {
        # interleave copies of $item with prices
        my @vals = map { $item, $_->{ $item} } @lists;
        no warnings 'uninitialized'; # take care of default
        printf '%6s %5.2f  ' x @lists . "\n", @vals;
    }

Anno


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

Date: Mon, 01 Mar 2004 22:39:19 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: finding common words
Message-Id: <c20auu$1njufo$1@ID-184292.news.uni-berlin.de>

Anno Siegel wrote:
> I'd make the individual %ListA .. %ListC an array of hashes, and
> write the code so that it works for an arbitrary number of them.

I thought of that, but skipped it since OP isn't likely ready for
complex data structures.

> Also, avoid tabs like the plague.  The meaning of tabs is too
> ill-defined for them to be of practical use.  Use (s)printf for
> formating, or use Text::Table.

That aspect was discussed previously in the thread.

> Thirdly, Perl's default value for numbers *is* 0.  The idiom " ...
> || 0" (soon " ... // 0", yay) has its place, but isn't needed here.

 ... provided (s)printf() and disabling the uninitialized warning ...

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



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

Date: Mon, 01 Mar 2004 19:35:52 +0000
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Getting status/response codes in Perl
Message-Id: <pkent77tea-239D94.19355101032004@pth-usenet-02.plus.net>

In article <124e26f8.0402291130.390bf3eb@posting.google.com>,
 AyCeeUK@hotmail.com (Ali) wrote:

> also called status codes and I've found how to create a page that is
> displayed when a certain status code is found but I can't find out how
> to log the status of the page that was loaded.

If you're using Apache then the default access log format includes the 
status code - so it's already being logged, albeit in a separate file.


> am I right in saying that for the
> page to have loaded correctly the code must be 200?

No, the web server can return a valid response with some content with a 
number of response codes.


> I thought it might be stored as an environment variable like when
> setting and retrieving cookies but I can't find any environment
> variables associated with status codes.

The response code is, AFAICT, decided on by the web server, not the CGI 
application (except in NPH mode). But if you want to explain in a bit 
more detail what you're trying to achieve then maybe I can be of a bit 
more help

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Mon, 1 Mar 2004 19:19:14 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Getting status/response codes in Perl
Message-Id: <c2029l$f4j$1@news.simnet.is>

"Ali" <AyCeeUK@hotmail.com> wrote in message
news:124e26f8.0403010331.5420f4e6@posting.google.com...
> Thanks very much, that was extremely helpful.  I think I know what I have
to do now!
>
that's good, but there is no need to quote the whole article you are
following up on. rather quote the relevant bits, and add your response
after it. That makes it so much more readable, specially if it develops
into a real thread.

>
> "gnari" <gnari@simnet.is> wrote in message
news:<c1tfq0$4qh$1@news.simnet.is>...
[snipped whole quoted article]

gnari






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

Date: Mon, 01 Mar 2004 11:26:26 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: Re: how die in AUTOLOAD
Message-Id: <40438E62.2020107@cisco.com>

If you canoot be polite than shut up yourself.


Anno Siegel wrote:
> Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
> 
>>
>>Anno Siegel wrote:
>>
>>>Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
>>
> 
> [...]
> 
> 
>>>>I do call this from an another module. I traced it with the debugger and 
>>>>with prints. The die statement gets invoked with no visible effect.
>>>
>>>Then how about showing us that mystery call?  The code you showed behaves
>>>exactly as expected.  So far this has been a waste of time.
>>
>>I apologize for wasting your time. It was unintentional.
>>
>>You can assume it was PACKAGE::foo(bla);
>>Where foo was nowhere to exist.
> 
> 
> Assume?  I don't want assumptions, I want to see the exact code that
> calls main::AUTOLOAD and doesn't die.  (Your "assumption" doesn't call
> main::AUTOLOAD, which was the only AUTOLOAD in your original code.)
> 
> 
>>Where PACKAGE is the package the AUTOLOAD is in.
>>As I said I saw the autload routine hit, but die exited silently.
> 
> 
> You have been claiming this in three postings now, but never shown
> code that demonstrates it.  Now please show the code or shut up.
> 
> [...]
> 
> Anno



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

Date: 1 Mar 2004 19:41:04 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: how die in AUTOLOAD
Message-Id: <c203kg$k2r$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Yuri Shtil:

> If you canoot be polite than shut up yourself.

If you do not want help, then just continue insulting those willing to
help.

Anyway, too late. You will have to find a new place now as no one is
willing to do anything for you any longer.

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, 01 Mar 2004 12:32:36 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: Re: how die in AUTOLOAD
Message-Id: <40439DE4.8010301@cisco.com>

Ah, only those "willing to help" can heap insults !!!

Thank you for pointing this out.

Tassilo v. Parseval wrote:
> Also sprach Yuri Shtil:
> 
> 
>>If you canoot be polite than shut up yourself.
> 
> 
> If you do not want help, then just continue insulting those willing to
> help.
> 
> Anyway, too late. You will have to find a new place now as no one is
> willing to do anything for you any longer.
> 
> Tassilo



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

Date: Mon, 1 Mar 2004 14:54:35 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: how die in AUTOLOAD
Message-Id: <slrnc478ob.kr5.tadmc@magna.augustmail.com>

Yuri Shtil <yshtil@cisco.com> wrote:

> If you canoot be polite 


You reap what you sow.


> than shut up yourself.


Oh my.

So long then.



[ snip TOFU yet again... ]

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


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

Date: Mon, 1 Mar 2004 21:22:01 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: how die in AUTOLOAD
Message-Id: <c209hp$gl3$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Yuri Shtil 
<yshtil@cisco.com>], who wrote in article <40410690.4090204@cisco.com>:
> Hi all
> 
> I wrote the following code to call functions in an another package and 
> process the return value.
> 
> I check if the computed routine exists in the target package and call
> die if it does not. When I run this code there is no die message 
> displayed, the program exits silently.

What happens with setting dieLevel=5 in debugger?  Giving `t'race
command may give more hints too.

Hope this helps,
Ilya


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

Date: Mon, 1 Mar 2004 13:25:10 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: how die in AUTOLOAD
Message-Id: <mn902c.rjd.ln@goaway.wombat.san-francisco.ca.us>

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

On 2004-03-01, Yuri Shtil <yshtil@cisco.com> wrote:
> Ah, only those "willing to help" can heap insults !!!

Those willing to post code are more likely to get help without insults.

Those unwilling to post code are more likely to get insults without
help.

So, which do you prefer, help or insults?  If the former, I suggest you post
code which duplicates your problem, as Anno suggested.

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAQ6o1hVcNCxZ5ID8RAlLTAJ0R3GlKmWOBm8rdMRbhs5pvcq0P6gCeKwvq
gXQE/xmtTv3wn6wI3SySqtM=
=tfXG
-----END PGP SIGNATURE-----


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

Date: Mon, 01 Mar 2004 13:54:03 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: Re: how die in AUTOLOAD
Message-Id: <4043B0FB.20005@cisco.com>



Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to
> Yuri Shtil 
> <yshtil@cisco.com>], who wrote in article <40410690.4090204@cisco.com>:
> 
>>Hi all
>>
>>I wrote the following code to call functions in an another package and 
>>process the return value.
>>
>>I check if the computed routine exists in the target package and call
>>die if it does not. When I run this code there is no die message 
>>displayed, the program exits silently.
> 
> 
> What happens with setting dieLevel=5 in debugger?  Giving `t'race
> command may give more hints too.
> 
> Hope this helps,
> Ilya

Thank you very much. It helped a lot.

The die message appeared when I set dieLevel=5. The message is not 
emitted when the code runs without the debugger or with dieLevel=1 
(default).

How do I make sure it appears with no debugger running?

Yuri.



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

Date: Mon, 01 Mar 2004 22:44:50 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: how die in AUTOLOAD
Message-Id: <4043bca1.261223180@news.erols.com>

Yuri Shtil <yshtil@cisco.com> wrote:
: Anno Siegel wrote:
: > Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
: >>Anno Siegel wrote:
: >>>Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
: >>>
: >>>>I check if the computed routine exists in the target package and call
: >>>>die if it does not. When I run this code there is no die message 
: >>>>displayed, the program exits silently.
: >>>
: >>>You are never calling anything, so AUTOLOAD is never triggered.  Add
: >>>a line "gibsnich()" somewhere, and it will die as expected.
: >>
: >>I do call this from an another module. I traced it with the debugger and 
: >>with prints. The die statement gets invoked with no visible effect.
: > 
: > Then how about showing us that mystery call?  The code you showed behaves
: > exactly as expected.  So far this has been a waste of time.
: 
: You can assume it was PACKAGE::foo(bla);
: Where foo was nowhere to exist.

That's nice, but there is still not enough information for readers to
reproduce the problem.  Given what's available so far, and further assuming
'bla' is meant to be a quoted string (Can we get a ballpark estimate of how
many more assumptions are needed?), someone trying to investigate might
scratch out a program like:

    #!perl
    use warnings;
    use strict;
    {{
    package PACKAGE;
    no strict;
    sub AUTOLOAD {
        my ($name, $oldsub);
        my $sub = $oldsub = $AUTOLOAD;
        $sub =~ s/.*::_(.+)$/package::$1/;
        $name = $1;
        if (! defined &$sub) {
            die "cannot autoload $oldsub";
        }
        $AUTOLOAD = $sub;
        my $ret = &$AUTOLOAD;
    }
    }}
    PACKAGE::foo('bla');
   __END__

And that dies magnificently with a "cannot autoload PACKAGE::foo ..."
message.

Please provide about a short, complete program (shebang to __END__) that
exhibits the phenomenon.

: >>>Why switch off strictures here?  Only one statement requires it.  Just
: >>>declare $AUTOLOAD with "our", and everything up to then is strict-proof.
: >>
: >>It is not relevant to the subject, but thank you anyway.
: > 
: > How do you know it isn't?
: 
: Ok, I suppose you will explain why it is relevant.

Don't be obtuse.  If you cannot answer the question, that discussion must
be deferred until you provide a complete program.



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

Date: Mon, 01 Mar 2004 15:04:16 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: Re: how die in AUTOLOAD
Message-Id: <4043C170.9050205@cisco.com>



Jay Tilton wrote:
> Yuri Shtil <yshtil@cisco.com> wrote:
> : Anno Siegel wrote:
> : > Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
> : >>Anno Siegel wrote:
> : >>>Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
> : >>>
> : >>>>I check if the computed routine exists in the target package and call
> : >>>>die if it does not. When I run this code there is no die message 
> : >>>>displayed, the program exits silently.
> : >>>
> : >>>You are never calling anything, so AUTOLOAD is never triggered.  Add
> : >>>a line "gibsnich()" somewhere, and it will die as expected.
> : >>
> : >>I do call this from an another module. I traced it with the debugger and 
> : >>with prints. The die statement gets invoked with no visible effect.
> : > 
> : > Then how about showing us that mystery call?  The code you showed behaves
> : > exactly as expected.  So far this has been a waste of time.
> : 
> : You can assume it was PACKAGE::foo(bla);
> : Where foo was nowhere to exist.
> 
> That's nice, but there is still not enough information for readers to
> reproduce the problem.  Given what's available so far, and further assuming
> 'bla' is meant to be a quoted string (Can we get a ballpark estimate of how
> many more assumptions are needed?), someone trying to investigate might
> scratch out a program like:
> 
>     #!perl
>     use warnings;
>     use strict;
>     {{
>     package PACKAGE;
>     no strict;
>     sub AUTOLOAD {
>         my ($name, $oldsub);
>         my $sub = $oldsub = $AUTOLOAD;
>         $sub =~ s/.*::_(.+)$/package::$1/;
>         $name = $1;
>         if (! defined &$sub) {
>             die "cannot autoload $oldsub";
>         }
>         $AUTOLOAD = $sub;
>         my $ret = &$AUTOLOAD;
>     }
>     }}
>     PACKAGE::foo('bla');
>    __END__
> 
> And that dies magnificently with a "cannot autoload PACKAGE::foo ..."
> message.
> 
> Please provide about a short, complete program (shebang to __END__) that
> exhibits the phenomenon.
> 
> : >>>Why switch off strictures here?  Only one statement requires it.  Just
> : >>>declare $AUTOLOAD with "our", and everything up to then is strict-proof.
> : >>
> : >>It is not relevant to the subject, but thank you anyway.
> : > 
> : > How do you know it isn't?
> : 
> : Ok, I suppose you will explain why it is relevant.
> 
> Don't be obtuse.  If you cannot answer the question, that discussion must
> be deferred until you provide a complete program.
> 

The problem is (was) that the complete program was very large and it was 
not practical to publish it here.

WHen I cut the code to the minimum, like:

------------------------ Start Program --------------------------------
#!/usr/local/bin/perl
use strict;

my $obj = new newpack;

$obj->foo();

package newpack;

sub new
   {
       my ($self) = @_;

       bless {}, $self;
}

sub DESTROY {};

sub AUTOLOAD
   {
       my ($name, $oldsub);
no strict;
       my $sub = $oldsub = $AUTOLOAD;
       $sub =~ s/.*::(.+)$/pims_smu3::$1/;

       $name = $1;

       if (! defined &$sub) {
#          print "cannot find $name in pims_smu3\n";
           die "cannot autoload $oldsub";
       }

       shift;
       my $ret = &$sub(@_);
}

------------------------ End Program --------------------------------

the die message appeared.

So the problem lies somewhere in  very large chunk of code that I 
omitted and as I said it was nor practical to post it here. I am not 
sure it would even compile since it uses a whole bunch of propriatory 
modules.

Ilya Zacharevitch suggested setting $DB:debugLevel to 5 which made the 
die message magically appear. Obviously there was a way to provide help 
without insulting.

I did not mean to appear obtuse or inflammatory but it ticks me when 
people tell me to shut up without a reason other that I posted 
incomplete code.



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

Date: Mon, 01 Mar 2004 13:23:23 -0800
From: Lowell Kirsh <lkirsh@cs.ubc.ca>
Subject: how do I choose between an explicit file and standard input
Message-Id: <c209kb$mdc$1@mughi.cs.ubc.ca>

I want to write a script that will take an optional filename as a 
command line argument and will use stdin if no parameter is supplied. 
What the script does is count the number of unique lines in a file. For 
example I want 'theScript foo' to act like:

system "uniq < foo | wc -l"

but if no parameter is supplied it should act like:

system "uniq < {standard input} | wc -l"

Does this make sense?

Lowell



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

Date: 1 Mar 2004 21:48:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how do I choose between an explicit file and standard input
Message-Id: <c20b37$clp$2@mamenchi.zrz.TU-Berlin.DE>

Lowell Kirsh  <lkirsh@cs.ubc.ca> wrote in comp.lang.perl.misc:
> I want to write a script that will take an optional filename as a 
> command line argument and will use stdin if no parameter is supplied. 
> What the script does is count the number of unique lines in a file. For 
> example I want 'theScript foo' to act like:
> 
> system "uniq < foo | wc -l"
> 
> but if no parameter is supplied it should act like:
> 
> system "uniq < {standard input} | wc -l"
> 
> Does this make sense?

It makes so much sense that Perl makes this the default behavior of
the input operator "<>" if no file handle is given.  It even allows you
to specify more than one file on the command line, which are read one
after the other.  If none is given, it reads from STDIN.

So your program could be written like this:

    my %h;
    @h{ <> } = ();
    print scalar keys %h, "\n";

Anno


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

Date: Mon, 1 Mar 2004 21:46:06 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: how do I choose between an explicit file and standard input
Message-Id: <c20asr$gco$1@news.simnet.is>

"Lowell Kirsh" <lkirsh@cs.ubc.ca> wrote in message
news:c209kb$mdc$1@mughi.cs.ubc.ca...
> I want to write a script that will take an optional filename as a
> command line argument and will use stdin if no parameter is supplied.
> What the script does is count the number of unique lines in a file. For
> example I want 'theScript foo' to act like:
>
> system "uniq < foo | wc -l"
>
> but if no parameter is supplied it should act like:
>
> system "uniq < {standard input} | wc -l"

the general answer to this is <>
usually in the form:
    while (<>) {
       # do stuff, like $c{$_}++;
    }
    # wrap up, like print scalar keys(%c),"\n";

in this particular case, you might want to use -n:
   #/usr/bin/perl -nl
   $c{$_}++;
  END {print scalar keys %c}

or a command line:
    perl -nle'$c{$_}++;END{print scalar keys %c}' input_file
another_input_file
    perl -nle'$c{$_}++;END{print scalar keys %c}' < input_file
    grep bla somefile | perl -nle'$c{$_}++;END{print scalar keys %c}'

gnari







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

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


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