[19381] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1576 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 21 09:05:32 2001

Date: Tue, 21 Aug 2001 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)
Message-Id: <998399109-v10-i1576@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 21 Aug 2001     Volume: 10 Number: 1576

Today's topics:
    Re: File handle persistance across fork() ? <paul.johnston@dsvr.co.uk>
    Re: File handle persistance across fork() ? (Villy Kruse)
        get html files with perl script BUT using a proxy! <esamson@web.de>
        Good old regexp teaser <s.warhurst@rl.ac.uk>
    Re: Good old regexp teaser (Eric Bohlman)
    Re: Good old regexp teaser (Anno Siegel)
    Re: Good old regexp teaser <paul@net366.com>
    Re: Good old regexp teaser <s.warhurst@rl.ac.uk>
    Re: Good old regexp teaser <s.warhurst@rl.ac.uk>
    Re: Good old regexp teaser <s.warhurst@rl.ac.uk>
    Re: How to remove duplicate records in a huge file?? <smitw1@hotmail.com>
        New Books on Web Site Design (scienceweb)
    Re: New Books on Web Site Design <dbrown@superbase.co.uk>
        passing arrays to a subroutine <eliben@il.ibm.comNOSPAM>
    Re: passing arrays to a subroutine <paul@net366.com>
    Re: passing arrays to a subroutine (Tad McClellan)
    Re: PERL compiler for windows <bart.lateur@skynet.be>
    Re: PERL compiler for windows <somewhere@in.paradise.net>
    Re: perldoc is like Greek to a beginner?? <bart.lateur@skynet.be>
    Re: simple (Martien Verbruggen)
    Re: Structuring a program (if statements) <mjcarman@home.com>
    Re: subroutines in @INC ? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: subroutines in @INC ? (Anno Siegel)
    Re: subroutines in @INC ? (Rafael Garcia-Suarez)
    Re: subroutines in @INC ? (Anno Siegel)
    Re: This is not a question ... call me slow if you like <bart.lateur@skynet.be>
    Re: Time functions and conversion <s.warhurst@rl.ac.uk>
    Re: Unix command : write - how to detect a message (Martien Verbruggen)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 21 Aug 2001 11:13:03 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: File handle persistance across fork() ?
Message-Id: <3B82342F.C0EE68DC@dsvr.co.uk>

Hi,

> I have always wondered what is the proper way to treat filehandles that are
> have been the subject of a fork() on *nix systems (Linux particularly), as
> per the simplified example below:

First rule: flush before you fork, or unflushed data at the time of fork
can end up duplicated. I think current versions of perl do this
automatically.

> Have I just been extremely lucky that the child pid did not tromp all over
> the log file output, or is this the designed behaviour ?

I think it's designed behaviour, in that writes up to a certain size are
guaranteed to be atomic.

> If the above snippet is considered "poor" in terms of its treatment of
> filehandles across processes, is there a "good" way ? Do I need to lock the
> log file across pid's, or should I be using a different log file for each
> pid (blech..) ?

I think you're code's fine. Should point out that I've found flock on
Linux doesn't work properly of file handles that have been forked. I've
found I can simultaneously get an exclusive lock in each process on a
file handle created before a fork. Presumably this problem/behaviour
exists on other OSs.

> And for bonus points - what happens if the child gives up the privileges
> that were needed to open the log file anywhay (eg changes from "root" ->
> "nobody" in the child for example where the log file is in a dir where
> "nobody" is not allowed to write) ? Or is it a case that since the file is
> already open, OS privileges are now moot ?

Almost all the checking takes place when you call open. This is how
programs like apache and bind are able to start as root, open a
privileged network socket, and then give up their root privileges
becoming a regular user. However there are a few special cases, for
example inside the FreeBSD /proc file system, as there have been
security flaws based on tracing another process owned by the same user,
and then running a setuid program in that process. Be aware that if you
have a nobody-owned process able to write to a root file, it may be
possible for a clever hacker to abuse that.

Paul


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

Date: 21 Aug 2001 11:40:01 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: File handle persistance across fork() ?
Message-Id: <slrn9o4i4h.kbp.vek@pharmnl.ohout.pharmapartners.nl>

On Tue, 21 Aug 2001 11:13:03 +0100,
    Paul Johnston <paul.johnston@dsvr.co.uk> wrote:


>
>I think you're code's fine. Should point out that I've found flock on
>Linux doesn't work properly of file handles that have been forked. I've
>found I can simultaneously get an exclusive lock in each process on a
>file handle created before a fork. Presumably this problem/behaviour
>exists on other OSs.
>



Linux systems have two locking methods: flock and fcntl.  fcntl locks
are tied to the pid and will therefore not be inherited by child processes,
whereas the flock lock is tied to the opened file descriptor which are
inherited by the child process.  It then depends on which system call is
used to implement the perl flock command, how this works across forks.

You could use strace to find out.

Also note that with file locking based on fcntl you could inadvertently
unlock the file if you open the same file for a second time in the same
process and then close it.


Villy


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

Date: 21 Aug 2001 13:41:55 +0200
From: Elvis Samson <esamson@web.de>
Subject: get html files with perl script BUT using a proxy!
Message-Id: <3b824903$1@netnews.web.de>

hi,


i have problems of downloading html files with a perl script, because the proxy 
of our network uses authentication. so i need a way, of telling the user/pass 
before downloading.


until now i use a system call with wget, but then i have to set http_proxy 
before running the script. i hope to sace resources, when i download the files 
directly into a perl string and not first into a file and so on...


i looked for a module in cpan, but i didn't understand this in lwp:ueragent


------------------------------------------------------------------------
$ua->credentials($netloc, $realm, $uname, $pass) 


Set the user name and password to be used for a realm. It is often more useful 
to specialize the get_basic_credentials() method instead. 
$ua->get_basic_credentials($realm, $uri, [$proxy]) 


This is called by request() to retrieve credentials for a Realm protected by 
Basic Authentication or Digest Authentication. 
Should return username and password in a list. Return undef to abort the 
authentication resolution atempts. 


This implementation simply checks a set of pre-stored member variables. 
Subclasses can override this method to e.g. ask the user for a username/password. 
An example of this can be found in lwp-request program distributed with this 
library. 
------------------------------------------------------------------------


what do i have to use for $netloc and $realm ?


thanks, elvis
-- 
__________________________________________________________
News suchen, lesen, schreiben mit http://newsgroups.web.de


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

Date: Tue, 21 Aug 2001 11:21:54 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Good old regexp teaser
Message-Id: <9ltco5$20je@newton.cc.rl.ac.uk>

Hi

Anyone fancy a regexp challenge? ;)

Just when you think you have regexp sussed, you get something you can get to
work like this! SO here goes:

Take a string:

$line = "subscription= by owner ack= yes confidential= yes";

These are listserv keywords and their appropriate settings, eg:
"subscription= by owner", "ack= yes" and "confidential= yes". What I want to
do is break them up into individual keyword/setting pairs.

I've tried allsorts of combinations of metacharacters and this is the
nearest one I get to working:

@pairs = $line =~ /(\S+=.+?)(\S+=|$)/g;

So it matches non-whitespace followed by an equals sign, followed by 1 or
more characters, up until it finds either more non-whitespace characters
followed by an equal sign, or the end of the string. Should be simple.
However, if I print out the array line by line I get the following:

'subscription= by owner '
'ack='
'confidential= yes'
''

[The quotes are not generated by the regexp, I've only put them in to show
up any whitespace or empty array positions]

So, it almost works, but it fails to pick up the "yes" after "ack" and I
cannot for the life of me figure out why.

Can anyone work it out?

Thanks

---------¦
  Bigus @ work
             ¦----------






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

Date: 21 Aug 2001 10:55:21 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Good old regexp teaser
Message-Id: <9ltemp$fek$1@bob.news.rcn.net>

S Warhurst <s.warhurst@rl.ac.uk> wrote:
> Take a string:

> $line = "subscription= by owner ack= yes confidential= yes";

> These are listserv keywords and their appropriate settings, eg:
> "subscription= by owner", "ack= yes" and "confidential= yes". What I want to
> do is break them up into individual keyword/setting pairs.

> I've tried allsorts of combinations of metacharacters and this is the
> nearest one I get to working:

> @pairs = $line =~ /(\S+=.+?)(\S+=|$)/g;

> So it matches non-whitespace followed by an equals sign, followed by 1 or
> more characters, up until it finds either more non-whitespace characters
> followed by an equal sign, or the end of the string. Should be simple.
> However, if I print out the array line by line I get the following:

> 'subscription= by owner '
> 'ack='
> 'confidential= yes'
> ''

> [The quotes are not generated by the regexp, I've only put them in to show
> up any whitespace or empty array positions]

> So, it almost works, but it fails to pick up the "yes" after "ack" and I
> cannot for the life of me figure out why.

> Can anyone work it out?

Yep.  Let's reproduce the target and pattern for reference:

> $line = "subscription= by owner ack= yes confidential= yes";

> @pairs = $line =~ /(\S+=.+?)(\S+=|$)/g;

The first time around, the first parenthesized expression matches up
through the space after "owner" and the second parenthesized expression
matches the "ack =."  Since they were parenthesized, they get stuck into
the return list.  Now the matching resumes starting with the space after
"ack=".  It doesn't match anything, so we move forward and don't find
anything that can successfully match until we hit the 'c' in
"confidential."  Now the first parenthesized expression matches through 
the end of the string and the second one matches the end of the string 
(giving an empty result).

I think you want a lookahead, not a second pair of capturing parens.




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

Date: 21 Aug 2001 11:05:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Good old regexp teaser
Message-Id: <9ltfa8$21f$1@mamenchi.zrz.TU-Berlin.DE>

According to S Warhurst <s.warhurst@rl.ac.uk>:
> Hi
> 
> Anyone fancy a regexp challenge? ;)
 
You have a rather mundane question.  Don't try to sell it as a
"challenge".

> Just when you think you have regexp sussed, you get something you can get to
> work like this! SO here goes:
> 
> Take a string:
> 
> $line = "subscription= by owner ack= yes confidential= yes";
> 
> These are listserv keywords and their appropriate settings, eg:
> "subscription= by owner", "ack= yes" and "confidential= yes". What I want to
> do is break them up into individual keyword/setting pairs.

One way to do it uses split to break the line at every "<name>=" point:

    my @pairs = split /(\S+=)/, $line;
    shift @pairs; # drop empty first field
    my %assoc = @pairs;

now $assoc{ subscription=} is " by owner", etc.  You can take it from
there.

Anno


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

Date: Tue, 21 Aug 2001 12:10:15 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: Good old regexp teaser
Message-Id: <998392148.13918.0.nnrp-13.d4f094e4@news.demon.co.uk>


"S Warhurst" <s.warhurst@rl.ac.uk> wrote in message
news:9ltco5$20je@newton.cc.rl.ac.uk...
> Hi
>
> Anyone fancy a regexp challenge? ;)
>
> Just when you think you have regexp sussed, you get something you can get
to
> work like this! SO here goes:
>
> Take a string:
>
> $line = "subscription= by owner ack= yes confidential= yes";
>
> These are listserv keywords and their appropriate settings, eg:
> "subscription= by owner", "ack= yes" and "confidential= yes". What I want
to
> do is break them up into individual keyword/setting pairs.
>
> I've tried allsorts of combinations of metacharacters and this is the
> nearest one I get to working:
>
> @pairs = $line =~ /(\S+=.+?)(\S+=|$)/g;
>
> So it matches non-whitespace followed by an equals sign, followed by 1 or
> more characters, up until it finds either more non-whitespace characters
> followed by an equal sign, or the end of the string. Should be simple.
> However, if I print out the array line by line I get the following:
>
> 'subscription= by owner '
> 'ack='
> 'confidential= yes'
> ''
>
> [The quotes are not generated by the regexp, I've only put them in to show
> up any whitespace or empty array positions]
>
> So, it almost works, but it fails to pick up the "yes" after "ack" and I
> cannot for the life of me figure out why.
>
> Can anyone work it out?
>
> Thanks
>
> ---------¦
>   Bigus @ work
>              ¦----------
>
>
>
>
the ack= is being swallowed by the second part of the regexp:
$line = "subscription= by owner ack= yes sir confidential= yes";

print "$1 $2\n" while $line =~ /(\S+=.+?)(\S+= |$)/g;


Shows the problem

$line = "subscription= by owner ack= yes sir confidential= yes";

print "$1 \n" while $line =~ /(\S+=.+?)(?=\S+= |$)/g;



Will give you the pairs, which you can then split. Note the ?=

There'll probably be a better answer if you wait a while!

Regards - Paul (I learnt it from a book)




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

Date: Tue, 21 Aug 2001 12:16:13 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Good old regexp teaser
Message-Id: <9ltftv$188u@newton.cc.rl.ac.uk>

"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:9ltemp$fek$1@bob.news.rcn.net...

> > @pairs = $line =~ /(\S+=.+?)(\S+=|$)/g;
>
> The first time around, the first parenthesized expression matches up
> through the space after "owner" and the second parenthesized expression
> matches the "ack =."  Since they were parenthesized, they get stuck into
> the return list.  Now the matching resumes starting with the space after
> "ack=".  It doesn't match anything, so we move forward and don't find
> anything that can successfully match until we hit the 'c' in
> "confidential."  Now the first parenthesized expression matches through
> the end of the string and the second one matches the end of the string
> (giving an empty result).
>
> I think you want a lookahead, not a second pair of capturing parens.

That's a very valuable lesson in how multiple matches are performed and is
very clearly worded (another piece of the jigsaw fits into place!)  :-)

I have now modified the expression, as such:

@pairs = $line =~ /(\S+\=.+?)(?= \S+\=|$)/g;

 .. and it generates exactly what I wanted.

Many thanks for replying.

Spencer





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

Date: Tue, 21 Aug 2001 12:29:51 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Good old regexp teaser
Message-Id: <9ltgok$18cc@newton.cc.rl.ac.uk>

Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9ltfa8$21f$1@mamenchi.zrz.TU-Berlin.DE...

> You have a rather mundane question.  Don't try to sell it as a
> "challenge".

Well, it'd been "challenging" me for over an hour! ;)

>     my @pairs = split /(\S+=)/, $line;
>     shift @pairs; # drop empty first field
>     my %assoc = @pairs;
>
> now $assoc{ subscription=} is " by owner", etc.

That's an interesting way of doing it.. I was going to use the regexp & then
split each pair into keyword and setting, because I thought that the actual
character(or characters in this case) a string is split on were lost.
Obviously not, so that's cool :)

Thanks

Spencer




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

Date: Tue, 21 Aug 2001 12:33:45 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Good old regexp teaser
Message-Id: <9ltgur$sce@newton.cc.rl.ac.uk>

"Paul Fortescue" <paul@net366.com> wrote in message
news:998392148.13918.0.nnrp-13.d4f094e4@news.demon.co.uk...
> $line = "subscription= by owner ack= yes sir confidential= yes";
>
> print "$1 \n" while $line =~ /(\S+=.+?)(?=\S+= |$)/g;
>
> Will give you the pairs, which you can then split. Note the ?=

Many thanks.. that was the direct answer to my problem :)

That's 2 of you who sussed out I was then going to further split the strings
into keywords & settings :)

Spencer





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

Date: Tue, 21 Aug 2001 10:21:53 GMT
From: Wim <smitw1@hotmail.com>
Subject: Re: How to remove duplicate records in a huge file??
Message-Id: <94e4otokigk03jmuj0shssrkin3rtc1qmp@4ax.com>

Very good solution!
Thanks!!

Wim

On 20 Aug 2001 13:58:14 -0700, mariorizzuti@yahoo.com (Mario Rizzuti)
wrote:

>"Wim" <smitw1@hotmail.com> schrieb im Newsbeitrag
>news:vk60otcm719i1q8qutk4cvmhk9iuhqtuad@4ax.com...
>
>> > How can I remove duplicate records in a huge file?
>> > The file contains about 3.000.000 records (=800Mb)
>
>"Steffen M?ler" <tsee@gmx.net> wrote in message news:<9lp60b$t36$03$1@news.t-online.com>...
>
>> I usually use the following code for arrays:
>> 
>> @array = sort @array;
>> {
>>   my $prev = '';
>>   @array = grep($_ ne $prev && ($prev = $_), @array);
>> }
>> 
>> But that won't be all that fast for such a large file.
>> You'd have to read the records into an array first anyway. Do you have 800Mb
>> memory to spare? The sort'd take hours (at the least, I guess). The quickest
>> step would be the actual removal of the duplicates.
>> 
>> I'm sure there's a better way to do this, but it won't be quick either.
>
>I am assuming that in real-world time sorting X arrays of Y elements
>each is faster than sorting 1 array of X*Y elements at least for big
>arrays.
>
>If that's true, I would split the original database in some smaller
>files based on a field value or maybe the first 2 chars of a field
>value (adding a LINE_NUM field if there isn't one).
>
>ITERAT_ORIGIN_FILE {
>   * read record @REC
>   * add LINE_NUM field to @REC
>   * AB = first 2 chars of field N
>   * append @REC to AB.txt 
>}
>
>2 or more duplicate records always fall in the same file, since they
>are identic in the N field too. I would then use your code (or an
>hash) on each file to just detect the duplicates.
>
>At this point, having a list of LINE_NUM that needs to be removed (an
>hash (DUPLICATED_LINE_NUMBER => '1'), it's easy to iterate over the
>original file and ignore the duplicates.
>
>N = -1
>ITERAT_AGAIN {
>   * N++
>   * defined($DUPLICATED_LINE_NUMBER{'N'}) ? append to <CLEAN_COPY> :
>next
>}
>
>---
>Mario Rizzuti



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

Date: 21 Aug 2001 03:19:51 -0700
From: scienceweb@my-deja.com (scienceweb)
Subject: New Books on Web Site Design
Message-Id: <4f08993c.0108210219.938a47d@posting.google.com>

New Books on Web Site Design are listed on 

www.science-books.net/wsdesign.htm

Let us know if you have any other suggestions for adding to the page.


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

Date: Tue, 21 Aug 2001 11:57:30 +0100
From: "Dave Brown" <dbrown@superbase.co.uk>
Subject: Re: New Books on Web Site Design
Message-Id: <3b823ea3_1@nnrp1.news.uk.psi.net>

I'm finding Jakob Nielsons 'Designing Web Usability' a good informative
read.

Dave Brown.


"scienceweb" <scienceweb@my-deja.com> wrote in message
news:4f08993c.0108210219.938a47d@posting.google.com...
> New Books on Web Site Design are listed on
>
> www.science-books.net/wsdesign.htm
>
> Let us know if you have any other suggestions for adding to the page.




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

Date: Tue, 21 Aug 2001 15:04:08 +0200
From: Eli Bendersky <eliben@il.ibm.comNOSPAM>
Subject: passing arrays to a subroutine
Message-Id: <3B825C48.17A60983@il.ibm.comNOSPAM>

    Hi,

I want a subroutine which receives 2 arrays as arguments
and does some computing with them.

How can I achieve it ?

Thanks in advance

--
Eli Bendersky




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

Date: Tue, 21 Aug 2001 13:17:33 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: passing arrays to a subroutine
Message-Id: <998396180.16285.0.nnrp-13.d4f094e4@news.demon.co.uk>


"Eli Bendersky" <eliben@il.ibm.comNOSPAM> wrote in message
news:3B825C48.17A60983@il.ibm.comNOSPAM...
>     Hi,
>
> I want a subroutine which receives 2 arrays as arguments
> and does some computing with them.
>
> How can I achieve it ?
>
> Thanks in advance
>
> --
> Eli Bendersky
>
>
I think this is what you want ...
@array=qw(A B);
print "$array[0], $array[1]\n";
thing(*array);

sub thing
{
local *arrayinsub= $_[0];
print "$arrayinsub[0], $arrayinsub[1]\n";
}

If not, I apologise ....





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

Date: Tue, 21 Aug 2001 07:44:31 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: passing arrays to a subroutine
Message-Id: <slrn9o4icv.ui9.tadmc@tadmc26.august.net>

Eli Bendersky <eliben@il.ibm.comNOSPAM> wrote:
>
>I want a subroutine which receives 2 arrays as arguments
>and does some computing with them.


Not possible in Perl.


>How can I achieve it ?


Pass two _references_ to arrays instead.

   perldoc perlreftut
   perldoc perlref


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


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

Date: Tue, 21 Aug 2001 11:22:31 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: PERL compiler for windows
Message-Id: <d0h4otk4r2ru2qtac46fnqt3ij4ovh8s18@4ax.com>

cyberian bear wrote:

>Is there any good ones other than Active PERL. Ive tried it and it's very
>hard to use and install.
>thanks in advance for help.

How is it hard to install and use?

Yes there are alternatives. There's Indigoperl (<www.indigostar.com>,
and the Perl from the Cygwin tools (<www.cygwin.com>, GNU for Win32).

But these aren't easier to use, or to install. (Well alright, if you
want an Apache webserver too, then IndigoPerl is easier to uninstall).
ActivePerl must be one of the easiest perl to install there is. Just
make sure that the path to perl doesn't contain spaces.

-- 
	Bart.


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

Date: Tue, 21 Aug 2001 22:00:33 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: PERL compiler for windows
Message-Id: <M4sg7.83$_M7.568403@news.interact.net.au>


"cyberian bear" <cyberian_bear@hotmail.com> wrote in message
news:cjig7.10$Ik4.282@typhoon.nyu.edu...
> Is there any good ones other than Active PERL. Ive tried it and it's very
> hard to use and install.
> thanks in advance for help.

How do you manage to install any other Windoze package?  Activestate Perl is
much easier than your average package.




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

Date: Tue, 21 Aug 2001 11:09:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <g9g4otkq84s1o24pveoiaaceipqpvtf24e@4ax.com>

Benjamin Goldberg wrote:

>> } > How about something like:
>> } > ---------------------
>> } > typedef int x ;
>> } >
>> } > x *y();
>> } > ---------------------
>> } >
>> } > Does it parse into an expression with a function call, or a
>> } > declaration?
>> }
>> } For it to be a funcion call, you would need an extra pair of parens:
>> }       (x)*y();
>> 
>> No, no -- the question is whether the parser can figure out whether
>> the second line is an expression [to be evaluated for its side effect]
>> or a declaration [of 'y' being a function that returns a pointer to an
>> 'x']
>
>Of course it's a declaration, not an expression.

"Of course"?

This is one example on how C, in this form, is not a context-free
language. The  fact that the typedef x has been defined, is context.

If you resolve typedefs by a preprocessor (is that what happens? I don't
know, I don't like C enough to figure it out), then the preprocessed
source code could well form a context-free language.

-- 
	Bart.


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

Date: Tue, 21 Aug 2001 21:37:12 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: simple
Message-Id: <slrn9o4hv8.3ga.mgjv@martien.heliotrope.home>

On 20 Aug 2001 12:06:06 GMT,
	Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> Paul Boardman wrote in comp.lang.perl.misc:
> } 
> } perl -ne '@line = split; print "$line[3]\t$line[0]-$line[1] $line[2]
> } $line[4] ", join(" ", @line[8..$#line]), "\n";' <filename>
> 			^^^^^^^^^^^^^^^^
> You can interpolate this in the double-quoted string and avoid the
> join().
> 					   ^^^^
> You can also leave the "\n" if you use the -l command-line switch.
> -l also chomps the input lines. 

 ... when used with -n or -p ---which in this case would be true--- but
not in general.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I used to have a Heisenbergmobile.
Commercial Dynamics Pty. Ltd.   | Every time I looked at the
NSW, Australia                  | speedometer, I got lost.


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

Date: Tue, 21 Aug 2001 07:38:10 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Structuring a program (if statements)
Message-Id: <3B825632.B12E4EA2@home.com>

Peter Mann wrote:
> 
> Could someone please advise me if there is a better method of
> structuring this program. I start by using a combo widget and
> populate it with the months of the year.
>
> I then need to determine which one has been selected, and assign
> it to the scalar $selectedMonth in the sub 'chooseMonth'.
>
> [...]
> 
> @months = qw/All January February March April May June July
>     August September October November December/;
> $monthCombo = $report_p->BrowseEntry(-textvariable =>
> \$month, -width=>'10')->place(-x=>40, -y=>200);
> $monthCombo->insert('end', @months);
> 
> sub chooseMonth{
>   my $selectedMonth;
> 
>   if ($month eq 'All') {
>     $selectedMonth = "All"
>   }
>   if ($month eq 'January') {
>     $selectedMonth = "January"
>   }
> ..... etc (im sure u get the idea!)

From what you've written, a simple

$selectedMonth = $month;

will do the job. But that leaves me wondering, why copy the value at
all? Unless you plan on modifying $selectedMonth, there's no reason you
can't use $month directly. (And eliminate chooseMonth() completely,
unless you're doing something else later.)

By the way, BrowseEntry doesn't support the -textvariable option. You
want -variable instead.

-mjc


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

Date: Tue, 21 Aug 2001 12:12:26 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: subroutines in @INC ?
Message-Id: <3B82340A.8050607@post.rwth-aachen.de>

Rafael Garcia-Suarez wrote:

> Yes I know ;-) perlvar describes that @INC contains names of
> directories. But @INC may also contain references to subroutines that
> return a filehandle from which the module should be read. Look at my
> sig. I grep'd the pods but I can't find a reference for this.

Ah, ok! Now I understand what you mean. Hmmh, I couldn't find anything 
either. Are you planning to use such hacks? ;-)

Anyway, according to your sig, the anonymous sub gets the part behind a 
require, do or use as first argument. So you are probably free to do 
anything with that. You could use that to scan your whole hard-disk for 
 .pm files and open a filehandle to the file when found. However, I doubt 
this would do the runtime of your scripts any good. ;-)

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: 21 Aug 2001 10:38:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: subroutines in @INC ?
Message-Id: <9ltdo0$lrl$1@mamenchi.zrz.TU-Berlin.DE>

According to Rafael Garcia-Suarez <rgarciasuarez@free.fr>:
> Tassilo von Parseval wrote in comp.lang.perl.misc:
> } 
> } > I can't find anymore in the docs where is documented the use of
> } > subroutines in @INC. In fact I don't remember if this is documented at
> } > all. I think this feature was introduced in Perl 5.6.0. Any help?
> } 
> } Look that up in perlvar.pod. In short: @INC contains the places where 
> } the Perl interpreter will look for modules that have been included in 
> } your script via do(), require() or use(). The docs also tell you how you 
> } can cleanly manipulate @INC.
> 
> Yes I know ;-) perlvar describes that @INC contains names of
> directories. But @INC may also contain references to subroutines that
> return a filehandle from which the module should be read. Look at my
  ^^^^^^^^^^^^^^^^^^^
I'm sure you meant to say "file name", but AFAIK a subref in @INC is
executed, but the return value ignored.  No, I don't think it's
documented.

Anno


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

Date: 21 Aug 2001 11:04:51 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: subroutines in @INC ?
Message-Id: <slrn9o4gd0.76m.rgarciasuarez@rafael.kazibao.net>

Anno Siegel wrote in comp.lang.perl.misc:
} > Yes I know ;-) perlvar describes that @INC contains names of
} > directories. But @INC may also contain references to subroutines that
} > return a filehandle from which the module should be read. Look at my
}   ^^^^^^^^^^^^^^^^^^^
} I'm sure you meant to say "file name", but AFAIK a subref in @INC is
} executed, but the return value ignored.  No, I don't think it's
} documented.

OK, I've finally found a reference to this feature :
http://www.perl.com/pub/a/2001/03/p5pdigest/THISWEEK-20010305.html#Coderef_INC

In fact I was investigating a behavior change between 5.6.1 and 5.7.2.
It was pretty disappointing to remember a feature while not remembering
where I learned it.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 21 Aug 2001 12:58:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: subroutines in @INC ?
Message-Id: <9ltlt6$af8$1@mamenchi.zrz.TU-Berlin.DE>

According to Rafael Garcia-Suarez <rgarciasuarez@free.fr>:
> Anno Siegel wrote in comp.lang.perl.misc:
> } > Yes I know ;-) perlvar describes that @INC contains names of
> } > directories. But @INC may also contain references to subroutines that
> } > return a filehandle from which the module should be read. Look at my
> }   ^^^^^^^^^^^^^^^^^^^
> } I'm sure you meant to say "file name", but AFAIK a subref in @INC is
> } executed, but the return value ignored.  No, I don't think it's
> } documented.
> 
> OK, I've finally found a reference to this feature :
> http://www.perl.com/pub/a/2001/03/p5pdigest/THISWEEK-20010305.html#Coderef_INC

Thanks, that's interesting.  Let me quote the code example:

    BEGIN {
        push @INC, \&somesub;
        sub somesub {
            my ($owncoderef, $wanted_file) = @_;
            # Produce a filehandle somehow
            if ($got_a_handle) {
                return *FH;
            } else {
                returm undef;
            }
        }
    }
 
So it appears that it does indeed expect a filehandle to be returned,
and a module is read from it if so.  No %INC entry is made.

Anno


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

Date: Tue, 21 Aug 2001 11:12:43 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: This is not a question ... call me slow if you like...
Message-Id: <kig4ot4682039n6ncu3kuh3jm1m048e4aj@4ax.com>

Przemyslaw Brojewski wrote:

>Modification of a read-only value attempted at cosik line 2.
>
>perl 5.6.1.
>
>what gives?

Put

	(local$_=$_),

in front of it, just before the very first "y".

-- 
	Bart.


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

Date: Tue, 21 Aug 2001 11:59:33 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Time functions and conversion
Message-Id: <9lteup$v4k@newton.cc.rl.ac.uk>

Run this little routine:

  $date2convert = "25/11/2000 10:00";
  # convert to seconds since epoch
  use HTTP::Date;
  $epochseconds = str2time($date2convert);
  # convert epoch seconds back to date
  $back2date = scalar localtime($epochseconds);
  # display results
  print "\nStarted with: $date2convert\nInto seconds: $epochseconds\nBack to
date: $back2date\n";


---------¦
  Bigus @ work
             ¦----------


"Doug Robbins" <sleddog@labradorstraits.net> wrote in message
news:1103_998355177@duron...
> time returns epoch time; gmtime converts epoch time to an array ($sec,
> $min,$hour ...) localized for GMT. How can I do the reverse -- convert
> *to* epoch time for a given date in some format like June 22, 2000 8:00
> am?
>




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

Date: Tue, 21 Aug 2001 21:40:50 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Unix command : write - how to detect a message
Message-Id: <slrn9o4i61.3ga.mgjv@martien.heliotrope.home>

On Sun, 19 Aug 2001 21:53:18 GMT,
	Christophe <newspub@free.fr> wrote:
> I would like to make a perl program to detect the message :
>     Message from someone@somewhere on ttyp3 at 23:49 ...
> which appears when someone tries to have a chat with you through the 'write'
> command.
> I don't know how to read the messages which appear in the term through
> 'write'.

You should probably ask this question on comp.unix.programmer. The
answer you get there may be C oriented, but the implementation would be
similar in Perl. 

I'm not sure that it would be that easy to do.

Martien
-- 
Martien Verbruggen              | My friend has a baby. I'm writing
Interactive Media Division      | down all the noises the baby makes so
Commercial Dynamics Pty. Ltd.   | later I can ask him what he meant -
NSW, Australia                  | Steven Wright


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

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


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