[26371] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8543 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 19 14:05:26 2005

Date: Wed, 19 Oct 2005 11:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 19 Oct 2005     Volume: 10 Number: 8543

Today's topics:
    Re: Record Output From System() <jurgenex@hotmail.com>
    Re: where is my text file? <tac@tac.ouch.co.uk>
    Re: where is my text file? <1usa@llenroc.ude.invalid>
    Re: why the perl docs suck (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Oct 2005 14:06:46 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Record Output From System()
Message-Id: <Wps5f.4705$t12.1731@trnddc03>

OttawaTrade wrote:
> I need a perl script to call another script. I current use
>
> system ("perl script2 ...");
>
> However, I need to take the output of the script2 and do regexp on it.
> Currently, it is just going to standout, and not returning to script1.
>
> Is there a way to solve this?

Why don't you just follow the advice given in the documentation of the 
function that you are using?
See third paragraph, fourth sentence of "perldoc -f system".

Or see the FAQ: "Why can't I get the output of a command with system()?"
Or just see DejaNews aka Google because this question is asked really 
frequently.

jue 




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

Date: Wed, 19 Oct 2005 14:33:57 +0100
From: "code_wrong" <tac@tac.ouch.co.uk>
Subject: Re: where is my text file?
Message-Id: <43564b35$1_4@mk-nntp-2.news.uk.tiscali.com>


"Eric Bohlman" <ebohlman@omsdev.com> wrote in message 
news:Xns96F44FC08CAA2ebohlmanomsdevcom@130.133.1.4...
> "code_wrong" <tac@tac.ouch.co.uk> wrote in
> news:43561be3$1_3@mk-nntp-2.news.uk.tiscali.com:
>
>>
>> "Tintin" <tintin@invalid.invalid> wrote in message
>> news:rfn5f.1402$S24.90630@news.xtra.co.nz...
>>> Throw that book away.  The code example is simply woeful.  You will
>>> be learning many, many bad habits if you follow the book.
>>>
>>> [horrible code snipped]
>>
>> how so?
>>
>> it does go on to demonstrate file locking and permissions ... although
>> .. since my host is running Windows IIS  .... I am not sure if I can
>> set file permissions
>
>> #!/usr/bin/perl
>
> No "use warnings" (or -w).
> No "use strict".
>
>> open(COUNT,"counter.txt");
>
> No check that the open succeeded.
> Assumption that the file is in the script's current working directory;
> where that is is extremely server-dependent.
>
>> $num = <COUNT>;
>
>> close(COUNT);
>
>> $num++;
>
> Up to this point, another instance of this script could also have read
> the same value from the file.
>
>> open(COUNT, ">counter.txt");
>
> No check that the open succeeded.
>
> At this point, the file is empty.  If another instance of the script
> comes along and tries to read it, its version of $num will be set to
> zero.
>
>> print COUNT $num;
>> close(COUNT);
>
> In the first scenario I mentioned, the count will have only gone up by
> one even though there were two accesses because both instances started
> with the same value.  In the second scenario, the count will be reset to
> 1 because the second instance read from an empty file.
>
>> $num=sprintf("%05d", $num);
>
>> print "content-type:text/html\n\n <html>";
>
> You've advertised that you're sending out HTML.
>
>> print "You are visitor number $num </html>";
>
> But what you've sent out isn't HTML (there's no <title>).

thanks this is useful stuff ....
I need to add error checking for file open
File locking for reading and writing
I know where the file is because I am choosing the path now:
open(COUNT,"<..\\private\\counter.txt");
and I need to print valid HTML
'use warnings' and 'use strict' I need to look into
cheers 




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

Date: Wed, 19 Oct 2005 17:09:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: where is my text file?
Message-Id: <Xns96F485F1E1238asu1cornelledu@127.0.0.1>

"code_wrong" <tac@tac.ouch.co.uk> wrote in news:43564b35$1_4@mk-nntp-
2.news.uk.tiscali.com:

> I know where the file is because I am choosing the path now:
> open(COUNT,"<..\\private\\counter.txt");

Wrong again on at least two counts:

1. The path you specify is still relative. There is no guarantee that 
the location to which it is relative will always be the same. You should 
specify an absolute path.

2. You still do not check if open succeeded.

3. Using lexical filehandles and the 3-argument form of open is 
preferable these days.

So, putting those together:


use strict;
use warnings;

use Readonly;
Readonly my $COUNTER_FILE => 'D:/wwwroot/private/counter.txt';

open my $count_fh, '<', $COUNTER_FILE
   or die "Cannot open $COUNTER_FILE: $!"; 

# etc

> 'use warnings' and 'use strict' I need to look into

They are not optional, especially at your level. Please read the posting 
guidelines.

Sinan
 
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 19 Oct 2005 14:26:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: why the perl docs suck
Message-Id: <dj5l1s$4s7$1@mamenchi.zrz.TU-Berlin.DE>

Fred@fred.net <Fred@fred.net> wrote in comp.lang.perl.misc:
> On Wed, 12 Oct 2005 21:19:44 -0500, Tad McClellan
> <tadmc@augustmail.com> wrote:
> 
> >Fred@fred.net <Fred@fred.net> wrote:
> >
> >> I was never welcome. 
> >
> >
> >Yes you were.
> >
> >Everybody is welcome here (until they do something socially unacceptable).
> >
> >
> >So, what was it that you did that got people mad that first time?
> 
> Were it that it was only once.
> Your good cop right?

I had to read that twice to understand that you mean "You're good cop, right?"
A quip, like a joke, must work at once or it doesn't work at all.  This
one has failed.

> I assert that people are not welcome here save for a set of procedures
> desribing the most tortured sets of considerations that one might
> never be able to ascertain for certain once and for all whether a
> given message should be even composed much less posted.

I had to read that three times, and it still doesn't really make sense.

If your purpose was to convince me you have clear and worthwhile thoughts
on the subject, you failed again.

If the purpose was to parody the Posting Guidelines, that fails too.
Its author is one who sacrifices originality for clarity, in Perl code
and in prose.  Convolution is carefully avoided in its style.

> So if ya call that welcome....

You can be sure your posting will be welcome if you follow plain common
sense.  As with all published text, the rule is:  Consider its purpose,
and consider its readers.  Apply the rule to the posting as a whole, and
to specific parts (Subject, code, quoted parts, etc).  If you do that (and
your purpose is benign, i.e. you're not a troll) your posting will be
welcome. That goes for all of Usenet, not just clpm.

The Posting Guidelines are for those whose posts fail to show that
consideration.  Obviously, they need to have the consequences spelled
out for them, that's why the document is long and has a lot of rules.
They are all corollaries of the one basic rule.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

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 V10 Issue 8543
***************************************


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