[28912] in Perl-Users-Digest
Perl-Users Digest, Issue: 156 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 20 21:09:49 2007
Date: Tue, 20 Feb 2007 18:09:09 -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, 20 Feb 2007 Volume: 11 Number: 156
Today's topics:
Re: Combining M-F school week and 6 day class cycle usenet@DavidFilmer.com
Re: Complex calculation of averages <attn.steven.kuo@gmail.com>
Re: Creating pivot table <1usa@llenroc.ude.invalid>
Re: fcntl call to check if a file is open - help needed <someone@example.com>
Re: Help with string replacement <johngnub@COX.NET>
How to replace a "/" in perl chunji08@gmail.com
Re: How to replace a "/" in perl <1usa@llenroc.ude.invalid>
Re: How to replace a "/" in perl <ced@blv-sam-01.ca.boeing.com>
Re: How to replace a "/" in perl chunji08@gmail.com
Re: Quick Question <rvtol+news@isolution.nl>
Re: Regex: Why is overreaching necessary? <nospam-abuse@ilyaz.org>
simple use of eval of somethinng else <bpatton@ti.com>
Re: simple use of eval of somethinng else <ch.l.ngre@online.de>
Re: simple use of eval of somethinng else <wahab-mail@gmx.de>
Re: simple use of eval of somethinng else xhoster@gmail.com
Re: Tool to create Perl based scripts <johngnub@COX.NET>
Re: Tool to create Perl based scripts <bik.mido@tiscalinet.it>
Re: Tool to create Perl based scripts usenet@DavidFilmer.com
Re: waitpid woes on Solaris, Perl 5.8.8 xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Feb 2007 13:25:45 -0800
From: usenet@DavidFilmer.com
Subject: Re: Combining M-F school week and 6 day class cycle
Message-Id: <1172006745.742470.15020@a75g2000cwd.googlegroups.com>
On Feb 20, 12:55 pm, gfo...@gmail.com wrote:
> I want to create (or find) a perl script that can take a start date,
> an end date, and a set of "off days" and output an iCalendar
> compatible file where each date in the iCalendar is marked as a DAY
> 1-6 or an off day.
....
> I'm currently looking at DateTime::Format::ICal.
DateTime::Format::ICal will allow you to create the iCalendar output,
but it won't help you parse the dates.
For that, I'd recommend Date::Manip (the Swiss Army Knife of date
manipulation). The DateCalc() method allows you to use "business
mode" which takes into account the duration of the work (or school)
week, holidays, etc (and all these things can be custom configured).
The module has many methods which may be of interest to you. For
example, if you want to iterate over a date range of work days you can
do so with the Date_NextWorkDay() method. The Date_IsHoliday() method
will tell you if any particular date is a holiday. Lots of other good
things.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 20 Feb 2007 15:34:57 -0800
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: Complex calculation of averages
Message-Id: <1172014497.605948.27800@k78g2000cwa.googlegroups.com>
On Feb 19, 8:33 am, "Bart Van der Donck" <b...@nijlen.com> wrote:
> Hello perl gurus,
>
> I have the following problem.
>
> $x{'63'} = "2006-05-17|2006-11-25|2006-12-04";
> $x{'67'} = "2005-04-30|2005-09-21|2006-07-17|2007-02-10";
> $x{'71'} = "2006-04-23|2006-10-05|2006-12-27|2007-01-21";
> etc.
>
> How can I calculate the average number of days between each date for
> %x for the last 1,2,3,4,5,6,12 months ?
>
> use Date::Calc(Delta_Days);
> print Delta_Days(2006,12,27,2007,1,21); # says '25'
>
> The dates in each value are sorted and in YYYY-MM-DD format.
>
> %x might be thought of as an array, because the hash values are unique
> and non-floating numbers.
>
> ------------------------
> Example 1
> ------------------------
>
> Today is 2007-02-19. 67 and 71 can be taken to calculate the average
> of the last month (=2007-01-19 to 2007-02-19) because 63 holds no data
> for it.
>
> Average of 208 (nr of days from 2006-07-17 to 2007-02-10 in $x{'67'})
> and 328 (nr of days from 2006-02-27 to 2007-01-21 in $x{'71'}) becomes
> 268.
>
> Result of example 1 is 268.
Isn't your interval from 2006-12-17 to 2007-01-21?
> ------------------------
> Example 2
> ------------------------
>
> Today is 2007-02-19. All three entries can be taken to calculate the
> average of last 5 months (=2006-09-19 to 2007-02-19).
Your data might be better off being stored in a database.
With something like SQLite, you could run:
BEGIN TRANSACTION;
CREATE TABLE elapsed (
my_id INTEGER PRIMARY KEY,
category INTEGER,
start_date DATE,
end_date DATE
);
INSERT INTO "elapsed" VALUES (1, 63, '2006-05-17', '2006-11-25');
INSERT INTO "elapsed" VALUES (2, 63, '2006-11-25', '2006-12-04');
INSERT INTO "elapsed" VALUES (3, 67, '2005-04-30', '2005-09-21');
INSERT INTO "elapsed" VALUES (4, 67, '2005-09-21', '2006-07-17');
INSERT INTO "elapsed" VALUES (5, 67, '2006-07-17', '2007-02-10');
INSERT INTO "elapsed" VALUES (6, 71, '2006-04-23', '2006-10-05');
INSERT INTO "elapsed" VALUES (7, 71, '2006-10-05', '2006-12-27');
INSERT INTO "elapsed" VALUES (8, 71, '2006-12-27', '2007-01-21');
END TRANSACTION;
SELECT category, AVG( JULIANDAY(end_date) - JULIANDAY(start_date))
FROM elapsed
WHERE end_date > DATE('now', '-1 month')
GROUP BY category;
SELECT category, AVG( JULIANDAY(end_date) - JULIANDAY(start_date))
FROM elapsed
WHERE end_date > DATE('now', '-5 month')
GROUP BY category;
If you need to access the information from perl, you
can use DBI + DBD::SQLite.
I get as outputs:
67|208.0
71|25.0
63|100.5
67|208.0
71|91.0
--
Hope this helps,
Steven
------------------------------
Date: Tue, 20 Feb 2007 22:11:01 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Creating pivot table
Message-Id: <Xns98DDAECBD5CA1asu1cornelledu@127.0.0.1>
"Thrill5" <nospam@somewhere.com> wrote in
news:fu-dnemKz9Qxw0bYnZ2dnUVZ_oqmnZ2d@comcast.com:
> "myperl" <arunmandalapu@gmail.com> wrote in message
> news:1171990081.659818.157280@m58g2000cwm.googlegroups.com...
>> Hi,
>>
>> I am bringing the data to an excel sheet and showing it as a report
>> through perl. Now my requirement is to produce a pivot table on the
>> same data and show it.I am using win32::OLE in my perl code to bring
>> the sheet. If some have an URL or code example will be great.
...
>
> As far as I know you can't create a pivot table in Excel using OLE.
> This is an Excel problem, not a Perl problem.
I don't have time to try this right now but it looks possible (at least in
Excel 2003).
To the OP, open Excel, go to Tools -> Macro -> Visual Basic Editor. Press
F2 to get the Object Browser. Note the classes whose names begin with
Pivot.
See http://www.unur.com/comp/ppp/perl-win32-ole-excel-ex1.html for an
example of how to get an Excel object via OLE. Once you have that, it looks
like a matter of figuring out the right order of calls. Give it a shot, and
report any problems you encounter.
Sinan
------------------------------
Date: Wed, 21 Feb 2007 00:26:41 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: fcntl call to check if a file is open - help needed
Message-Id: <5lMCh.96831$Fd.14620@edtnps90>
sa wrote:
>>>I don't see how it's going to work for me - I need to check whether a
>>>file is open by another process. Sorry if it wasn't clear. I need to
>>>copy the file and I should not do it if there is another process
>>>writing to it. To complicate things further, the file is located on a
>>>CIFS share. I'm in the process of checking if fcntl can do it for a
>>>network drive but I'm having problems using it on a local file.
>>Well, the first thing to do would be to check that the CIFS protocol
>>is capable of conveying such a query (I don't think it is). If I'm
>>wrong then see if the particular server implementation implements it.
>>The look to see if the client implements it. Then, and only then,
>>should you consider how to get Perl to tell the CIFS client to ask the
>>CIFS server if the file is open.
>>
>>I think this is probably XY. The safest, most portable and widely
>>accepted approach to having one process create a file and another read
>>it only after creation is complete is to rename the file upon
>>completion of creation.
>
> Ha! I wish I had control over the process of creating of those files!
> Unfortunately, this is totally out of the question.
>
> The CIFS protocol and client do know something - when I open a CIFS
> file in say, notepad, and try mv'ing it from the shell prompt - I get
> this:
>
> [root@willow tmp]# mv test.txt test.txt_
> mv: preserving ownership for `test.txt_': Operation not permitted
> mv: cannot unlink `test.txt': Text file busy
> mv: cannot remove `test.txt': Text file busy
>
> I get $! of "Text file busy" from perl when I try to rename. It looks
> like this info can be tapped into, I just don't know how.
#!/usr/bin/perl -w
use strict;
my $old_file = shift or die "usage: $0 filename\n";
my $new_file = "$old_file.$$";
do {
$! = '';
rename $old_file, $new_file;
} while $! =~ /Text file busy/;
open my $fh, '<', $new_file or die "$new_file: Cannot open ($!)\n";
# etc. ...
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: 20 Feb 2007 13:23:28 -0800
From: "johngnub" <johngnub@COX.NET>
Subject: Re: Help with string replacement
Message-Id: <1172006607.952660.235260@s48g2000cws.googlegroups.com>
On Feb 20, 1:49 pm, Ala Qumsieh <nore...@invalid.net> wrote:
> ame...@iwc.net wrote:
>
> > Hi,
>
> > I'm trying to use the -pi switches to replace some strings in a file.
> > However, I'm getting some very strange results.
>
> > My test file looks like this:
>
> > daily_rank.sh|22:30|22:31|22:35|Y
> > dart_process.sh|17:45|17:45|14:46|Y
> > prft_trck.sh|7:30|7:30|7:46|Y
>
> > Here is my command line:
>
> > perl -pi -e "s/$x/$y/;" job_control
>
> > $x = daily_rank.sh|22:30|22:31|22:35|Y
> > $y = daily_rank.sh|22:30|14:13|22:35|N
>
> > After the Perl command executes, my file looks like this:
>
> > daily_rank.sh|22:30|14:13|22:35|N|22:30|22:31|22:35|Y
> > dart_process.sh|17:45|17:45|14:46|daily_rank.sh|22:30|14:13|22:35|N
> > prft_trck.sh|7:30|7:30|7:46|daily_rank.sh|22:30|14:13|22:35|N
>
> > This is not what I expected. I excpected just the first line to be
> > replaced.
>
> > This may have to do with quotes? Or maybe it has to do with the pipe
> > being a special character? But, I've been at it for hours and was
> > looking for a bit of help?
>
> Yes, the pipe. You need to quotemeta-it:
>
> s/\Q$x/$y/
>
> checkout 'perlre' and '-f quotemeta' for more info.
>
> --Ala
# Simple but simple example use of the \Q quote meta. Just 2 cents.
$foo = "a b c ";
print "\Q$foo";
$data = "\Q$foo";
print "\nD $data \n";
$foo = '$ % abc \ ';
$data = "\Q$foo";
print "\nD $data \n";
# jb
------------------------------
Date: 20 Feb 2007 14:15:38 -0800
From: chunji08@gmail.com
Subject: How to replace a "/" in perl
Message-Id: <1172009738.829363.189370@v45g2000cwv.googlegroups.com>
I have a list of sql files, in which it ends with a "/". Now I want to
replace it with "//end" for all files. And here is my perl command,
"
perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
"
Suprisingly it does not work. Does someone know how to make it
working ?
I am using perl 5.6.1 on Linux.
Charlie
------------------------------
Date: Tue, 20 Feb 2007 22:43:25 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to replace a "/" in perl
Message-Id: <Xns98DDB44999B28asu1cornelledu@127.0.0.1>
chunji08@gmail.com wrote in news:1172009738.829363.189370
@v45g2000cwv.googlegroups.com:
> I have a list of sql files, in which it ends with a "/". Now I want to
> replace it with "//end" for all files. And here is my perl command,
> "
> perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
> "
>
> Suprisingly it does not work.
It does not work is a bad description. Please read the posting
guidelines for this group.
#!/usr/bin/perl
use strict;
use warnings;
while ( <DATA> ) {
s{^/$}{//end} and print;
}
__DATA__
/
/
/
/
/
/
/
Sinan
------------------------------
Date: 20 Feb 2007 14:55:52 -0800
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: How to replace a "/" in perl
Message-Id: <1172012152.010793.188910@j27g2000cwj.googlegroups.com>
On Feb 20, 2:15 pm, chunj...@gmail.com wrote:
> I have a list of sql files, in which it ends with a "/". Now I want to
> replace it with "//end" for all files. And here is my perl command,
> "
> perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
* if you add -w to the options, you'll
get a fatal syntax error,
perl -pi.org -we ...
* you don't want the ^ on the left-hand side
for regular expression help, see:
perldoc perlrequick
perldoc perlretut
* use alternative substitution delimiter to
avoid backslash-itis, eg.,
s{something}{for something else}
--
Charles DeRykus
------------------------------
Date: 20 Feb 2007 15:00:38 -0800
From: chunji08@gmail.com
Subject: Re: How to replace a "/" in perl
Message-Id: <1172012437.943794.304490@h3g2000cwc.googlegroups.com>
On Feb 20, 2:43 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> chunj...@gmail.com wrote in news:1172009738.829363.189370
> @v45g2000cwv.googlegroups.com:
>
> > I have a list of sql files, in which it ends with a "/". Now I want to
> > replace it with "//end" for all files. And here is my perl command,
> > "
> > perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
> > "
>
> > Suprisingly it does not work.
>
> It does not work is a bad description. Please read the posting
> guidelines for this group.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> while ( <DATA> ) {
> s{^/$}{//end} and print;
>
> }
>
> __DATA__
> /
> /
> /
> /
> /
> /
> /
>
> Sinan
My Fault.
The correct answer should be:
"
perl -pi.org -e 's/^\/$/\/\/end/' *.SQL
"
C
------------------------------
Date: Tue, 20 Feb 2007 23:15:18 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Quick Question
Message-Id: <erfvj9.vo.1@news.isolution.nl>
usenet@DavidFilmer.com schreef:
> open (my $logfile, ">", '/tmp/log.log');
> [...]
> open (my $in, "<", $file);
Look ma, no checks.
:)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 21 Feb 2007 01:06:48 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Regex: Why is overreaching necessary?
Message-Id: <erg5v8$17oa$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Shannon Jacobs
<Shannon.Jacobs.nospam@gmail.com>], who wrote in article <1172003598.103049.218420@t69g2000cwt.googlegroups.com>:
> So in my next round of experiments, I manually trimmed the search
> target to see what it was really matching on. This broke my mind...
> However, I think I found the minimal example of the problem. If I
> limit the search target to this:
>
> 909|1101
>
> It produces the false match of that second line. But as
>
> 1101| 909
>
> there is no problem. The problem is somehow apparently due to the
> leading space, since
>
> 908|1101
>
> also produces the false match (though the rest of the results are
> correct). Lisp and Japanese make more sense to me... If this was a
> contest, I would say that the laurels rest with Anno, and I think I'll
> just try to live with this slight peculiarity.
If we could see the actual code you used, it would be much easier to
understand what problem you see.
$_ = ' 908|1101';
print "Matched!\n" if / /; # <--- Fill this line
Thanks,
Ilya
------------------------------
Date: Tue, 20 Feb 2007 09:48:29 -0600
From: "Billy Patton" <bpatton@ti.com>
Subject: simple use of eval of somethinng else
Message-Id: <erf58d$3j0$1@home.itg.ti.com>
I have a string
$expecxted_status = "!= 0";
$status = 0;
What I'm trying to do is
if ($status != 0) {
...
}
How do I get the $expected_status to evaluate to the boolean that it is, in
relation to $status?
$a = '== 0';
$b = '2';
eval { "$b $a" }; warn $@ if $@;
The above does nothing.
------------------------------
Date: Tue, 20 Feb 2007 22:54:59 +0100
From: Ch Lamprecht <ch.l.ngre@online.de>
Subject: Re: simple use of eval of somethinng else
Message-Id: <erfqnj$qlv$1@online.de>
Billy Patton wrote:
> I have a string
> $expecxted_status = "!= 0";
> $status = 0;
>
> What I'm trying to do is
>
> if ($status != 0) {
> ...
> }
>
>
> How do I get the $expected_status to evaluate to the boolean that it is, in
> relation to $status?
use strict;
use warnings;
my $s = '==1';
my $t = '0';
my $result = eval $t.$s ? 1:0;
print $t,$s,' evaluates to ',$result;
If you describe your task , you most probably will get answers that are more
useful than this.
Christoph
>
>
> $a = '== 0';
> $b = '2';
> eval { "$b $a" }; warn $@ if $@;
>
> The above does nothing.
>
>
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
------------------------------
Date: Tue, 20 Feb 2007 23:00:31 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: simple use of eval of somethinng else
Message-Id: <erfrc7$aeg$1@mlucom4.urz.uni-halle.de>
Billy Patton wrote:
> How do I get the $expected_status to evaluate to the
> boolean that it is, in relation to $status?
>
> $a = '== 0';
> $b = '2';
> eval { "$b $a" }; warn $@ if $@;
>
> The above does nothing.
use strict;
use warnings;
my $s1 = '== 0';
my $s2 = '2';
print eval( "$s2 $s1" ) ? 'true' : 'false';
print "\nerror $@" if $@;
see: perldoc -f eval
(EXPR eval)
Regards
M.
------------------------------
Date: 20 Feb 2007 23:54:31 GMT
From: xhoster@gmail.com
Subject: Re: simple use of eval of somethinng else
Message-Id: <20070220185558.555$va@newsreader.com>
"Billy Patton" <bpatton@ti.com> wrote:
> I have a string
> $expecxted_status = "!= 0";
> $status = 0;
>
> What I'm trying to do is
>
> if ($status != 0) {
> ...
> }
>
> How do I get the $expected_status to evaluate to the boolean that it is,
> in relation to $status?
>
> $a = '== 0';
> $b = '2';
> eval { "$b $a" }; warn $@ if $@;
You are using the block eval on something which just happens to be
a string. You probably want to do a string eval:
my $result = eval "$b $a"; warn $@ if $@;
print something_to_do_with($result);
> The above does nothing.
It does plenty. It prints nothing. Which is expected, as you
haven't told it to print anything.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 20 Feb 2007 13:13:03 -0800
From: "johngnub" <johngnub@COX.NET>
Subject: Re: Tool to create Perl based scripts
Message-Id: <1172005983.559613.246920@j27g2000cwj.googlegroups.com>
On Feb 20, 3:52 am, "IJALAB" <balaji.d...@gmail.com> wrote:
> Hi All,
>
> I have to automate a lot of validation scripts in Perl. Is there a
> simple way/tool to do the same. basically log files will be created
> and i have to look for certain keywords in the log files and make a
> decision to validate the tests. I am just looking to save time in
> automating my perl writing task.
> any pointers welcome..thanks a lot
>
> regards
> bala
Well, Not a CS major, but willing to try ..Some step by step tasks,
und allways in Perl, more then one way around the barn to milk the
cow...
# To open a file:
open (IN,"<some.dat");
@then = <IN>;close (IN);
# Now then has data, info from the file
To loop over a file, the array of lines from the file, in the array
then:
foreach $line (@then){
# To see if it has "fun", simple match,
if ($line =~ /fun/ ) {
print "OH fun!\n";
}
# simiple but usefull regex meta opers, ,
# \s+ equiv to spaces, \S+ equiv to words that are not spaces, \d+
digits,
# To see if its a word then fun, thus ich bin "foo fun bar"
if ($line =~ /\S+\s+fun\s+\S+/ ) {
print "A word then fun and a word.\n";
}
# close out the loop, hint use the "%" key in vi to spy the (){} of
life.
}
# The end.
# PS: put the car in 1st gear, then step on the pedal, NASCAR is not a
good way to learn how to drive. Yada. jb.
------------------------------
Date: Tue, 20 Feb 2007 23:22:56 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Tool to create Perl based scripts
Message-Id: <2osmt25n0alcogev52261in23shitvb0hf@4ax.com>
On 20 Feb 2007 13:13:03 -0800, "johngnub" <johngnub@COX.NET> wrote:
>> decision to validate the tests. I am just looking to save time in
>> automating my perl writing task.
[snip]
>Well, Not a CS major, but willing to try ..Some step by step tasks,
>und allways in Perl, more then one way around the barn to milk the
>cow...
I was be tempted to say that good will never hurts, but reading what
follows I really can't!
># To open a file:
>open (IN,"<some.dat");
>@then = <IN>;close (IN);
[snip the rest OMG!]
1) That is not what he's asking;
2) In order: bareword filehandles, two args open(), unchecked open(),
whole file slurping, no strict code, *presumably* no warnings either,
awkward style...
All in all... it's a good thing that you're willing to help. But
there's a ton already of awful Perl "tutorials" out there, that
contribute to spread bad programming techniques, and to give Perl a
bad name...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 20 Feb 2007 15:34:47 -0800
From: usenet@DavidFilmer.com
Subject: Re: Tool to create Perl based scripts
Message-Id: <1172014487.794152.12650@a75g2000cwd.googlegroups.com>
On Feb 20, 1:13 pm, "johngnub" <johng...@COX.NET> wrote:
> @then = <IN>;
.....
> foreach $line (@then){
Never, ever, ever read a file into an array if your only intention is
to process the file line-by-line.
Just read each line and process it as it is read:
foreach my $line(<$in>) { #and use lexical filehandles
#do something with each $line
}
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 21 Feb 2007 00:14:01 GMT
From: xhoster@gmail.com
Subject: Re: waitpid woes on Solaris, Perl 5.8.8
Message-Id: <20070220191528.394$iU@newsreader.com>
"A" <ad_101@yahoo.com> wrote:
>
> >
> > > On your advice to remove the $SIG{CLD}, there are 3 statements,
> >
> > > the first statement saves the handler,
> > > the second statement installs the current one needed by this
> > > routine
> > > and the last one re-installs the saved handler.
> >
> > > which one(s) would you suggest I remove?
> >
> > Probably all of them, but it is not really possible to know from what
> > you give. We would need to see the code that set the orginal handler
> > that is getting saved and then restored. If the handler you inherit is
> > necessary, then why would it be safe to overwrite it with something
> > else for even the duration of this routine? On the other hand, if the
> > handler you inherit is not necessary, then what is the point of saving
> > and re-installing it? If there is no other code which intalls a
> > handler in the first place, then I'd remove all three of those things.
> > (And even if not, remove at least two, see below)
...
> I am not sure I understand your remark that the rest of the code
> should be a factor in determining what signal handling should be used
> here.
If the rest of the code installed a sig-child handler, it probably did it
for a reason--it expects to get signaled upon the exit of a child it
started, and expects to do some needful thing upon that signal. So let's
say you uninstall that handler for a brief period, and before you
re-install it the child that the other part of the code spawned exits. Now
the originally installed handler is restored, but it is never going to get
called, because your code already ate that signal. That is probably bad.
Why is that bad? I don't know, because I don't know what the rest of the
code does. But presumably it wouldn't have installed a signal handler if
it didn't need to--and if it did need it then having it not get called is
bad. On the other hand, the code you showed us installed a signal handler
despite (apparently) not needing to, so maybe assuming that the rest of the
code would only install a signal handler if it needed it is a bad
assumption.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 156
**************************************