[18659] in Perl-Users-Digest
Perl-Users Digest, Issue: 827 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 3 11:05:51 2001
Date: Thu, 3 May 2001 08:05:15 -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: <988902314-v10-i827@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 3 May 2001 Volume: 10 Number: 827
Today's topics:
Re: [OT: language religion ] Re: Should Perl be first? (Martien Verbruggen)
calling C functions <pef@trasra.noXX>
Re: calling C functions nobull@mail.com
Re: calling C functions <bart.lateur@skynet.be>
Re: calling C functions <bart.lateur@skynet.be>
Re: Does anyone have anything to do with perl.org? (EED)
GBDM flush (Diana McCarthy)
Re: How to: Create Regex which extracts N number of wor <notmyrealemail@example.com>
Is it possible to find the position of a mismatch using <c.manley@_NOREPLY_chello.nl>
MIME::Lite ??? <hendrik.danz@gmx.net>
Re: MIME::Lite ??? <bart.lateur@skynet.be>
Re: MIME::Lite ??? (Villy Kruse)
Own module: how to export constants/subroutines of othe (EED)
Re: Perl for Dreamweaver Extension Posted <notmyrealemail@example.com>
Re: Perl for Dreamweaver Extension Posted <henryhartley@westat.com>
Re: Please repost name of ssi offline processor <andras@mortgagestats.com>
Re: Plz help a newbie juggle fish and paint cows and ad <dodger@necrosoft.net>
Posting Guidelines for comp.lang.perl.misc ($Revision: clpmisc@dfw.pm.org
Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <godzilla@stomp.stomp.tokyo>
Problem with File::stat() mode (Gwen)
Problem with the subroutine (closure?) for the "sort" (EED)
Re: re-evaluate as a scalar <andras@mortgagestats.com>
RE: Removing blank lines from end of data <perl@programacionweb.com>
Re: Removing blank lines from end of data <dodger@necrosoft.net>
Re: Removing blank lines from end of data <dodger@necrosoft.net>
Re: Removing blank lines from end of data <bart.lateur@skynet.be>
Re: Removing blank lines from end of data <godzilla@stomp.stomp.tokyo>
SIGCHLD on hpux <risto.vaarandi@eyp.ee>
Re: SIGCHLD on hpux (Villy Kruse)
size information of sequences? <jbehren@gwdg.de>
Re: Test for integer? <jfreeman@tassie.net.au>
Re: Test for integer? <dodger@necrosoft.net>
Re: Test for integer? <bart.lateur@skynet.be>
Re: Test for integer? <"relaxedrob@optushome.com.au">
Re: Test for integer? nobull@mail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 3 May 2001 21:06:36 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: [OT: language religion ] Re: Should Perl be first?
Message-Id: <slrn9f2ets.v5e.mgjv@martien.heliotrope.home>
On Wed, 2 May 2001 18:29:01 +0200,
Rudolf Polzer <eins@durchnull.de> wrote:
> Billy Chambless <bchambless@nrlssc.navy.mil> wrote:
>
>> OBOnTopic: Whatever language one writes production code in, Perl is a must
>> for tools, etc.
>
> Of course. On UNIX Perl is 1st choice.
On Unix the most appropriate language is my first choice [1]. It happens
to be Perl for most administrative tools, and many other things.
However, for production code, it more often turns out to be C, C++, or
sometimes (*shudder*) Java. For the latter case I am normally not
involved in writing actual code [2].
Martien
[1] And on any other platform I tend to follow the same rule.
[2] because a) I loathe Java, and b) we employ people who enjoy writing
in it.
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Thu, 03 May 2001 13:07:53 +0200
From: "P.Eftevik" <pef@trasra.noXX>
Subject: calling C functions
Message-Id: <3AF13C09.D2649B63@trasra.noXX>
I'm writing a system, partly in perl - partly in C.
So I'd like my C code and perl code to communicate, e.g. calling
C functions from the perl program ( or vice versa ).
Any suggestions how to do it are welcome, including any experience using
sockets or pipes for such purposes.
Thanx,
Peftie
------------------------------
Date: 03 May 2001 12:15:59 +0100
From: nobull@mail.com
Subject: Re: calling C functions
Message-Id: <u9snimu1hs.fsf@wcl-l.bham.ac.uk>
"P.Eftevik" <pef@trasra.noXX> writes:
FAQ: "Where can I learn about linking C with Perl?"
You are expected to check the FAQ _before_ you post.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 03 May 2001 12:23:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: calling C functions
Message-Id: <dgi2ftc390f0nfsd3u8plfjv7ssbfg5vci@4ax.com>
P.Eftevik wrote:
>I'm writing a system, partly in perl - partly in C.
>
>So I'd like my C code and perl code to communicate, e.g. calling
>C functions from the perl program ( or vice versa ).
>
>Any suggestions how to do it are welcome, including any experience using
>sockets or pipes for such purposes.
What platform?
Since you mention pipes and sockets, I'm tempted to advice you to get
Lincoln Stein's book, "Network Programming with Perl". His discussion
begins from the very basic level, and works up to, well, pretty advanced
daemons.
Other solutions:
A) Do what other module writers do, and turn you C code into an XS file.
Not the simplest solution. SWIG is another but similar option. That's
what I heard.
B) If on Unix, with a C compiler present, you can incorporate C code
into your perl script. See the Inline module on CPAN:
<http://search.cpan.org/search?dist=Inline>
There's an intro text on <http://www.perl.com/pub/2001/02/inline.html>.
According to the docs, it ought to work on Win32, too, although CPAN
testers don't mention that platform.
C) If on Win32, you can create a plain and simple DLL from your C code,
and call it through the Win32::API module.
For this and other Win32 solutions, see this page:
"Using Perl on Win32 for Fun and Profit"
<http://opensource.activestate.com/authors/jandubois/Perl/TPC3/fun.html>
HTH,
Bart.
------------------------------
Date: Thu, 03 May 2001 12:25:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: calling C functions
Message-Id: <hfi2ftov8qhbanscj9kh9noscqkk22o85k@4ax.com>
nobull@mail.com wrote:
>FAQ: "Where can I learn about linking C with Perl?"
>
>You are expected to check the FAQ _before_ you post.
That FAQ entry *only* talks about using XS. This is not the easiest way.
--
Bart.
------------------------------
Date: Thu, 03 May 2001 15:25:39 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Does anyone have anything to do with perl.org?
Message-Id: <3AF15C53.5293A7F6@eed.ericsson.se>
Richard,
Richard Lawrence wrote:
> Can anyone help? A long time ago I (foolishly) posted a message to the
> perl5porters list regarding a bug in Net::Ping from my work address. Less
> than
> several weeks later, I experienced large amounts of unsolicited commercial
> email (spam) to my always unpublished email address.
>
> Several months later I came across a webpage at perl.org which contained my
> email address so I sent an letter to an email address I have long forgotten
> asking that my posting be either removed or that my email address be masked
> so
> that web crawlers would not pick up this address. I received a response,
> which
> I have long since deleted, which indicated this would happen.
>
> About 18 months later, whilst searching on the web, I was a little surprise
> to
> find the offending page at http://tmtowtdi.perl.org/archive/25/3360 which is
> still showing my email address despite assurances that it would be removed,
> or
> at least munged.
>
> So I fired off another letter asking if it would be possible to have either
> the posting removed or if they wish to preserve the content to munge my
> email
> address and remove the signature that contains my work and mobile number as
> well as my email address. As of yet I've had nothing back.
I think you shouldn't bother those people,
because they definetely are busy with things
which are more important than taking care
of your "always unpublished email address".
Your address is obviously now in some spammers
database anyway and you will never clean it up
from there.
So please give up or install some anti-SPAM
solution _yourself_ (maybe MAPS, procmail?).
Regards
Alex
------------------------------
Date: 3 May 2001 13:31:31 GMT
From: dianam@cogs.susx.ac.uk (Diana McCarthy)
Subject: GBDM flush
Message-Id: <9crmjj$1u6$1@ames.central.susx.ac.uk>
Keywords: gbdm flush buffer
I know I can do
select("FILE");
$| = 1;
but how can one use $| with output that goes to a dbm file, from within perl.
I posted this already, having checked FAQ. Somehow it disappeared. Since I am
new to newsgroups can any reply be posted here and emailed to
dianam@cogs.susx.ac.uk. Also any advice on why my query disappeared before.
Thanks
Diana
------------------------------
Date: Thu, 03 May 2001 13:00:14 GMT
From: "BarryK" <notmyrealemail@example.com>
Subject: Re: How to: Create Regex which extracts N number of words before target word
Message-Id: <yDcI6.54072$U4.12693339@news1.rdc1.tn.home.com>
"Richard J. Rauenzahn" <nospam@hairball.cup.hp.com|> wrote in message
|> usr/bin/perl -wl
|> use strict;
|>
|> my $t = "word1 word2 word3 cat word5 cat word7 word8 word9 cat word11";
|> split(/\W+/, $t);
|>
|> my @s;
|> my $b = 2; # number of before words
|> my $a = 2; # number of after words
|>
|> foreach (@_) {
|> push(@s, $_);
|> if(@s == $b+$a+1) {
|> print "@s" if($s[$b] eq 'cat');
|> shift @s;
|> }
|> }
Much obliged to Rich, Bart, and Ren for their masterly attempts to solve
this problem. In my ignorance, I thought this was a short one-line solution.
I now see I have a lot of work to do.
Barry Krusch
------------------------------
Date: Thu, 03 May 2001 16:54:09 +0200
From: Craig Manley <c.manley@_NOREPLY_chello.nl>
Subject: Is it possible to find the position of a mismatch using regular expressions in Perl?
Message-Id: <3AF17111.662D2DF0@_NOREPLY_chello.nl>
Hi all,
I've got this simple regular expression that checks the syntax of a
string of comma seperated phonenumbers starting with 00. The problem is
- if the string doesn't match my regex, then I don't know where the
mismatch occured. Is there a practical solution to this problem?
my $req = '0031615015032,0031655388294,0031620075361';
if ($req =~ /^00\d{7,14}(,00\d{7,14}){0,999}$/) {
print "Match\n";
}
else {
print "No match!\n";
# but at which character position did the matching go wrong?
}
-Craig Manley
------------------------------
Date: Thu, 3 May 2001 12:46:28 +0200
From: "Hendrik Danz" <hendrik.danz@gmx.net>
Subject: MIME::Lite ???
Message-Id: <9crbrc$5m9$1@koroth.muc.eurocyber.net>
hi,
i'm looking for mime-lite module but can't find it anywhere.
does anybody have a link?
thnx
hendrik
------------------------------
Date: Thu, 03 May 2001 10:41:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: MIME::Lite ???
Message-Id: <acd2ft8v7jdp5ei64eqk4utnnnl451st4a@4ax.com>
Hendrik Danz wrote:
>i'm looking for mime-lite module but can't find it anywhere.
>does anybody have a link?
<http://search.cpan.org/search?dist=MIME-Lite>
and for 5.6.0 per lfor Win32 (Activestate or compatible):
<http://www.Activestate.com/PPMpackages/5.6/MIME-Lite.ppd>
<http://www.Activestate.com/PPMpackages/5.6/MSWin32-x86-multi-thread/MIME-Lite.tar.gz>
--
Bart.
------------------------------
Date: 3 May 2001 13:05:23 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: MIME::Lite ???
Message-Id: <slrn9f2lsj.b3j.vek@pharmnl.ohout.pharmapartners.nl>
On Thu, 03 May 2001 10:41:37 GMT, Bart Lateur <bart.lateur@skynet.be> wrote:
>Hendrik Danz wrote:
>
>>i'm looking for mime-lite module but can't find it anywhere.
>>does anybody have a link?
>
> <http://search.cpan.org/search?dist=MIME-Lite>
>
>and for 5.6.0 per lfor Win32 (Activestate or compatible):
>
> <http://www.Activestate.com/PPMpackages/5.6/MIME-Lite.ppd>
>
><http://www.Activestate.com/PPMpackages/5.6/MSWin32-x86-multi-thread/MIME-Lite.tar.gz>
>
You could also use the CPAN module.
$ perldoc CPAN
NAME
CPAN - query, download and build perl modules from CPAN
sites
SYNOPSIS
Interactive mode:
perl -MCPAN -e shell;
Batch mode:
use CPAN;
autobundle, clean, install, make, recompile, test
...
Villy
------------------------------
Date: Thu, 03 May 2001 13:56:24 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Own module: how to export constants/subroutines of other modules
Message-Id: <3AF14768.E4B5E0D0@eed.ericsson.se>
Hi,
I have grouped the variables and subroutines shared by
several scripts into my own module. I wonder however,
how to make avalailable some constants from other
modules that I am using in these scripts, particularly:
NOTIFY STORE from IPC::ChildSafe
and
CS_STATUS_RESULT from DBD::Sybase.
Here is how my module looks like:
package DeliveryTool;
use strict;
use vars qw ($VERSION @ISA @EXPORT_OK $CLEAR
$EEDHR $STYLE %COLS $INIT
$DBSERV $DBUSER $DBPASS $PASSWD);
use Exporter;
use DBI;
use DBD::Sybase; # import CS_STATUS_RESULT
use IPC::ChildSafe qw (NOTIFY STORE);
use CGI::Carp qw (fatalsToBrowser);
#use Data::Dumper; # for debugging purposes
use lib qw (/www/cgi-bin/libs);
use EED::CGI; # EED header / footer
local $| = 1; # no buffering
local $CGI::DISABLE_UPLOADS = 1; # no file uploads
local $CGI::POST_MAX = 2 * 1024 * 1024; # max. 2 MB input
$VERSION = 1;
@ISA = qw (Exporter);
@EXPORT_OK = qw (print_header db_connect valid_pass abstract
%COLS $CLEAR $EEDHR $INIT $STYLE);
$EEDHR = '<HR SIZE=1 NOSHADE>';
$CLEAR = '/usr/atria/bin/cleartool';
$EEDHR = '<HR SIZE=1 NOSHADE>';
...
And I get the following error:
:!perl -wT delivery-projects.cgi
[Thu May 3 13:53:11 2001] delivery-projects.cgi: Bareword "STORE" not allowed while "strict subs" in use at delivery-projects.cgi line 261.
When I use this in my scripts:
#!/opt/local/perl-5.6.0/bin/perl -T
use strict;
use vars qw ($CHECK);
use lib qw (/home/eedalf/apache/cgi-bin);
use DeliveryTool qw (db_connect print_header abstract valid_pass
$CLEAR $EEDHR $STYLE %COLS);
...
Thanks in advance
Alex
------------------------------
Date: Thu, 03 May 2001 12:21:29 GMT
From: "BarryK" <notmyrealemail@example.com>
Subject: Re: Perl for Dreamweaver Extension Posted
Message-Id: <d3cI6.53817$U4.12669811@news1.rdc1.tn.home.com>
"Jfreeman" <jfreeman@tassie.net.au| wrote in message
news:3AF0EF64.21C18B59@tassie.net.au...
|
| BarryK wrote:
|
| Macromedia has announced a Perl for Ultradev extension. I have no idea
what
| it does, but if you have Ultradev I suspect it's powerful. You can get it
| at:
|
| http://www.macromedia.com/exchange/ultradev/
|
| If you can explain to me a) what it does and
|
| This is not a perl question. But here is an answer anyway:
|
| Most people can not code. Many would like the benefits of code for thier
| website. You can write software to allow users to point and click on
| behabiours'. The required code is then automatically generated by the
visual
| development tool. This machine generated code is generally quite
reliable.
| Basically a GUI approach to coding trying to make it idiot proof.
|
| Sounds good and I guess it is if you have no coding background.
Unfortunately
| these visual development tools generally produce the most convoluted,
complex,
| bloated, unwieldy code you have ever seen. It is generally almost
impossible for
| humans to decode let alon modify.
Agreed. But apparently this will let you integrate Perl in their environment
in some way.
------------------------------
Date: Thu, 03 May 2001 10:13:02 -0400
From: Henry Hartley <henryhartley@westat.com>
Subject: Re: Perl for Dreamweaver Extension Posted
Message-Id: <3AF1676E.B441F840@westat.com>
BarryK wrote:
>
> Agreed. But apparently this will let you integrate Perl in their environment
> in some way.
Apparently it allows you to "Call Perl subroutines from within
Dreamweaver Extensions"
From http://www.macromedia.com/exchange/ultradev/, follow the link "Perl
for Dreamweaver" and you will see:
------------------------------------
Perl for Dreamweaver Extension
Call Perl subroutines from within Dreamweaver Extensions
Perl for Dreamweaver
Copyright © 2001 robert nix - http://www.rnix.com/macromedia
This utility has dependencies on:
- ActivePerl 5.6 - http://www.activestate.com/activeperl
Call Perl from Dreamweaver
--------------------------
There are two extension routines in this jsExtension.
- invoke() calls a subroutine in a file. Any JavaScript datatype except
Objects
can be passed but they will all be flattened into a single array. Any
Perl
datatype can be returned but all scalars will be converted to Strings
and
hashes will be converted to a 2D array as follows:
a[0] is an array of Keys, a[1] is an array of Values.
- eval() evaluates a string (i.e. just like perl -e)
Configuration
--------------
This extension requires directory entries in the PATH that contain
perl56.dll.
- Additional configuration is performed through the 'Commands | DWperl
Control' menu. A disabled 'Commands | DWperl Control' menu indicates
that
perl56.dll is not in the PATH.
Miscellaneous
--------------
See DWsample.pl for documentation and examples of callable Perl
subroutines.- See DWsample.js for JavaScript documentation and examples
of calling the DWperl subroutines.- All jsExtension DLL calls are logged
to
DWperl.log.- Since it's so easy to output to a file in Perl stdout and
stderr are
not redirected. In other words, unless redirected in your Perl module
output to
these streams is lost.
--
Henry Hartley
------------------------------
Date: Thu, 03 May 2001 10:41:41 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Please repost name of ssi offline processor
Message-Id: <3AF16E25.BB3418D8@mortgagestats.com>
Alun Moon wrote:
> Recently someone asked about the name of a Perl program that performed
> the SSI translations and substitutions offline.
> I've forgotten the name of the program, can some kind soul repost the
> name so I can go search for it (or even a URI).
>
> Many thanks
>
> Alun Moon
Do you mean fakessi.pl?
http://www.sarangworld.com/showscript.php3?/fakessi.pl
------------------------------
Date: Thu, 03 May 2001 12:21:53 GMT
From: "Dodger" <dodger@necrosoft.net>
Subject: Re: Plz help a newbie juggle fish and paint cows and add up elements of an array
Message-Id: <B3cI6.45215$B22.11276549@news1.rdc2.pa.home.com>
<nobull@mail.com> wrote in message news:u9r8y7vh5l.fsf@wcl-l.bham.ac.uk...
> Shawn Holman <holman_sh@MailAndNews.com> writes:
>
> > Subject: Plz help a newbie add up elements of an array
>
> Please think about your subject lines.
>
> "Plz help a newbie" - contains no usefull information, do not waste
> space in the subject line.
Bleah. It does contain useful information.
As a matter of fact, you seemed quite plzed to try tp 'help' (or berate) the
newbie.
> "add up elements of an array" - describes the bit you've already
> worked out how to do, not the bit you haven't.
Not the way they _wanted to_ though.
Take it easy, mate.
--
Dodger
www.dodger.org
www.necrosoft.net
www.gothic-classifieds.com
------------------------------
Date: Thu, 03 May 2001 14:06:18 GMT
From: clpmisc@dfw.pm.org
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <uBdI6.206669$lj4.5935761@news6.giganews.com>
Outline
Before posting to comp.lang.perl.misc
Must
- Check the Perl Frequently Asked Questions (FAQ)
- Check the other standard Perl docs (*.pod)
Really Really Should
- Lurk for a while before posting
- Search a Usenet archive
If You Like
- Check Other Resources
Posting to comp.lang.perl.misc
Is there a better place to ask your question?
- Question should be about Perl, not about the application area
How to participate (post) in the clpmisc community
- Carefully choose the contents of your Subject header
- Use an effective followup style
- Speak Perl rather than English, when possible
- Do not expect people to do a machine's work
- Do not type in Perl code
- Provide enough information
- Do not provide too much information
- Do not post binaries, HTML, or MIME
Social faux pas to avoid
- Asking a Frequently Asked Question
- Asking a question easily answered by a cursory doc search
- Asking for emailed answers
- Beware of saying "doesn't work"
- Count to ten before composing a followup when you are upset
- Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------
Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
The comp.lang.perl.misc (clpmisc) Usenet newsgroup is for the discussion
of using the Perl programming language.
Since clpmisc is such a high-traffic newsgroup (more than 100 articles
per day), there a number of measures that we all should take to keep the
group useful for everyone.
This article describes things that you should, and should not, do to
increase your chances of getting an answer to your Perl question. It is
available in POD, HTML and plain text formats at
<URL:http://dfw.pm.org/clpmisc.shtml/>.
[snip for testing]
AUTHOR
Tad McClellan <tadmc@augustmail.com>
------------------------------
Date: Thu, 03 May 2001 07:28:12 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <3AF16AFC.6EAF7582@stomp.stomp.tokyo>
clpmisc@dfw.pm.org wrote:
(snipped)
> - Speak Perl rather than English, when possible
Otherwords, "Obfuscate when possible."
" - Speak Perl in Plain English, when possible."
Addendum:
" - Provide clear and concise parameters."
Godzilla!
------------------------------
Date: Thu, 03 May 2001 14:37:26 GMT
From: pettigrewg@cf.ac.uk (Gwen)
Subject: Problem with File::stat() mode
Message-Id: <3af169c1.19901356@netnews.cf.ac.uk>
Hi
Im trying to use the File::stat module to give me the mode settings of
some files. I am using version 5.6.0 on a Tru64 Unix box.
The problem I am seeing is that the values that are being returned to
me for the file modes I am check are not making andy sense ( well to
me anyway)
EG one of the file I am checking gives me the following permissions
from a ls -l command
-rwxr--r-- which I make a numerical value of 0744
When I use the File::stat module to get the mode I get a value of
33252 returned
My question is should I expect to see the 0744 value? If the 33252 is
the right one, is there away of translating that value into the
standard UNIX numerical method of displaying a file code?
Here is the part of my script that is giveing me the "strange" result
foreach $ext (@check_extn) {
if ( $name =~ /\.$ext$/i )
{
$stats = stat($name);
$mode = ($stats->mode);
$gid = ($stats->gid);
print "$mode\t$gid\t";
print "$name\n";
}
}
Thanks. I hope some one can help as this is driving me nuts
Crisis? What crisis? This is normal
------------------------------
Date: Thu, 03 May 2001 17:04:02 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Problem with the subroutine (closure?) for the "sort"
Message-Id: <3AF17362.AC5CB907@eed.ericsson.se>
Hi,
I have a ref to a hash of hashes $hohref. That hash of
hashes should be ouputted in an HTML table and the order
of the output should be defined by the PATH_INFO. This
way I just print the headers of the table as links to
$query -> script_name . '/BLAH' and then the user can
click the link to define the order.
This works:
if ($query -> path_info =~ /\/PROJ$/) # sort alphab. by projects
{
$sort = sub { $hohref -> {$a} -> {PROJ} cmp $hohref -> {$b} -> {PROJ} };
}
elsif ($query -> path_info =~ /\/TCMPROJ$/) # sort alphab. by TCMPROJ
{
$sort = sub { $hohref -> {$a} -> {TCMPROJ} cmp $hohref -> {$b} -> {TCMPROJ} };
}
...
else
{
$sort = sub { $a cmp $b }; # sort by project names
}
for my $proj (sort $sort keys %$hohref)
{
...
But I would rather handle it with a subroutine, because
I have several CGI-scripts which use this sorting method.
So I have tried the following:
sub sort_sub ($$)
{
my $path = shift;
my $hohref = shift;
if ($path =~ /\/PATH$/) # sort alphab. by path
{
return sub { $hohref -> {$a} -> {PATH} cmp $hohref -> {$b} -> {PATH} };
}
if ($path =~ /\/STAT$/) # sort alphab. by status
{
return sub { $hohref -> {$a} -> {STAT} cmp $hohref -> {$b} -> {STAT} };
}
print 'DEBUG';
return sub { $a cmp $b }; # sort by subsystem names
}
...
my $sort = sort_sub ($query -> path_info, $hohref); # the sorting subroutine
for my $sub (sort $sort keys %$hohref)
{
...
But it doesn't work: I always see the 'DEBUG' printed,
which means, I always get the last "sub { $a cmp $b }"
and I also suspect that $a and $b are undefined anyway...
Thank you in advance
Alex
------------------------------
Date: Thu, 03 May 2001 09:53:24 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: re-evaluate as a scalar
Message-Id: <3AF162D3.60D782C7@mortgagestats.com>
Rob wrote:
> Hi all!
>
> I want to have scalar that includes another scalar:
>
> use strict;
> my $one = "";
> $two = "Isn't this a nice $one!";
>
> I want to assign a particular value to $one whenever I need and then output
> $two so it will contain a 'dynamic' value of $one.
>
> My problem is that perl interpolates into $two whatever value of $one it has
> when the scalars are declared and then forgets it was ever a variable..
>
> So how do I declare $two in such a way that perl will remember the embedded
> $one is a scalar and re-evaluate it when I output $two?
>
> Thanks!
> Rob
You could try using an anonymous sub like this:
$two=sub{"This is a nice $animal.\n"};
$animal="elephant";
print $two->();
$animal="giraffe";
print $two->();
I think the -> only works from perl 5.004 onward, but don't quote me on that.
If you want to read up on this stuff, look for documents on references, such as
perlref, chapter 11 of the Perl Cookbook or chapter 4 of the camel book.
------------------------------
Date: Thu, 3 May 2001 12:13:17 +0200
From: "Perl Programación Web" <perl@programacionweb.com>
Subject: RE: Removing blank lines from end of data
Message-Id: <9craq1$5eu$1@talia.mad.ttd.net>
Try this
$page =~ s/\n+$//gs;
Note that the last carriage return of the text is also removed.
Regards,
Fermín
Dan <nospam@newsranger.com> escribió en el mensaje de noticias
FX_H6.7530$SZ5.616955@www.newsranger.com...
> I have code that will remove ALL the blank lines from data with this
regular
> expression:
>
> $page =~ s/\s{2,}/\n/gs;
>
> But I would only like to remove blank lines at the end of the data. How
would I
> do that?
>
> Thanks,
> Dan
>
>
------------------------------
Date: Thu, 03 May 2001 12:09:44 GMT
From: "Dodger" <dodger@necrosoft.net>
Subject: Re: Removing blank lines from end of data
Message-Id: <cUbI6.45194$B22.11273408@news1.rdc2.pa.home.com>
"Dan" <nospam@newsranger.com> wrote in message
news:FX_H6.7530$SZ5.616955@www.newsranger.com...
> I have code that will remove ALL the blank lines from data with this
regular
> expression:
>
> $page =~ s/\s{2,}/\n/gs;
>
> But I would only like to remove blank lines at the end of the data. How
would I
> do that?
#I'd use this:
$line =~ s/^\s+$//;
#but I'd use it like this:
my @fi = reverse (<>);
for (@fi) { s/^\s+$// or last; }
print reverse @fi;
# that should do the trick.
--
Dodger
www.dodger.org
www.necrosoft.net
www.gothic-classifieds.com
------------------------------
Date: Thu, 03 May 2001 12:16:27 GMT
From: "Dodger" <dodger@necrosoft.net>
Subject: Re: Removing blank lines from end of data
Message-Id: <v_bI6.45203$B22.11275429@news1.rdc2.pa.home.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9cq1f2$pfa$1@mamenchi.zrz.TU-Berlin.DE...
> According to Dan <nospam@newsranger.com>:
> > But I would only like to remove blank lines at the end of the data. How
would I
> > do that?
>
> You would anchor the pattern to the end of the string ($) and remove
> the now-superfluous /g:
>
> s/\n{2,}$/\n/
I gathered he wanted to remove any lines at the end of the data that
contained only space characters, the end of this vacuously astral entity
called 'the data' (unless he means DATA), being the _end_lines_ not the end
_of_ the lines.
thus my reply,
my @fi = reverse (<>);
for (@fi) { s/^\s+$// or last; }
print reverse @fi;
I hope I wasn't off in my interpretation of the problem... lots of people
seem to have interpreted differently.
--
Dodger
www.dodger.org
www.necrosoft.net
www.gothic-classifieds.com
------------------------------
Date: Thu, 03 May 2001 12:33:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Removing blank lines from end of data
Message-Id: <o0k2ftk2060ep6glc4q46rijn2jdku0m48@4ax.com>
Dan wrote:
>I have code that will remove ALL the blank lines from data with this regular
>expression:
>
>$page =~ s/\s{2,}/\n/gs;
>
>But I would only like to remove blank lines at the end of the data. How would I
>do that?
split and join.
$page = join "\n", split(/\n/, $page), '';
Or:
$page =~ s/\n+$//;
--
Bart.
------------------------------
Date: Thu, 03 May 2001 07:42:23 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Removing blank lines from end of data
Message-Id: <3AF16E4F.628AFFB3@stomp.stomp.tokyo>
Dan wrote:
> I have code that will remove ALL the blank lines from data
> with this regular expression:
> $page =~ s/\s{2,}/\n/gs;
> But I would only like to remove blank lines at the end of
> the data. How would I do that?
I am making a presumption your "blank line" consists
of nothing more than a newline character. Your parameters
are not clear and concise and, your code does not remove
blank lines; it deals with spaces.
Work at posting coherent articles to avoid ambiguity.
do
{ chomp $page; }
until (substr ($page, -1, 1) ne "\n");
Godzilla!
------------------------------
Date: Thu, 03 May 2001 12:56:16 +0200
From: Risto Vaarandi <risto.vaarandi@eyp.ee>
Subject: SIGCHLD on hpux
Message-Id: <3AF13950.5FE1FC7E@eyp.ee>
hello,
I have written a perl program that forks child processes, and logs their
exit status when it receives SIGCHLD from kernel.
The program works fine on linux and solaris, but on hpux10.20 the parent
process receives SIGCHLD endlessly, so the parent is unable to get out
of the signal handler. The program does not call waitpid() in the
handler, but just sets a flag to indicate that waitpid() must be called
later.
Has anyone experienced that, and is that normal behaviour?
regards,
risto
------------------------------
Date: 3 May 2001 13:09:01 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: SIGCHLD on hpux
Message-Id: <slrn9f2m3d.b3j.vek@pharmnl.ohout.pharmapartners.nl>
On Thu, 03 May 2001 12:56:16 +0200,
Risto Vaarandi <risto.vaarandi@eyp.ee> wrote:
>hello,
>
>I have written a perl program that forks child processes, and logs their
>exit status when it receives SIGCHLD from kernel.
>The program works fine on linux and solaris, but on hpux10.20 the parent
>process receives SIGCHLD endlessly, so the parent is unable to get out
>of the signal handler. The program does not call waitpid() in the
>handler, but just sets a flag to indicate that waitpid() must be called
>later.
>Has anyone experienced that, and is that normal behaviour?
>
Old SVR3 will re-isuue a SIGC(H)LD signal when you install a signal
handler for SIGC(H)LD and you have a zombie pending. Can't say if that
is also the case for HP-UX.
Villy
------------------------------
Date: 03 May 2001 16:43:50 +0200
From: Joerg Behrens <jbehren@gwdg.de>
Subject: size information of sequences?
Message-Id: <qgzocu4hnd.fsf@umpp07.gwdg.de>
Yet another fine-tune question:
Do strings and arrays carry information about their actual size?
And if so, does it mean that expressions containing lots of
$#array, scalar @array, length($string)
are at least not slower than expressions where all size info
has been copied to local scalars first (assuming constant sizes)?
Thanks,
Jörg
------------------------------
Date: Thu, 03 May 2001 21:11:02 +1000
From: James Freeman <jfreeman@tassie.net.au>
Subject: Re: Test for integer?
Message-Id: <3AF13CC5.B60FCF9@tassie.net.au>
Jfreeman wrote:
> Rob wrote:
>
> > Hi all!
> >
> > Is there a way for me to test if a scalar holds an integer value (positive
> > or negative)?
>
> Yes, run this
>
> James
>
> #!usr/bin/perl -w
>
> use strict;
>
> my $do_this_sub;
>
> print "Simple match\n\n";
> $do_this_sub = \&is_integer1;
> &tests;
> print "\nMore flexible match\n\n";
> $do_this_sub = \&is_integer2;
> &tests;
> print "\nVery Accomodating match\n\n";
> $do_this_sub = \&is_integer3;
> &tests;
>
> sub tests {
> &$do_this_sub('2');
> &$do_this_sub('+2');
> &$do_this_sub('-2');
> &$do_this_sub('42');
> &$do_this_sub(' + 2 ');
> &$do_this_sub(' 2000');
> &$do_this_sub('2,000');
> &$do_this_sub('+2.0');
> &$do_this_sub('2000.00');
> &$do_this_sub('2,000,000.00');
> &$do_this_sub(',2000.');
> &$do_this_sub('20 00');
> &$do_this_sub('foo');
> &$do_this_sub('foo+2');
> &$do_this_sub('255.255.255.0');
> }
>
> #this allows only a leading + - or '' with digits ie an integer
> sub is_integer1 {
> my $int = shift;
> $int =~ /^[+-]?\d+$/ ? print "'$int' is an integer\n" : print "'$int' is not
> an integer\n";
> }
>
> #this ismore flexible it allows spaces before and after the + or - and
> # after the numberno inter number spaces
> sub is_integer2 {
> my $int = shift;
> $int =~ /^\s*[+-]?\s*?\d+\s*$/ ? print "'$int' is an integer\n" : print "'$int'
> is not an integer\n";
> }
>
> # this is even more flexy it allows spaces commas (not at begining or end)
> # and a decimal point no inter number spaces
> sub is_integer3 {
> my $int = shift;
> $int =~ /^\s*[+-]?\s*(?:\d+,)*\d+(?:\.\d+)?\s*$/ ? print "'$int' is an
> integer\n" : print "'$int' is not an integer\n";
Whoops this will let 1.7 through. This will only let 1.00000 etc
$int =~ /^\s*[+-]?\s*(?:\d+,)*\d+(?:\.\0+)?\s*$/ ? print "'$int' is an
integer\n" : print "'$int' is not an integer\n";
>
> print "\n$int is actually a default subnet mask!\n\nCheers\n\nJames\n" if
> $int =~ m/^(?:\d+\.){3}\d$/;
> }
>
> >
> >
> > Thanks!
> >
> > Rob
------------------------------
Date: Thu, 03 May 2001 12:03:43 GMT
From: "Dodger" <dodger@necrosoft.net>
Subject: Re: Test for integer?
Message-Id: <zObI6.45192$B22.11271486@news1.rdc2.pa.home.com>
"Rob" <"relaxedrob@optushome.com.au"> wrote in message
news:2t6I6.1899$76.7930@news1.rdc1.nsw.optushome.com.au...
> Hi all!
>
> Is there a way for me to test if a scalar holds an integer value (positive
> or negative)?
>
> Thanks!
Saw a lot of replies, some very elabourate. However, it seems to me that:
($val == int $val)
should do the trick fine...
--
Dodger
www.dodger.org
www.necrosoft.net
www.gothic-classifieds.com
------------------------------
Date: Thu, 03 May 2001 12:29:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Test for integer?
Message-Id: <dmj2fts3f8bab4u094rvjo95pc87el3t4f@4ax.com>
Dodger wrote:
>Saw a lot of replies, some very elabourate. However, it seems to me that:
>($val == int $val)
>should do the trick fine...
Only if you're sure it contains a number.
$^W = 1;
$val = "123foo!";
if($val==int $val) {
print "Equal!";
}
First, this complains that "this is not numeric", and then it says that
both sides are equal. I wouldn't really call this an integer, though.
--
Bart.
------------------------------
Date: Thu, 03 May 2001 12:38:46 GMT
From: "Rob" <"relaxedrob@optushome.com.au">
Subject: Re: Test for integer?
Message-Id: <qjcI6.2051$76.8785@news1.rdc1.nsw.optushome.com.au>
Dodger:
my $val = 3;
print "1. $val is an integer!\n" if ($val == int $val);
$val = 3.3;
print "2. $val is an integer!\n" if ($val == int $val);
$val = "io";
print "3. $val is an integer!\n" if ($val == int $val);
$val = 0;
print "4. $val is an integer!\n" if ($val == int $val);
OUTPUT
1. 3 is an integer!
Argument "io" isn't numeric in int at disktop.pl line 57.
3. io is an integer!
4. 0 is an integer!
btw.. I am verrrry impressed with dodger.ord - the tabs look great!
Rob
:)
"Dodger" <dodger@necrosoft.net> wrote in message
news:zObI6.45192$B22.11271486@news1.rdc2.pa.home.com...
> "Rob" <"relaxedrob@optushome.com.au"> wrote in message
> news:2t6I6.1899$76.7930@news1.rdc1.nsw.optushome.com.au...
> > Hi all!
> >
> > Is there a way for me to test if a scalar holds an integer value
(positive
> > or negative)?
> >
> > Thanks!
>
> Saw a lot of replies, some very elabourate. However, it seems to me that:
> ($val == int $val)
> should do the trick fine...
>
> --
> Dodger
> www.dodger.org
> www.necrosoft.net
> www.gothic-classifieds.com
>
>
>
------------------------------
Date: 03 May 2001 13:42:16 +0100
From: nobull@mail.com
Subject: Re: Test for integer?
Message-Id: <u9oftatxhz.fsf@wcl-l.bham.ac.uk>
"Dodger" <dodger@necrosoft.net> writes:
> "Rob" <"relaxedrob@optushome.com.au"> wrote in message
> news:2t6I6.1899$76.7930@news1.rdc1.nsw.optushome.com.au...
> > Hi all!
> >
> > Is there a way for me to test if a scalar holds an integer value (positive
> > or negative)?
> >
> > Thanks!
>
> Saw a lot of replies, some very elabourate. However, it seems to me that:
> ($val == int $val)
> should do the trick fine...
So "banana" is an integer in your book?
------------------------------
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 827
**************************************