[18218] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 386 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 1 09:11:27 2001

Date: Thu, 1 Mar 2001 06:10:17 -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: <983455817-v10-i386@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 1 Mar 2001     Volume: 10 Number: 386

Today's topics:
        regex substitution <tfiedler@zen.moldsandwich.com>
    Re: regex substitution <wyzelli@yahoo.com>
    Re: regex substitution (Gwyn Judd)
    Re: regex substitution (Abigail)
    Re: regex substitution <krahnj@acm.org>
    Re: regex substitution <gtoomey@usa.net>
    Re: shell environement variables (Edouard MERCIER)
    Re: shell environement variables (Edouard Mercier)
    Re: shell environement variables <monojohnny@yahoo.com>
    Re: shell environement variables <crowj@aol.com>
        skeleton to read arrays in xs? <ivo.nospam@yale.edu>
    Re: Sorting by date <sorryno@email.at.all>
        what's wrong with my byacc? <jck1@seed.net.tw>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 01 Mar 2001 11:15:39 GMT
From: Ted Fiedler <tfiedler@zen.moldsandwich.com>
Subject: regex substitution
Message-Id: <Pine.LNX.4.21.0103010614510.10873-100000@zen.moldsandwich.com>

why wont this work? 

#!/usr/bin/perl -w

use strict;

my ($info);
open (WEATHERFILE, "+<weather.dat")
                        || die "cannot open weather.dat\n";
while (<WEATHERFILE>) {
        $info =~ (s/-//);
        print $info;
}
close WEATHERFILE;

all i am trying t do is remove a bunch of dashes (-) from lines in a
file.


thanks in advance

Ted



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

Date: Thu, 1 Mar 2001 20:51:10 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: regex substitution
Message-Id: <Agqn6.4$UL1.1647@vic.nntp.telstra.net>

"Ted Fiedler" <tfiedler@zen.moldsandwich.com> wrote in message
news:Pine.LNX.4.21.0103010614510.10873-100000@zen.moldsandwich.com...
> why wont this work?
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my ($info);
> open (WEATHERFILE, "+<weather.dat")
>                         || die "cannot open weather.dat\n";
> while (<WEATHERFILE>) {

You don't assign the line read to $info, so it goes into $_

>         $info =~ (s/-//);

either change the above to :

while ($info = <WEATHERFILE>){

or make the substitution line simply :

s/-//g;  (the g is required only if you want to remove more than one - pre
line, which is possibly implied by your statement below.

>         print $info;

If you make the second change above, you then just need :

print; # prints $_ by default

> }
> close WEATHERFILE;
>
> all i am trying t do is remove a bunch of dashes (-) from lines in a
> file.
>

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Thu, 01 Mar 2001 11:21:41 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: regex substitution
Message-Id: <slrn99scgi.1ff.tjla@thislove.dyndns.org>

I was shocked! How could Ted Fiedler <tfiedler@zen.moldsandwich.com>
say such a terrible thing:
>why wont this work? 

You never assign to $info. Also you possibly want to use the /g modifier
on the regex.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Some husbands are living proof that a woman can take a joke.


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

Date: 1 Mar 2001 11:57:03 GMT
From: abigail@foad.org (Abigail)
Subject: Re: regex substitution
Message-Id: <slrn99se8f.eh.abigail@tsathoggua.rlyeh.net>

Ted Fiedler (tfiedler@zen.moldsandwich.com) wrote on MMDCCXXXIX September
MCMXCIII in <URL:news:Pine.LNX.4.21.0103010614510.10873-100000@zen.moldsandwich.com>:
^^ why wont this work? 
^^ 
^^ #!/usr/bin/perl -w
^^ 
^^ use strict;
^^ 
^^ my ($info);
^^ open (WEATHERFILE, "+<weather.dat")
^^                         || die "cannot open weather.dat\n";
^^ while (<WEATHERFILE>) {
^^         $info =~ (s/-//);
^^         print $info;
^^ }
^^ close WEATHERFILE;
^^ 
^^ all i am trying t do is remove a bunch of dashes (-) from lines in a
^^ file.


Because you are printing to STDOUT. Not that printing to WEATHERINFO
would help you here.


But try the following magic:

    perl -wi- -pey:-::d weather.dat


Abigail
-- 
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");


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

Date: Thu, 01 Mar 2001 12:03:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regex substitution
Message-Id: <3A9E3BEE.E1410584@acm.org>

Ted Fiedler wrote:
> 
> why wont this work?
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my ($info);
> open (WEATHERFILE, "+<weather.dat")
                      ^^
Are you writing to as well as reading from the file?

>                         || die "cannot open weather.dat\n";
> while (<WEATHERFILE>) {
>         $info =~ (s/-//);
>         print $info;

$info contains no data.

while ( <WEATHERFILE> ) {
        tr/-//d;
        print;

# OR

while ( defined( $info = <WEATHERFILE> ) ) {
        $info =~ tr/-//d;
        print $info;

> }
> close WEATHERFILE;
> 
> all i am trying t do is remove a bunch of dashes (-) from lines in a
> file.


John


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

Date: Thu, 1 Mar 2001 23:51:25 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: regex substitution
Message-Id: <yfsn6.6176$v5.22334@newsfeeds.bigpond.com>

You have the BEST signatures.

Do you have a Ph.D. in regular exressions??
gtoomey
-------------------
"Abigail" <abigail@foad.org> wrote in message
news:slrn99se8f.eh.abigail@tsathoggua.rlyeh.net...
> Ted Fiedler (tfiedler@zen.moldsandwich.com) wrote on MMDCCXXXIX September
> MCMXCIII in
<URL:news:Pine.LNX.4.21.0103010614510.10873-100000@zen.moldsandwich.com>:
> ^^ why wont this work?
> ^^
> ^^ #!/usr/bin/perl -w
> ^^
> ^^ use strict;
> ^^
> ^^ my ($info);
> ^^ open (WEATHERFILE, "+<weather.dat")
> ^^                         || die "cannot open weather.dat\n";
> ^^ while (<WEATHERFILE>) {
> ^^         $info =~ (s/-//);
> ^^         print $info;
> ^^ }
> ^^ close WEATHERFILE;
> ^^
> ^^ all i am trying t do is remove a bunch of dashes (-) from lines in a
> ^^ file.
>
>
> Because you are printing to STDOUT. Not that printing to WEATHERINFO
> would help you here.
>
>
> But try the following magic:
>
>     perl -wi- -pey:-::d weather.dat
>
>
> Abigail
> --
> sub camel
(^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
> h[{e
**###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
>
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@
#@);
> print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.|
|d)&&$llama."\n");




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

Date: Thu, 1 Mar 2001 11:17:49 +0000 (UTC)
From: emerciern@et2s.com (Edouard MERCIER)
Subject: Re: shell environement variables
Message-Id: <Xns90577D170FC0Eemerciernet2scom@202.81.252.27>

first of all, thanks a lot to everybody;

Some additional information concerning the previous problem:
1. I really need to use environment variable since I'm running an ORB 
(CORBA) whith the Implementation Repository, a kind of deamond which 
automatically lanches processes on demand. Some processes need environment 
to work reasonably well.
2. the well articulated question was: how to write a UNIX-universal script 
that sets environment variables, in a given sehell-session, without 
creating a new one ?
3. I like the idea of having a single file to maintain but I prefer not 
writing a single PERL script with lots of "($ENV{"SHELL"} eq "sh")" 
branching tests, tedious and imposing me to know precisely the different 
shell grammars. Besides, my little PERL script already proposes through a 
over-layer of shell.
4. I appreciate very much the grammar parsing proposed, writen in shell, 
but I'm pretty sure this is going to take me a long time to understand it, 
and if, in the future, I use shell commands not recognized by the 
parser.... A bit dangereous. Moreover, there must already be something on 
the web (where ?) which performs that parsing and re-translation.

I would like to make things clear concerning what I understood from you 
answers:

1. it is not possible under UNIX to export the environment variable from a 
shell-session into its parent. Besides, this is not the philosophy of UNIX
2. a remark : it seems that the "source" shell command - which is fully C-
shell available - does only execute shell scripts, even if it allows to 
execute that script in the same shell-session that the one which invokes it 
! The corresponding pure shell command is "."
3. unfortunately, the "eval" shell command - which is shell universal - 
does execute a shell script in another shell-session
4. it does not cost much to stack a shell session upon another. As you 
mention, the RAM memory used by the newly stacked shell session may be 
swapped. 

Thanks to you, I've made up my mind clearly. I now give my solution.

1. I still use a PERL script, named my_perl_script.pl, I explain why
2. I use only PERL command, ie. no "system" call, except at the end of the 
script, where I invoke the PERL command "system($ENV{\"SHELL\"})" or even 
system($ENV{\"SHELL\"} -f)" if I do not wnat to execute the .login nor the 
 .cshrc scripts, so as to launch the same kind of shell-session as the one 
invoking ther PERL script. Inside this script, I masively use the %ENV PERL 
hash variable, which enables me to set very gently my environment variables
3. I finally execute my PERL script via the UNIX-universal "exec 
my_perl_script.pl", which prevents me from stacking a new shell-session, 
and which delivers me a shell-session recovering the old one and inheriting 
its environement variables
4. OK then, it stacks a new my_perl_script.pl process, but I prefer it 
because it sounds more familiar and reminds me that my environment 
variables are correctly set
5. before, I used to develop a PERL script which generated various-shell 
scripts, I no longer thanks the only use of the %ENV PERL has variable. 
It's really worth.

I hope that I was clear enough.
If you have something better, feel free to communicate.
If anyone is interested, I publish the PERL script... 

Edouard MERCIER
---
Posted via freenews.netfront.net
Complaints to news@netfront.net


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

Date: Thu, 1 Mar 2001 12:31:56 +0000 (UTC)
From: emercier@net2s.com (Edouard Mercier)
Subject: Re: shell environement variables
Message-Id: <Xns905789A895473emerciernet2scom@202.81.252.27>

abigail@foad.org (Abigail) wrote in
<slrn99sffj.eh.abigail@tsathoggua.rlyeh.net>: 
>Why not:
>
>    exec $ENV {SHELL};
>
>which solves point 4 mentioned below?
>
>++ 4. OK then, it stacks a new my_perl_script.pl process, but I prefer
>it ++ because it sounds more familiar and reminds me that my environment
>++ variables are correctly set
>Abigail
>

You're totally right ! In this case, the PERL script end command becomes
"system("exec $ENV{\"SHELL\")")" and the PERL script should be simply 
invoked through : "my_perl_script.pl".

Thanks for this usefull comment, this time ;-)

Edouard
---
Posted via freenews.netfront.net
Complaints to news@netfront.net


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

Date: Thu, 1 Mar 2001 12:38:05 -0000
From: "John Pritchard-Williams" <monojohnny@yahoo.com>
Subject: Re: shell environement variables
Message-Id: <rmrn6.90424$Dd3.1452224@monolith.news.easynet.net>

Also note that in /bin/sh and /bin/ksh (and presumably variants) you can run
a script within the same process using the '.' 'command' - (ie it's
equivalent of the csh 'source'):

eg)
Contents of script 'setvars.sh':

variable1=value1
variable2=value2
 ...

To read in these values from shell command prompt:
(which would need also to be /bin/sh or /bin/ksh)

 . setvars.sh

Cheers
John



Gregory Toomey <gtoomey@usa.net> wrote in message
news:y5on6.5944$v5.21691@newsfeeds.bigpond.com...
> This is not really Perl related but ...
>
> You can't export environment variables to a perent process!!
> There is a linux command called "source" which runs a script as part of
the
> current process
> and does not invoke a new shell.
>
> The linux "bash" man page says the following about source:
> "  Read and execute commands from filename in the current  shell
> environment and
>  return the exit status  of the last command  executed  from  filename."
>
> Why do you need environment variables anyway?
> Could you use files as you interprocess communication mechanism?
>
> gtoomey
>
> -------------------
> "Edouard MERCIER" <emercier@net2s.com> wrote in message
> news:Xns905764C2D67F9emerciernet2scom@202.81.252.27...
> > Hi to everyone;
> >
> > So many times I thought into myself "this is a stupid and simple
> question".
> > And yet, I've been wandering throughout the web, just in vane: I
could'nt
> > find an answer. Here is my problem.
> >
> > I wrote a C-shell script which works fine. I had to migrate it into a
pure
> > shell script: I did that "by hand". But now, I have to maintain both of
> > them. And I'm seek and tired of doing stupid things like that.
> >
> > The aim of this shell script is just to set some environment variables,
> > depending on their former state (basically, I just use setenv/export and
> > some if/then/else procedures).
> >
> > I've performed some kind of inquiry, and I eventually came to learn PERL
> > and to write a script which set my environment variables. PERL is
supposed
> > to be supported on all shells, so fine !
> >
> > The problem is that a PERL-script always run under a new shell-session,
so
> > that all the environment variables set in this PERL-script are lost for
> the
> > parent shell-session that invoked it. According to what I understood
from
> > the UNIX philosophy, it is not directly possible to "export" the
> > environment variables set in a shell-session into its parent
> shell-session.
> >
> > My problem is the following: I would like to export environment variable
> > set in a shell-session into its parent shell-session !!!
> >
> > So as to work around things, I added the invocation of a new shell at
the
> > end of my PERL-script, so that I get a shell-session with all my new
> > environement variables. Not very nice, since I have two shells stacked
> > instead of a single one.
> >
> > I eventually modified my PERL-script so that it generates my C-
> > shell/tcsh/sh/bash... script according to the $SHELL - though I'm pretty
> > sure that there is already something which does the stuf right... This
> > work, but I eventually wrote a kind of new syntax, a layer above shell-
> > scripts. I'm not satisfied at all with my work.
> >
> > This is why I come to you.
> > Thanks a lot for your attention.
> > I would appreciate a lot a piece of answer.
> >
> > Edouard MERCIER
> > ---
> > Posted via freenews.netfront.net
> > Complaints to news@netfront.net
>
>




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

Date: Thu, 01 Mar 2001 08:35:59 -0500
From: John Crowley <crowj@aol.com>
Subject: Re: shell environement variables
Message-Id: <3A9E503F.7CA3343B@aol.com>

> The aim of this shell script is just to set some environment variables,
> depending on their former state (basically, I just use setenv/export and
> some if/then/else procedures).
> 
> I've performed some kind of inquiry, and I eventually came to learn PERL
> and to write a script which set my environment variables. PERL is supposed
> to be supported on all shells, so fine !
> 
> The problem is that a PERL-script always run under a new shell-session, so
> that all the environment variables set in this PERL-script are lost for the
> parent shell-session that invoked it. According to what I understood from
> the UNIX philosophy, it is not directly possible to "export" the
> environment variables set in a shell-session into its parent shell-session.
> 
> My problem is the following: I would like to export environment variable
> set in a shell-session into its parent shell-session !!!
> 
> So as to work around things, I added the invocation of a new shell at the
> end of my PERL-script, so that I get a shell-session with all my new
> environement variables. Not very nice, since I have two shells stacked
> instead of a single one.
> 
> I eventually modified my PERL-script so that it generates my C-
> shell/tcsh/sh/bash... script according to the $SHELL - though I'm pretty
> sure that there is already something which does the stuf right... This
> work, but I eventually wrote a kind of new syntax, a layer above shell-
> scripts. I'm not satisfied at all with my work.
> 

why not have a configuration file of name-value pairs that you can
load into whatever application and set values as the language or
application needs?

for example, foobar.ini contains:
foo=bar
bar=foo

in ksh:
  #!/bin/ksh -p

  while IFS= read line;  do
    eval export $line
    print $line
  done < x.ini

  env

would read each line of the config file and make env variables.

in perl you could load it into a hash, or with C into a linked list
or whatever is required.


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

Date: Thu, 01 Mar 2001 07:57:02 -0500
From: ivo welch <ivo.nospam@yale.edu>
Subject: skeleton to read arrays in xs?
Message-Id: <3A9E471E.E44105C1@yale.edu>


linux:

would anyone have a skeleton program that interfaces to

    my @floatarrayout = callCfunction(\@floatarrayin1, \@floatarrayin2);

and/or
    my %floathashout = callCfunction(\@floatarrayin1, \@floatarrayin2);

It would be even better if it could accept an arbitrary number of
arrays...

/iaw




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

Date: Thu, 1 Mar 2001 11:24:12 -0000
From: "Brian J" <sorryno@email.at.all>
Subject: Re: Sorting by date
Message-Id: <3a9e316b_2@news2.uncensored-news.com>


"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3A9E2284.DBF65EC5@stomp.stomp.tokyo...
> Brian J wrote:

> > Anno Siegel wrote:
> > > Brian J wrote:
> > I see, I have tested the forum with false dates and you are correct,
the
> > order gets messed up at precisely 02:46am on the 9th of September
this
> > year.  I have however fixed the problem by appending a 0 to the
> > beginning of the last modified time if it has less than 10
characters.
>
>
> September 9 2001 at 01:46:40 hours


Oh yes, I forgot about daylight savings time.

--
Brian



______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
 With Servers In California, Texas And Virginia - The Worlds Uncensored News Source
  


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

Date: Thu, 1 Mar 2001 13:30:44 +0800
From: <jck1@seed.net.tw>
Subject: what's wrong with my byacc?
Message-Id: <97kn73$3ip@netnews.hinet.net>

Hi, all
I get the perl-byacc1.8.2 from the
http://www.perl.com/CPAN-local/src/misc/perl-byacc1.8.2.tar.Z. Also, I get
the perl5-byacc-patches-0.5.tar.gz.
My system run the linux redhat 6.2. After I make the byacc by the default
Makefile,
I try the example calc.y which copyed from the patches directory, but the
byacc not work for argument -P. Waht's wrong with that?
Thanks a lot.







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

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


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