[15576] in Perl-Users-Digest
Perl-Users Digest, Issue: 2989 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 9 11:10:48 2000
Date: Tue, 9 May 2000 08:10:26 -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: <957885025-v9-i2989@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 9 May 2000 Volume: 9 Number: 2989
Today's topics:
Conditional compilation in Perl?? <danielg@tid.es>
Re: Conditional compilation in Perl?? <rootbeer@redcat.com>
Re: Conditional compilation in Perl?? nobull@mail.com
Re: Conditional compilation in Perl?? (Bbirthisel)
Re: converting input to <p></p> pairs via perl <gellyfish@gellyfish.com>
Re: DIRHANDLE problems <djberg96@hotmail.com>
Re: efficiency with data separation. [was Re: HTTP::Req <uri@sysarch.com>
Re: efficiency with data separation. [was Re: HTTP::Req <iltzu@sci.invalid>
Re: Error at line 0 ? [Was: Exceptions that can't be ca <johnlin@chttl.com.tw>
Re: Flame my code (Eric Bohlman)
Re: Function to filter HTML? <c.treczoks@ndh.net>
Hiding System Window ? <stuart.tavener@greenwichnatwest.com>
How to include lines beginning and ending with a string c_neak@my-deja.com
How to include/exclude lines ? c_neak@my-deja.com
Re: How to include/exclude lines ? nobull@mail.com
Re: How to include/exclude lines ? <t.klinger@mobilkom.at>
Re: How to include/exclude lines ? <rhomberg@ife.ee.ethz.ch>
How to make SNMP in parallel? (Hans J Jakobsen)
Re: How to print '%' character with printf ? (Csaba Raduly)
Re: Is Perl fast enough? <rootbeer@redcat.com>
Re: keep-alive <rootbeer@redcat.com>
Library to read ini files (CUESTA CUESTA)
Re: Library to read ini files <rootbeer@redcat.com>
Re: Library to read ini files <jeff@vpservices.com>
Re: Library to read ini files nobull@mail.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 09 May 2000 10:41:03 +0200
From: Daniel Garcia Fernandez <danielg@tid.es>
Subject: Conditional compilation in Perl??
Message-Id: <3917CF1F.2278108E@tid.es>
This is a multi-part message in MIME format.
--------------51342D7116695844D3CDB2AB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Im trying to port a win32 perl script to unix, but i have a problem with
it: Some of the modules I use are exclusive from w32 (like TieRegistry),
and even though I call them in a part of code that is not runned under
unix i get an error telling that the module doesn't exist.
I would like to know If anyone has had this problem before and how did
he dealt dealt with it.
The part of problematic code is:
# Load modules
BEGIN
{
if ($^O eq "MSWin32")
{
print "Usas Guindows de 32 bits\n";
use Win32::TieRegistry;
$valueData= $Registry->{"LMachine\\Software\\Tid\\Mf\\\\BaseDirTemp"};
print "$valueData\n";
my($MfDir) = $ENV{'MFDIR'} ? $ENV{'MFDIR'} : "$valueData";
}
else
{
print "Usas Unix, no?\n";
my($MfDir) = $ENV{'MFDIR'} ? $ENV{'MFDIR'} : "#(MFDIR)#";
}
push( @INC, "$MfDir/perl",
$ENV{'PERLMOD'} ? $ENV{'PERLMOD'} : "$ENV{'HOME'}/Perl" );
}
use Mf qw(1.29 mfconfig_open mfconfig_close
mfconfig_dump);$ENV{'PERLMOD'} : "$ENV{'HOME'}/Perl" );
Thanks anyway
--------------51342D7116695844D3CDB2AB
Content-Type: text/x-vcard; charset=us-ascii;
name="danielg.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Daniel Garcia Fernandez
Content-Disposition: attachment;
filename="danielg.vcf"
begin:vcard
n:García;Daniel
tel;work:983-367798
x-mozilla-html:FALSE
org:Telefonica I+D;Tecnologia Multimedia
adr:;;;;;;
version:2.1
email;internet:danielg@tid.es
title:<img src="http://tid/images/telefonica.gif">
fn:Daniel Garcia
end:vcard
--------------51342D7116695844D3CDB2AB--
------------------------------
Date: Tue, 9 May 2000 04:45:50 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Conditional compilation in Perl??
Message-Id: <Pine.GSO.4.10.10005090438140.3921-100000@user2.teleport.com>
On Tue, 9 May 2000, Daniel Garcia Fernandez wrote:
> Im trying to port a win32 perl script to unix, but i have a problem with
> it: Some of the modules I use are exclusive from w32 (like TieRegistry),
> and even though I call them in a part of code that is not runned under
> unix i get an error telling that the module doesn't exist.
You probably want something like this, where the windows-only program
would have the 'use' declaration. Change the "Something" parts as needed.
BEGIN {
if ($^O =~ /Something/i) {
require "Something.pm";
import Something qw/ Something /;
}
}
Does that get you started? Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 09 May 2000 12:47:59 +0100
From: nobull@mail.com
Subject: Re: Conditional compilation in Perl??
Message-Id: <u9puqwhrm8.fsf@wcl-l.bham.ac.uk>
Daniel Garcia Fernandez <danielg@tid.es> writes:
> Im trying to port a win32 perl script to unix, but i have a problem with
> it: Some of the modules I use are exclusive from w32 (like TieRegistry),
> and even though I call them in a part of code that is not runned under
> unix i get an error telling that the module doesn't exist.
Code inside BEGIN{} is executed as soon as it has been compiled. Code
inside a BEGIN{} block is executed even if the flow of exection
outside the BEGIN{} block would never reach it.
If there are statements in side the BEGIN{} block that themselves act
at compile time (e.g. a use() or another explicit BEGIN{}) then they
will act during the compliation of the code within the outer BEGIN{}
in exactly the same way.
You need to replace your use() with the equivalent code without
another implicit BEGIN{}. See "perldoc -f use" for details.
> --------------51342D7116695844D3CDB2AB
> Content-Type: text/x-vcard; charset=us-ascii;
This is not a binaries group so that is in effect a 21-line sig. And
I thought mine was big!
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 09 May 2000 14:08:02 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Conditional compilation in Perl??
Message-Id: <20000509100802.07426.00002180@ng-cl1.aol.com>
Hi Daniel:
>Im trying to port a win32 perl script to unix, but i have a problem with
>it: Some of the modules I use are exclusive from w32 (like TieRegistry),
>and even though I call them in a part of code that is not runned under
>unix i get an error telling that the module doesn't exist.
>I would like to know If anyone has had this problem before and how did
>he dealt dealt with it.
A functional example:
!/usr/bin/perl
#---------------------------------------------------------------------------
# Title:
# Cross-Platform Demo - "use" right module on either Win32 or linux
# Usage:
# perl any_os.plx PORT
# Author:
# Bruce Winter brucewinter@home.net http://members.home.net/winters
#---------------------------------------------------------------------------
# must be LF-only line ends to run on both platforms
use strict;
use vars qw($OS_win);
BEGIN {
$OS_win = ($^O =~ /Win/i) ? 1 : 0;
print "Perl version: $]\n";
print "OS version: $^O\n";
# This must be in a BEGIN in order for the 'use' to be conditional
if ($OS_win) {
print "Loading Windows module\n";
eval "use Win32::SerialPort";
die "$@\n" if ($@);
}
else {
print "Loading Unix module\n";
eval "use Device::SerialPort";
die "$@\n" if ($@);
}
} # End BEGIN
die "\nUsage: perl any_os.plx PORT\n" unless (@ARGV);
my $port = shift @ARGV;
my $serial_port;
if ($OS_win) {
$serial_port = Win32::SerialPort->new ($port,1);
}
else {
$serial_port = Device::SerialPort->new ($port,1);
}
die "Can't open serial port $port: $^E\n" unless ($serial_port);
my $baud = $serial_port->baudrate;
print "\nopened serial port $port at $baud baud\n";
$serial_port->close || die "\nclose problem with $port\n";
undef $serial_port;
-bill
Making computers work in Manufacturing for over 25 years (inquiries welcome)
------------------------------
Date: Tue, 09 May 2000 11:22:22 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <OxSR4.714$Kc1.62558@news.dircon.co.uk>
On Tue, 09 May 2000 05:57:40 GMT, Uri Guttman Wrote:
>>>>>> "TW" == The WebDragon <nospam@devnull.com> writes:
>
> TW> In article <8f3cil$m31$1@orpheus.gellyfish.com>, Jonathan Stowe
> TW> <gellyfish@gellyfish.com> wrote:
>
> TW> | I think you mean :
> TW> |
> TW> | $reviewBody .= map { "<P>\n$_</P>\n" }
> TW> | map { s/\n/<BR>\n/g; $_ }
> TW> | split /\n\n/, param('reviewtext');
>
> dunderhead! why are you string appending a list from a map? i think you
> mean to join the maps and just assign to $review_body
>
Er. Yes.
> $review_body = join '', map { s/\n/<BR>\n/g; "<P>\n$_</P>\n" }
> split /\n\n/, param('reviewtext') ;
>
> i also combined the 2 maps into one. untested as well but it looks ok.
> i have not been following this thread closely so i don't know the
> problem description well other than something about html and paragraph
> stuff.
>
> TW> this returns 1 as the result in $reviewBody not exactly what I
> TW> wanted, either. :)
>
> gellyfish had too much guiness in his belly when he wrote that code.
>
ESB actually but the effect's the same.
------------------------------
Date: Tue, 9 May 2000 09:46:49 -0500
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: DIRHANDLE problems
Message-Id: <391822df$0$73582@news.execpc.com>
Well, sometimes you get an idea in your head that it "ought to work
the way I think it should work" and simply ignore the obvious. Oh,
well. Works great now. Thanks again.
Dan
"Tom Phoenix" <rootbeer@redcat.com> wrote in message
news:Pine.GSO.4.10.10005081646130.3921-100000@user2.teleport.com...
> On Sun, 7 May 2000, Daniel Berger wrote:
>
> > I take it passing a new value to opendir doesn't actually change the
> > current working directory?
>
> No; why would it? :-)
>
> --
> Tom Phoenix Perl Training and Hacking Esperanto
> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
>
------------------------------
Date: Tue, 09 May 2000 07:18:59 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: efficiency with data separation. [was Re: HTTP::Request=HASH(0x7bb141c) ?]
Message-Id: <x7itwour6o.fsf@home.sysarch.com>
>>>>> "TW" == The WebDragon <nospam@devnull.com> writes:
TW> the html is the EASY part.. it's parsing the INPUT that's my problem =:o
TW> Please re-read the previous post again! the script was NOT my problem..
TW> I have stuff that has to come AFTER maps_list.txt is created!
then i don't understand this problem.
TW> |
TW> | TW> die "$baseURL $_ failed: ",$response->error_as_HTML
TW> | TW> unless $response->is_success;
TW> |
TW> | notice how you have the open first and die second? you should do the
TW> | same for the $response test. generally you emphasize the test which is
TW> | important and then the failure code. of course saying:
TW> true, but this works the way I think, and 'feels' perfectly normal..
TW> TMTOWTDI :)
true, but some are considered better by most than others. i agree it is
your choice but IMHO most would feel better if that was reversed. the
key thing you are checking is the response, not the die.
TW> I read something somewhere regarding variable interpolation within "" as
TW> opposed to the bare variable itself in the "Programming Perl" book and
TW> took it to heart. I don't recall offhand the exact reference, but I got
TW> the strong impression that the way I wrote it up there, was inclined to
TW> be more efficient.
they compile to the same internal code. and as a newbie you should be
worrying more about correctness and style than speed. don't prematurely
optimize is a good rule to learn.
TW> | TW> s!\r!!g;
TW> |
TW> | first, don't use odd delimiters unless you have to have / in the
TW> | expressions. second, i showed you the better way to do that before.
TW> well I did it because of suggestions on readability I've observed.
TW> There's nothing wrong inherently with the odd delimiters as long as it
TW> improves readability. Don't forget I'm still somewhat new at this and am
TW> trying to make MY life easier when I go back and look at these things
TW> later. :)
but odd delimiters are not as readable. otherwise there would be no
reason for the default use of / in regexes. use odd ones only when they
are syntactically needed.
TW> NOW.. go back to the original post, now that you've commented on the
TW> script, and re-read the questions I asked.. which you completely skipped
TW> over (why, I don't know)..
because i felt like highlighting some stuff rather than tackling the
whole problem. it is my perogative. :-)
TW> please, re-read the previous post! :))
i can't right now. i also promised to work on your html paragraph hing
tomorrow. maybe i will get back to this one then.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 9 May 2000 12:48:50 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: efficiency with data separation. [was Re: HTTP::Request=HASH(0x7bb141c) ?]
Message-Id: <957868274.26716@itz.pp.sci.fi>
In article <x7itwour6o.fsf@home.sysarch.com>, Uri Guttman wrote:
>>>>>> "TW" == The WebDragon <nospam@devnull.com> writes:
[two levels of attribution missing]
> TW> |
> TW> | TW> die "$baseURL $_ failed: ",$response->error_as_HTML
> TW> | TW> unless $response->is_success;
> TW> |
> TW> | notice how you have the open first and die second? you should do the
> TW> | same for the $response test. generally you emphasize the test which is
> TW> | important and then the failure code. of course saying:
>
> TW> true, but this works the way I think, and 'feels' perfectly normal..
> TW> TMTOWTDI :)
>
>true, but some are considered better by most than others. i agree it is
>your choice but IMHO most would feel better if that was reversed. the
>key thing you are checking is the response, not the die.
I've come to the conclusion that this is indeed purely a matter of
personal preference, and that, though logical justification may be
given for either choice, neither can be claimed to be better in
general.
To me, WebDragon's statement if fact does emphasize the test, since it
is on is own line, indented, and therefore stands out when scanning
the code. The fact that not everyone agrees is presumably because
other people tend to scan code in different patterns - based on past
discussion of this issue, I would assume that many others tend to read
code more sequentially, whereas I normally look at whole blocks at a
time, reading the subexpressions in the order they catch my eye.
Futhermore, there is my tendency to equate statements - especially in
Perl with its "poetic" syntax - with imperative sentences, which means
that putting a simple condition where an action would be expected
seems unnatural to me. "open or die;" and "die if failed;" both parse
naturally as sentences. "failed and die;" doesn't - not only there no
verb in the first half, but the only English idiom I can think of that
ends in "and die" is commonly abbreviated "FOAD".
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: Tue, 9 May 2000 16:51:29 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: Error at line 0 ? [Was: Exceptions that can't be caught by eval {} and local $SIG]
Message-Id: <8f8jjg$7ti@netnews.hinet.net>
Jonathan Stowe wrote
> What does it do if you leave out the 'use diagnostics' ?
Just two less lines of messages.
#!perl -w
use DBI;
my $connect=DBI->connect(
'dbi:Oracle:dvwork3','stat','stat',
{RaiseError=>0,PrintError=>0}
) or die 'connect failed'; # use a valid connection string to test
Error message:
(in cleanup) Can't call method "FETCH" on an undefined value at
D:/Perl/site/lib/Win32/TieRegistry.pm line 1486 during global destruction.
I wonder whether this is reproducible (at least YES on my machine).
Anyone else?
John Lin
------------------------------
Date: 9 May 2000 10:18:38 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Flame my code
Message-Id: <8f8olu$ha4$3@slb0.atl.mindspring.net>
Tony Curtis (tony_curtis32@yahoo.com) wrote:
: my %seen;
: for (@files) {
: next if $seen{$_}; # had this one before
: $seen{$_} = 1; # mark new one as seen now ...
: push @new_files, $_; # ... and record it
: }
my %seen;
@new_files=grep {!$seen{$_}++} @files;
should be faster (too lazy to benchmark right now) because it uses fewer
Perl operations (though the speedup is only by a constant factor).
------------------------------
Date: Tue, 09 May 2000 11:05:02 +0200
From: Christian Treczoks <c.treczoks@ndh.net>
Subject: Re: Function to filter HTML?
Message-Id: <3917D4BE.AEC48DC8@ndh.net>
Bart Lateur schrieb:
> my $p = HTML::TokeParser->new('test.htm')
> or die "Cannot read HTML file: $!";
> # Alternatively, you may pass a string containing the HTML,
> # by passing a reference to the scalar, as:
> # $p = HTML::TokeParser->new(\$html);
Ahhhh! So this is what Randal wrote about (thanks, Randal, Bart!)
I obviously missed this piece of info, and dropped this HTML::*
stuff to early... (Actually, the Synopsis for TokeParser,
"TokeParser->('index.html')" threw me off the track way to early.
Maybe someone should add your comments to the original Synopsis...
I think I understood, and I'm very sorry to have wasted your
time with my ignorance. Thank you very much, Perl Magicians
out there!
Yours, thankfully, Christian Treczoks
------------------------------
Date: Tue, 09 May 2000 09:18:18 GMT
From: "Stuart" <stuart.tavener@greenwichnatwest.com>
Subject: Hiding System Window ?
Message-Id: <3917e6bd.0@news2.cluster1.telinco.net>
Ive got some simple code, but i need to hide the black system window (on
NT4) that appears for basic text output, is there some option in compiling
(using perl2exe) or other switch in perl ?
Stuart.
------------------------------
Date: Tue, 09 May 2000 09:09:25 GMT
From: c_neak@my-deja.com
Subject: How to include lines beginning and ending with a string
Message-Id: <8f8kju$hes$1@nnrp1.deja.com>
Hi all ,
I want to include lines in a array , and include only the lines which
begins with a string which is "SEIINF" and ends with another string
which is "SCEIINF" . "SEIINF" and "SCEIINF" are excluded from my array .
Why the code below does'nt work (I'm newbie in Perl) ?
$file_stat="STAT_2000020400.txt";
open(FILE,$file_stat) || die "Cannot open $file_stat :$!...\n";
while ($line = <FILE>){
if ($line =~ /SEIINF(RT\D{4})SCEIINF/){ #problem here !!!
chomp($line) ; my @array = split /\s/,$line ;
$line =~ s/\s//;$line =~ s/\n/;/;$line =~ s/\s/;/;
print "\n@array";
}
}
The file "STAT_2000020400.txt" i must read from :
------------------------------
EIDLGS 0
SEINOT 0
GEITRN 0
SEIINF #beginning of extracting lines
RTICMM 0 2241 1 1 1 122
RTGALR 2 0 2 0 0 36
.....
TEIINF
RTRTRY 0 36 3 2 14 56
RTDLVA 1 56 2 3 36 21
.....
DLVMS0 12 3 2 0 5 56
DLVMS1 15 3 2 0 5 520
.....
GEIINF
RTRTFD 0 36 3 2 14 56
RTDHBN 1 56 2 3 36 21
SCEIINF #ending there
RTICMM 0 36 3 2 14 56
RTGALR 1 56 2 3 36 21
.....
------------------------------
TIA !
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 09 May 2000 10:28:55 GMT
From: c_neak@my-deja.com
Subject: How to include/exclude lines ?
Message-Id: <8f8p8u$m6i$1@nnrp1.deja.com>
Subject : How to include lines beginning and ending with a string
Hi all ,
I want to include lines in a array , and include only the lines which
begins with a string which is "SEIINF" and ends with another string
which is "SCEIINF" . "SEIINF" and "SCEIINF" are excluded from my array .
Why the code below does'nt work (I'm newbie in Perl) ?
$file_stat="STAT_2000020400.txt";
open(FILE,$file_stat) || die "Cannot open $file_stat :$!...\n";
while ($line = <FILE>){
if ($line =~ /SEIINF(RT\D{4})SCEIINF/g){ #problem here !!!
chomp($line) ; my @array = split /\s/,$line ;
$line =~ s/\s//;$line =~ s/\n/;/;$line =~ s/\s/;/;
print "\n@array";
}
}
The file "STAT_2000020400.txt" i must read from :
------------------------------
EIDLGS 0
SEINOT 0
GEITRN 0
SEIINF #beginning of extracting lines
RTICMM 0 2241 1 1 1 122
RTGALR 2 0 2 0 0 36
.....
TEIINF
RTRTRY 0 36 3 2 14 56
RTDLVA 1 56 2 3 36 21
.....
DLVMS0 12 3 2 0 5 56
DLVMS1 15 3 2 0 5 520
.....
GEIINF
RTRTFD 0 36 3 2 14 56
RTDHBN 1 56 2 3 36 21
SCEIINF #ending there
RTICMM 0 36 3 2 14 56
RTGALR 1 56 2 3 36 21
.....
.....
EIDLGS 0
SEINOT 0
GEITRN 0
SEIINF #beginning of extracting lines
RTICMM 0 2241 1 1 1 125
RTGALR 5 0 2 0 0 35
.....
------------------------------
TIA !
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 09 May 2000 12:34:53 +0100
From: nobull@mail.com
Subject: Re: How to include/exclude lines ?
Message-Id: <u9r9bchs82.fsf@wcl-l.bham.ac.uk>
c_neak@my-deja.com writes:
> Subject : How to include lines beginning and ending with a string
>
> Hi all ,
>
> I want to include lines in a array , and include only the lines which
> begins with a string which is "SEIINF" and ends with another string
> which is "SCEIINF" .
There are no such lines in your data that start with "SEIINF" and ends
with "SCEIINF". There is a line that reads "SEIINF" and one that
reads "SCEIINF" and you presumably want to process only the lines
between them.
> Why the code below does'nt work (I'm newbie in Perl) ?
What you have is not a Perl programming problem but a programming
problem per se - you simply are not thinking clearly about your
problems. The fact that your Perl code does not correctly implement
your misstatement of your problem is nowhere near as serious as the
fact that your Perl code attempts to solve the misstated problem
rather than the real one.
Clearly we could simply write your program for you but we've done that
for you several times already and it does not appear to have helped you.
I think you need to step back and start learning to program. There
were a couple of threads a while back about tutorials for people
leaning Perl as a first programming language.
Alternatively learn to program in some other language then learn Perl.
Whatever you choose to do always read the documentation on each thing
you use for the first time. You clearly have no clue as to what a
regular expression is and what the Perl pattern match operator does.
> if ($line =~ /SEIINF(RT\D{4})SCEIINF/g){ #problem here !!!
What do you think this does and why?
Perhaps if you try to explain it that will help you.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 9 May 2000 14:49:53 +0200
From: "Tom Klinger" <t.klinger@mobilkom.at>
Subject: Re: How to include/exclude lines ?
Message-Id: <9QTR4.50$6u3.2144@nreader2.kpnqwest.net>
<c_neak@my-deja.com> schrieb in im Newsbeitrag:
8f8p8u$m6i$1@nnrp1.deja.com...
> Subject : How to include lines beginning and ending with a string
> while ($line = <FILE>){
better: while (<FILE>) { # you've $_ to work with
> if ($line =~ /SEIINF(RT\D{4})SCEIINF/g){ #problem here !!!
try this instead:
chomp; # because in $_ is only 1 line
# i think this should work.
# when SEEINF is found $i is set and in the second loop you can work with.
# if SCEIINF is found $i will be unset and next lines are ignored until
SEIINF will be found again
if (/^SEIINF/) {
$i=1;
} elsif (/^SCEIINF/) {
undef $i;
}
if ($i) {
next if /^SEIINF/;
print "$_\n";
}
> chomp($line) ; my @array = split /\s/,$line ;
> $line =~ s/\s//;$line =~ s/\n/;/;$line =~ s/\s/;/;
This won't work. First you strip the spaces and then you try to replace
spaces with semicolon. There's nothing anymore. :)
Also s/\n/;/ will not work because of your file newlines are only at the end
of the line which are already cut off with chomp.
- tom
------------------------------
Date: Tue, 09 May 2000 15:28:14 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: How to include/exclude lines ?
Message-Id: <3918126E.D720206F@ife.ee.ethz.ch>
c_neak@my-deja.com wrote:
> I want to include lines in a array , and include only the lines which
> begins with a string which is "SEIINF" and ends with another string
> which is "SCEIINF" . "SEIINF" and "SCEIINF" are excluded from my array .
> $file_stat="STAT_2000020400.txt";
> open(FILE,$file_stat) || die "Cannot open $file_stat :$!...\n";
>
> while ($line = <FILE>){
> if ($line =~ /SEIINF(RT\D{4})SCEIINF/g){ #problem here !!!
> chomp($line) ; my @array = split /\s/,$line ;
> $line =~ s/\s//;$line =~ s/\n/;/;$line =~ s/\s/;/;
> print "\n@array";
> }
> }
>
Check the .. operator in perlop
my @the_lines_between;
while(<FILE>) { #use $_, as you can use it for regexps
push @the_lines_between, $_ if (/^SEIINF/ .. /^SCEIINF/) !~ /^1?$|E0/;
}
- Alex
------------------------------
Date: 9 May 2000 16:17:03 +0200
From: hjj@news1.tele.dk (Hans J Jakobsen)
Subject: How to make SNMP in parallel?
Message-Id: <8f96kv$bbk$1@news1.tele.dk>
Keywords: SNMP ucd-snmp parallel
I have a perl script that uses the SNMP module for ucd-snmp.
Function of script is ok. Do not take much cpu. Most time is spent waiting
for requests to be answered. The number of nodes/hosts visited
is large so I would like to service all or some nodes in parallel.
The basic layout of the program is:
foreach host
snmpset
sleep
foreach host
snmpget
What would be the best way to have this done in parallel.
1) Perl threads
2) Event.pm
3) C or C++ with threads.
4) ?
What models have succeded for you or what did not work?
/hjj
--
Hans Jørgen Jakobsen
------------------------------
Date: 9 May 2000 09:54:09 GMT
From: csaba_r@my-deja.com (Csaba Raduly)
Subject: Re: How to print '%' character with printf ?
Message-Id: <8F2F61BC2quuxi@193.82.145.131>
06 May 2000: A formal bug report was sent to Seti@Home, because the
following message originated from lr@hpl.hp.com (Larry Rosler) was
reported as containing signs of intelligence:
>In article <8f1c29$iod$1@inxs.ncren.net> on 6 May 2000 15:00:25 GMT,
>msouth@fulcrum.org <msouth@fulcrum.org> says...
>> Larry Rosler <lr@hpl.hp.com> wrote:
[snip]
>While we're still at it, here's yet another way of solving this and
>similar problems:
>
>printf ' %i %s of the files', $percentage, '%';
>
printf ' %i %c of the files', $percentage, ord('%');
--
Csaba Raduly, Software Developer (OS/2), Sophos Anti-Virus
mailto:csaba.raduly@sophos.com http://www.sophos.com/
US Support +1 888 SOPHOS 9 UK Support +44 1235 559933
Life is complex, with real and imaginary parts.
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/IT/MU d- s:- a31 C++$ UL+ P+>+++ L++ E- W+ N++ w++>$ O++$
M-(+) V- PGP- t+ X++ R* tv++ b++ DI+++ D++ G- e+++ h-- r-- !y+
-----END GEEK CODE BLOCK-----
------------------------------
Date: Tue, 9 May 2000 04:19:56 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Is Perl fast enough?
Message-Id: <Pine.GSO.4.10.10005090407250.3921-100000@user2.teleport.com>
On Tue, 9 May 2000 pohanl@my-deja.com wrote:
> Subject: Is Perl fast enough?
Probably. :-)
> Perl is a scripting language that basically has an interpreter
> that goes through the code and follows the script.
I humbly disagree. Your description in the next sentence is much more
accurate:
> It is my understanding that there is a compilation stage where the
> script is compiled into something that resembles bytecodes in java,
> and the interpreter will then run the bytecode (am I correct on this?)
Sounds good to me.
> Bytecodes contain instructions for a virtual machine cpu (like Load
> and Store operations in assembly).
Not really. At least, not really in my opinion, when it comes to Perl. As
far as I know. In the current version. Subject to modification without
notice. All rights reserver. Do not taunt Happy Fun Perl.
> I know in Java the Virtual machines is supposed to run a garbage
> collector in the background (or when idle) to reclaim memory used by
> unreferenced variables. Early versions of the VM simply allocated
> memory and didn't even bother to garbage collect (the code for it
> wasn't even in there!) I think the latest versions have some sort of
> garbage collection built in.
Okay....
> Does perl have garbage collection? When is it run? Or if there
> even is a garbage collector? If it does exist, when does unreferenced
> variables get garbage collected? Right when they are not referenced?
> Or does a background garbage collection comes around and frees up
> memory when memory is low, or when it is idle, or checks periodically
> now and then, or runs constantly in the background (don't know if
> this is possible if multi-threads are not supported on some platforms).
Have you seen the perlobj manpage? It has a section called "Two-Phased
Garbage Collection" which may answer all of your questions. Then again,
maybe not - you have quite a few. :-)
> But anyhow, because it is a dictionary type of perl program, it
> uses a lot of memory and it does a lot of comparisons (it will
> need speed). So I am guessing there is an upperlimit number
> of glossary terms that it can handle before Perl cannot be used
> anymore. (In this case needing a c/c++ replacement).
I wonder whether you should be using some sort of tied data structure
which would let you keep more data in memory efficiently. In general, when
you need a "very large" data structure, especially one with homogeneous
data (such as an array of 10e10 two-byte integers, say), it's often a good
idea to use a tied array or hash. See the perltie manpage.
Or, maybe you should keep your data on disk and only have some sort of
index in memory. This solution may take the most "brain sweat" to create,
but it could be the fastest way in the end. Then again, you could spend a
year thinking about it and never find a solution. That's life!
Or, maybe you could put the key code into an XS-based module. That can let
you get a big speed advantage for the things that C can do quickly while
still using Perl for what Perl can do quickly (such as, cut down your time
at the keyboard).
> Has anyone ever created a memory intensive and speed sensitive
> application in perl?
One or two. :-)
> Can you comment on this? Has anyone ever written a perl program that
> crashed because of some upper bound in speed or memory requirement?
Once or twice. :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 9 May 2000 03:50:08 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: keep-alive
Message-Id: <Pine.GSO.4.10.10005090348480.3921-100000@user2.teleport.com>
On Mon, 8 May 2000 atomshop_1@my-deja.com wrote:
> Is this the proper systax for keep-alive in the http header?
It _looks_ like the right syntax to me. Have you tried using the debugging
mode? That should let you verify that the right headers are going out.
> How effective is this at creating persistent connections?
That sounds like a question better-suited to a newsgroup about web
servers. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 9 May 2000 10:29:11 GMT
From: jcuesta@tid.es (CUESTA CUESTA)
Subject: Library to read ini files
Message-Id: <8f8p9n$h6d1@tid.tid.es>
Can anybody tell me if exists any module that reads ascii files with a format
like Windows INI files: sections ([section_name]) and values in a section (
variable_name=variabla_value)?
Thanks
J. C. Cuesta
------------------------------
Date: Tue, 9 May 2000 04:48:01 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Library to read ini files
Message-Id: <Pine.GSO.4.10.10005090447330.3921-100000@user2.teleport.com>
On 9 May 2000, CUESTA CUESTA wrote:
> Can anybody tell me if exists any module that reads ascii files with
> a format like Windows INI files:
Have you looked on CPAN? Cheers!
http://search.cpan.org/search?mode=doc&query=.ini
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 09 May 2000 04:57:34 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Library to read ini files
Message-Id: <3917FD2E.C6A3BE9A@vpservices.com>
CUESTA CUESTA wrote:
>
> Can anybody tell me if exists any module that reads ascii files with a format
> like Windows INI files: sections ([section_name]) and values in a section (
> variable_name=variabla_value)?
>
DBD::RAM can treat ini files like a DBI/SQL accessible database. The
current version does not support sections but I will be adding support
for them in the next few weeks.
--
Jeff
------------------------------
Date: 09 May 2000 12:59:54 +0100
From: nobull@mail.com
Subject: Re: Library to read ini files
Message-Id: <u9og6ghr2d.fsf@wcl-l.bham.ac.uk>
jcuesta@tid.es (CUESTA CUESTA) writes because he can't be bothered to read:
> Can anybody tell me if exists any module...
Yes at least two exist and can be found in the place you should have
looked before you posted (CPAN). Hint: they have the characters "ini"
in their names (although not necessarilty all in lowercase).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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 V9 Issue 2989
**************************************