[18420] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 588 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 29 18:11:25 2001

Date: Thu, 29 Mar 2001 15:10:53 -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: <985907452-v10-i588@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 29 Mar 2001     Volume: 10 Number: 588

Today's topics:
        ePerl + mySQL  search, authentication, and update examp (Todd H.)
    Re: ePerl + mySQL  search, authentication, and update e <bcoon@sequenom.com>
    Re: external shell commands with perl script <Noatec@netscape.net>
    Re: fetch back STDERR outputs <rick.delaney@home.com>
    Re: fetch back STDERR outputs (Mark Jason Dominus)
    Re: fetch back STDERR outputs <johnlin@chttl.com.tw>
        file reading and writing <shino_korah@yahoo.com>
    Re: file reading and writing (Gwyn Judd)
    Re: file reading and writing (Logan Shaw)
    Re: file reading and writing <wyzelli@yahoo.com>
        Funny behavior? <bcoon@sequenom.com>
    Re: Help to Install Perl (Ben Okopnik)
    Re: help!! confuse problem about flow control. <lauren_smith13@hotmail.com>
    Re: help!! confuse problem about flow control. nobull@mail.com
    Re: help!! confuse problem about flow control. nobull@mail.com
    Re: How adding Hours & Days to current date? (MAC)
    Re: how do i delete already printed characters <crt@highvision.net>
    Re: How safe is Safe? (Andy Dougherty)
    Re: How safe is Safe? (Gwyn Judd)
        How to detect whether STDERR is duped to another file h <johnlin@chttl.com.tw>
    Re: How to search and replace certain word lines in a f <peb@bms.umist.ac.uk>
    Re: How to search and replace certain word lines in a f (Garry Williams)
    Re: How to search and replace certain word lines in a f (Tad McClellan)
    Re: How to search and replace certain word lines in a f <peb@bms.umist.ac.uk>
        How to search and replace certain word lines in a file  tvn007@hotmail.com
    Re: How to search and replace certain word lines in a f (Bernard El-Hagin)
    Re: How to search and replace certain word lines in a f (Logan Shaw)
    Re: Locking a file while a process on it nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 29 Mar 2001 15:59:03 -0600
From: comphelp@toddh.net (Todd H.)
Subject: ePerl + mySQL  search, authentication, and update examples?
Message-Id: <lyn1a4me3c.fsf@k2.onsight.com>


If this is not the appropriate group I'd appreciate any pointers to
relevant groups and/or mailing lists.

I'd like to create an address/contact database that allows an account
holder on a site to update their own contact information.  I'm using
ePerl and mySQL under Apache.  

Are there any relevant examples where I can find samples of how to do
        a) a record update
        b) authentication (cookies?) for an individual account holder?
        c) record search. 

I'd like an account holder to be able to view the names and photos of
other account holders, but only be able to update account info on
their own record, for instance. 

-- 
Todd H.
http://www.toddh.net/


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

Date: Thu, 29 Mar 2001 14:10:52 -0800
From: Bryan Coon <bcoon@sequenom.com>
Subject: Re: ePerl + mySQL  search, authentication, and update examples?
Message-Id: <3AC3B2EC.F1E749D4@sequenom.com>

"Todd H." wrote:

> If this is not the appropriate group I'd appreciate any pointers to
> relevant groups and/or mailing lists.
>
> I'd like to create an address/contact database that allows an account
> holder on a site to update their own contact information.  I'm using
> ePerl and mySQL under Apache.
>
> Are there any relevant examples where I can find samples of how to do
>         a) a record update
>         b) authentication (cookies?) for an individual account holder?
>         c) record search.
>
> I'd like an account holder to be able to view the names and photos of
> other account holders, but only be able to update account info on
> their own record, for instance.
>
> --
> Todd H.
> http://www.toddh.net/

These are pretty standard things, there are examples galore all around.
For the best howto though, I think the best place is to peek at the
documentation for the appropriate perl module documentation and mysql
faq.

Record updates and searches just use the appropriate sql query, the perl
DBI module is pretty much the standard (I think anyway) for this.  For
how to do mysql updates, get the MySQL book from new riders by Paul
Dubois, or you can subscribe to the mysql mailing list from the
www.mysql.com site.  Perl also has modules for authentication, hassle
free.

Good luck
Bryan



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

Date: Wed, 28 Mar 2001 22:18:13 -0600
From: The Noatec <Noatec@netscape.net>
Subject: Re: external shell commands with perl script
Message-Id: <3AC2B785.7E6EC7D@netscape.net>

Thanks Wy,

Your beer script is cool, you should put it in the shape of a bottle.

Wyzelli wrote:

> "The Noatec" <Noatec@netscape.net> wrote in message
> news:3AC2AA06.2A1471B@netscape.net...
> > Hello all,
> > Quick and simple question.
> > How would I execute a korn, or other shell command with a perl script.
> > I used it once and cannot find the script it is in or a reference in
> my
> > perl 5 book.
>
> perldoc -f system
> perldoc -f exec
>
> Wyzelli
> --
> ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
> it around');
> for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
> $_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";

--
The Noatec

"No problem can withstand the assault of sustained thinking"

Voltaire




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

Date: Thu, 29 Mar 2001 14:21:41 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: fetch back STDERR outputs
Message-Id: <3AC34836.BB261E6@home.com>

John Lin wrote:
> 
> <nobull> wrote
> > "John Lin" writes:
> > > open TOUCH,"+>zero-length.file" or die $!;
> > > Name "main::TOUCH" used only once: possible typo at line 1.
> >
> > If all you want is to suppress the "used once" I think I'd prefer:
> > use vars qw ( *TOUCH );
>
> I was just suspicious why won't you use our()...
> Today, I found our() can't be used here at all!!!
> 
> our *TOUCH;       # syntax error at line 1
> our(*TOUCH);      # Can't declare ref-to-glob cast in "our" at line 1
> our TOUCH;        # No such class TOUCH at line 1
> ...
> 
> What's going on?  The 'perldoc vars' says this 'use vars' pragma
> is obsolete and has been superseded by 'our' declarations...

The purpose of 'use vars' is to prevent 'use strict' from complaining
about unqualified package variables.  In this sense, it is obsolete
because 'our' can now fill that role.

It has never been necessary to declare typeglobs or filehandles since
'use strict' has never complained about them.  So there is nothing for 

    our(*TOUCH) 

to do.  I suppose it could DWIM to do

    our($TOUCH, @TOUCH, %TOUCH)

(which is pretty much what "use vars '*TOUCH'" does) but I'm not sure
how useful that would be.  If you only want to suppress the "used once"
warning then I'd suggest 'use warnings'.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 29 Mar 2001 15:23:19 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: fetch back STDERR outputs
Message-Id: <3ac35366.23ce$39d@news.op.net>
Keywords: Asher, Chartres, inundate, phyla


In article <3AC34836.BB261E6@home.com>,
Rick Delaney  <rick.delaney@home.com> wrote:
>The purpose of 'use vars' is to prevent 'use strict' from complaining
>about unqualified package variables.  In this sense, it is obsolete
>because 'our' can now fill that role.

That's not exactly true.  'use vars' has also been advertised as a way
to avoid 'only once' warnings.  The manual for 'vars' says:

       This will predeclare all the variables whose names are in the
       list . . . disabling any typo warnings.

But as you see, 'our' is not a suitable replacement for 'vars' when
you want to disable typo warnings for globs.  

You also cannot use it to declare fully-qualified names.  For example,
after

        use CGI ':standard';

        import_names('R');
        print "Hello, $R::name.\n";

you get an 'only once' warning, and our($R::name) does not work.  

This is considered to be a feature, for some reason I don't
understand.  See

        http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-05/msg00713.html
        
for more complete discussion.

>So there is nothing for 
>
>    our(*TOUCH) 
>
>to do.

I find it amazing that you could say this in response to an article of
John's which shows quite clearly that there *is* something for
our(*touch) to do.

The real problem here is of documentation.  What our() actually does
is create a lexical variable which is aliased to the corresponding
global variable.  When viewed in this light, it becomes clear why
our(*foo) can't work, and why our($x) allows use of the global
variable $x under 'strict':  You are not really using a global
variable at all, because $x has been made into a lexical variable. 

But 'our()' was advertised as a replacement for 'vars', which was
something of a mistake, and then people started saying that 'vars' was
obsolete, which is just wrong, since 'our' and 'vars' are not really
doing the same thing at all.

>If you only want to suppress the "used once"
>warning then I'd suggest 'use warnings'.

'use warnings' does not work properly in 5.6.0 with regard to 'only
once' warnings.  





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

Date: Thu, 29 Mar 2001 14:29:12 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: fetch back STDERR outputs
Message-Id: <99ukkj$8ov@netnews.hinet.net>

<nobull> wrote
> "John Lin" writes:
> > open TOUCH,"+>zero-length.file" or die $!;
> > Name "main::TOUCH" used only once: possible typo at line 1.
>
> If all you want is to suppress the "used once" I think I'd prefer:
> use vars qw ( *TOUCH );

I was just suspicious why won't you use our()...
Today, I found our() can't be used here at all!!!

our *TOUCH;       # syntax error at line 1
our(*TOUCH);      # Can't declare ref-to-glob cast in "our" at line 1
our TOUCH;        # No such class TOUCH at line 1
 ...

What's going on?  The 'perldoc vars' says this 'use vars' pragma
is obsolete and has been superseded by 'our' declarations...

Thank you.

John Lin





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

Date: Wed, 28 Mar 2001 19:44:37 -0800
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: file reading and writing
Message-Id: <99ub36$mo@news.or.intel.com>

Hi,


   I'm trying to read and write to a file
my file...
    john is apple
   george is orange
   u r grapes

I want to read this file and write back
     john is apple
     george is BANANA
    u r grapes
so I'm seraching the file for george and then how to write back at the same
point?
I tried seek tell etc?
how can I do this in an efficient way?

Thanks
Shino




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

Date: Thu, 29 Mar 2001 08:24:04 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: file reading and writing
Message-Id: <slrn9c5s92.o4s.tjla@thislove.dyndns.org>

I was shocked! How could Logan Shaw <logan@cs.utexas.edu>
say such a terrible thing:

>By using seek and tell and all that great stuff, you are saving one
>thing, which is memory.  If you have a 25 GB file, then using the seek
>and tell method is going to save you from having to read the whole
>thing into memory, which could be important.

How do you figure? I don't necessarily disagree with you, but how is
using seek and tell and so on going to use less memory than reading the
file in line by line and writing out the changed lines? Line by line
means you only need to store one line at a time. With seek and tell, if
the field you want to write out is longer (or shorter) than it
originally was, wont you have to move all of the other fields up or down
to compensate?

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Death cannot stop true love. It can only delay it for a while.
		-- Westley, "The Princess Bride"


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

Date: 29 Mar 2001 02:31:06 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: file reading and writing
Message-Id: <99ursa$k0s$1@boomer.cs.utexas.edu>

In article <slrn9c5s92.o4s.tjla@thislove.dyndns.org>,
Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>I was shocked! How could Logan Shaw <logan@cs.utexas.edu>
>say such a terrible thing:
>
>>By using seek and tell and all that great stuff, you are saving one
>>thing, which is memory.  If you have a 25 GB file, then using the seek
>>and tell method is going to save you from having to read the whole
>>thing into memory, which could be important.
>
>How do you figure? I don't necessarily disagree with you, but how is
>using seek and tell and so on going to use less memory than reading the
>file in line by line and writing out the changed lines?  Line by line
>means you only need to store one line at a time. With seek and tell, if
>the field you want to write out is longer (or shorter) than it
>originally was, wont you have to move all of the other fields up or down
>to compensate?

Sorry, I was assuming that in both cases no temporary file will be
used.  (That was what the original posted seemed to be looking for, as
I read it.)  The traditional Perl way of doing it without a temporary
file is something like this:

	open (FOO, "foo") or die;
	@lines = <FOO>;
	close FOO;

	twiddle (\@lines);

	open (FOO, ">foo") or die;
	print FOO @lines;
	close FOO;

And in fact, if you read the entire file in order and you don't use a
temporary file, you have to store the whole file in memory.

On the other hand, changing the layout of the file with seek() and
stuff, while painful, doesn't require more than one byte of data from
the file to be in memory at any given time.  (Of course, to make this
happen, you have to be careful about what *order* to read and write
those bytes, but it's definitely possible.)

  - Logan
-- 
whose?  my  your   his  her   our   their   _its_
who's?  I'm you're he's she's we're they're _it's_


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

Date: Thu, 29 Mar 2001 13:50:27 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: file reading and writing
Message-Id: <qxyw6.23$US1.4946@vic.nntp.telstra.net>

"terminalsplash" <shino_korah@yahoo.com> wrote in message
news:99ub36$mo@news.or.intel.com...
> Hi,
>
>
>    I'm trying to read and write to a file
> my file...
>     john is apple
>    george is orange
>    u r grapes
>
> I want to read this file and write back
>      john is apple
>      george is BANANA
>     u r grapes
> so I'm seraching the file for george and then how to write back at the
same
> point?
> I tried seek tell etc?
> how can I do this in an efficient way?
>

You should read PerlFAQ 5

How do I change one line in a file/delete a line in a file/insert a line
in the middle of a file/append to the beginning of a file?

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Thu, 29 Mar 2001 14:03:36 -0800
From: Bryan Coon <bcoon@sequenom.com>
Subject: Funny behavior?
Message-Id: <3AC3B138.A0DA485D@sequenom.com>

If I do this:

my $test = <<END
  Some garbage in here, blah, blah
END

No problem.  However if I do this:
sub foo {
  my $test = <<END
    Some garbage in here, blah, blah
  END
}

It fails.  The indention of the END tweaks things.  Not a big deal, but
it sure looks funny style-wise when it is buried in a sub, a for loop,
and maybe an if statement.

Does the end have to be without preceding spaces?  Is this normal, or am
I using this wrong?  By the way *ahem* what is that called?  The
<<END...END stuff?

Thanks!




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

Date: 29 Mar 2001 04:45:49 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: Help to Install Perl
Message-Id: <slrn9c5fjf.lvd.ben-fuzzybear@Odin.Thor>

The ancient archives of Fri, 16 Mar 2001 09:05:21 GMT showed
Uri Guttman of comp.lang.perl.misc speaking thus:
>>>>>> "SRG" == Scott R Godin <webmaster@webdragon.munge.net> writes:
>
>  SRG> | for(reverse (0..99)){($a,$b,$c)=(' bottles of beer',' on the
>  SRG> wall', | 'Take one down, pass it around');$a=~s/s//
>  SRG> if/1/;print"$_$a$b\n\n" |
>  SRG> unless/99/;print"$_$a$b\n$_$a\n$c\n"unless/0/;}print"*hic*\n"
>
>  SRG> ROFL, and the sig was SO apropos too :D
>
>about 2 years ago, we had a golf thread on printing out that song. there
>is a web site devoted to ways of printing that song in as many computer
>languages as possible. the perl entry stunk so we worked at making it
>much better/shorter.
>
>here was one. i don't have the author's name.
>
>$_=shift||99;$b='"$_ bottle$s[$_==1] of beer"';$w=' on the wall';@s='s';print
>eval$b,"$w, ",eval$b,"!\nTake one down, pass it around,\n",eval'$_--;'.$b,$w,
>"!\n\n"while$_


<Happy laugh> I don't believe it. Mine is shorter!

Is there anything wrong with it, or is this the new Perl submission?


Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
for(reverse 0..99){($a,$b)=(' bottles of beer',' on the wall');
$a=~y/s//dif/1/;print"$_$a$b\n\n"if!/99/;print"$_$a$b\n$_$a
Take one down, pass it around\n"if!/0/;}


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

Date: Thu, 29 Mar 2001 07:21:35 GMT
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: help!! confuse problem about flow control.
Message-Id: <3oBw6.3062$0H2.551379@dfiatx1-snr1.gtei.net>


"sky" <tbsky.bbs@openbazaar.net> wrote in message
news:3fYD7F$Wf_@openbazaar.net...
> Hello!
>  if i have this line :
>       open(FILE,"/tmp/a") or die ;
>
>  and i want to replace "die" to 2 commands
>
>       print STDERR "can not open";exit(1)

Why don't you just do a

open FILE, "/tmp/a" or die "/tmp/a: $!";

The die is designed to write to STDERR.

>       if i wirte
>       open(FILE,"/tmp/a") or (print STDERR "can not open" ; exit(1));
>
>       is is wrong syntax

Use brackets instead of parens.

open (FILE, "/tmp/a") or {print STDERR "can not open"; exit (1);}

>
>       how can i write more commands instead of "die" in one line ??
>       thanks for ur help !!!

Use brackets to define blocks.

Lauren





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

Date: 29 Mar 2001 08:41:38 +0100
From: nobull@mail.com
Subject: Re: help!! confuse problem about flow control.
Message-Id: <u9oful3qdj.fsf@wcl-l.bham.ac.uk>

tbsky.bbs@openbazaar.net (sky) writes:

>       open(FILE,"/tmp/a") or die ;
> 
>  and i want to replace "die" to 2 commands
> 
>       print STDERR "can not open";exit(1)
> 
> 
>       i write
>       open(FILE,"/tmp/a") or (print STDERR "can not open" and exit(1));
> 
>       but it is not good, BC4 exit(1) must depend on "print STDERR" success
> 
>       if i wirte
>       open(FILE,"/tmp/a") or (print STDERR "can not open" ; exit(1));
> 
>       is is wrong syntax
> 
>       how can i write more commands instead of "die" in one line ??

Linebreaks in Perl are not (in most contexts) syntactically
significant - they just aid readability.  Personally I'd probably put
some in if I were to use any of the following:

  open(FILE,"/tmp/a") or ((print STDERR "can not open"), exit(1));

  open(FILE,"/tmp/a") or do { print STDERR "can not open"; exit(1); };

  unless( open(FILE,"/tmp/a") ) { print STDERR "can not open"; exit(1); }
  
-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 29 Mar 2001 12:17:03 +0100
From: nobull@mail.com
Subject: Re: help!! confuse problem about flow control.
Message-Id: <u9hf0c4yfk.fsf@wcl-l.bham.ac.uk>

"Lauren Smith" <lauren_smith13@hotmail.com> writes carelessly:

> "sky" <tbsky.bbs@openbazaar.net> wrote in message
> news:3fYD7F$Wf_@openbazaar.net...
> >       open(FILE,"/tmp/a") or (print STDERR "can not open" ; exit(1));
> >
> >       is is wrong syntax
> 
> Use brackets instead of parens.

And insert 'do'.
 
> open (FILE, "/tmp/a") or {print STDERR "can not open"; exit (1);}

Does not compile.

> >       how can i write more commands instead of "die" in one line ??
> 
> Use brackets to define blocks.

And use 'do' to put a BLOCK in a context where an EXPR is expected.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 29 Mar 2001 02:37:08 GMT
From: macv@multiweb.nl (MAC)
Subject: Re: How adding Hours & Days to current date?
Message-Id: <odxw6.16865$t9.1674779@news.soneraplaza.nl>

Arek@nospam.tv (Arek P) wrote in <99o2f9$2e9i$1@earth.superlink.net>:


>Try this;
>
>$hr=60*60;      #60 second * 60 minutes in an hour
>$day=$hr*24;     #see the logic?
>
>so to add 2 days and 5 hours to right now would be ;
>
>my $future=time() + 2*$day + 5* $hr ;
>
>U may want to read about time and localtime....

I got it, and checked it....... this is my conclusion:

Why all the fuss in adding thos date modules, cause by simply adding the 
number to the date and calling localtime, this function returns a valid 
date !!

Thnks everyone... could not do without your help !


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

Date: Wed, 28 Mar 2001 21:08:04 -0500
From: Casey West <crt@highvision.net>
Subject: Re: how do i delete already printed characters
Message-Id: <Pine.OSF.4.21.0103282107140.15534-100000@home.kiski.net>

Today around 10:58pm, Eric hammered out this masterpiece:

: How do i delete already printed characters?
: Like if u do this
: 
: print "Status: Loading...\n";
: print "Now doing something else...\n";
: 
: it prints like this
: 
: Status Loading...
: Now doing something else...
: 
: but can i not delete the first line so that when i print "Now doing
: something else..."
: it replaces the first line "Status: Loading..."

Use C<\b>.  Example:

foreach ( qw( Hello There Young Fellow ) ) {
  print $_;
  sleep 2;
  print "\b" x length($_);
}
print "\n";


-- 
Casey West



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

Date: Thu, 29 Mar 2001 15:14:34 -0000
From: doughera@maxwell.phys.lafayette.edu (Andy Dougherty)
Subject: Re: How safe is Safe?
Message-Id: <slrn9c6kda.rla.doughera@maxwell.phys.lafayette.edu>

In article <m3r8zi814c.fsf@alum.mit.edu>, David Bakhash wrote:

>problem is that when I tried to download the Safe.pm module, I found
>that the only way I could get it was to download a complete Perl
>distribution and then pull it out of there; it wasn't like installing
>other modules.

You shouldn't have to download anything.  Safe is part of the standard
Perl install, at least for recent versions.  It should already be
installed.

-- 
    Andy Dougherty		doughera@lafayette.edu
    Dept. of Physics
    Lafayette College, Easton PA 18042


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

Date: Thu, 29 Mar 2001 08:55:26 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: How safe is Safe?
Message-Id: <slrn9c5u3r.o4s.tjla@thislove.dyndns.org>

I was shocked! How could David Bakhash <cadet@alum.mit.edu>
say such a terrible thing:

>Beyond installation difficulties, I'd like to know if someone has used 
>Safe.pm to do anything even remotely similar to what I want to use
>Safe.pm for, which is simply to create an environment for evaluating
>arithmetic Perl code, with a few functions, and variables
>pre-defined.  Denial of service attacks are always an issue, but
>
>Has anyone used Safe.pm for something similar to me?  Anyone willing

hmm. well if all you want to do is arithmetic and a few other functions,
why not write your own Perl parser in Perl? That way you can control
exactly what is done. Additionally you don't have to worry about
installing Safe. Look into eg. Parse::RecDescent and Parse::Yapp.
Shouldn't be too difficult, *if* you limit the sorts of expressions that
will be allowed.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
A tutor who tooted a flute
Tried to tutor two tutors to toot
	Said the two to the tutor:
	"Is it harder to toot or
To tutor two tutors to toot"


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

Date: Thu, 29 Mar 2001 14:58:32 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: How to detect whether STDERR is duped to another file handle
Message-Id: <99umbi$c1a@netnews.hinet.net>

Dear all,

In the following program

open LOG,">>logfile" or die $!;
open STDERR,">>&LOG" or warn "can't dup STDERR\n";
if(fileno(STDERR) == fileno(LOG)) { print "Yes" } else { print "No" }
print ": STDERR = ",fileno(STDERR),", LOG = ",fileno(LOG),"\n";

__END__
No: STDERR = 2, LOG = 3    (The same result for ">>=&LOG")

I know I can't use

if(fileno(STDERR) == fileno(LOG))

to detect whether STDERR is duped to LOG or not.
Then, what should I use?

Thank you.

John Lin





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

Date: Thu, 29 Mar 2001 13:45:34 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: How to search and replace certain word lines in a file without a   temp. file
Message-Id: <3AC32E6E.B270AD85@bms.umist.ac.uk>


> > how about using a one liner?
> >
> > perl -npi -e 's/foo/bar/' <filename>
>         ^
>         ^
> Lose the -n option.  It's superfluous.

oops.

> > 'perldoc perlrun' to findout more
> 
> Indeed.

hmm... no need to be sarky, it was just a quick suggestion.

Paul


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

Date: Thu, 29 Mar 2001 12:36:51 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: How to search and replace certain word lines in a file without a  temp. file
Message-Id: <slrn9c6b33.fl2.garry@zfw.zvolve.net>

On Thu, 29 Mar 2001 09:22:14 +0100, Paul Boardman
<peb@bms.umist.ac.uk> wrote:

> tvn007@hotmail.com wrote:
>> 
>> Could someone help me ?
>> 
>> I need to search in a file for certain word. Once I find
>> that word I need to replace it with something else.
>> I would like to do this without a temporary file.
> 
> how about using a one liner?
> 
> perl -npi -e 's/foo/bar/' <filename>
        ^
        ^
Lose the -n option.  It's superfluous.  

> 'perldoc perlrun' to findout more

Indeed.  

-- 
Garry Williams


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

Date: Thu, 29 Mar 2001 07:05:40 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to search and replace certain word lines in a file without a  temp. file
Message-Id: <slrn9c698k.la5.tadmc@tadmc26.august.net>

Paul Boardman <peb@bms.umist.ac.uk> wrote:
>tvn007@hotmail.com wrote:

[ snip search and replace ]

>how about using a one liner?
>
>perl -npi -e 's/foo/bar/' <filename>
       ^
       ^
That switch is not necessary.


>'perldoc perlrun' to findout more


'perldoc perlrun' to findout why.

:-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 29 Mar 2001 09:22:14 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: How to search and replace certain word lines in a file without a  temp. file
Message-Id: <3AC2F0B6.BBA267DE@bms.umist.ac.uk>

tvn007@hotmail.com wrote:
> 
> Hi,
> 
> Could someone help me ?
> 
> I need to search in a file for certain word. Once I find
> that word I need to replace it with something else.
> I would like to do this without a temporary file.

how about using a one liner?

perl -npi -e 's/foo/bar/' <filename>

Paul

p.s.

'perldoc perlrun' to findout more


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

Date: Thu, 29 Mar 2001 06:24:41 GMT
From: tvn007@hotmail.com
Subject: How to search and replace certain word lines in a file without a temp. file
Message-Id: <JyAw6.141851$47.2080007@news.bc.tac.net>


Hi,

Could someone help me ?

I need to search in a file for certain word. Once I find
that word I need to replace it with something else. 
I would like to do this without a temporary file.

Thanks




==================================
Posted via http://nodevice.com
Linux Programmer's Site


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

Date: Thu, 29 Mar 2001 09:31:04 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: How to search and replace certain word lines in a file without a temp. file
Message-Id: <slrn9c604n.21k.bernard.el-hagin@gdndev32.lido-tech>

On 29 Mar 2001 01:21:19 -0600, Logan Shaw <logan@cs.utexas.edu> wrote:
>In article <slrn9c5lpe.13u.bernard.el-hagin@gdndev32.lido-tech>,
>Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
>>On Thu, 29 Mar 2001 06:24:41 GMT, tvn007@hotmail.com
>><tvn007@hotmail.com> wrote:
>>>I need to search in a file for certain word. Once I find
>>>that word I need to replace it with something else. 
>>>I would like to do this without a temporary file.
>>
>>For the search and replace read about s/// in perldoc perlop and for the
>>in-place editing of the file read about the -i switch in perldoc perlrun.
>
>"-i" doesn't actually edit a file in place.  It just creates a
>temporary file behind the scenes so that you don't have to worry about
>it.  At least, not until you run out of disk space.

I assumed (I believe correctly) that if someone needs to ask this
question then that someone wants to do exactly what -i does, but not by
hand. Hence my reply. :-)

Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'


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

Date: 29 Mar 2001 01:21:19 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: How to search and replace certain word lines in a file without a temp. file
Message-Id: <99unpf$jee$1@boomer.cs.utexas.edu>

In article <slrn9c5lpe.13u.bernard.el-hagin@gdndev32.lido-tech>,
Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
>On Thu, 29 Mar 2001 06:24:41 GMT, tvn007@hotmail.com
><tvn007@hotmail.com> wrote:
>>I need to search in a file for certain word. Once I find
>>that word I need to replace it with something else. 
>>I would like to do this without a temporary file.
>
>For the search and replace read about s/// in perldoc perlop and for the
>in-place editing of the file read about the -i switch in perldoc perlrun.

"-i" doesn't actually edit a file in place.  It just creates a
temporary file behind the scenes so that you don't have to worry about
it.  At least, not until you run out of disk space.

  - Logan
-- 
whose?  my  your   his  her   our   their   _its_
who's?  I'm you're he's she's we're they're _it's_


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

Date: 29 Mar 2001 18:09:06 +0100
From: nobull@mail.com
Subject: Re: Locking a file while a process on it
Message-Id: <u9u24c33kd.fsf@wcl-l.bham.ac.uk>

"Etienne Laverdiere" <etienno@sympatico.ca> insults us by asking:

[ FAQ: "I still don't get locking.  I just want to increment the
number in the file.  How can I do this?" ]

You are expected to read the FAQ _before_ you post.

> 2- Does Unix manage well those locker on a file... making a good queue of
> process?

I think most operating systems including most Unix implementations
queue lock requests.  However I'm fairly sure an OS can be called Unix
even if it doesn't.  ISTR that early versions of Linux (strictly
"Unix-like", not "Unix") did not.

This, of course, has nothing to do with Perl.

-- 
     \\   ( )
  .  _\\__[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 V10 Issue 588
**************************************


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