[18431] in Perl-Users-Digest
Perl-Users Digest, Issue: 599 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 30 18:10:46 2001
Date: Fri, 30 Mar 2001 15:10:24 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985993823-v10-i599@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 30 Mar 2001 Volume: 10 Number: 599
Today's topics:
remove unwanted lines from file <bing-du@tamu.edu>
Re: remove unwanted lines from file (Tad McClellan)
Re: remove unwanted lines from file (Damian James)
Re: require problem, help?? nobull@mail.com
retrieving data from a flat file, help needed <lhooghe@hotmail.com>
rounding up or down with Perl <milliwave@rfengineering.freeserve.co.uk>
Re: rounding up or down with Perl (Jay Tilton)
Re: rounding up or down with Perl (Greg Bacon)
Re: rounding up or down with Perl <dperham@dperham.eng.tvol.net>
Re: segmentation fault CGI/Perl -> DBI (Mark Jason Dominus)
Taint problem? <Daniel.Maloney@bms.com>
Re: Why does no window open at executing the batch file <founder@pege.org>
Re: Why does no window open at executing the batch file <founder@pege.org>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 30 Mar 2001 13:06:15 -0600
From: Bing Du <bing-du@tamu.edu>
Subject: remove unwanted lines from file
Message-Id: <3AC4D927.DA43D8E0@tamu.edu>
How can I remove several lines from the beginning of the file up to the
line (always looks the same) that I want to start keeping? The number
of removed lines can not be determined in advance. The file is about
100M. I have read 'perlfaq5 - Files and Formats' and I'm not satisfied
with the following approach:
"The general solution is to create a temporary copy of the text file
with the changes you want, then copy that over the original."
I use 5.004_04 built for irix-n32. Any better ideas?
Thanks,
Bing
------------------------------
Date: Fri, 30 Mar 2001 16:07:30 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: remove unwanted lines from file
Message-Id: <slrn9c9tci.oda.tadmc@tadmc26.august.net>
Bing Du <bing-du@tamu.edu> wrote:
>How can I remove several lines from the beginning of the file up to the
>line (always looks the same) that I want to start keeping?
Create a temporary copy of the text file with the changes you want,
then copy that over the original.
Let perl do the copying and moving for you.
>The number
>of removed lines can not be determined in advance. The file is about
>100M. I have read 'perlfaq5 - Files and Formats' and I'm not satisfied
^^^^^^^^^^^^^^^^^
What does that mean?
_Why_ are you not satisfied with it?
>with the following approach:
>"The general solution is to create a temporary copy of the text file
>with the changes you want, then copy that over the original."
>
>I use 5.004_04 built for irix-n32. Any better ideas?
That depends on what you mean by "better".
If there is something about the solution that you have that you
do not like, we could perhaps help you find another solution
if you would share with us what it is that you object to.
Not much sense in spewing solutions just to have you remain unsatisfied.
Give a spec for what you want, and maybe someone will be able to help you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 30 Mar 2001 22:31:09 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: remove unwanted lines from file
Message-Id: <slrn9ca27v.4fn.damian@puma.qimr.edu.au>
Bing Du chose Fri, 30 Mar 2001 13:06:15 -0600 to say this:
>How can I remove several lines from the beginning of the file up to the
>line (always looks the same) that I want to start keeping? The number
>of removed lines can not be determined in advance. The file is about
>100M. I have read 'perlfaq5 - Files and Formats' and I'm not satisfied
>with the following approach:
>"The general solution is to create a temporary copy of the text file
>with the changes you want, then copy that over the original."
>
Either as in the FAQ, which is probably the best way, or:
* load the entire file into memory, remove lines, write it back
(you irix box has more than 128M RAM, doesn't it?)
* switch to using an RDBMS (or some database-like format)
A related response would be something like: "You canna change the laws of
physics", but to be more precise, you can't change the way that a computer
regards a flat file -- as a series of bytes. You must throw memory at it to
do want you want -- it's your choice whether that's RAM or diskspace. If
you're doing this a lot, maybe a flat file is the wrong choice.
Why exactly don't you like the answer in the FAQ?
>I use 5.004_04 built for irix-n32. Any better ideas?
>
I use 5.6.0 built for solaris 2.7 on sparc. Maybe that would be a better
idea :-). You think this is relevent? Were you looking for an SGI-specific
solution?
HTH,
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;){;(
$:=rand$;+$|)==$;&&next;@;[$;,$:]=@;[$:,$;]}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3 -- a JAPH in progress, I guess...
------------------------------
Date: 30 Mar 2001 20:12:31 +0100
From: nobull@mail.com
To: mickm@baygate.com
Subject: Re: require problem, help??
Message-Id: <u9r8zfjckg.fsf@wcl-l.bham.ac.uk>
Mickey Mestel <mickm@ix.netcom.com> writes:
> Subject: require problem, help??
perldoc -f require
> require $foo;
>
> then it works. so it seems that using require in this
> situation, i'm able to get it to find it if i provide a file name,
> but not a package name.
That is correct, as documented.
> can anyone give me a hand on this? i'm sure i'm missing
> something
What you are apparently missing is the self discipline to read the
manaul entry for require() all the way through before posting to
usenet.
> also, i don't have access to the newsgroups from work, or very
> often, so i have to get there through this channel.
Not only is this matter addressed in the manual but it was also
addresses in comp.lang.perl.* several timne within the last few weeks.
Can you read/search newsgroups on the web, for example
groups.google.com.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 30 Mar 2001 21:04:55 +0200
From: "lieven hooghe" <lhooghe@hotmail.com>
Subject: retrieving data from a flat file, help needed
Message-Id: <AV5x6.104$Ja1.2927@iguano.antw.online.be>
can somebody help me please ?
the following syntax doesn't work on my computer, the if-statement doesn't
give anything true
my flat file (Rzinnen.txt) is as follow :
casnr ; nameproduct ; Rzin ; Szin ; Azin
1 ; octyl ; 1,2 ; 4,7 ; 4,9,18
44 ; docetyl ; 4,8,9 ; 7,8 ; 7,8,9
2 ; benzeen ; 1,2,7 ; 7,9,10; 7,8,10,15
45 ; hexane ; 4,8,9 ; 4,5,6 ; 8,15,21
457 ; methaan ; 7,9,10; 7,15 ; 15,16
34 ; ethane ; 8,9 ; 10,11 ; 15/16
1241 ; chlore ; 10,10 ; 15,16 ; 19,20,45
I need to search into the flat file database and find the nameproduct.
I want to search on that name (nameproduct) with which in a line
to get the output op de Casnr Rzin Szin and Azin
example : input methaan
output on screen :
name : methaan
Casnr :
457
Rzin :
7
9
10
Szin :
7
15
Azin :
15
16
What am i doing wrong ?
Here's some from the command line:
#!/usr/bin/perl -w
use strict;
my $database = "Rzinnen.txt";
open(Rzinnen,$database) or die "fault file";
my @ary = <Rzinnen>;
close(Rzinnen);
my $jeRzin = 'methaan';
my %pruductbase = &search_database( $jeRzin, @ary );
sub search_database{
my( $jeRzin, @ary ) = @_;
my %pruductbase = ();
foreach my $line( @ary ) {
my @aryb = split( /;/, $line );
%pruductbase=( 'casnr' => $aryb[0],
'nameproduct' => $aryb[1],
'Rzin' => $aryb[2],
'Szin' => $aryb[3],
'Azin' => $aryb[4]);
}
return %pruductbase;
}
if( $pruductbase{'nameproduct'} ) {
print"$pruductbase{'casnr'}",
"$pruductbase{'nameproduct'}",
"$pruductbase{'Rzin'}",
"$pruductbase{'Szin'}",
"$pruductbase{'Azin'}";
}
------------------------------
Date: Fri, 30 Mar 2001 20:10:24 +0100
From: "Milliwave" <milliwave@rfengineering.freeserve.co.uk>
Subject: rounding up or down with Perl
Message-Id: <9a2ljc$l34$1@newsg1.svr.pol.co.uk>
I am hoping someone can provide me with a speedy reply to this quesry I have
with the following;
Example
If I want to round the following up or down to the nearest integer,
1) 7.4 rounded down to = 7
2) 7.8 rounded up to = 8
3) -0.3 rounded down to =0
4) -0.7 rounded up to = -1
I do have code which consists of detecting whether the digit is postive or
negative
and neumorous conditional statements, all of which is too messy!! Is there
an easy
way to round the above postive and negative numbers to the nearest digit?
Question 2
---------------
I do I specify "pi" = 3.1428, In C, I remember I used to simply write "pi".
Any ideas how to specify it?
Question 3
---------------
Mathematical operations like sin(expr) cos(expr) are all done in radians, is
there a way around
this where I can feed in expr=degrees. I.e work in degrees?
Thanking you
------------------------------
Date: Fri, 30 Mar 2001 20:22:59 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: rounding up or down with Perl
Message-Id: <3ac4e081.130833354@news.erols.com>
On Fri, 30 Mar 2001 20:10:24 +0100, "Milliwave"
<milliwave@rfengineering.freeserve.co.uk> wrote:
>Example
>If I want to round the following up or down to the nearest integer,
perldoc -q round
>I do I specify "pi" = 3.1428, In C, I remember I used to simply write "pi".
>Any ideas how to specify it?
use Math::Trig;
print pi;
Or roll your own.
use constant pi => atan2(1,1) * 4;
print pi;
But don't do both at the same time.
>Mathematical operations like sin(expr) cos(expr) are all done in radians, is
>there a way around
>this where I can feed in expr=degrees. I.e work in degrees?
Angle conversion functions are also in Math::Trig, though creating
your own is utterly trivial once you have established a value for pi.
------------------------------
Date: Fri, 30 Mar 2001 20:37:35 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: rounding up or down with Perl
Message-Id: <tc9rkf17ht3ib7@corp.supernews.com>
In article <9a2ljc$l34$1@newsg1.svr.pol.co.uk>,
Milliwave <milliwave@rfengineering.freeserve.co.uk> wrote:
: I am hoping someone can provide me with a speedy reply to this quesry I have
: with the following;
:
: Example
: If I want to round the following up or down to the nearest integer,
:
: 1) 7.4 rounded down to = 7
: 2) 7.8 rounded up to = 8
: 3) -0.3 rounded down to =0
: 4) -0.7 rounded up to = -1
:
: I do have code which consists of detecting whether the digit is
: postive or negative and neumorous conditional statements, all of which
: is too messy!! Is there an easy way to round the above postive and
: negative numbers to the nearest digit?
Put it in a subroutine. Here's a simple implementation:
#! /usr/local/bin/perl -w
use strict;
sub round {
my $x = shift;
int $x + ($x >= 0 ? 0.5 : -0.5);
}
for (7.4, 7.8, -0.3, -0.7) {
print "$_ => ", round($_), "\n";
}
: I do I specify "pi" = 3.1428, In C, I remember I used to simply write
: "pi". Any ideas how to specify it?
The documentation for the constant pragma uses the following trick:
use constant PI => 4 * atan2 1, 1;
: Mathematical operations like sin(expr) cos(expr) are all done in
: radians, is there a way around this where I can feed in expr=degrees.
: I.e work in degrees?
#! /usr/local/bin/perl -w
use strict;
use constant PI => 4 * atan2 1, 1;
use subs qw( sin cos );
sub sin { CORE::sin(PI / 180 * $_[0]) }
sub cos { CORE::cos(PI / 180 * $_[0]) }
for (0, 30, 45, 60, 90) {
print "sin($_) = ", sin($_), "\n",
"cos($_) = ", cos($_), "\n";
}
Hope this helps,
Greg
--
It will be generally found that those who sneer habitually at human
nature and affect to despise it, are among its worst and least pleasant
examples.
-- Charles Dickens
------------------------------
Date: 30 Mar 2001 15:46:12 -0500
From: Doug Perham <dperham@dperham.eng.tvol.net>
Subject: Re: rounding up or down with Perl
Message-Id: <81d7azm1d7.fsf@wgate.com>
"Milliwave" <milliwave@rfengineering.freeserve.co.uk> writes:
> I am hoping someone can provide me with a speedy reply to this quesry I have
> with the following;
>
> Example
> If I want to round the following up or down to the nearest integer,
>
> 1) 7.4 rounded down to = 7
> 2) 7.8 rounded up to = 8
> 3) -0.3 rounded down to =0
> 4) -0.7 rounded up to = -1
>
sub round { my $r = int(abs($_[0])/$_[1] + 0.5)*$_[1]; $_[0] < 0 ? -$r : $r; }
i.e.
round(7.4, 1) => 7
> I do have code which consists of detecting whether the digit is postive or
> negative
> and neumorous conditional statements, all of which is too messy!! Is there
> an easy
> way to round the above postive and negative numbers to the nearest digit?
>
>
> Question 2
> ---------------
>
> I do I specify "pi" = 3.1428, In C, I remember I used to simply write "pi".
> Any ideas how to specify it?
>
my $pi = 3.14159;
write it as "$pi"
> Question 3
> ---------------
>
> Mathematical operations like sin(expr) cos(expr) are all done in radians, is
> there a way around
> this where I can feed in expr=degrees. I.e work in degrees?
>
my $PI = 3.14159;
my $DEG = $PI/180;
sin($x * $DEG);
or alternatively
use constant PI => atan2(1,1)
use constant DEG => atan2(1,1)/45;
use subs qw(sin);
sub sin { CORE::sin($_[0] * DEG); }
print sin(45), "\n";
>
>
>
> Thanking you
--
Doug Perham o{..}o
dperham@wgate.com moo! (oo)___
WorldGate Communications, Inc. (______)\
/ \ / \
------------------------------
Date: Fri, 30 Mar 2001 19:51:56 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: segmentation fault CGI/Perl -> DBI
Message-Id: <3ac4e3db.4654$186@news.op.net>
In article <3AC4C31F.1964F1AD@schaffhausen.de>,
Malte Ubl <ubl@schaffhausen.de> wrote:
>well I had a first timer for me. My Perl called a segmentation
>fault/core dump.
What DBD modules are you using with DBI?
------------------------------
Date: Fri, 30 Mar 2001 15:53:53 -0500
From: Daniel P Maloney <Daniel.Maloney@bms.com>
Subject: Taint problem?
Message-Id: <3AC4F261.1C208527@bms.com>
What would cause this snippet to work fine in the shell but fail
within a setuid script?
$file = shift;
$ENV{PATH} = q(/bin:/usr/bin);
delete @ENV{qw/IFS CDPATH ENV BASH_ENV/};
@tmp = qx/zipinfo -sT --h--t $file/;
foreach (@tmp) {
chomp;
@fields = split /\s+/;
push @ret, join ",", @fields[-2..-1]
}
foreach (sort @ret) {
print;
print "\n";
}
When I execute this code in the shell, this is the output:
20010214.080732,logo.txt
20010228.104258,blank.txt
20010228.110330,blank10x40.txt
When I run it in my program, I get nothing - @tmp is empty ($#tmp
= -1). The cgi program needs to run setuid because another
function needs to write files to the local filesystem. $file is
NOT derived from cgi parameters, so there shouldn't be a taint
problem, but I tried laundering $file through a regex first with
no change. Perl isn't complaining about insecurities. Any
thoughts?
--
================================================================
Dan Maloney daniel.maloney@bms.com
Instrumentation Technologies Group 203.677.7135
Discovery Technologies fax: 203.677.6417
Bristol-Myers Squibb Co. pager: 2223044@archwireless.net
------------------------------
Date: Fri, 30 Mar 2001 21:32:36 +0200
From: "Roland Mösl" <founder@pege.org>
Subject: Re: Why does no window open at executing the batch file
Message-Id: <3ac4df58$0$22464@SSP1NO25.highway.telekom.at>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:m2m9ctgdblh88jb8lup9ho10lq3ks1o4dt@4ax.com...
> Roland Mösl wrote:
>
> > Win32::Shell::Execute( "open", "command.bat", "", ".\\",
> >"SW_SHOWMAXIMIZED" );
> >
> >The batch file is executed, but invisible
>
> Why so much trouble? Simply do
>
> system('command.bat');
>
> True, that will be in a normal window.
Now start.hta hangs.
Maybe system () works only when the Perl program
is executed from the command prompt.
But in this case, it's used in a
HTA Hyper Text Application with
Perl as PerlScript scripting language
--
Roland Mösl
http://pege.org Clear targets for a confused civilization
http://BeingFound.com Web Design starts at the search engine
------------------------------
Date: Fri, 30 Mar 2001 23:19:07 +0200
From: "Roland Mösl" <founder@pege.org>
Subject: Re: Why does no window open at executing the batch file
Message-Id: <3ac4f80b$0$20400@SSP1NO25.highway.telekom.at>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:m2m9ctgdblh88jb8lup9ho10lq3ks1o4dt@4ax.com...
> system('command.bat');
>
> True, that will be in a normal window.
BTW, what to write at the end of a batch file,
that it waits for a keypress instead of closing
immedeateley the command prompt window ?
--
Roland Mösl
http://pege.org Clear targets for a confused civilization
http://BeingFound.com Web Design starts at the search engine
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 599
**************************************