[23747] in Perl-Users-Digest
Perl-Users Digest, Issue: 5951 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 18 09:05:44 2003
Date: Thu, 18 Dec 2003 06:05:08 -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 Thu, 18 Dec 2003 Volume: 10 Number: 5951
Today's topics:
$dbh->tables() returns nothing <jds@nospantrumpetweb.co.uk>
building a crm solution using Perl (Julie Smith)
Re: Can you undo a read from a file <clpm1812031@dontmind.net>
Re: Creating a list of HASHes (Patrick Paquet)
Re: Creating a list of HASHes (Anno Siegel)
Re: Creating a list of HASHes <1usa@llenroc.ude>
Determine DaysInMonth($month) <Eric@nowhere.com>
Re: Determine DaysInMonth($month) <carsten@welcomes-you.com>
Re: Determine DaysInMonth($month) <matthew.garrish@sympatico.ca>
Re: Determine DaysInMonth($month) <carsten@welcomes-you.com>
Re: Determine DaysInMonth($month) <matthew.garrish@sympatico.ca>
Re: Determine DaysInMonth($month) <matthew.garrish@sympatico.ca>
Re: Determine DaysInMonth($month) <richard@zync.co.uk>
Re: Determine DaysInMonth($month) <richard@zync.co.uk>
Re: Error with cgi script writing to STDERR <nobull@mail.com>
Nested tables with RTF::Writer <mahesha@mahesha.net>
Re: Ordering arrays? <raisin@delete-this-trash.mts.net>
Re: Passing a hash by reference (Anno Siegel)
Re: Redirect url <jwillmore@remove.adelphia.net>
Re: RegExp check for nothing or pattern <Eric@nowhere.com>
Re: RegExp check for nothing or pattern <matthew.garrish@sympatico.ca>
Re: Simple text file operation (logic1)
Re: Simple text file operation (Anno Siegel)
strange results using m//g in while loop... <not_a_real@adress.getting.too.much.spam.org>
Re: strange results using m//g in while loop... (Anno Siegel)
Re: strange results using m//g in while loop... <kuujinbo@hotmail.com>
Re: strange results using m//g in while loop... <kuujinbo@hotmail.com>
When closing DOS window... <spikeywan@bigfoot.com.delete.this.bit>
Re: Where do -T warnings go? <jwillmore@remove.adelphia.net>
Re: Where do -T warnings go? <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 Dec 2003 11:58:55 -0000
From: "Julia deSilva" <jds@nospantrumpetweb.co.uk>
Subject: $dbh->tables() returns nothing
Message-Id: <3xXDb.22875$5F2.897@news-binary.blueyonder.co.uk>
Hi there all,
Unix Perl MYSQL
Has anyone experienced on some servers ...
my @tables = $dbh->tables() returning nothing Nil Nada zilch when you are
100% sure you have oodles of tables ?
Is this a known problem, is there a fix, workaround ?
TIA and Merry Xmas.
J
------------------------------
Date: 18 Dec 2003 04:39:05 -0800
From: julie_smith@operamail.com (Julie Smith)
Subject: building a crm solution using Perl
Message-Id: <269c023e.0312180439.3c52eb9@posting.google.com>
Hi,
I wanted to implement a crm(customer relationship management) solution
using perl.
It will have to easily integrate and migrate all the existing systems
used by my companies sales,marketing,accounting departments and give a
customer centric view of the whole company.
what architecture should I use.
I have evaluated the exisintg popular out of the box solutions like
accpacc,update.com,upshot.com but they cost money.!!!
company size is under 200 persons.
any help will be appreciated!
thanks in advance,
Julie
------------------------------
Date: 18 Dec 2003 08:17:51 GMT
From: Dave Weaver <clpm1812031@dontmind.net>
Subject: Re: Can you undo a read from a file
Message-Id: <slrnbu2olf.59a.zen13097@dontmind.net>
On 17 Dec 2003 15:24:10 -0800, Tim Greenwood <timothy@greenwood.name> wrote:
> Is it possible (and preferably simple) to undo a line input from STDIN
> or any file handle? I want to do something like
>
>
> $line = <STDIN>;
> if ($line =~ $my_pattern) {
> # process it all
> } else {
> # push the line back to be read by some other part of the program
> }
Perhaps something like this? :
#!/usr/bin/perl
use warnings;
use strict;
{{
my %buffer;
# Read a line from the given file handle
sub getline {
my ($fh) = @_;
if (exists $buffer{$fh} and @{$buffer{$fh}}) {
return shift @{$buffer{$fh}};
}
return scalar <$fh>;
}
# "Push back" a line to the given filehandle, so that
# it will be returned on the next getline() call.
sub ungetline {
my ($fh, $line) = @_;
push @{$buffer{$fh}}, $line;
}
}}
my $in = getline(\*STDIN);
print "Got: $in";
ungetline(\*STDIN, "One\n");
ungetline(\*STDIN, $in);
$in = getline(\*STDIN);
print "Got: $in";
$in = getline(\*STDIN);
print "Got: $in";
__END__
[not _fully_ tested]
Cheers,
Dave
------------------------------
Date: 18 Dec 2003 02:48:14 -0800
From: jack_luminous@hotmail.com (Patrick Paquet)
Subject: Re: Creating a list of HASHes
Message-Id: <14e35cbb.0312180248.715a3fc8@posting.google.com>
Hello,
Again responding to my previous post, as both Anno Siegel and A. Sinan
Unur provided useful methods to fix my problem. I tested both out on
my code and both worked.
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<brpgg7$f83$1@mamenchi.zrz.TU-Berlin.DE>...
<Snip>
> Okay, but you ought to have some means to tell new information (that
> isn't in the DB yet) from old information. Otherwise you'd have to
> write back everything on every update.
True. I've been thinking about that as well, for the moment I'm
concentrating on checking a few 'key' values, if any of those have
changed then I update the lot. Not the most efficient, but if I find
it to be too lengthy I'll look at cleaning that up. Since this is a
replacement for an existing script (that is WAY heavier...), just
skipping over the workstations that haven't changed is a major
performance boost.
<More snippage>
> > my ($Key, $Value, %InfosMachine);
>
> Declare your variables in the smallest possible scope. Declaring them
> together with the first use (if possible) guarantees that. Scratch
> the last line.
>
> > my $InfosMachine = @_;
Damn... Thought I had that sorted out. I seem to have a tenious
grasp on scope at this point.
> When you have this up and running you may want to change the passing of
> the hash to a reference (which may win a little speed), but I suggest
> you try the straight-forward way first.
This is another thing I have a tenious (at best!) grasp of, hashes,
and references to hashes. I find it all very confusing, and usually
end up trying out a bunch of syntax permutations until I find
something that works. But I'm getting better at that too.
> Let me add that you have done a good job with the code you prepared.
> Even though I didn't actually run it, it's a far easier read when you
> can see the author made an effort to make it self-contained.
Thanks, I read the posting guidelines... :-) Also noticed that
properly written out posts got useful replies... And the whole
process of making the thing self contained, and making sure that the
code would run when copy/pasted was educationnal as well.
And...
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns9454825E92C74asu1cornelledu@132.236.56.8>...
> jack_luminous@hotmail.com (Patrick Paquet) wrote in
> news:14e35cbb.0312170310.22a6ac66@posting.google.com:
<Snippety>
> I would prefer to use references to hashes all around.
Again with the references to hashes, gonna have to wrap my head around
this.
<Snipperoony>
> May I suggest dropping the & unless you really need it. (from perldoc
> perlsub:
Done, works fine without &.
<Snipety doo da>
> You have not moved all your variables to the smallest possible scope;
> there is still some room for improvment.
<Sigh> Scope... I'll get that right too, at some point.
<Snipety day>
> my $InfosMachine = shift;
That's interesting, had to look up SHIFT, and think it thru for a few
minutes. So Shift passes the first element (the hash reference) to
$InfosMachine. And you're right, it makes things pretty clear. If
you have time, I'd be curious to see how you would handle multiple
arguments to a sub, for example (off the top of my head.... really):
EcriteSQL($SQLConnect,$RecordStatus,\%InfoMachine)
I guess shift is not useable in that context since it only returns the
first element from the array.(?)
And after all that, I've got the script running properly now, and I
also have a better (although not yet perfect) grasp of scope, hashes
(and their references) and clean code. I also learned that taking the
time to properly formulate a question will most likely get me a proper
answer (the old stupid question/stupid answer thing I guess).
Thanks to all of you for taking the time to help me understand all
this. Hope everybody has a good day.
Patrick Paquet
------------------------------
Date: 18 Dec 2003 11:40:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Creating a list of HASHes
Message-Id: <brs3mo$8s2$1@mamenchi.zrz.TU-Berlin.DE>
Patrick Paquet <jack_luminous@hotmail.com> wrote in comp.lang.perl.misc:
> Hello,
>
> Again responding to my previous post, as both Anno Siegel and A. Sinan
> Unur provided useful methods to fix my problem. I tested both out on
> my code and both worked.
>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<brpgg7$f83$1@mamenchi.zrz.TU-Berlin.DE>...
> <Snip>
> > Okay, but you ought to have some means to tell new information (that
> > isn't in the DB yet) from old information. Otherwise you'd have to
> > write back everything on every update.
>
> True. I've been thinking about that as well, for the moment I'm
> concentrating on checking a few 'key' values, if any of those have
> changed then I update the lot. Not the most efficient, but if I find
> it to be too lengthy I'll look at cleaning that up. Since this is a
> replacement for an existing script (that is WAY heavier...), just
> skipping over the workstations that haven't changed is a major
> performance boost.
Okay, let's leave that aside for the moment. (You can, of course,
use a second hash to store only the new keys, and write only them back
if necessary.)
> <More snippage>
> > > my ($Key, $Value, %InfosMachine);
> >
> > Declare your variables in the smallest possible scope. Declaring them
> > together with the first use (if possible) guarantees that. Scratch
> > the last line.
> >
> > > my $InfosMachine = @_;
>
> Damn... Thought I had that sorted out. I seem to have a tenious
> grasp on scope at this point.
I hope you didn't overlook the more severe error of assigning an array
to a scalar. That's what made your attempt fail.
[...]
> > Let me add that you have done a good job with the code you prepared.
> > Even though I didn't actually run it, it's a far easier read when you
> > can see the author made an effort to make it self-contained.
>
> Thanks, I read the posting guidelines... :-) Also noticed that
Good thing :)
> properly written out posts got useful replies... And the whole
> process of making the thing self contained, and making sure that the
> code would run when copy/pasted was educationnal as well.
That last point can't be stressed enough. Explaining a problem clearly
helps understand it better, sometimes to the point of finding a solution.
Anno
------------------------------
Date: 18 Dec 2003 14:01:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Creating a list of HASHes
Message-Id: <Xns94555BDBBC99Aasu1cornelledu@132.236.56.8>
jack_luminous@hotmail.com (Patrick Paquet) wrote in
news:14e35cbb.0312180248.715a3fc8@posting.google.com:
> "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message
> news:<Xns9454825E92C74asu1cornelledu@132.236.56.8>...
>> my $InfosMachine = shift;
>
> That's interesting, had to look up SHIFT, and think it thru for a few
> minutes. So Shift passes the first element (the hash reference) to
> $InfosMachine. And you're right, it makes things pretty clear. If
> you have time, I'd be curious to see how you would handle multiple
> arguments to a sub, for example (off the top of my head.... really):
>
> EcriteSQL($SQLConnect,$RecordStatus,\%InfoMachine)
>
> I guess shift is not useable in that context since it only returns the
> first element from the array.(?)
Well, one could do:
EcriteSQL($SQLConnect,$RecordStatus,\%InfoMachine) {
my $SQLConnect = shift;
my $RecordStatus = shift;
my $InfoMachine =shift;
}
But, that is cumbersome. I did not mean to stress the use of shift, but
rather, the practice of initializing your subroutine's lexical variables
from parameters as the first thing to do in the sub. In fact there has been
some discussion in this group about why one should stick with
sub somesub {
my $var = @_;
}
rather than
sub somesub {
my $var = shift;
}
unless one really wants to remove elements from @_.
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: Thu, 18 Dec 2003 12:57:39 -0000
From: "Eric" <Eric@nowhere.com>
Subject: Determine DaysInMonth($month)
Message-Id: <brs87j$phm$1@news7.svr.pol.co.uk>
Hi,
Can you help me write a piece of code to do this:
my $daysinmonth = &DaysInMonth($month)
Where $month is the month num (1-12).
I don't have the ability to install modules as I'm on a shared server. And I
don't have Time::DaysInMonth installed.
Thank you!
Eric
------------------------------
Date: Thu, 18 Dec 2003 14:18:31 +0100
From: Carsten Aulbert <carsten@welcomes-you.com>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <brs9g1$71q8c$1@ID-213226.news.uni-berlin.de>
Eric wrote:
> Hi,
>
> Can you help me write a piece of code to do this:
>
> my $daysinmonth = &DaysInMonth($month)
>
> Where $month is the month num (1-12).
That's pretty simple, all month have (at least) 28 days ;-)
Ok, enough of the kidding:
sub DaysInMonth {
my $month = shift;
my $year = shift; # need full year, i.e. 03 is _not_ sufficient
my @month_length = (0,31,28,31,30,31,30,31,31,30,31,30,31);
# only special month is February
return $month_length[$month] unless $month == 2;
# February has always 28 days, except if the year is
# dividable by 4 (without remainder). Exceptions are
# full centuries
return 29 if $year % 4 == 0 and $year % 100 != 0;
return 29 if $year % 400 == 0;
return 28;
}
That should work and does not need extra modules.
HTH
Carsten
------------------------------
Date: Thu, 18 Dec 2003 08:20:29 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <tQhEb.15984$CK3.1385735@news20.bellglobal.com>
"Eric" <Eric@nowhere.com> wrote in message
news:brs87j$phm$1@news7.svr.pol.co.uk...
> Hi,
>
> Can you help me write a piece of code to do this:
>
> my $daysinmonth = &DaysInMonth($month)
>
> Where $month is the month num (1-12).
>
Create a hash with all the values:
my %DaysInMonth = ( 1 => 31, 2 => 28, 3 => 31);
my $daysinmonth = $DaysInMonth{$month};
Of course, you'll have to add an extra hash value for leap years and check
whether February should have 28 or 29 days.
Matt
------------------------------
Date: Thu, 18 Dec 2003 14:41:57 +0100
From: Carsten Aulbert <carsten@welcomes-you.com>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <brsarq$6urbp$1@ID-213226.news.uni-berlin.de>
Matt Garrish wrote:
> Create a hash with all the values:
>
> my %DaysInMonth = ( 1 => 31, 2 => 28, 3 => 31);
>
Why a hash? I think an array is not so redundent, isn't it?
CA
------------------------------
Date: Thu, 18 Dec 2003 08:36:28 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <t3iEb.16131$CK3.1393357@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:j1iEb.16103$CK3.1392896@news20.bellglobal.com...
>
> You'd be better off using an array and incrementing the value
> of entry 2 if it happens to be a leap year...
>
And before that gets corrected, I obviously mean [2], not the second entry
in the array, which would be January's. Ugh, I'm going back to bed...
Matt
------------------------------
Date: Thu, 18 Dec 2003 08:34:11 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <j1iEb.16103$CK3.1392896@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:tQhEb.15984$CK3.1385735@news20.bellglobal.com...
>
> Create a hash with all the values:
>
> my %DaysInMonth = ( 1 => 31, 2 => 28, 3 => 31);
>
Too early. I was thinking of using the abbreviated month returned by
localtime and not paying attention to what I was writing (i.e., 'Jan' => 31,
'Feb' => 28). You'd be better off using an array and incrementing the value
of entry 2 if it happens to be a leap year...
Matt
------------------------------
Date: Thu, 18 Dec 2003 13:51:13 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <brsbch$c8u$1@news.freedom2surf.net>
In article <brs87j$phm$1@news7.svr.pol.co.uk>, "Eric" <Eric@nowhere.com>
wrote:
> Hi,
> Can you help me write a piece of code to do this: my $daysinmonth =
> &DaysInMonth($month) Where $month is the month num (1-12). I don't
> have the ability to install modules as I'm on a shared server. And I
> don't have Time::DaysInMonth installed. Thank you!
> Eric
>
sub DaysInMonth {
return (31,28,31,30,31,30,31,31,30,31,30,31)[(my $month = shift) - 1]
}
Might be more useful with a year specification ...
Rich
------------------------------
Date: Thu, 18 Dec 2003 13:53:53 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <brsbhh$c8u$2@news.freedom2surf.net>
In article <brsbch$c8u$1@news.freedom2surf.net>, "Richard Gration"
<richard@zync.co.uk> wrote:
> In article <brs87j$phm$1@news7.svr.pol.co.uk>, "Eric" <Eric@nowhere.com>
> wrote:
>
>> Hi,
>> Can you help me write a piece of code to do this: my $daysinmonth =
>> &DaysInMonth($month) Where $month is the month num (1-12). I don't
>> have the ability to install modules as I'm on a shared server. And I
>> don't have Time::DaysInMonth installed. Thank you! Eric
>>
> sub DaysInMonth {
> return (31,28,31,30,31,30,31,31,30,31,30,31)[(my $month = shift) - 1]
> }
> Might be more useful with a year specification ... Rich
Even better ...
sub DaysInMonth {
return (0,31,28,31,30,31,30,31,31,30,31,30,31)[shift]
}
------------------------------
Date: 18 Dec 2003 12:23:15 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Error with cgi script writing to STDERR
Message-Id: <u9llpa1fik.fsf@wcl-l.bham.ac.uk>
Zbigniew Fiedorowicz <fiedorow@hotmail.com> writes:
> I was tracking down a problem with a cgi-based web service I am running
> and found that it was due to the following puzzling behavior of our Apache 2.0
> web server (running under RedHat 9.0 Linux): if a cgi perl script writes more
> than 182 lines to STDERR, the script hangs - after about 10 minutes the
> web server reports a "Premature end of script headers" error. Then after a
> few more minutes, the stuff that the script was trying to write to STDERR
> appears in the web server error logs.
>
> Has anyone else experienced this?
Yes, but only on Win32 not on POSIX-like OSs to date. I'm also not
the only other person I've seen report this as you can see in...
http://groups.google.com/groups?selm=u9el6pzhqa.fsf%40wcl-l.bham.ac.uk
> Is there in any web server configuration setting which is
> responsible for this?
I never found one.
This, of course, is very unlikely to have anything to do with Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 18 Dec 2003 08:21:38 GMT
From: Mahesh A <mahesha@mahesha.net>
Subject: Nested tables with RTF::Writer
Message-Id: <msdEb.17835$G9.12573@nwrddc01.gnilink.net>
Hi,
I am trying to use RTF::Writer to create an RTF document that contains
nested tables (or table with nested cells).
Followng is what i've come up with. Nested $rtf->table() call looks
pretty wrong - table() doesnot return a string. The inner table() call
executes first and I end up getting get two separate tables instead of
nested tables as intended.
Help/guidance from someone with experience in this area would be greatly
appriciated.
Thanks,
Mahesh.
------------------------------------
#!/usr/local/bin/perl -w
# Intent:
# ,-----------------.------------------------------------,
# | Cell1:1 | Cell1:2 |
# |-----------------+------------------.-----------------|
# | Cell2:1 | Cell2:2:1:1 | Cell2:2:1:2 |
# | |------------------+-----------------|
# | | Cell2:2:2:1 | Cell2:2:2:2 |
# `-----------------'------------------'-----------------'
use strict;
use RTF::Writer;
my $rtf = RTF::Writer->new_to_file("table.rtf");
$rtf->prolog( 'title' => "Nested Tables" );
my $parentRow = RTF::Writer::TableRowDecl->new(
'widths' => [3000, 4000]);
my $childRow = RTF::Writer::TableRowDecl->new(
'widths' => [2000, 2000]);
$rtf->table($parentRow,
["Cell1:1", "Cell1:2"],
["Cell2:1", $rtf->table($childRow,
["Cell2:2:1:1", [\'\i', 'Cell2:2:1:2']],
["Cell2:2:2:1", [\'\i', 'Cell2:2:2:2']])]);
$rtf->close;
------------------------------
Date: Thu, 18 Dec 2003 08:02:34 -0600
From: Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: Ordering arrays?
Message-Id: <MPG.1a4b6f745e342c2e989718@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <brqhgo$gc8$1@newsg4.svr.pol.co.uk>, gary@tgpmakers.com
says...
> Hi,
> I'm trying to get an array into order i've got this array,
> $number[1] = "5";
> $number[2] = "7";
> $number[3] = "4";
> $number[4] = "8";
> $number[5] = "7";
>
> i'm trying to get it into another array it looks like this,
> $number2[1] = "8";
> $number2[2] = "7";
> $number2[3] = "7";
> $number2[4] = "5";
> $number2[5] = "4";
>
> So far i've got some code like this,
> for($i=1;$i<=$count;$i++) {
> for($ii=1;$ii<=$count;$ii++) {
> if ($number[$ii]>=$highest[$i]) {
> $number2 = $number[$i];
> print "\n$number2[$i]";
> }
> }
> }
>
> I've tried the pseudo but could figure out the logic. This is the first
> time i've had to do ordering of this sort so i'm a bit stuck at which
> way to go next. I've checked out cpan but couldn't find anything that
> looked like it would do what i wanted.
>
> Has anyone got any ideas please.
>
> Thanks
>
> Gary
You should use perl's builtin "sort" function. See "perldoc -f sort"
for further details.
------------------------------
Date: 18 Dec 2003 12:31:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Passing a hash by reference
Message-Id: <brs6ns$b7n$1@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "GK" == G Klinedinst <g_klinedinst@hotmail.com> writes:
>
> TORE> sub PrintHashEntries {
> TORE> my $rh_hashref = shift;
>
> TORE> sub AddHashEntries {
> TORE> my $rh_hashref = shift;
>
> URI> $rh_hashref->{"key$_"} = "value$_" for 1 .. 10 ;
>
> > Thank you Uri and Tore for "Perlizing" his code. I also write Perl
> > code which looks suspiciously like C, so seeing how everyone else does
> > it is a great help to me. I particularly like the "1..10" and shifting
> > the first value out of @_ at the beginning of each function...I mean
> > subroutine.
>
> well, since you are in a learning mode, i prefer to assign with @_
> instead of shift (except where shifting @_ does something important).
>
> my ( $arg, $foo ) = @_ ;
>
> that style will usually mean fewer lines of code and it is easier to add
> more args or slurp the rest with an array or hash:
>
> my ( $file, %opts ) = @_ ;
>
> but as i said shift has its place there but IMO only when you need to
> have a shorter @_ for use later on.
One such place is, in my praxis, the first parameter of a method. It
is a good rule to always shift it off the parameter list (and probably
call it $class for a class method, and $self, or an abbreviation of the
class name, for an object method). That way, the parameters left after
the shift correspond to the (method-) call parameters the way they do
with normal sub calls. It also gives methods a distinctive style that
may help tell them from other subs.
Anno
------------------------------
Date: Thu, 18 Dec 2003 09:40:49 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Redirect url
Message-Id: <20031218044049.50ab9aa2.jwillmore@remove.adelphia.net>
On Wed, 17 Dec 2003 16:41:58 +0200
user@domain.invalid wrote:
> I keep getting "The document has moved here" when trying to redirect
> a browser using mod_perl (2) and apache 2. Is there a way around
> this?
>
I think there's a mod_perl mailing list you could search/post for
answers.
http://perl.apache.org/
We here in comp.lang.perl.misc deal more with code than server
configuration.
HTH and Good luck
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Fine day to work off excess energy. Steal something heavy.
------------------------------
Date: Thu, 18 Dec 2003 11:02:18 -0000
From: "Eric" <Eric@nowhere.com>
Subject: Re: RegExp check for nothing or pattern
Message-Id: <brs1fb$rc6$1@news6.svr.pol.co.uk>
>
> I posted my answer to your other post entitled: "RegExp to match pattern
or
> BLANK?"
>
> Why did you post the same question twice with two different subject lines?
>
For the sole purpose of annoying you.
------------------------------
Date: Thu, 18 Dec 2003 08:24:01 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: RegExp check for nothing or pattern
Message-Id: <OThEb.15991$CK3.1388107@news20.bellglobal.com>
"Eric" <Eric@nowhere.com> wrote in message
news:brs1fb$rc6$1@news6.svr.pol.co.uk...
> >
> >
> > Why did you post the same question twice with two different subject
lines?
> >
>
> For the sole purpose of annoying you.
>
And in the process everyone else who reads this group. Well done!
Matt
------------------------------
Date: 18 Dec 2003 00:15:35 -0800
From: logic1@esatclear.ie (logic1)
Subject: Re: Simple text file operation
Message-Id: <6e20e34b.0312180015.2d604aed@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<brp9l4$a00$1@mamenchi.zrz.TU-Berlin.DE>...
>
> What have you tried so far?
>
> We can help you with a script, but we're not in the habit of writing
> complete solutions from scratch.
>
> Anno
Hi,
Sorry about that I did mean to include the shell script I had so far.
It's basically pseudo code as my perl knowledge is extremly limited
and I'm trying to learn as I go.
for $file in `ls *.blob` do
date=`echo $file `gawk -F '{ print $1 }'`
ver=`echo $file `gawk -F '{ print $2 }'`
for line in `cat $file`
do
echo "$date $ver $line";
There's obviously numerous errors in there in syntax and language but
as I said my perl knowledge is limited and I need this solution fairly
quickly.
.logic.
------------------------------
Date: 18 Dec 2003 09:45:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Simple text file operation
Message-Id: <brrt0j$3kn$1@mamenchi.zrz.TU-Berlin.DE>
logic1 <logic1@esatclear.ie> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<brp9l4$a00$1@mamenchi.zrz.TU-Berlin.DE>...
>
> >
> > What have you tried so far?
> >
> > We can help you with a script, but we're not in the habit of writing
> > complete solutions from scratch.
> >
> > Anno
>
> Hi,
>
> Sorry about that I did mean to include the shell script I had so far.
>
> It's basically pseudo code as my perl knowledge is extremly limited
> and I'm trying to learn as I go.
>
> for $file in `ls *.blob` do
> date=`echo $file `gawk -F '{ print $1 }'`
> ver=`echo $file `gawk -F '{ print $2 }'`
> for line in `cat $file`
> do
> echo "$date $ver $line";
That's a shell script. This is a Perl group.
> There's obviously numerous errors in there in syntax and language but
> as I said my perl knowledge is limited and I need this solution fairly
> quickly.
Doesn't everybody...
Here is a solution. See if you can use it.
my $dir = '/tmp/aux';
opendir my $d, $dir or die "Can't read directory $dir: $!";
for my $file ( grep /\.blob$/, readdir( $d) ) {
my ( $date, $ver, $n) = $file =~ /([^_]*)_([^_]*)_AT.*(\d+)/;
my $f;
unless ( open $f, "$dir/$file" ) {
warn "Can't read $dir/$file: $!";
next;
}
while ( <$f> ) {
chomp;
my ( $ref, $val) = split /\s*\|\s*/;
print "$date | $ver | $ref | $val\n"
}
}
Anno
------------------------------
Date: Thu, 18 Dec 2003 01:15:53 -0800
From: "Damian" <not_a_real@adress.getting.too.much.spam.org>
Subject: strange results using m//g in while loop...
Message-Id: <brrr81$6mdao$1@ID-196529.news.uni-berlin.de>
The following works as expected (examples):
my $re_d = qr|(\d),(\d),(\d)|;
my $s = "abcde1,2,3hk4,5,6hkgk7,8,9dfdfdfd";
while ($s =~ m|$re_d|g) {
print "[$1 $2 $3]\n";
}
And prints:
[1 2 3]
[4 5 6]
[7 8 9]
However, if I try to capture the $1, $2, ... matches ot an array, it
turns into na infinate loop:
my $re_d = qr|(\d),(\d),(\d)|;
my $s = "abcde1,2,3hk4,5,6hkgk7,8,9dfdfdfd";
my @r;
while (@r = $s =~ m|$re_d|g) {
print "[@r]\n";
}
And keeps printing:
[1 2 3 4 5 6 7 8 9]
[1 2 3 4 5 6 7 8 9]
[1 2 3 4 5 6 7 8 9]
[1 2 3 4 5 6 7 8 9]
[1 2 3 4 5 6 7 8 9]
[1 2 3 4 5 6 7 8 9]
.
.
.
Why is ading the array to suck up the results causing the behavior to
change?
And for that matter, how can I capture the $1, $2... in an array like
this?
(That @& talked about a couple years ago would really come in handy.)
Thanks.
------------------------------
Date: 18 Dec 2003 10:04:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: strange results using m//g in while loop...
Message-Id: <brru2s$4th$1@mamenchi.zrz.TU-Berlin.DE>
Damian <not_a_real@adress.getting.too.much.spam.org> wrote in comp.lang.perl.misc:
> The following works as expected (examples):
>
>
> my $re_d = qr|(\d),(\d),(\d)|;
> my $s = "abcde1,2,3hk4,5,6hkgk7,8,9dfdfdfd";
>
> while ($s =~ m|$re_d|g) {
> print "[$1 $2 $3]\n";
> }
>
> And prints:
>
> [1 2 3]
> [4 5 6]
> [7 8 9]
>
>
>
> However, if I try to capture the $1, $2, ... matches ot an array, it
> turns into na infinate loop:
Yup, that's expected.
There's a whole lot of magic going on with //g in scalar context that
doesn't happen in list context. In particular, in scalar context, each
//g matches only once (despite the /g), but sets the position (pos())
of the string to the place past the last match. The next match implicitly
starts matching at pos(), not at the start of the string. That mechanism
steers you safely through the loop when you match in scalar context.
In list context, a global match is just a global match: It starts at
the beginning and matches everything it can to the end of the string.
The next match does exactly the same thing, hence the endless loop.
> my $re_d = qr|(\d),(\d),(\d)|;
> my $s = "abcde1,2,3hk4,5,6hkgk7,8,9dfdfdfd";
>
> my @r;
> while (@r = $s =~ m|$re_d|g) {
> print "[@r]\n";
> }
>
> And keeps printing:
>
> [1 2 3 4 5 6 7 8 9]
> [1 2 3 4 5 6 7 8 9]
Anno
------------------------------
Date: Thu, 18 Dec 2003 19:00:04 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: strange results using m//g in while loop...
Message-Id: <brru2q$5df$1@pin3.tky.plala.or.jp>
Damian wrote:
[snip]
> However, if I try to capture the $1, $2, ... matches ot an array, it
> turns into na infinate loop:
>
> my $re_d = qr|(\d),(\d),(\d)|;
> my $s = "abcde1,2,3hk4,5,6hkgk7,8,9dfdfdfd";
>
> my @r;
> while (@r = $s =~ m|$re_d|g) {
> print "[@r]\n";
> }
>
> And keeps printing:
>
> [1 2 3 4 5 6 7 8 9]
> [1 2 3 4 5 6 7 8 9]
> [1 2 3 4 5 6 7 8 9]
> [1 2 3 4 5 6 7 8 9]
> [1 2 3 4 5 6 7 8 9]
> [1 2 3 4 5 6 7 8 9]
> .
> .
> .
>
> Why is ading the array to suck up the results causing the behavior to
> change?
> And for that matter, how can I capture the $1, $2... in an array like
> this?
>
> (That @& talked about a couple years ago would really come in handy.)
>
> Thanks.
When the /g modifier is used in list context, it gets *all* matches.
That's normal behavior. So in this case @r is assigned nine elements.
Since this is evaluated in scalar context, basically what you get is:
while (9) {
print "[@r]\n";
}
which is an infinite loop.
HTH - keith
------------------------------
Date: Thu, 18 Dec 2003 20:09:54 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: strange results using m//g in while loop...
Message-Id: <brs25p$anm$1@pin3.tky.plala.or.jp>
ko wrote:
[snip]
> Since this is evaluated in scalar context, basically what you get is:
>
> while (9) {
> print "[@r]\n";
> }
>
> which is an infinite loop.
Whoa, *what* was I thinking? A true value, of course, is also returned
when the regex matches in scalar context. As Anno explained, pos()
allows you to break out of the loop.
------------------------------
Date: Thu, 18 Dec 2003 13:24:30 -0000
From: "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit>
Subject: When closing DOS window...
Message-Id: <brs9tg$igu$1@newshost.mot.com>
Guys,
I ahve written a script that runs in a DOS window, and parses a log file
into Excel.
If a user decides to terminate the script whilst running, the Excel process
gets left running, and messes up the operation of the script, and Excel
afterwards.
I invoke Excel like this:
my $excel;
eval {$excel = Win32::OLE->GetActiveObject('Excel.Application')};
die "WARNING! Excel not installed" if $@;
unless (defined $excel) {
$excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die
"ERROR, cannot start Excel";
}
I have an END block that closes Excel down, and I have successfully trapped
Control C so that the END block gets executed and Excel is closed properly.
However, I have found that if the user presses the X button on the window,
then I am again left with an orphan Excel process.
Should I start Excel differently so that it terminates when the script does?
Alternatively, can anyone give me any pointers on how to trap the user
clicking on the X so that I can ensure that my END block is run, like I now
do for control C?
Thanks.
--
R.
GPLRank +79.699
------------------------------
Date: Thu, 18 Dec 2003 09:34:17 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Where do -T warnings go?
Message-Id: <20031218043416.74289014.jwillmore@remove.adelphia.net>
On Thu, 18 Dec 2003 06:55:16 +0100
Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:
> James Willmore wrote (Wednesday 17 December 2003 15:46):
> > On Wed, 17 Dec 2003 11:30:15 +0100
> > Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:
<snip>
> > As far as getting errors about insecure dependencies, you
> > *should* get
> > them like any other warnings and errors.
>
> One SuSE 7.3 (5.8.0) they do get back (through STDERR). When
> running on RedHat (also 5.8.0) qx($cmd) just seems to die without
> leaving any trace anywhere.
Well, one other "tool" you could use is the CGI::Carp module.
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
Or, whatever way you'd like to use CGI::Carp. Just be sure to remove
the *ToBrowser imports when running in a production environment. This
may help track down whatever issues you're running into.
However, as a general rule, you should run your scripts at the command
line first, then through the server. My guess is that you're running
into a suexec issue if you're using Apache. If that's the case, you
get nothing in the browser or the error log. However, you will see
something in the suexec log file.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Smoking is one of the leading causes of statistics. -- Fletcher
Knebel
------------------------------
Date: Thu, 18 Dec 2003 12:36:12 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Where do -T warnings go?
Message-Id: <newscache$ck93qh$iy1$1@news.emea.compuware.com>
James Willmore wrote (Thursday 18 December 2003 10:34):
[well taken and appreciated advise snipped]
> My guess is that you're
> running
> into a suexec issue if you're using Apache. If that's the case,
> you
> get nothing in the browser or the error log. However, you will
> see something in the suexec log file.
That's a new one. I didn't figure that one out yet. Will look into
that. Thanks!
--
KP
43rd Law of Computing: "Anything that can go wr
fortune: Segmentation violation -- Core dumped
------------------------------
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 5951
***************************************