[22293] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4514 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 5 09:09:02 2003

Date: Wed, 5 Feb 2003 06:07:12 -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           Wed, 5 Feb 2003     Volume: 10 Number: 4514

Today's topics:
        @{undef} behaves different. Why? <g111@netcologne.de>
    Re: @{undef} behaves different. Why? (Anno Siegel)
    Re: @{undef} behaves different. Why? <g111@netcologne.de>
    Re: @{undef} behaves different. Why? (Tad McClellan)
    Re: APL's relation to perl <bik.mido@tiscalinet.it>
        Bidirectional communication -- solution ok? [long, nice <joerg.ziefle@gmx.de>
    Re: Converting a string to time value (seconds since Ep <bart.lateur@pandora.be>
    Re: Crossposting (was: Fetchrow Question) (Anno Siegel)
    Re: Crossposting (was: Fetchrow Question) (Helgi Briem)
    Re: Crossposting (was: Fetchrow Question) <me@privacy.net>
    Re: Crossposting (was: Fetchrow Question) <me@privacy.net>
        Font lock problems in xemacs 20.0 in perl-mode (Daniel Chandran)
    Re: Font lock problems in xemacs 20.0 in perl-mode <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: How do you: 'make install PREFIX=somepath', and the (Anno Siegel)
        How to capture an event ? (rusneht)
    Re: How to capture an event ? (Anno Siegel)
        PERL + SQL (fredduc)
    Re: perl simple script (zr)
    Re: perl simple script (Anno Siegel)
    Re: perl simple script <tassilo.parseval@post.rwth-aachen.de>
        Return the index of an array <alex@alexbanks.com>
    Re: sort, my concoction of <abigail@abigail.nl>
        Splitting data into variables <Geezer@Freezer.com>
    Re: Splitting data into variables <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Splitting data into variables (Anno Siegel)
    Re: Splitting data into variables <Geezer@Freezer.com>
    Re: Splitting data into variables <bernard.el-hagin@DODGE_THISlido-tech.net>
        Strange behaviour using underscore "_" as a subroutine  <scriptyrich@yahoo.co.uk>
    Re: Strange behaviour using underscore "_" as a subrout <sfandino@yahoo.com>
    Re: Strange behaviour using underscore "_" as a subrout (Tad McClellan)
        www.giveawayclub.com 42" Plasma $500 , Double your mone <promo@giveawayclub.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 05 Feb 2003 10:20:18 +0100
From: Gert Brinkmann <g111@netcologne.de>
Subject: @{undef} behaves different. Why?
Message-Id: <b1qkui$d80$2@newsreader2.netcologne.de>


Just for interest. Why does

use strict;
my $lr = undef;
push @{$lr}, "foo";

work, but

use strict;
my $lr = undef;
print @{$lr};

does throw the exception "Can't use an undefined value as an ARRAY 
reference"?

Thanks,

Gert



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

Date: 5 Feb 2003 09:53:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: @{undef} behaves different. Why?
Message-Id: <b1qmv1$aud$1@mamenchi.zrz.TU-Berlin.DE>

Gert Brinkmann  <g111@netcologne.de> wrote in comp.lang.perl.misc:
> 
> Just for interest. Why does
> 
> use strict;
> my $lr = undef;
> push @{$lr}, "foo";

This works because $lr is autovivified.  Autovivification happens
when an expression is used as a reference in an lvalue context and
is undefined (and capable of holding a reference).  The first argument
of push() is an lvalue position, so $lr is autovivified to contain
an arrayref.  Print out $lr after the push() to see this.

> work, but
> 
> use strict;
> my $lr = undef;
> print @{$lr};
> 
> does throw the exception "Can't use an undefined value as an ARRAY 
> reference"?

In print() the arguments are not in an lvalue (assignable) context,
so no autovivification happens.

Anno


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

Date: Wed, 05 Feb 2003 11:10:27 +0100
From: Gert Brinkmann <g111@netcologne.de>
Subject: Re: @{undef} behaves different. Why?
Message-Id: <b1qnsk$k94$1@newsreader2.netcologne.de>


Thank you for your quick answer.

Anno Siegel wrote:

>>use strict;
>>my $lr = undef;
>>push @{$lr}, "foo";
> 
> 
> This works because $lr is autovivified.  Autovivification happens

Autovivification, cool word. :)

> when an expression is used as a reference in an lvalue context and
> is undefined (and capable of holding a reference).  The first argument
> of push() is an lvalue position, so $lr is autovivified to contain
> an arrayref.  Print out $lr after the push() to see this.

Interesting is, that the lvalue is autovivified recursively. For the code

my @list;
push @list, "foo";

i did know that it works. But that the dereferencing is autovivified, 
too, was astonishing for me.

Thanks,

Gert



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

Date: Wed, 5 Feb 2003 07:09:18 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: @{undef} behaves different. Why?
Message-Id: <slrnb4237u.b0b.tadmc@magna.augustmail.com>

Gert Brinkmann <g111@netcologne.de> wrote:
> Anno Siegel wrote:
> 
>>>use strict;
>>>my $lr = undef;
>>>push @{$lr}, "foo";
>> 
>> 
>> This works because $lr is autovivified.  Autovivification happens
> 
> Autovivification, cool word. :)


Uri wrote a nice article about autoviv:

   http://tlc.perlarchive.com/articles/perl/ug0002.shtml


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


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

Date: Wed, 05 Feb 2003 09:58:02 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: APL's relation to perl
Message-Id: <a4k14vg8ucrv43gmg3s8rtn03clvs9l30u@4ax.com>

On 4 Feb 2003 09:06:54 GMT, "Tassilo v. Parseval"
<tassilo.parseval@post.rwth-aachen.de> wrote:

>> Sorry, I do know in general what 'aliasing' is in programming
>> languages context. For some reason yesterday I was unable to connect
>> this plain piece of information with the subject matter we're
>> discussing!
>
>I don't know whether 'aliasing' is a general concept in programming
>languages context. But it is certainly a concept to know about in Perl.

It is: especially for what regards the subject of passing
parameters... (e.g. for what regards the difference between passing
parameters "by reference" and certain forms of passing "by copy").

>It really means what it sounds like: You have two names for the same
>thing. There are a couple of spots where aliasing comes into the game in
>Perl. For instance:

Thanks for you detailed explanation, but I did already know these
matters... hopefully they will be useful to someone else.

>>> work would be to create a source filter, which finds stuff like that
>>                             ^^^^^^^^^^^^^
>>>and changes the @a (x) @b into some_function(\@a, \@b).
>> 
>> Where is this kind of things documented? Do you consider it to be too
>> far above the top of a relative newbie's head, anyway?
>
>It is hidden in modules. Filter::Util::Call is the most powerful
>implementation of it. Damian Conway has written a more usable front-end
>for it (see Filter::Simple on the CPAN).

Thanks.

>I don't think it is 'far above the top of a relative newbie's head'.
>Perl does not impose an order in which you are supposed to learn the
>language. If you call yourself a newbie but think that source-filters
>are cool, then please use them. Everyone is allowed to indulge with

Let's say that I'm very curious!

>whatever feature/subset he/she likes best about Perl. That's part of
>Perl's success.

Agreed!!


Michele
-- 
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth.  See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"


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

Date: Wed, 05 Feb 2003 12:56:39 +0100
From: =?ISO-8859-1?Q?J=F6rg?= Ziefle <joerg.ziefle@gmx.de>
Subject: Bidirectional communication -- solution ok? [long, nice ASCII chart :-]
Message-Id: <3e40fbf7@pfaff.ethz.ch>

I want to use the bayesian SPAM filter bogofilter in my Mail::Audit filter
(under Unix). To avoid temporary files (probably even the better solution
in terms of expense), I want to communicate directly with the program. 
After reading perlfaq8, perlipc and failing to use IPC::Open2, I set up an
asynchronous bidirectional communication (I have to do it asynchronously,
because bogofilter does not operate one-line-in-one-line-out) after the
following scheme:

Nice ASCII chart:
-----------------
                                  +-----+
                                  |     |
                          (RH2)  WH2    |
+------+                    +-----+     |
|parent|                    |child|     |
+------+                    +-----+     |
RH1 (WH1)                 (RH1) (WH1)   |
 |                                      |
/|\          +--------------------------+
 |           | 
 |          \|/
 |           |
 |          RH2  (WH2)
 |         +-|-------+
 |         | 0       |
 |         |   bogo  |
 |         |       1 |
 |         +-------|-+
 |         (RH1)  WH1
 |                 |
 +-----------------+

Legend of nice ASCII chart:
---------------------------
0: STDIN
1: STDOUT
Filehandles in parens: closed
parent, child, bogo:
bogo: bogofilter -pu

Explanation of nice ASCII chart:
--------------------------------
In the parent, I generate a connected file handle pair (with pipe()). Then I
fork and generate another connected file handle pair in the child. By
forking again in the child, I create a third process which will eventually
be used to run the bogofilter program (with exec()). But before doing this,
I am connecting the STDOUT and STDIN of the process which will become
bogofilter to the write handle of the parent (WH1) and the readhandle of
the child (RH2), respectively. I am closing all the unused file handles in
the three processes as well. Then I exec bogofilter, and the communication
goes as follows:


 * The STDOUT of bogofilter goes to WH1 which is connected to RH1 of the
parent.
 * The write handle WH2 of the child is connected to the read handle RH2 of
bogofilter which then goes to its STDIN.

This way, I can let the child write to bogofilter's STDIN, and the parent
read from its STDOUT asynchronously.

Implementation of nice ASCII chart:
-----------------------------------
# caution: error checking and child reaping omitted
sub do_bogo { # pass mail to bogofilter and read it back

  my @data = @{+shift}; # get mail as arrayref

  pipe RH1, WH1;
  if (fork()) {    # parent
    close WH1;
    @data = <RH1>; # read mail to bogofilter
  } else {         # child
    pipe RH2, WH2;
    if (fork()) {  # (same) child
      close RH1;
      close WH1;
      close RH2;
      print WH2 @data; # print mail to bogofilter
      exit;
    } else {       # bogofilter (child of child)
      close RH1;
      close WH2;
      open STDOUT, '>&WH1';
      open STDIN,  '>&RH2';
      exec @BOGO;  # run bogofilter (@BOGO = qw/bogofilter -p -u/)
      die "Couldn't exec @BOGO: $!\n;";
    }
  }

  return \@data;

}

Questions:
---------
I've tested the above a little, and it seems to work well.  However, as the
code is dealing with my mail, and this setup seems to be quite fragile to
me, I would rather not have it loose data due to some hidden quirk. :)

 * I this solution robust, correct and working (heavy load, ...)? 
Specifically, are there chances that it will block or generate a SIGPIPE?
 * Would it be better to
   a) pass the data over to bogofilter in temporary files and just read back
itsbogofilter STDOUT
   b) write an XS extension to bogofilter to avoid creating new processes?
 * Is there -- generally speaking -- a better solution to the problem?

Well, I think I know the answer to the second question. :)

Thanks for listening,

Joerg

P.s.: I am aware that the 'real' content (asynchronous bidirectional
communication) would rather belong comp.unix.programmer. Nevertheless I am
posting this to a Perl newsgroup to get hints on the specific Perl
implementation (bayesian SPAM checking).


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

Date: Wed, 05 Feb 2003 12:28:47 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Converting a string to time value (seconds since Epoch)
Message-Id: <lp024vodm8rq6j60mthdjoomgvdavv023h@4ax.com>

Flynn wrote:

>I've scoured every resource I have, and although it's easy enough to turn a
>time value into a string with the help of the localtime() function, I can't
>figure out how to do it the other way round. Basically, I need to convert a
>date typed on a form, and store it as a value. How ????

Date::Calc. Time::Local.

For the latter, see here:

	<http://perlmonks.org/index.pl?node_id=232687>

-- 
	Bart.


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

Date: 5 Feb 2003 08:34:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Crossposting (was: Fetchrow Question)
Message-Id: <b1qiae$6hg$2@mamenchi.zrz.TU-Berlin.DE>

mgarrish <mgarrish@rogers.com> wrote in comp.lang.perl.misc:
> 
> "Uri Guttman" <uri@stemsystems.com> wrote in message
> news:x7u1fjpumi.fsf@mail.sysarch.com...
> >
> > matt, i am not arguing with you. i am trolling you.
> >
> 
> I'm well aware of that. But trolling is not a one way street, so until the
> next time you make the mistake of stepping in my pond, remember that it is
> now Matt 3 Uri 0...

It must be nice to be player and umpire in one person.  Now go back
to your sandbox.

Anno


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

Date: Wed, 05 Feb 2003 10:21:06 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Crossposting (was: Fetchrow Question)
Message-Id: <3e40e544.583736538@news.cis.dfn.de>

On Tue, 04 Feb 2003 21:40:43 GMT, "mgarrish"
<mgarrish@rogers.com> wrote:
>
>"Ben Morrow" <mauzo@mimosa.csv.warwick.ac.uk> wrote in message
>news:b1p015$nk6$1@wisteria.csv.warwick.ac.uk...
>>
>> *plonk*
>>
>And why do you think that I or anyone else cares?

When people see a knowledgable poster killfile
someone, they often realise that said person
posts rubbish and ignore him or downgrade their
opinion of him.  In this way Ben's public plonk
has great value.
-- 
Regards, Helgi Briem
helgi AT decode DOT is


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

Date: Wed, 5 Feb 2003 23:29:23 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Crossposting (was: Fetchrow Question)
Message-Id: <b1r05c$15tljn$1@ID-172104.news.dfncis.de>


"mgarrish" <mgarrish@rogers.com> wrote in message
news:vrW%9.269780$pDv.258039@news04.bloor.is.net.cable.rogers.com...
>
> "Ben Morrow" <mauzo@mimosa.csv.warwick.ac.uk> wrote in message
> news:b1p015$nk6$1@wisteria.csv.warwick.ac.uk...
> >
> > *plonk*
> >
>
> And why do you think that I or anyone else cares?

I care, because Ben and other posters of value and expertise obviously find
you tiresome.  Their opinion counts for a lot of other people.




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

Date: Wed, 5 Feb 2003 23:30:35 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Crossposting (was: Fetchrow Question)
Message-Id: <b1r05e$15tljn$2@ID-172104.news.dfncis.de>


"mgarrish" <mgarrish@rogers.com> wrote in message
news:HAR%9.555155$F2h1.421665@news01.bloor.is.net.cable.rogers.com...
>
> "Uri Guttman" <uri@stemsystems.com> wrote in message
> news:x7n0lcskv0.fsf@mail.sysarch.com...
> > >>>>> "m" == mgarrish  <mgarrish@rogers.com> writes:
> >
> > so low volume and mostly wrong is better than high volume (which is
> > easily handled with a good newsreader) which has many perl experts
> > around?
> >
>
> You really aren't very good with logic are you? His assertion was that the
> only people who read alt.perl fell into his two simplistic categories.
CLPM
> has only a few people who could be considered "experts" (of which you are
> not one, I'm afraid), but a vast number of people who think they are
because
> all they can say is RTFM or parrot the answers of the one or two experts.

Matt.  Matt.  So young and so much to learn.




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

Date: 5 Feb 2003 04:51:46 -0800
From: DanielChandran@comcast.net (Daniel Chandran)
Subject: Font lock problems in xemacs 20.0 in perl-mode
Message-Id: <c10ee31b.0302050451.5287f729@posting.google.com>

I am using XEmacs v 20.0, and have a strange font
lock problems in perl mode.

sub MySub
{

}

does not font lock  the function name whereas 

sub MySub {

} 

does fine.  Is there any var I need to set for the first form
to get syntax highlighting?

Thanks,
daniel


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

Date: Wed, 5 Feb 2003 12:58:14 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Font lock problems in xemacs 20.0 in perl-mode
Message-Id: <Xns93198D787ED36elhber1lidotechnet@62.89.127.66>

Daniel Chandran wrote:

> I am using XEmacs v 20.0, and have a strange font
> lock problems in perl mode.
> 
> sub MySub
> {
> 
> }
> 
> does not font lock  the function name whereas 
> 
> sub MySub {
> 
> } 
> 
> does fine.  Is there any var I need to set for the first form
> to get syntax highlighting?


This is an Emacs question, not a Perl question.


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



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

Date: 5 Feb 2003 08:29:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How do you: 'make install PREFIX=somepath', and then platform-independantly find somepath?
Message-Id: <b1qi0o$6hg$1@mamenchi.zrz.TU-Berlin.DE>

Asfand yar Qazi  <f_ker@yahoo.co.uk_NO_SPAM> wrote in comp.lang.perl.misc:

[...]
 
> I think I know what to do now.  After MUCH MUCH thought I can say that 
> the following program, when executed, outputs a path to append to the 
> end of PREFIX.  This gives a path that, when used with 'perl -I', allows 
> perl to find modules in PREFIX, regardless of where/why/when/how perl 
> was installed.
> 
> #!/usr/local/bin/perl -w
> 
> use Config;
> use strict;
> 
> my $stem = $Config{sitelib_stem};
> my $prefix = $Config{prefix};
> $stem =~ m!($prefix)(.+)!;
> print $2;
> __END__
> 

Ah, so the elusive quantity is $Config{ sitelib_stem}.

The above could also be written

    my ( $x) = $Config{ sitelib_stem} =~ /^\Q$Config{ prefix}\E(.+)/;
    print $x;

It is a little more robust (note anchoring and the \Q ... \E pair).

Anno


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

Date: 5 Feb 2003 00:07:06 -0800
From: ramthen@yahoo.com (rusneht)
Subject: How to capture an event ?
Message-Id: <ab96940e.0302050007.3e475a1c@posting.google.com>

Hi gurus ,
 I am trying to capture occurrence of certain events ; these events
when completed are stored in unique files. As each event gets over, I
would like to caputre at what time it was complete ?

 Any ideas ?

Thanks
RUS


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

Date: 5 Feb 2003 08:37:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to capture an event ?
Message-Id: <b1qih4$6hg$3@mamenchi.zrz.TU-Berlin.DE>

rusneht <ramthen@yahoo.com> wrote in comp.lang.perl.misc:
> Hi gurus ,
>  I am trying to capture occurrence of certain events ; these events
> when completed are stored in unique files. As each event gets over, I
> would like to caputre at what time it was complete ?
> 
>  Any ideas ?

No, only questions.  What is an event, and how does your program
learn that it happened?

Anno


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

Date: 5 Feb 2003 02:46:06 -0800
From: fredduc@hotmail.com (fredduc)
Subject: PERL + SQL
Message-Id: <7f151cfe.0302050246.4f7792e6@posting.google.com>

Hi all,


This is just a newbie question, here it comes:

I want run an APACHE web server (no problem so far), but now I want to
make it able to run ASP. Is it correct I need mod_perl-2.0 for it?

And second question: I use a lot of (shame on me) MS Access databases.
Is this Perl compatible with MS-SQL? Because I do have too much
ASP-pages based on MS-SQL and NOT MySQL...

Thanks in advance!

Fred


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

Date: 5 Feb 2003 01:43:59 -0800
From: zabo@mixmail.com (zr)
Subject: Re: perl simple script
Message-Id: <70ac9e9a.0302050143.38cb7bae@posting.google.com>

> But to say the truth, I'm wondering about the client. Unless he/she is a
> Perl regexp master, the more power of Perl's regexps isn't really useful.
> And if he/she is, it's a simple one ... three liner, I wouldn't pay
> anybody to do it!

The regexp used in the script will be generated by a program, not by
the client.
Thanks for the anwser.

> 
> > Thanks to all (not to you, Tassilo, get a life), I guess I will use
> > Tonys 1 line code.
> 
> I'm sure Tassilo has a life. But, he also uses a lot of his time to 
> help people finding _good_ solutions without any credit in this newsgroup.
> You really can take him serious. In fact, I had the same opinion like him!

I see. But if a message if offtopic from someone's view, maybe is
better to ignore it than to reply in a harsh way (maybe its my
english, but 'go away' does not seem good manners for me).

> 
> 
> Cheerio,
> Janek


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

Date: 5 Feb 2003 10:09:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl simple script
Message-Id: <b1qns8$bi4$1@mamenchi.zrz.TU-Berlin.DE>

zr <zabo@mixmail.com> wrote in comp.lang.perl.misc:

[...]

> > > Thanks to all (not to you, Tassilo, get a life), I guess I will use
> > > Tonys 1 line code.
> > 
> > I'm sure Tassilo has a life. But, he also uses a lot of his time to 
> > help people finding _good_ solutions without any credit in this newsgroup.
> > You really can take him serious. In fact, I had the same opinion like him!
> 
> I see. But if a message if offtopic from someone's view, maybe is
> better to ignore it than to reply in a harsh way (maybe its my
> english, but 'go away' does not seem good manners for me).

It isn't particularly polite, but then polite behavior on Usenet
would require you to watch a newsgroup a while so you can judge
yourself if your posting is on topic, or learn enough about local
customs to know how you can slip in an off-topic question in an
acceptable way.  Did you do that?

Off-topic postings are a major waste of time for those of us who
regularly scan all the postings to see if they can answer a question.
Most of the time, off-topic postings are indeed ignored, but from time
to time a reminder is in order to point out that the group does have
a topic.  These reminders tend to be curt and sarcastic.

Anno


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

Date: 5 Feb 2003 13:29:50 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: perl simple script
Message-Id: <b1r3ke$5cm$1@nets3.rz.RWTH-Aachen.DE>

Also sprach zr:

[ Attributes missing ]

>> > Thanks to all (not to you, Tassilo, get a life), I guess I will use
>> > Tonys 1 line code.
>> 
>> I'm sure Tassilo has a life. But, he also uses a lot of his time to 
>> help people finding _good_ solutions without any credit in this newsgroup.
>> You really can take him serious. In fact, I had the same opinion like him!
> 
> I see. But if a message if offtopic from someone's view, maybe is
> better to ignore it than to reply in a harsh way (maybe its my
> english, but 'go away' does not seem good manners for me).

It wasn't off-topicness that made me reply to you. It was rather your
"I-dont-want-to-learn-Perl-since-it-doesnt-pay-off"-attitude. Such a
thing is a major social faux-pas: You can't simply step into the 'realm'
of a particular community, request help from them and at the same time
imply that their topics are rather meaningless to you. They aren't,
otherwise you hadn't posted.

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: Wed, 5 Feb 2003 13:54:47 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Return the index of an array
Message-Id: <3e4117ab$0$230$cc9e4d1f@news.dial.pipex.com>

I need a way to reference the index of an array element in a foreach style
loop, as my array indices maybe out of sequence.

For example:

my @alex = ("one","two","three");
$alex[52] = "four";
for (@alex) {print}

This prints the contents of the array, but inside the for loop I need to
retrieve the index for that element. So the loop will print 0, 1, 2, 52 (in
using this method I trust that my array does not allocate space for 53
elements, but only for the four that I use).

Any ideas - is this possible?


Alex
---------------------------
alex@alexbanks.com
http://www.alexbanks.com




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

Date: 05 Feb 2003 08:18:06 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: sort, my concoction of
Message-Id: <slrnb41i5t.p46.abigail@alexandra.abigail.nl>

Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMMCDXLIV September
MCMXCIII in <URL:news:slrnb40hrt.se5.mgjv@verbruggen.comdyn.com.au>:
%%  
%%  Using things like [:upper:], [:lower:], [:alpha:], [:alnum:] etc in a
%%  regular expression character class is much more reliable.

Some some values of 'reliable'. They aren't very usefull if you maintain
a module that should also work on pre-5.6 perl. Furthermore, [:upper:]
and [:lower:] are *not* equivalent to [A-Z] and [a-z]. If Unicode is
in effect [:upper:] matches all uppercase letters, and [:lower:]
matches all lowercase letters. That's why in Regexp::Common I use
[a-z], [A-Z] and [0-9] instead of [:upper:], [:lower:], \w or \d.

I also thought that '[a-z]' and such was special cased on EBCDIC
platforms to match all lowercase letters, but I don't have the time
to search the manual for it right now.



Abigail
-- 
perl -wle 'print prototype sub "Just another Perl Hacker" {};'


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

Date: Wed, 05 Feb 2003 10:27:52 +0000
From: Geezer From The Freezer <Geezer@Freezer.com>
Subject: Splitting data into variables
Message-Id: <3E40E728.C2E34508@Freezer.com>

I need to do the following with this variable assume the variable is called
datavar

3 packets transmitted, 3 packets received, 0% packet loss round-trip (ms)
min/avg/max = 3/3/3

I need to grab the 0% and the 2nd field (from 3/3/3 - i.e. the middle 3 and put
them into
variables.

How do I do this ?


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

Date: Wed, 5 Feb 2003 10:48:09 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Splitting data into variables
Message-Id: <Xns9319776BD522Eelhber1lidotechnet@62.89.127.66>

Geezer From The Freezer wrote:

> I need to do the following with this variable assume the variable is
> called datavar
> 
> 3 packets transmitted, 3 packets received, 0% packet loss round-trip
> (ms) min/avg/max = 3/3/3
> 
> I need to grab the 0% and the 2nd field (from 3/3/3 - i.e. the middle
> 3 and put them into
> variables.
> 
> How do I do this ?


Do you mean that $datavar contains the text "3 packets transmitted, 3 
packets received, 0% packet loss round-trip (ms) min/avg/max = 3/3/3"?


If so you can try:


my ($percent, $middle) = $datavar =~ m!(\d+%).*\d+/(\d+)/!;


But whether this works for you or not depends on how much your real input 
changes from your example.


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


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

Date: 5 Feb 2003 10:50:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Splitting data into variables
Message-Id: <b1qq9m$bi4$2@mamenchi.zrz.TU-Berlin.DE>

Geezer From The Freezer  <Geezer@Freezer.com> wrote in comp.lang.perl.misc:
> I need to do the following with this variable assume the variable is called
> datavar
> 
> 3 packets transmitted, 3 packets received, 0% packet loss round-trip (ms)
> min/avg/max = 3/3/3
> 
> I need to grab the 0% and the 2nd field (from 3/3/3 - i.e. the middle 3 and put
> them into
> variables.
> 
> How do I do this ?

    my ( $percent, $average) = m!(\d+)%.*/(\d+)/!; # untested

Anno


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

Date: Wed, 05 Feb 2003 11:57:28 +0000
From: Geezer From The Freezer <Geezer@Freezer.com>
Subject: Re: Splitting data into variables
Message-Id: <3E40FC28.59083071@Freezer.com>

I'm not very familiar with perl
how do I get the figure that has the percent into a seperate variable
and the middle other value into a variable?



i.e.

0% into a var called percent and 3 into a var called roundtrip?



Bernard El-Hagin wrote:
> 
> Geezer From The Freezer wrote:
> 
> > I need to do the following with this variable assume the variable is
> > called datavar
> >
> > 3 packets transmitted, 3 packets received, 0% packet loss round-trip
> > (ms) min/avg/max = 3/3/3
> >
> > I need to grab the 0% and the 2nd field (from 3/3/3 - i.e. the middle
> > 3 and put them into
> > variables.
> >
> > How do I do this ?


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

Date: Wed, 5 Feb 2003 12:13:28 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Splitting data into variables
Message-Id: <Xns931985E16F917elhber1lidotechnet@62.89.127.66>


[Please don't top post]


Geezer From The Freezer wrote:

> Bernard El-Hagin wrote:
>> 
>> Geezer From The Freezer wrote:
>> 
>> > I need to do the following with this variable assume the variable is
>> > called datavar
>> >
>> > 3 packets transmitted, 3 packets received, 0% packet loss round-trip
>> > (ms) min/avg/max = 3/3/3
>> >
>> > I need to grab the 0% and the 2nd field (from 3/3/3 - i.e. the middle
>> > 3 and put them into
>> > variables.
>> >
>> > How do I do this ?
>
> I'm not very familiar with perl
> how do I get the figure that has the percent into a seperate variable
> and the middle other value into a variable?
> 
> 
> 
> i.e.
> 
> 0% into a var called percent and 3 into a var called roundtrip?


In the code I provided (which you snipped) change the word "middle" into 
"roundtrip". The rest does what you want, as far as I can tell. You can 
also use Anno's code, but your input should be in $_ not in $datavar.


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


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

Date: Wed, 05 Feb 2003 12:58:02 +0000
From: Scripty <scriptyrich@yahoo.co.uk>
Subject: Strange behaviour using underscore "_" as a subroutine name
Message-Id: <b1r1ni$jjl$1@newsg4.svr.pol.co.uk>

Hello

I've just started to I18N my code and have hit a problem!

I'm trying to stick to (unofficial AFAIK) conventions re strings, and am 
using underscore to tag strings to be localized eg:

_("Unable to open file: %1", $filename);

This keeps things unobtrusive and allows xgettext to work - I want to use 
existing frameworks rather than create one from scratch.

I obviously then need a way to get _ imported into every module that 
requires I18N. I can declare the _ subroutine in my I18N module and export 
it implicitly using Exporter and @EXPORT = qw( _ ) - yes I know this may be 
bad and I might use @EXPORT_OK instead!

But I'm sure the behaviour I'm seeing is wrong: "_" gets redefined in EVERY 
module, whether I "use" my I18N module or not, and consequently any module 
using cached stat structures, -e $file && -f _ && -T _ etc, fails 
miserably. As I use File::Temp in a number of places this is clearly a no 
go.

But this behaviour isn't down to Exporter, I've got the same thing with 
extremely simple code, as shown below:

########### File 1 Ridas/A.pm ##############

package Ridas::A;

sub _
{
  print __PACKAGE__, ": Underscore called\n";
}

1;

########### File 2 Ridas/B.pm ##############

package Ridas::B;

use File::Temp;

print File::Temp::tempfile();

1;

########### File 3: a.pl ##############

use Ridas::A;

_("");

########### File 4: b.pl ##############

use Ridas::A;
use Ridas::B;

_("");

############## Results ###############

[rich@dev1 Ridas]$ perl -v

This is perl, v5.8.0 built for i386-linux-thread-multi


[rich@dev1 Ridas]# perl a.pl
Ridas::A: Underscore called


[rich@dev1 Ridas]# perl b.pl
Ridas::A: Underscore called
Ridas::A: Underscore called
Error in tempfile() using /XXXXXXXXXX: Parent directory (/) is not writable
 at /usr/lib/perl5/vendor_perl/Ridas/A.pm line 5
Compilation failed in require at b.pl line 2.
BEGIN failed--compilation aborted at b.pl line 2.

Both these results show the problem - surely both should give the error 
"Undefined subroutine &main::_ called"?

Instead, "main::_" AND "_" in File::Temp are getting defined/redefined, with 
disastrous results.

Can someone explain what the heck is going on? Is underscore highly magical 
and simply too dangerous to be mucking about with?

OK, I can directly manipulate the symbol table, which appears to work.

package Ridas::A;

*{__PACKAGE__ . "::_"} = sub { print __PACKAGE__, ": Underscore called\n" };


BUT I want to make sure I understand what's going on, and currently I don't 
:(

Equally, does anyone have experience of I18Ning apps and can advise me on 
what to do/not to do. I'm currently considering Locale::Maketext and 
Locale::Maketext::Lexicon, xgettext.pl to extract .po files and kbabel for 
L10N.

Sorry this is a long posting!
--
Rich
scriptyrich@yahoo.co.uk


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

Date: Wed, 05 Feb 2003 14:28:46 +0000
From: =?ISO-8859-1?Q?Salvador_Fandi=F1o_Garc=EDa?= <sfandino@yahoo.com>
Subject: Re: Strange behaviour using underscore "_" as a subroutine name
Message-Id: <3E411F9E.9090908@yahoo.com>

Hi

> 
> But I'm sure the behaviour I'm seeing is wrong: "_" gets redefined in EVERY 
> module, whether I "use" my I18N module or not, and consequently any module 
> using cached stat structures, -e $file && -f _ && -T _ etc, fails 
> miserably. As I use File::Temp in a number of places this is clearly a no 
> go.


This is because '_' subroutine is special, it's the same sub in any 
package (the same happens with $_ and also with @_ and %_). Just use 
other name for your sub like 'T'.

Bye,

   - Salva



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

Date: Wed, 5 Feb 2003 08:00:24 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Strange behaviour using underscore "_" as a subroutine name
Message-Id: <slrnb4267o.b6g.tadmc@magna.augustmail.com>

Salvador Fandiño García <sfandino@yahoo.com> wrote:
>> 
>> But I'm sure the behaviour I'm seeing is wrong: "_" gets redefined in EVERY 
>> module,

> This is because '_' subroutine is special, it's the same sub in any 
> package (the same happens with $_ and also with @_ and %_). Just use 
> other name for your sub like 'T'.


or, to remain "unobtrusive":

   sub __ { code; }


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


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

Date: Wed, 05 Feb 2003 12:56:23 GMT
From: "Give Away Club Promos" <promo@giveawayclub.com>
Subject: www.giveawayclub.com 42" Plasma $500 , Double your money
Message-Id: <XR70a.118169$HG.18480766@news4.srv.hcvlny.cv.net>

                 We started on ebay. Now we are open to the public
                  Its

http://www.giveawayclub.com/cds.htm
                 
                 They have Sony plasma for $500 , playstation for $50
                 and Sony Notebooks for $500
                 They also have a double and even triple your money
                 program.
                 
                 http://www.giveawayclub.com/cds.htm
                 
                 Any Questions? email us promo@giveawayclub.com
                 thanks
                 
                 






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

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


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