[22140] in Perl-Users-Digest
Perl-Users Digest, Issue: 4361 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 7 21:06:03 2003
Date: Tue, 7 Jan 2003 18:05:06 -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 Tue, 7 Jan 2003 Volume: 10 Number: 4361
Today's topics:
Re: autoresponse email <goldbb2@earthlink.net>
Re: Detecting media change/closing of CD tray? <spamfilter@cheiron-it.nl>
Re: Detecting media change/closing of CD tray? <mouseslinger@hotmail.com>
Re: Detecting media change/closing of CD tray? (Sam Holden)
Re: Detecting media change/closing of CD tray? <spamfilter@cheiron-it.nl>
File IO, append (Jeff Mott)
Re: File IO, append (Malcolm Dew-Jones)
How to use the function of "Regular Expression Search/R (niudou)
Lexical scope bug in eval()? (Ben Morrow)
Re: Need help grabbing text from multiple lines <jkeen@concentric.net>
Re: Need help grabbing text from multiple lines <uri@stemsystems.com>
Re: Need help grabbing text from multiple lines (Tad McClellan)
Need to enter to finish perl script (c0rum_z)
Re: Need to enter to finish perl script <mouseslinger@hotmail.com>
Re: Nested sort <jkeen@concentric.net>
Re: Nested sort <krahnj@acm.org>
Re: Nested sort <goldbb2@earthlink.net>
Re: nested try blocks causing problems <goldbb2@earthlink.net>
Re: Perl quotations problem <goldbb2@earthlink.net>
Re: pointer & stack data structure? <goldbb2@earthlink.net>
Re: These are discouraging stats to Perlistas & Pythoni <wlfraed@ix.netcom.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Jan 2003 19:00:07 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: autoresponse email
Message-Id: <3E1B6A07.E41F2ACE@earthlink.net>
web tur wrote:
>
> How can I run a perl script after receiving an email.
> Where can I find some solution
That depends entirely on how your machine recieves mail.
For most folks with dialup connections, we have to fetch our mail with
either the pop3 or imap protocol; this, of course, needs to be run
regularly, every X minutes, so that mail will be seen in a timely
manner.
For folks who are permanantly connected to the internet, it's not
uncommon to have mail delivered directly to their machine -- either by
having the domain part of their email address resolve to their machine's
address, or else by having the machine which does recieve it, forward it
to their machine.
If your normal mode of operation is to fetch mail with pop3 or imap,
then that's what your script will have to do.
If you normally recieve mail directly (this normally requires having a
sendmail daemon running all the time), then you need to modify it's
configuration files so that some program (procmail or whatever) gets
invoked when a mail message arrives.
To fetch mail with the pop3 protocol, Net::POP3 module.
To fetch mail with imap, use Net::IMAP, or Net::IMAP::Simple, or
IMAPGet, or Mail::IMAPClient, or some of the modules in the
Mail-Box-3.034 distribution.
For a procmail-like response, use Mail::Procmail or Mail::Audit.
There are, of course, other ways to do it, but these are the most likely
to fit your needs.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Wed, 8 Jan 2003 01:34:09 +0100
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <3e1b7201$0$126$e4fe514c@dreader5.news.xs4all.nl>
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> schreef in bericht
news:slrnb1louo.tnd.sholden@flexal.cs.usyd.edu.au...
> On Tue, 7 Jan 2003 13:29:28 +0100, Frank Maas <spamfilter@cheiron-it.nl>
wrote:
> > Hi,
> >
> > I tried to find something on this subject on the web, but probably used
> > the wrong keywords. What I want to do is detect if someone closes the
> > CD-ROM player (on a laptop) from within Perl. Since it is not certain
> > that a CD is placed in it, I cannot simply check for the capacity or
> > such a thing.
> > The system is running Linux, kernel 2.4.17. My search included 'how does
> > Linux tell me...', but that did not result in something useful either.
> >
> > I would be delighted if you could help me on this!
>
> i don't see linux in the name of this group, why don't try a group
> which does in fact have such a word in its name.
Well... all of you: very, very, very much thanks for all your help.
It's not that this is a first time post or an unthought one. As Perl
is quite heavily used in Linux environments and the issue described
is not that exotic, it was not a strange thing to do to try out here.
Especially not since the solution must be implemented using Perl, so
esoteric kernel based examples do not apply.
But hey, my bad luck. Thought this was the place people helped each
other. In stead the only thing I get for an answer is 'go ask somewhere
else' and this is the result of putting it through MakeFriendly.pm.
I was wrong, apparently.
Frank
------------------------------
Date: Wed, 08 Jan 2003 00:55:45 GMT
From: <mouseslinger@hotmail.com>
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <HFKS9.603898$P31.219364@rwcrnsc53>
----- Original Message -----
From: "Sam Holden" <sholden@flexal.cs.usyd.edu.au>
Newsgroups: comp.lang.perl.misc
Sent: Tuesday, January 07, 2003 6:27 AM
Subject: Re: Detecting media change/closing of CD tray?
> On Tue, 7 Jan 2003 13:29:28 +0100, Frank Maas <spamfilter@cheiron-it.nl>
wrote:
> > Hi,
> >
> > I tried to find something on this subject on the web, but probably used
> > the wrong keywords. What I want to do is detect if someone closes the
> > CD-ROM player (on a laptop) from within Perl. Since it is not certain
> > that a CD is placed in it, I cannot simply check for the capacity or
> > such a thing.
> > The system is running Linux, kernel 2.4.17. My search included 'how does
> > Linux tell me...', but that did not result in something useful either.
> >
> > I would be delighted if you could help me on this!
>
> i don't see linux in the name of this group, why don't try a group
> which does in fact have such a word in its name.
>
> --
> Sam Holden
Geez. Sam. A little grumpy towards the Linux aren't you?
Did you have a bad experience with a Penguin when you were a child or
something?
All the person said was that his/her computer OS was Linux.
It was mentioned earlier that the task was probably OS Specific.
This IS a Perl newsgroup and the original question was about accessing the
CD Rom via Perl.
As for your telling the person to go elsewhere, do I detect that your
preference would be that Linux users go elsewhere? Perhaps you should take
notice of the newsgroups name "comp.lang.perl.misc", I don't see ANY
specific OS mentioned at all actually.
In any event, here is some information regarding how to access the CD rom
drive via Perl.
Check out http://search.cpan.org
POE::Component::CD::Detect
Detects CD insertions and provides TOC.
You should be able to detect an insertion and/or media change using the
above module.
And then if you want to eject the CD Rom, you can probably just use the
following to call "eject" from Linux.
#eject the cdrom tray.
system('eject');
David
http://www.cgiwebsite.com
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.437 / Virus Database: 245 - Release Date: 1/6/03
------------------------------
Date: 8 Jan 2003 01:30:26 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <slrnb1mvph.6jf.sholden@flexal.cs.usyd.edu.au>
On Wed, 08 Jan 2003 00:55:45 GMT, mouseslinger@hotmail.com wrote:
[snip]
>
> Geez. Sam. A little grumpy towards the Linux aren't you?
No.
>
> Did you have a bad experience with a Penguin when you were a child or
> something?
No.
>
> All the person said was that his/her computer OS was Linux.
>
> It was mentioned earlier that the task was probably OS Specific.
>
> This IS a Perl newsgroup and the original question was about accessing the
> CD Rom via Perl.
>
> As for your telling the person to go elsewhere, do I detect that your
> preference would be that Linux users go elsewhere? Perhaps you should take
> notice of the newsgroups name "comp.lang.perl.misc", I don't see ANY
> specific OS mentioned at all actually.
Since I'm a linux user, I obviously don't wish them to go elsewhere. Once
the poster knows the question is OS specific, asking in a newsgroup
appropriate to that OS makes far more sense. That way you might actually
get a useful answer.
>
> In any event, here is some information regarding how to access the CD rom
> drive via Perl.
>
> Check out http://search.cpan.org
>
> POE::Component::CD::Detect
> Detects CD insertions and provides TOC.
>
> You should be able to detect an insertion and/or media change using the
> above module.
Which is specifically *not* what was wanted. As indicates by the text
in the original post 'it is not certain that a CD is placed in it'. Of
course my interpretation that that includes the CD drive being
opened while empty and then closed, might be wrong also...
> And then if you want to eject the CD Rom, you can probably just use the
> following to call "eject" from Linux.
>
> #eject the cdrom tray.
> system('eject');
Emphasis on the 'probably':
; ssh mrmph
sholden@mrmph's password:
Linux mrmph 2.4.19-686 #1 Mon Nov 18 23:59:03 EST 2002 i686 unknown [snip]
Most of the programs included with the Debian GNU/Linux system are
freely redistributable; the exact distribution terms for each program
are described in the individual files in /usr/share/doc/*/copyright
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jan 7 15:04:04 2003
sholden@mrmph:~$ eject
-bash: eject: command not found
Though of course installing it wouldn't be a problem.
--
Sam Holden
------------------------------
Date: Wed, 8 Jan 2003 02:35:04 +0100
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <3e1b8047$0$144$e4fe514c@dreader5.news.xs4all.nl>
<mouseslinger@hotmail.com> schreef in bericht
news:HFKS9.603898$P31.219364@rwcrnsc53...
>
>
> Geez. Sam. A little grumpy towards the Linux aren't you?
--8<-- snip
> In any event, here is some information regarding how to access the CD rom
> drive via Perl.
>
> Check out http://search.cpan.org
>
> POE::Component::CD::Detect
> Detects CD insertions and provides TOC.
--8<--
> David
Hey thanks! Why on earth this did not come up when I tried Randy Kobes'
search engine... I probably sticked too much to CDROM in stead of simply
'CD'. The module does not show good in the testresults and POE is a large
thing to take in, but I will look into this deeper in the morning.
Thanks again!
Frank
------------------------------
Date: 7 Jan 2003 17:02:52 -0800
From: jeffmott@twcny.rr.com (Jeff Mott)
Subject: File IO, append
Message-Id: <f9c0ce19.0301071702.31cd1e2c@posting.google.com>
open DAT, '>>test.txt' or die $!;
seek DAT, 0, SEEK_SET or die $!;
print DAT 'hello' or die $!;
seek DAT, 0, SEEK_SET or die $!;
print DAT 'foo' or die $!;
The resulting file is hellofoo instead of foolo
Is the append mode not supposed to allow you to overwrite previous
data? Is there a way around it? I need open a file for writing,
creating it if necessary, without truncating the contents. Am I going
to have to use sysopen?
------------------------------
Date: 7 Jan 2003 17:35:10 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: File IO, append
Message-Id: <3e1b804e@news.victoria.tc.ca>
Jeff Mott (jeffmott@twcny.rr.com) wrote:
: open DAT, '>>test.txt' or die $!;
: seek DAT, 0, SEEK_SET or die $!;
: print DAT 'hello' or die $!;
: seek DAT, 0, SEEK_SET or die $!;
: print DAT 'foo' or die $!;
: The resulting file is hellofoo instead of foolo
: Is the append mode not supposed to allow you to overwrite previous
: data? Is there a way around it? I need open a file for writing,
: creating it if necessary, without truncating the contents. Am I going
: to have to use sysopen?
perldoc -f open
Append mode means that data is always appended, i.e. added to the end of
the file, which is what your example shows has happened (assuming the file
was empty to begin with).
What you want is read/write access, which is explained in the above
perldoc. Key thing to look for in the doc is the + sign.
------------------------------
Date: 7 Jan 2003 17:03:12 -0800
From: niudou@hotmail.com (niudou)
Subject: How to use the function of "Regular Expression Search/Replace"?
Message-Id: <324590c7.0301071703.2fa374d@posting.google.com>
When use it every time, there will be a prompt message, showing "You
must select some text first". So where and how to "select" the text,
and what does the "text" mean?
Thanks in advance!
------------------------------
Date: Tue, 7 Jan 2003 23:19:21 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Lexical scope bug in eval()?
Message-Id: <avfn9p$ckr$1@wisteria.csv.warwick.ac.uk>
I have come across something which I can only explain as a bug in perl. Am I
correct?
Test case:
[bug]
#!/usr/bin/perl5.6.1 -l
use warnings;
use strict;
use Bar;
Bar::test;
[Bar.pm]
package Bar;
use warnings;
use strict;
use subs qw/test foo/;
my $var;
sub foo {
# $var = $var; # uncommenting this removes the bug.
eval "print defined(\$var) ? 'yes' : 'no'";
}
sub test {
$var = "1";
eval "print defined(\$var) ? 'yes' : 'no'";
foo;
}
1;
[end]
Running ./bug as it stands produces
yes
no
. Uncommenting the line marked produces
yes
yes
as I would have expected.
This occurs with both perl5.6.1 and perl5.8.0, both on a Linux box.
The 'no' does not occur unless the eval is both in a module (ie. is pulled in
with use rather than being included verbatim in the program) and is in a
function which makes no reference to $var. It does, however, occur if 'use Bar'
is replaced with 'require Bar' (and an & added to satisfy strictures), so it
seems to be file-related and not BEGIN-related.
My guess would be this is some bug in setting up the function's lexical pad? I
don't know enough perl internals to attempt to verify this.
Should I go ahead and report this? Is it known already?
Ben
------------------------------
Date: 07 Jan 2003 23:10:05 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Need help grabbing text from multiple lines
Message-Id: <avfmod$bf7@dispatch.concentric.net>
"John Kingsley" <jfkingsley@earthlink.net> wrote in message
news:WzIS9.21902$9N5.1978729@newsread2.prod.itd.earthlink.net...
> I haven't used perl in awhile and I'm having trouble writing a script
> that will copy text from a file based upon custom markup (e.g., <info>
> </info>). The problem is that the beginnning tag could be in one line
> and the ending tag could be many lines down and I want to capture
> everything in between and just that.
>
> Can someone please point me in the right direction? Thanks!
>
The following is a very partial solution:
use strict; use warnings;
my $str = "Some text <info> some more text \n another line \n some more text
</info> that is all.\n";
$str =~ m|<info>(.*)</info>|s;
my $captured = $1 if defined $1;
print $captured;
Key aspects: Use of delimiters other than '/' in regex because key elements
of text use '/'. Use of /s modifier so that '.' will match '\n'. HTH.
------------------------------
Date: Tue, 07 Jan 2003 23:16:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need help grabbing text from multiple lines
Message-Id: <x7d6n8sg8v.fsf@mail.sysarch.com>
>>>>> "MH" == Mike Hunter <mthunter@students.uiuc.edu> writes:
MH> On Tue, 07 Jan 2003 22:32:22 GMT, John Kingsley wrote:
>> I haven't used perl in awhile and I'm having trouble writing a script
>> that will copy text from a file based upon custom markup (e.g., <info>
>> </info>). The problem is that the beginnning tag could be in one line
>> and the ending tag could be many lines down and I want to capture
>> everything in between and just that.
>>
>> Can someone please point me in the right direction? Thanks!
MH> You can change the record separator and then use regular expressions.
MH> From perl.about.com:
MH> $INPUT_RECORD_SEPARATOR This variable is used when you read data in from
MH> a file.
that variable is meaningless unless you use English. and that module is
generally deprecated for speed and other reasons. most perl hackers
never use it and won't even recognize the long names if used.
MH> The default is "\n", and lines of data are considered to be everything
MH> up to and including "\n". But you can change it to suit the data in your
MH> file. For instance, suppose you had the following file, "test.dat"
MH> One\Two\Three\Four#Five\Six\Seven\Eight#
MH> If you set $/ to "#", and then read the file, it would work like this
and what does setting $/ (IRS) have to do with the actual question?
MH> Then something like
MH> /\<info\>(.*)\<\/info\>/
MH> $my_stuff = $1;
MH> (are angle brackets special characters? I don't remember....
they aren't. simple enough for you to lookup in the docs.
and if you need / in a regex, it is best to change the delimiters to
something other than /.
and what about getting more than one region of text? you don't show
anything there.
the best answer is the scalar .. (range) operator and a simple line
loop.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Tue, 7 Jan 2003 18:02:25 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help grabbing text from multiple lines
Message-Id: <slrnb1mqkh.hm9.tadmc@magna.augustmail.com>
John Kingsley <jfkingsley@earthlink.net> wrote:
> I haven't used perl in awhile and I'm having trouble writing a script
> that will copy text from a file based upon custom markup (e.g., <info>
></info>). The problem is that the beginnning tag could be in one line
> and the ending tag could be many lines down and I want to capture
> everything in between and just that.
>
> Can someone please point me in the right direction? Thanks!
Not enough information provided to give a useful answer.
Might the tags be on a line by themselves (if so, it's
really easy, and it's a FAQ: perldoc -q "lines between").
Might they really be XML, where </info > could occur?
Might they really be SGML, where </info> or </INFO> could occur?
Are the files small enough to fit entirely in RAM?
Got any example input?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Jan 2003 17:11:10 -0800
From: c0rum_z@yahoo.com (c0rum_z)
Subject: Need to enter to finish perl script
Message-Id: <dcfb988b.0301071711.3b6b61e7@posting.google.com>
Hi all,
I'm a very new person in Perl.
I have this perl script and it's running fine in unix/linux, but in
WIndows, I need to press enter to finish the execution of the script.
Any idea how do I troubleshoot where is the enter key need to be
simulated by print "\r\n"; or any other way to make my script run to
the end without have to press enter?
Many thanks in advance
c0rum_z
------------------------------
Date: Wed, 08 Jan 2003 01:18:54 GMT
From: <mouseslinger@hotmail.com>
Subject: Re: Need to enter to finish perl script
Message-Id: <20LS9.603980$P31.219065@rwcrnsc53>
"c0rum_z" <c0rum_z@yahoo.com> wrote in message
news:dcfb988b.0301071711.3b6b61e7@posting.google.com...
> Hi all,
>
> I'm a very new person in Perl.
>
> I have this perl script and it's running fine in unix/linux, but in
> WIndows, I need to press enter to finish the execution of the script.
>
> Any idea how do I troubleshoot where is the enter key need to be
> simulated by print "\r\n"; or any other way to make my script run to
> the end without have to press enter?
>
> Many thanks in advance
>
When asking for help, you need to be as specific as possible and it also
would be helpful if you could include any relevant script code that you
might be talking in reference to.
Please post the relevant code so that we can see it.
- David
- http://www.cgiwebsite.com
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.437 / Virus Database: 245 - Release Date: 1/6/03
------------------------------
Date: 07 Jan 2003 23:10:06 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Nested sort
Message-Id: <avfmoe$bfl@dispatch.concentric.net>
"Lee" <zarkssmjkn@yahoo.com> wrote in message
news:261ce853.0301071340.693b024d@posting.google.com...
> Hello,
>
> Learning Perl. Browsing this group and learning more...
>
> I need to
>
> - Sort the fileA with the data in the <......> <Grp1-01> <Rrp1-01>
> - the data under each of these group <....> also needs to be sorted.
>
> I was able to do sort the groups using associated array but I am not
> successful in doing the sort under each <.....>
>
Could you show us the code you used to get this far, i.e., the code which
used an associated array (more commonly referred to as a hash)? Thanks.
------------------------------
Date: Tue, 07 Jan 2003 23:42:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Nested sort
Message-Id: <3E1B6571.4CD94C90@acm.org>
Lee wrote:
>
> I need to
>
> - Sort the fileA with the data in the <......> <Grp1-01> <Rrp1-01>
> - the data under each of these group <....> also needs to be sorted.
>
> I was able to do sort the groups using associated array but I am not
> successful in doing the sort under each <.....>
>
> I think there might be scripts which I can use to solve this issue (in
> this forum already????).
>
> Any help available? Sure there must be scripts already.
> Thanks.Happy New Year.
>
> ---------------------------------------------------------------------
>
> FileA
>
> <Grp1-10> what-01 89 72
> ma01.5 1234.4 we1-rt 12345.9 aa-s34 test01
> ca02.5 4321.5 sr1_tr 45679.5 aa-wttest02
> ka99.5 4321.3 sr41_tr 45679.5 aa-wt test02
>
> <Grp2-77> what-11 39 42
> va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
> da02.5 2321.5 sr2_tr 45679.5 aa-wt test02
> fa99.5 1321.3 sr41_tr 45679.5 aa-wttest02
>
> <Rrp99-35> peek-21 33 44
> va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
> da02.5 2321.5 sr2_tr 45679.5 aa-wttest02
> fa99.5 1321.3 sr41_tr 45679.5 aa-wt test02
>
> <Rrp99-55> peek-21 33 44
> va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
> da02.5 2321.5 sr2_tr 45679.5 aa-wttest02
> fa99.5 1321.3 sr41_tr 45679.5 aa-wt test02
> -----------------------------------------------------------------------------
Here is one way to do it:
$/ = ''; # set paragraph mode
open my $fh, '<', 'FileA' or die "Cannot open FileA $!";
my $text = join "\n\n",
map { join "\n", @$_ }
sort { $a->[0] cmp $b->[0] }
map { chomp;
my ( $key, @text ) = split /\n/;
[ $key, sort @text ]
}
<$fh>;
print "$text\n";
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 07 Jan 2003 19:10:20 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Nested sort
Message-Id: <3E1B6C6C.7A939F15@earthlink.net>
Lee wrote:
>
> Hello,
>
> Learning Perl. Browsing this group and learning more...
>
> I need to
>
> - Sort the fileA with the data in the <......> <Grp1-01> <Rrp1-01>
> - the data under each of these group <....> also needs to be sorted.
[snip]
> FileA
>
> <Grp1-10> what-01 89 72
> ma01.5 1234.4 we1-rt 12345.9 aa-s34 test01
> ca02.5 4321.5 sr1_tr 45679.5 aa-wttest02
> ...
> ka99.5 4321.3 sr41_tr 45679.5 aa-wt test02
>
> <Grp2-77> what-11 39 42
> va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
> da02.5 2321.5 sr2_tr 45679.5 aa-wt test02
> ...
> fa99.5 1321.3 sr41_tr 45679.5 aa-wttest02
>
> <Rrp99-35> peek-21 33 44
> va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
> da02.5 2321.5 sr2_tr 45679.5 aa-wttest02
> ...
> fa99.5 1321.3 sr41_tr 45679.5 aa-wt test02
>
> <Rrp99-55> peek-21 33 44
> va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
> da02.5 2321.5 sr2_tr 45679.5 aa-wttest02
> ...
> fa99.5 1321.3 sr41_tr 45679.5 aa-wt test02
How about this:
#!/usr/local/bin/perl -w
use strict;
local ($/, @ARGV) = ("", "fileA");
for( sort <> ) {
s/^(.+\n)// or next;
print "$1", (sort /(.+\n)/g), "\n";
}
__END__
[untested]
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Tue, 07 Jan 2003 19:38:10 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: nested try blocks causing problems
Message-Id: <3E1B72F2.900F6855@earthlink.net>
Matt Venn wrote:
>
> Hi, I've got a (what I consider weird) problem that I've spent some
> time trying to work out.
>
> I'm trying to eliminate a memory leak, which is caused by a circular
> references.
>
> I have traced a particular leak to some code that I have made sure
> should never be run, and yet a circular reference is still made
> there that then cannot be destroyed.
>
[snip]
> try
> {
> if( 0 )
> {
> try
> {
> warn "creating child\n";
> #circular reference is made here
> my $object = child->new( $self );
> }
> otherwise {};
> }
> }
> otherwise {};
The problem is not the circular reference of *objects*. The problem is
the circular references amongst the anonymous coderefs that the 'try'
and 'otherwise' keywords create.
I believe that this type of problem is mostly fixed with perl 5.8, but
I'm not entirely sure. I do know, with certainty, that you can solve
the problem if you were to eliminate your use of 'use Error', and change
the 'try' blocks to 'eval' blocks. That is:
sub new {
my $class = shift;
my $self = bless {}, $class;
eval {
if( 0 ) {
warn "Creating child";
eval {
my $object = child->new( $self );
}
}
};
return $self;
}
Also, to avoid the problems caused by circular references amongst
objects, try use the weaken() function from Scalar::Util (which comes
with perl 5.8, or which you can get from CPAN).
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Tue, 07 Jan 2003 19:26:02 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl quotations problem
Message-Id: <3E1B701A.21A269F7@earthlink.net>
Cmps wrote:
>
> I am not sure about the compatibility possibilities, but I have
> encountered the following error when testing Perl/CGI scripts on
> ActivePerl versus actual server running. The following is an example:
>
> $str1="friendlynospam"+"@"+".org";
> $str2="filename.ext";
>
> Note the quoatations in split quotations in $str1 and no-split in
> $str2. $str2 is a whole string, commonly recognized. $str1 is a
> broken string, but usually excepted by most scripts. Now if you test
> it on ActivePerl, it executes ok.
Really? That's quite amazing. I would expect a syntax error (due to
your attempt to interpolate the @" array in an unterminated string).
> However, attempting to run this on the server, it will not
> execute. When correctly changed to $str1='friendlynospam'+'@'+'.org'
> it amazingly works.
For some dubious definition of "works". You no longer have an
unterminated string, true, so it no longer produces a syntax error, but
I seriously doubt that it produces the results that you expect.
> Other quoation rules do not matter as they work fine. But firstly,
> single quotes are commonly for character referencing though I know
> in Perl and scripts this is not always true.
What do you mean 'for character referencing'?
In C and C++, you use single quotes around a character to produce a
numeric literal of type char. Is that what you mean? Perl is not C;
the meaning in some other language has nothing to do with the meaning in
Perl.
In perl, you use single quotes around a string to prevent interpolation
from happening. Most things which are special in "" quotes are not
special in '' quotes.
> But why then is this not allowed in the joining of quotations in the
> first manner with $str1.
The error is not what you think it is. The joining of strings has
nothing to do with the probem you are having.
Your problem is because you've got a " starting a string, then you've
got the @" array being interpolated into the string, then you've got a
plus sign (inside the quoted string), then the closing ", then you
concatenate (the . operator is concatenation) the results of the
function call org(";\n$str2="), then you've got this bareword 'filename'
in the place where an operator was expected... which is a syntax error.
> Is there some rule about Perl here?
Why not read the documentation? Perl comes with this nifty tool, called
perldoc, which tells you all about how the perl language works. Type
the following things from the command line:
perldoc perl
perldoc perlsyn
perldoc perldata
perldoc perlop
> The point of the matter is you can debug for hours and miss this one
> point.
Only if you're foolish enough to try programming without the 'use
strict' and 'use warnings' pragmas. All professional programmers write
their programs with these in place, and usually leave them in during
production.
If you'd done that, you'd have found the problem in seconds.
Also, for a beginner, there's the 'use diagnostics' pragma, which causes
those warnings and errors which perl itself produces to be fully
explained (with the explanations coming from the same file as perldoc
perldiag).
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Tue, 07 Jan 2003 19:41:35 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: pointer & stack data structure?
Message-Id: <3E1B73BF.A9D9E14D@earthlink.net>
Mark Chou wrote:
>
> Dear Perl Guru,
>
> Does Perl support pointer & stack data structure? It would be even
> better if you could provide simple example.
To declare a stack, you simply do:
my @stack;
To push something onto the stack, do:
push @stack, $thing;
To pop something off of the stack, do:
my $thing = pop @stack;
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Tue, 07 Jan 2003 15:15:38 -0800
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: These are discouraging stats to Perlistas & Pythonistas...
Message-Id: <r2nfva.su3.ln@beastie.ix.netcom.com>
Sara fed this fish to the penguins on Tuesday 07 January 2003 07:21 am:
> Looks like Bill is successfully creating his "clone army".
>
> At least we're way above PHP, which barely beat Fortran! Lords of
> Light it's amazing anyone who isn't one of Bill's or Sun's drones is
> employed.... It looks like a Perl programmer has about an equal chance
That isn't funny, you know... I've been laid-off since September
(mostly FORTRAN 77 for 20 years).
I'd be willing to try for COBOL even though my last real program was
in college back in 79 -- but I do have the "learning version" of
Fujitsu COBOL 4 from /two/ separate recent books (including their
VB-like GUI development: PowerCOBOL). Unfortunately the COBOL openings
want LOTS of experience on AS400.
--
> ============================================================== <
> wlfraed@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed@dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
------------------------------
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 4361
***************************************