[16442] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3854 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 31 06:05:30 2000

Date: Mon, 31 Jul 2000 03:05:12 -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: <965037911-v9-i3854@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 31 Jul 2000     Volume: 9 Number: 3854

Today's topics:
    Re: cleaning up temp files Please Help <elephant@squirrelgroup.com>
    Re: Confirming IP address and subnet mask <gellyfish@gellyfish.com>
    Re: DBI database access problem <jbroz@transarc.com>
        DBI, Oracle and Perl 5.003 president@whitehouse.gov
    Re: DBI, Oracle and Perl 5.003 <tarjei@onsite.no>
    Re: Good Perl Courses In UK? <gellyfish@gellyfish.com>
    Re: I Am An Idiot <godzilla@stomp.stomp.tokyo>
        Memory leak in perl code <peiagee@hotmail.com>
    Re: metatags <gellyfish@gellyfish.com>
    Re: newb q - help with write to file script <gellyfish@gellyfish.com>
    Re: newb q - help with write to file script <gellyfish@gellyfish.com>
        Newbii file write perl question rune@clamon.dk
        Parse::RecDescent with left-recursive grammar. <ocschwar@mit.edu>
    Re: regexp match inside a time interval ? <man@rila.bg>
        remove the newline? <chaptera@hotmail.com>
    Re: remove the newline? <tarjei@onsite.no>
    Re: Running other programs in background <bart.lateur@skynet.be>
    Re: Running other programs in background ericr@yankthechain.com
    Re: simple script, please help! <gellyfish@gellyfish.com>
        sort some columns (James McCallum)
    Re: sort some columns (Marcel Grunauer)
        System background work <lucas@cplhk.com>
    Re: System background work (Marcel Grunauer)
    Re: taint checking with perlis/perlex <gellyfish@gellyfish.com>
        tricky regexp rapapullo@my-deja.com
    Re: tricky regexp <tarjei@onsite.no>
        Wraping data file with XML envelope <Sasa.Danicic@eurodyn.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 31 Jul 2000 08:13:18 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: cleaning up temp files Please Help
Message-Id: <MPG.13efd278e28a95f698969c@news>

David Tsai writes ..
>webmaster@sandiegopetandvet.com wrote:
>
>> I have been banging my head on this one for several hours and combed
>> nearly every post to the forum and looked through my books. I am just
>> not getting it.
>>
>> All I want to do it delete all files from a directory that have an
>> extension of tmp
>>
>> This is the closest I have come, I think.
>>
>> The relative directory variable is defined in the script setup which is
>> also where I write the temp files.
>>
>> $relative_directory = "../userdefined/";
>>
>> I figured out how to create temp files for reading, but now I can't
>> figure out how to get rid of them!
>>
>> sub goto_cleanup
>> {
>> unlink(glob("$relative_directory*.tmp")) or die;
>> &create_main_form("<B>The tempory files were deleted</B>");
>> exit;
>> }
>>
>> Any help is very much appreciated. I know the answer is simple, but I
>> just can seem to get it.
>>
>> Sent via Deja.com http://www.deja.com/
>> Before you buy.
>
>This probably isn't the easiest way to do it but it works.....
>
>opendir(DIR,"$relative_directory") || die "Can't open directory\n";
>while($file = readdir(DIR)) {
>    if($file =~ /.+\.tmp/) {
>        unlink("$relative_directory/$file");
>    }
>}
>closedir(DIR);

that will delete files that have .tmp anywhere in their name (except at 
the beginning) .. you need a tail anchor to ensure that it's an 
'extension' .. and the plus in this context is not needed (assuming that 
'extension' means that there must be at least one character in the 
filename before the '.tmp' end)

I'd also recommend using a for loop and incorporating the filter into 
the list generation - also including $! in your die() .. eg.

  opendir DIR, $relative_directory or die "Bad opendir: $!";
  for my $file ( grep /.\.tmp$/ => readdir DIR )
  {
    unlink $relative_directory. $file;
  }
  closedir DIR;

-- 
  jason -- elephant@squirrelgroup.com --


------------------------------

Date: 31 Jul 2000 08:59:02 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Confirming IP address and subnet mask
Message-Id: <8m3bk6$6fn$1@orpheus.gellyfish.com>

On Sun, 30 Jul 2000 10:40:21 +0100 Derek Fountain wrote:
> Can anyone point me to a piece of code which will take an IP address and
> a subnet mask, and confirm that that IP address is valid for the subnet?
> 

You might want to check out the module Net::IPv4Addr from CPAN to see if
it does what you want.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: Mon, 31 Jul 2000 10:13:37 +0100
From: "Joe_Broz@transarc.com" <jbroz@transarc.com>
Subject: Re: DBI database access problem
Message-Id: <39854341.76D67946@transarc.com>

Barry Kimelman wrote:
> 
> I am having a problem accessing an Informix database table on my UNIX
> system at the office while using the DBI interface.
> 
> The connect succeeds, but the "prepare" statement fails with the
> following error message :
> 
>     DBD::Informix::db prepare failed: SQL: -479: The number of DESCRIBED
> columns is greater than the allocated space.
> 
> According to the perl -v command we are running perl version 5.004_04
> built for RM600-unix.

What's RM600 unix? Removed comp.lang.perl (it hasn't existed for 5 years).
Also removed alt.perl

> 
> The table in question has 201 columns. Is there some built in limit with
> respect to the number of columns ? Is there some parameter or

Not in perl. perl and the DBI don't care how many columns your table has.

> configuration option which can be used to solve this problem ?

You can change something in the database I suspect (but I don't know
Informix).

> Please advise as to how to solve this problem.
> 

This is an Informix problem. The Informix documentation should describe how
to fix this if it can be fixed.


------------------------------

Date: Mon, 31 Jul 2000 10:10:22 +0100
From: president@whitehouse.gov
Subject: DBI, Oracle and Perl 5.003
Message-Id: <3985427E.A7CBB57@whitehouse.gov>

Hi all,
I've got a task, part of which involves running a simple SELECT against
Oracle, we're just interested in the status of a single record and the
rest of the task is Oracle-free (It will one day be CGI, but my proof of
concept will be a command line utility).

Unfortunately the machines in question are all running Perl 5.003, and
DBD::Oracle requires 5.004 or better. The responsible SAs are resisting
my request to upgrade because there's lots of Perl stuff in that
environment and they don't want break any of it. (Or, I suspect, create
work for themselves.)

So I'm probably stuck with running Oracle's client via backticks. I
haven't used DBI before and it looks great, but is it really worth me
pushing an upgrade? Is it something we should all be using, or do you
really only get the pay off if you're doing intesive DB work on multiple
platforms? Should I just follow my easy-life instincts and just use the
backticks? Or will that cause more tears in the long term? Anything
obvious I've overlooked?

Thanks
---
Nick



------------------------------

Date: Mon, 31 Jul 2000 09:18:42 GMT
From: Tarjei Vassbotn <tarjei@onsite.no>
Subject: Re: DBI, Oracle and Perl 5.003
Message-Id: <398545A2.CFD6057E@onsite.no>

> Hi all,
> I've got a task, part of which involves running a simple SELECT against
> Oracle, we're just interested in the status of a single record and the
> rest of the task is Oracle-free (It will one day be CGI, but my proof of
> concept will be a command line utility).
> 
> Unfortunately the machines in question are all running Perl 5.003, and
> DBD::Oracle requires 5.004 or better. The responsible SAs are resisting
> my request to upgrade because there's lots of Perl stuff in that
> environment and they don't want break any of it. (Or, I suspect, create
> work for themselves.)
> 
> So I'm probably stuck with running Oracle's client via backticks. I
> haven't used DBI before and it looks great, but is it really worth me
> pushing an upgrade? Is it something we should all be using, or do you
> really only get the pay off if you're doing intesive DB work on multiple
> platforms? Should I just follow my easy-life instincts and just use the
> backticks? Or will that cause more tears in the long term? Anything
> obvious I've overlooked?

When facing the option of installing/using a module instead of
backticks,
system, fork or other nasty solutions you should always choose the
module-
approach - IMHO.
DBD is a great module, both for small projects (which often tends to get
bigger by the time :), as well as big.

A solution to the problem with programs breaking by upgrading to
5.00[456],
would be to install it other than in the usual /usr/bin/perl (say, 
/local/perl/5.006/bin/perl ?), that way you would get what you want, and
they don't have to worry about programs not working (altough they'd have
to
be pretty bad and/or use deep-dark perl-functionality to not survive an
upgrade to 5.00[456]).

- Tarjei


------------------------------

Date: Mon, 31 Jul 2000 09:21:22 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Good Perl Courses In UK?
Message-Id: <mybh5.725$82.27033@news.dircon.co.uk>

On Fri, 28 Jul 2000 17:04:57 GMT, gavin_gibson@my-deja.com Wrote:
> Hello All,
> 
> Myself and a colleague, are already fairly experienced shell coders and
> have a smattering of Perl, learnt from books etc. However the
> opportunity for Perl training has come up and we're now looking for a
> course.
> 
> Ideally we want something which will teach us about Perl, rather than
> just about programming with Perl, as we won't need the concept of
> loops, boolean operators etc to be explained to us.
> 
> We're both DBA's and so specifically we'd be interested in DBI stuff
> but we couldn't afford just to learn this exclusively.
> 
> Does anyone know of a good course that would meet these needs? + if
> it's in London all the better!
> 

You could do worse than asking on the London.pm mailing list - there are
one or two people there that do training I know of.  Check out the site
at <http://london.pm.org> or mail me and I'll sort you out ...

/J\


------------------------------

Date: Mon, 31 Jul 2000 00:35:32 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: I Am An Idiot
Message-Id: <39852C44.911E4624@stomp.stomp.tokyo>

Larry Rosler wrote:

> Godzilla! wrote:


> > > open HANDLE, "not_a_file" or die "Cannot open: $!";
> > > open HANDLE, "not_a_file" || die "Cannot open: $!";

> > Both kill your program. Reality dictates there is no difference.

> The second of the two lines cannot kill the program, because the string
> literal is always TRUE.  Failure to open the file will be ignored.
 
> > * waves another white flag in sarcastic jest *
 
> Is that an advance acknowledgment of your outright error?


As you know Mr. Rosler, I have a well earned reputation
for testing "things" before committing myself to any
knowledgable statement. My tests reflect a different
reality than you attempt to impose:

http://la.znet.com/~callgirl/rosler.jpg

This image holds true for all tests I ran,
for both case examples.


My suggestion for personal enlightment, Mr. Rosler,
is to setup scripts of your own and, test to verify
your thoughts are correct, before utterance. Both
kill a program unless you write code to compensate
for a file open failure. First one outright kills
your program. Second kills your program if you do
not provide alternative output data under failure
conditions.

Be sure you are clear on this. Both kill your program.
Compensation code is all which keeps your program alive,
for both case examples and, especially for the second
case example presented of || die. 

Shirley you didn't think I failed to plan ahead for
opportunities of malice intent? Just a matter of
attaching a file name to my jpg image. I am an
English teacher and an English professor. You know 
how pedantic we are about homework. I always do
my homework and submit it in a timely fashion.

* smiles *


Godzilla!

==
I am Dr. Victoria Frankie Einstein. I will rock you.
http://la.znet.com/~callgirl5/frank.mid


------------------------------

Date: Mon, 31 Jul 2000 07:08:17 GMT
From: Greg Roberts <peiagee@hotmail.com>
Subject: Memory leak in perl code
Message-Id: <8m38l0$apm$1@nnrp1.deja.com>

Hi. I've recently written a perl script that has an infinite loop inside
which constantly checks a directory for any new files. What I've
noticed, with using top, is that the script's memory usage grows at a
rapid rate until it dies from taking up too much system memory. The loop
looks something like this:

while(1)
{
  chdir (dir)
  @contents = `ls -l`

  foreach $entry (@contents)
  {
    process $entry...
  }
}

It starts off at around 2.7MB, but quickly grows in size (it's currently
at 16MB). It will take several hours before it dies, but this needs to
run pretty much 24/7. Now I'm no programming guru by any means, so I
don't really know how to tackle this one. I've read in other posts
recommendations saying to exec copies of itself after a certain number
of iterations to get around this, but I wanted to know if there was a
particular way of using infinite loops in perl and how to best manage
memory leaks?

Any advice will be greatly appreciated.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 31 Jul 2000 08:54:28 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: metatags
Message-Id: <8m3bbk$5ig$1@orpheus.gellyfish.com>

On Sun, 30 Jul 2000 02:11:49 -0700 randythefirst wrote:
> 
> Question is, "Do the indexing spiders for search engines index
> my perl scripts(.pl, .cgi) in the cgi-bin?"
> 

Who knows ?  This would be a design decision made by the programmer of the
robot. Moreover the answer would be the same whichever language you had
used to create your CGI programs so the question would be better asked in
some comp.infosystems.www.* group .

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: 31 Jul 2000 09:51:05 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: newb q - help with write to file script
Message-Id: <8m3elp$gep$1@orpheus.gellyfish.com>

On Fri, 28 Jul 2000 13:57:45 GMT pooh23@my-deja.com wrote:
> Hello,
> I'm trying to get data from a survey form and write to a file.  I'm
> getting syntax error when I test it out on my computer at lines 8 and
> 18.  Could someone tell what syntaxical errors I may have?
> 
> CODE:
> 
> #!/usr/perl/bin -w
> use strict;
> 

Good, good.

> $printmail = 'data/surveydata.dat';
> 
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'})
> 
                                              ^ missing ; is your problem

However as you have used 'strict' you will also get

  'Global symbol "$buffer" requires explicit package name at blah line 7'

unless you at least place a 'my $buffer;' before that line.

> foreach split(/&/, $buffer) {            #line 8
> ($name, $value) = split(/=/, $buffer);

same applies to the above line with respect to the 'strict' preface the
line with a 'my' and it will be alright.

> 
> #maybe call function here that will parse hexidecimal
> 

maybe use CGI.pm instead eh ?

> open(FILE, ">>$printmail") or die "Can't open file";

You probably want to put '$!' in that 'die' for the diagnostic information
it affords.  You should also bear in mind that if you 'die' at this point
your user will get a confusing 'Internal Server Error' - you might consider
either using CGI::Carp to cause the diagnostic message to be sent to the
browser or test the success of the file open in another way and print a
more anodyne message if it fails.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: 31 Jul 2000 10:23:53 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: newb q - help with write to file script
Message-Id: <8m3gj9$mnf$1@orpheus.gellyfish.com>

[ Followups set ]

On Fri, 28 Jul 2000 13:15:21 -0400 jtoy wrote:
> Uri Guttman wrote:
> 
>> >>>>> "j" == jtoy  <toyboy@toy.eyep.net> writes:
>>
>>   j> I know
>>   j> "Alex T." wrote:
>>
>>   >> "Good argument"
>>   >>
>>   >> jtoy wrote:
>>   >>
>>   >> > shut up
>>   >> >
>>
>> he was being sarcastic. but it was wasted on such an experienced worldly
>> high school kid who makes so much money.
>>
>> to quote that great philosopher curly (from city slickers):
>>
>> "i take shits bigger than you."
>>
>> just go away before you have a chance to grow up. if you hang around and
>> perchance mature, you will be so embarrassed at your current
>> behavior.
>>
>> 18 year olds who know everything. what a concept!
>>
>> and as always, my new rule applies, the kewler the nickname, the lamer
>> the poster.
>>

Couldnt agree more - the 'Guttman principle' I think we'll call it.

> 
> I agree that I a high school kid.  I am not experienced worldy.
> I do think that I know more about computers then the average person.

Except you should realise that you probably dont know more about computers
than the average person in this group - there are people here who have
been programming computers since before you were born.  Of course people
generally dont care what age someone is, but they do care about the age
someone acts and you are the one who has made an issue of it.

> Because I am young, I geel proud that I make a lot of money, but
> If I was old and making the same money then I wouldn't be so happy.
> I'm sorry if you thought I was trying to show off, I was just trying
> to post stupid comments there like everyone else on that thread.
> I would think that you are the one who is less mamture if you have to
> talk back and yell at me.  It is expected for punbks like me to act
> like this.  It is not expected for a 'teacher' (as you are acting0 to
> try and teach and talk shit in the same sentence.  Your point failed
> when you started to insult me.  Thank you for trying though.

I dont know what happened in the rest of the thread as only this post
and the original one turned up here as yet ( or maybe I just killfiled
everyone else in the group by accident :) so I dont really know what this
is all about but it looks like you have failed to take cognizance of the
prevailing culture in this newsgroup before posting.  You blunder in here
and start behaving in a way that is likely to upset people, of course
you didnt know that it was likely to upset people because either you didnt
bother to observe or because you lack the social skills to determine the
line between what is and what isnt acceptable, OK the difference on occasion
can be rather subtle but that should at least be apparent to you and give
you cause to keep quiet and observe, but oh no ...  I do hope you
realise that failure to take into account the culture of environment you
find yourself in in the way that you have appeared to have done could
in certain places in the real world land you in a lot more trouble than
having the piss taken out of you by the locals.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: Mon, 31 Jul 2000 09:00:53 GMT
From: rune@clamon.dk
Subject: Newbii file write perl question
Message-Id: <8m3f84$fuq$1@nnrp1.deja.com>

I'm writing a script to increase a versionnumber in a source file. My
problem is that when I have the path to the file I want to find a
spicific place in the file and increase it's version number in the file
and write it back to disk. The procedure goes as folows:

open the file

find the place to increase
   -the line looks like this:
   //version control information: helloWorld.java $version: 001

increase the version number by 1

write file back to disk with new information

Thanks for the help,
best regards,
Rune Christensen


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 31 Jul 2000 07:08:32 +0000
From: Omri Schwarz <ocschwar@mit.edu>
Subject: Parse::RecDescent with left-recursive grammar.
Message-Id: <398525F0.ABCA33F9@mit.edu>

Hi, all!

Say, um, a frieend of mine, yeh, that's it, a friend of mine,
writes a left-recursive grammar using RecDescent and sets 'nocheck', 
and runs it, what could happen?

1. nothing?

2. shamefull waste of CPU cycles?

3. infinite loops?

4. the end of the world as we know it?

Regards,

Omri, Perl neophyte


------------------------------

Date: Mon, 31 Jul 2000 07:29:40 GMT
From: Margarit Nickolov <man@rila.bg>
Subject: Re: regexp match inside a time interval ?
Message-Id: <8m39t3$ci1$1@nnrp1.deja.com>

In article <3981A664.FC78F721@arnis-bsl.com>,
  Ilja Tabachnik <billy@arnis-bsl.com> wrote:
> Margarit Nickolov wrote:
> >
> > In article <MPG.13ea329f29f83e0e98abf5@nntp.hpl.hp.com>,
> >   Larry Rosler <lr@hpl.hp.com> wrote:
> > > In article <8lootb$20c$1@nnrp1.deja.com> on Thu, 27 Jul 2000
07:38:19
> > > GMT, man@rila.bg <man@rila.bg> says...
> > > > Hello All, need a help, question follows:
> > > >   I want if some regexp has not matched for a specified time(1-2
> > secs),
> > > > then the match statement should be interrupted(some flag set)
and
> > > > script continues the statement after regexp match.
> > > >
> > > > example of what I need:
> > > >
> > > > if( m/complex regexp over huge string(file)/ ) {
> > > >   #ok
> > > > }
> > > >
> > > > if( $failure_flag ) { # if failure, then flag is set
> > > >   #failure
> > > > }
> > >
> > > perlfaq8: "How do I timeout a slow event?"
> >
> > I have already tried this, but when control is returned from
alarm-sub,
> > macthing the pattern continues(control is not passed on the
statement
> > after, what I really need). May be I miss something, here is example
of
> > the code, which does NOT work:
> >
> > package filters::lib::Weather_generic;
> >
> > use strict;
> > use vars qw/$errstr/;
> >
> > sub fetch {
> >     undef $errstr;
> >     my $url = shift;
> >     local $_ = shift; # content of HTML-page
> >     my %result = ();
> >     my $host;
> >
> >     local $SIG{ALRM} = sub { $errstr = "Can not parse
> > '$url'(timeouted)\n";
> > warn "caught ALRM:$errstr";  return (); };
> >     alarm 1; # if not matched for that time, probably will never
match.
> >
> >     # $1 - city, $2 - img_src, $3 - img_alt(cloudy...), $4 -
curr_temp
> >     $url =~ m|^(http://)?[^/]+|; # only host is not stripped
> >     $host = $&;
> >
> >   if(
> >
m/<p>\s*(\d+)\s*<\/p>.*?<font\s+face=.*?>\s*<b>\s*([^,]+).*?<img\s+src="([^"]
> > +).*?<font face=.*?>\s*<b>\s*([^<]*).*?Current
Temp:\s*<b>([.\d]+)/ios ) {
> > %result = ('zip' => $1, 'city' => $2, 'img_src' => "$host$3",
'img_alt' =>
> > $4, 'curr_temp' => $5); } else {  $errstr = "Can not parse
'$url'\n";  return
> > (); }#if match  alarm 0;  return () if defined $errstr; #alarm is
caught
> > return %result; }#fetch
> >
> > 1;
> >
>
> Please re-read 'perldoc perlipc', section "Signals".
> At the very bottom this sections contains some info
> about timeouts and a code example.
>
> eval {
>        local $SIG{ALRM} = sub { die "alarm" };
>        alarm 10;
>        # do your time-consuming operation here
>        alarm 0;
>     };
> if ($@ =~ /alarm/)
> {
>    # do something usefull
> }
>
> Got the idea?
>
> Hope this helps.

Thank you, it really helps, but only for the play - is there any
alternative ways to achieve the same(do not bother explicitly!)?

                    best regards, margarit nickolov.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 31 Jul 2000 15:32:24 +0800
From: Tom <chaptera@hotmail.com>
Subject: remove the newline?
Message-Id: <39852B88.9F30D0EC@hotmail.com>

Hi all,
I have a file like this:
c.txt
===


line 4
line 5
line 6
 ....

<EOF>

I want to write a perl program to remove the blank line/only the enter
key line.

open(INFILE, "c.txt") or die "Cannot ok it";
@lines = <INFILE>;
close(INFILE);
open(FILE, ">>d.txt") or die "Cannot ok it";
foreach $line (@lines)
{
   $line =~ s/\n\n*/\n/sg;
   print FILE $line;
}
close(FILE);

But I found that the "s/\n\n*/\n/sg"
is not work?

Am I going wrong?

thanks
---
Tom



------------------------------

Date: Mon, 31 Jul 2000 08:55:08 GMT
From: Tarjei Vassbotn <tarjei@onsite.no>
Subject: Re: remove the newline?
Message-Id: <3985401D.E8A5B91E@onsite.no>

> Hi all,
> I have a file like this:
> c.txt
> ===
> 
> line 4
> line 5
> line 6
> ....

[SNIP]

> But I found that the "s/\n\n*/\n/sg"
> is not work?
> 
> Am I going wrong?

Well, there is a better way to do it;

This should do the trick:

--
open (INFILE, "c.txt") or die "Cannot ok it";
open (FILE, ">>d.txt") or die "Cannot ok it";
while (<INFILE>) {
  print FILE unless m/^$/; # Uses $_ implicit
}
close (FILE);
close (INFILE);
--

Please note that if you also wanted to skip lines containing
whitespaces also, you could do this by changing the regex to /^\s*$/

- Tarjei


------------------------------

Date: Mon, 31 Jul 2000 07:18:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Running other programs in background
Message-Id: <5j9aos0sfh35irdb81qlhhdtfcnuhpd3k6@4ax.com>

ericr@yankthechain.com wrote:

>	my $return = $WinExec->Call("data/mplayer2  data/$sndfile", 0);
>
>Any ideas? I'm running Windows 98.

So am I. Do you even have notepad on your system? I get no visible clue
that notepad is running. But if I press ctrl-alt-del, there it is, in
the task list.

Have you checked the return value? If it's less than 32, an error
occurred. Error codes:

	0	out of memory
	2	file not found
	3	path not found	
	11	not a valid EXE file

"data/mplayer2" looks like a strange path to a program. Usually, people
make sure that the executable is in PATH, and then call it using the
bare program name. But, if it opens, that's not the problem. Have you
tried replacing the 0 with a 6?

-- 
	Bart.


------------------------------

Date: Mon, 31 Jul 2000 08:46:49 GMT
From: ericr@yankthechain.com
Subject: Re: Running other programs in background
Message-Id: <8m3edp$fh4$1@nnrp1.deja.com>

In article <5j9aos0sfh35irdb81qlhhdtfcnuhpd3k6@4ax.com>,
  Bart Lateur <bart.lateur@skynet.be> wrote:
> ericr@yankthechain.com wrote:
>
> >	my $return = $WinExec->Call("data/mplayer2  data/$sndfile", 0);
> >
> >Any ideas? I'm running Windows 98.
>
> So am I. Do you even have notepad on your system? I get no visible
clue
> that notepad is running. But if I press ctrl-alt-del, there it is, in
> the task list.
>
> Have you checked the return value? If it's less than 32, an error
> occurred. Error codes:
>
> 	0	out of memory
> 	2	file not found
> 	3	path not found
> 	11	not a valid EXE file
>
> "data/mplayer2" looks like a strange path to a program. Usually,
people
> make sure that the executable is in PATH, and then call it using the
> bare program name. But, if it opens, that's not the problem. Have you
> tried replacing the 0 with a 6?
>
> --
> 	Bart.

I haven't. I put a copy of mplayer2 in the "data" folder of my program.
As I said, the code above makes the player play the song fine, it's
just that it pops up in front of the window of the Perl/Tk program. And
I certainly didn't replace the 0 with a 6... and when I type "notepad"
into the MS-DOS prompt it launches notepad, so no problem there. The
thing is that the MS-DOS window that the program opens up when trying
to launch notepad IS hidden, it's only visble on the taskbar, but when
I open it up there's nothing there and I can't type anything into it...
I really don't know what's going on... I'm going to do some searching
for in depth documentation on the Win32::API module, as I found the
Perldoc page very confusing...


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 31 Jul 2000 08:48:53 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: simple script, please help!
Message-Id: <V3bh5.723$82.26661@news.dircon.co.uk>

[ removed pointless alt.perl - must copy that killfile to this machine ]

In comp.lang.perl.misc Penguin Knight <penguinknight@yahoo.com> wrote:
> Hello,
> How would one find out if a user is logged on from within a perl script?
> Is there a functions that does that?
> 

There is a module that does this :

<http://search.cpan.org/search?mode=module&query=Utmp>

/J\


------------------------------

Date: Mon, 31 Jul 2000 09:26:45 GMT
From: james.mccallum@bradford.gov.uk (James McCallum)
Subject: sort some columns
Message-Id: <3985458a.4601397@newscore.theplanet.net>

Hi,
I've got a file with two columns as so

2	C
4	D
3	A
1	B

I'd like to sort it on the second column so I get the following result

3	A
1	B
2	C
4	D

How can I do this using perl?

Thanks


------------------------------

Date: Mon, 31 Jul 2000 09:16:00 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: sort some columns
Message-Id: <slrn8oah9m.2bc.marcel@gandalf.local>

On Mon, 31 Jul 2000 09:26:45 GMT, James McCallum
<james.mccallum@bradford.gov.uk> wrote:

>I'd like to sort it on the second column so I get the following result


perldoc -q sort

(How do I sort an array by (anything)? - perlfaq4)


-- 
Marcel
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


------------------------------

Date: Mon, 31 Jul 2000 16:13:51 +0800
From: "Lucas Tsoi" <lucas@cplhk.com>
Subject: System background work
Message-Id: <8m3c9n$8eh1@imsp212.netvigator.com>

Hi all,
How do I run some background work regularly by Perl in linux?
e.g. everyday's 12pm

Thanks very much




------------------------------

Date: Mon, 31 Jul 2000 08:40:00 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: System background work
Message-Id: <slrn8oaf63.1jj.marcel@gandalf.local>

On Mon, 31 Jul 2000 16:13:51 +0800, Lucas Tsoi <lucas@cplhk.com> wrote:

>How do I run some background work regularly by Perl in linux?
>e.g. everyday's 12pm


man cron


-- 
Marcel
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


------------------------------

Date: 31 Jul 2000 09:30:12 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: taint checking with perlis/perlex
Message-Id: <8m3dek$cfd$1@orpheus.gellyfish.com>

On Sun, 30 Jul 2000 15:47:41 GMT Colin Keith wrote:
> In article <972097A1F1360AB1.5CD40BCFE202CF9E.C0968634F952A71B@lp.airnews.net>, Grant Boyle <gboyle@sympatico.ca> wrote:
>>Unfortunately I haven't been able to figure out how to enable taint
>>checking when using perl for ISAPI (perlis.dll) under NT4/IIS4. I
>>tried the -T switch on a #! line but that just gave the usual 'too
>>late' message. I did some searching on the net but came up empty.
> 
> Wouldn't you need to add it to the bit that calls the perl interpreter? I 
> though this came out of the registry, but IIS4 might have its own settings 
> for this. I would suggest you look for and try changing the command line 
> that's run from the registry. (but obviously back it up first, *disclaim* 
> *disclaim* *disclaim*)


The unfortunate thing here is that because the thing is a DLL it cant
take any command line switches AFAIK - the OP would probably be better
off asking in comp.infosystems.www.servers.ms-windows about this though.

> 'nyway, you don't *have* to have taint checking enabled afaik. It is
> a very good idea for CGI scripts because it kicks you squarely in the
> direction of having to think about the data you're given, and catches
> (some) human errors. It can't (unfortunately) force you to ensure that
> the data is clean.  /^(.*)$/ will untaint your data, but its a *very*
> stupid thing to do.

Its not an absolutely stupid thing to do.  The nature of the data might
preclude using a regex to validate it, but you do need to use a regex
to detaint it - you use the naive regular expression to detaint then use
other program code to validate and sanitize the input.  As you say, one
has to think about the data and how it is going to be used in the program.

> Worse is if you say "I want to allow my Win32 users to upload files,
> they can have spaces, hyphens, letters and numbers, etc. in the file
> name" and your reg exp will then allow the 'filename' "rm -rf" ...
> 

There is nothing intrinsically wrong with having a filename 'rm -rf' :)
You might just want to be careful not to use it in a way that might
prove harmful though.  

> (Hey, P6 coders, wanna make (.*) not untaint?  

I'd rather it did, actually.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: Mon, 31 Jul 2000 08:45:37 GMT
From: rapapullo@my-deja.com
Subject: tricky regexp
Message-Id: <8m3ebh$fgr$1@nnrp1.deja.com>

Despite hours of pondering, I haven't reached an elegant (or even
working) regular expression to handle the following: given a string
that contains an arbitrary name encapsulated by underscores (eg
"lorem _ipsum_ dolor"), the substring "_ipsum_" would need to be
replaced by the value of the perl variable $ipsum ..ie the variable to
be used would be determined by the name in between the
underscores.
Any help would be oh-so-much appreciated!

Antti.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 31 Jul 2000 09:11:22 GMT
From: Tarjei Vassbotn <tarjei@onsite.no>
Subject: Re: tricky regexp
Message-Id: <398543EB.287ED58E@onsite.no>

> Despite hours of pondering, I haven't reached an elegant (or even
> working) regular expression to handle the following: given a string
> that contains an arbitrary name encapsulated by underscores (eg
> "lorem _ipsum_ dolor"), the substring "_ipsum_" would need to be
> replaced by the value of the perl variable $ipsum ..ie the variable to
> be used would be determined by the name in between the
> underscores.
> Any help would be oh-so-much appreciated!

This should do what you (apperantly) want;

my $text='lorem _ipsum_ dolor';
my $ipsum='REPLACED';
$text=~ s/_([^_]+)_/${$1}/g;
print $text; # prints 'lorem REPLACED dolor'

But note that strict is going to complain about it.
A more elegant solution would be to build a hash, and
use the found variable-name as the key, and the
value as the content;

my $text='lorem _ipsum_ dolor';
my %replacers=(ipsum => 'REPLACED');
$text=~ s/_([^_]+)_/$replacers{$1}/g;
print $text; # prints 'lorem REPLACED dolor'

- Tarjei


------------------------------

Date: Mon, 31 Jul 2000 12:23:55 +0300
From: Sasa Danicic <Sasa.Danicic@eurodyn.com>
Subject: Wraping data file with XML envelope
Message-Id: <398545AB.23532515@eurodyn.com>

I've need to wrap a binary file with a portion of XML-like code.
XML-like code is something so called "an envelope".

How can I wrap a binary file with an envelope, in fact how can I "glue"
or "concatenate" the envelope to the beginning of file ?

Type of file is not important: DOC, PDF, PostScript, JPG, HTML, ...

As opposite, in one moment I need to strip that enevelope from data/file
and process them separately.

Sasa


------------------------------

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 3854
**************************************


home help back first fref pref prev next nref lref last post