[20036] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2231 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 28 18:10:42 2001

Date: Wed, 28 Nov 2001 15:10:14 -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: <1006989014-v10-i2231@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 28 Nov 2001     Volume: 10 Number: 2231

Today's topics:
    Re: query exitstatus of a pipe ? (open (FH,"| program") nobull@mail.com
    Re: query exitstatus of a pipe ? (open (FH,"| program") <pilsl_@goldfisch.at>
    Re: recursive regexp <admin@asarian-host.net>
    Re: recursive regexp nobull@mail.com
    Re: recursive regexp <vze33mmh@verizon.net>
    Re: recursive regexp <uri@stemsystems.com>
    Re: recursive regexp <bart.lateur@pandora.be>
    Re: recursive regexp <uri@stemsystems.com>
    Re: Regular Expression <Laocoon@eudoramail.com>
    Re: Request Regex Help <jc_va@hotmail.com>
        Script works in CLI, but not GUI <nwang@shell3.shore.net>
    Re: syswrite on closed socket? nobull@mail.com
    Re: taint problems nobull@mail.com
    Re: Unix dictionary lookups in perl <dennis_marti@yahoo.com>
        Upload table content? <minh26@hotmail.com>
    Re: Using CGI.pm to obtain a list of params - Eureka! <wsegrave@mindspring.com>
    Re: Using CGI.pm to obtain a list of params - Eureka! <admin@asarian-host.net>
    Re: Using CGI.pm to obtain a list of params - Eureka! <wsegrave@mindspring.com>
    Re: Using CGI.pm to obtain a list of params - Oops! <wsegrave@mindspring.com>
    Re: Using CGI.pm to obtain a list of params - Oops! <uri@stemsystems.com>
        Why isn't grep an l-valued function? <joe+usenet@sunstarsys.com>
    Re: Why isn't grep an l-valued function? <comdog@panix.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Nov 2001 19:54:00 +0000
From: nobull@mail.com
Subject: Re: query exitstatus of a pipe ? (open (FH,"| program"))
Message-Id: <u91yiiy8mf.fsf@wcl-l.bham.ac.uk>

peter pilsl <pilsl_@goldfisch.at> writes:

> if (open (FH,"| /usr/cyrus/bin/deliver ".$user)) {
>    print FH $content;
>    close FH;    
> } else {$error=1;}
> 
> the open itself works fine but I need additionally query the exitstatus of 
> the deliver-programm,

> I just read the faqs and looked around at googles and hope that there is an 
> easy solution to my problem.

FAQs are not the primary documentation.  FAQs are really there to fill
in the gaps.  If there's an obvious place where a question would be
answered in the reference manual then it should be answered there and
not in the FAQ.

In this case, try looking for the word 'status' in then reference
manual's description of the open function.

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


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

Date: Wed, 28 Nov 2001 23:08:39 +0100
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: query exitstatus of a pipe ? (open (FH,"| program"))
Message-Id: <3c056068$1@e-post.inode.at>

nobull@mail.com wrote:

> 
> In this case, try looking for the word 'status' in then reference
> manual's description of the open function.
> 

uups. thnx a lot. 

Is it only me, or is the value of $? actually the exitstatus<<8 (bitshift) ?
while this is not a problem its interesting to notice.

thnx for you help (again)

peter



-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Wed, 28 Nov 2001 19:29:29 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: recursive regexp
Message-Id: <tWaN7.78655$uB.12275088@bin3.nnrp.aus1.giganews.com>

"Luciano Ponte" <webmaster@docotrexpress.it> wrote in message
news:9u38cm$k9b$1@nreada.inwind.it...

> I have a file on a single line:

What, pray-tell, is a "file" on a single line?

> xxxxx(variable text)xxx<prefix>string1<suffix>xxxxx(variable
> text)xxx<prefix>string2<suffix>xxx ... and so on for 20 times.
>
> I need to extract string1, string2 ...string20 and put them on a new
> file. How to do this?

Suppose you had that line stored in "my $stringy", then you might try this:

while ($stringy =~ /<prefix>(.+?)<suffix>/mgi) {
    print "Hi, I am $1\n";
}

Ommit "i" (case-insensitive), "m" (across newline chars) at your descretion.

- Mark




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

Date: 28 Nov 2001 19:26:10 +0000
From: nobull@mail.com
Subject: Re: recursive regexp
Message-Id: <u97ksay9wt.fsf@wcl-l.bham.ac.uk>

Luciano Ponte <webmaster@docotrexpress.it> writes:

> Subject: recursive regexp

Nothing to do with recusion here.

> I have a file on a single line:
> 
> xxxxx(variable text)xxx<prefix>string1<suffix>xxxxx(variable 
> text)xxx<prefix>string2<suffix>xxx ... and so on for 20 times.
> 
> I need to extract string1, string2 ...string20 and put them on a new file.
> How to do this?

perl -ne 'print /<prefix>(.*?)<suffix>/g' <a_file >a_new_file

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


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

Date: Wed, 28 Nov 2001 20:31:37 GMT
From: sysop <vze33mmh@verizon.net>
Subject: Re: recursive regexp
Message-Id: <pan.2001.11.28.15.46.21.254098.20280@verizon.net>

On Wed, 28 Nov 2001 12:53:13 -0500, Luciano Ponte wrote:

> I have a file on a single line:
> 
> xxxxx(variable text)xxx<prefix>string1<suffix>xxxxx(variable
> text)xxx<prefix>string2<suffix>xxx ... and so on for 20 times.
> 
> I need to extract string1, string2 ...string20 and put them on a new
> file. How to do this?

Assuming <prefix> can be taken to have the unique characteristic of
starting  some stringN, I think you could:
open(IN, "fn");
$input = <>;
close IN;

@res = split(/<prefix>/, $input);
@results = map {m/(.*)<suffix>.*|()/; $_ = $1} @res; 

open(OUT, ">strings.out");
foreach (@results) {
	print $_\n" if defined $_;
}
close OUT;

--
RobC
Please note I know only enough perl to be dangerous, certainly not enough
to take what I write as gospel.  My suggestions are just that,
suggestions, not answers.  Don't ever simply cut and paste any code I've
written and run it.  Nonetheless, I hope my contibution was helpful.  :)


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

Date: Wed, 28 Nov 2001 20:45:51 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: recursive regexp
Message-Id: <x74rne7hds.fsf@home.sysarch.com>

>>>>> "s" == sysop  <vze33mmh@verizon.net> writes:

  s> On Wed, 28 Nov 2001 12:53:13 -0500, Luciano Ponte wrote:
  >> I have a file on a single line:
  >> 
  >> xxxxx(variable text)xxx<prefix>string1<suffix>xxxxx(variable
  >> text)xxx<prefix>string2<suffix>xxx ... and so on for 20 times.
  >> 
  >> I need to extract string1, string2 ...string20 and put them on a new
  >> file. How to do this?

  s> open(IN, "fn");

always check open for failure, even in examples. you never know who may
read this.

  s> @res = split(/<prefix>/, $input);
  s> @results = map {m/(.*)<suffix>.*|()/; $_ = $1} @res; 

why the assignment to $_? map will just return the same value and that
code modifies the elements of @res.

and what's with the null grab? i think you mean something more like
this:

	@results = map { m/(.*)<suffix>.*/ ? $1 : () } @res; 

let the normal booleans work for you and test the regex for success.


  s> open(OUT, ">strings.out");
  s> foreach (@results) {
  s> 	print $_\n" if defined $_;

the if is not needed as the code above will not have undef values in the
map results.

  s> Please note I know only enough perl to be dangerous, certainly not
  s> enough to take what I write as gospel.  My suggestions are just
  s> that, suggestions, not answers.  Don't ever simply cut and paste
  s> any code I've written and run it.  Nonetheless, I hope my
  s> contibution was helpful.  :)

since that is a signature and will be posted often, please spell check
it.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 28 Nov 2001 21:39:54 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: recursive regexp
Message-Id: <e6ma0u8v5mveopgufm99q1fm1dk5ruet0u@4ax.com>

Uri Guttman wrote:

>i think you mean something more like
>this:
>
>	@results = map { m/(.*)<suffix>.*/ ? $1 : () } @res; 


You don't need the ?:. Just

	@results = map { m/(.*)<suffix>.*/} @res; 

will do, as /.../ returns an empty list if the match failed. See:

	@a = qw(1x a 2y b 3z c);
	@b = map /(\d+)/, @a;
	($\, $,) = ("\n", "+");
	print @b;
-->
	1+2+3

-- 
	Bart.


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

Date: Wed, 28 Nov 2001 22:35:42 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: recursive regexp
Message-Id: <x71yii7cao.fsf@home.sysarch.com>

>>>>> "BL" == Bart Lateur <bart.lateur@pandora.be> writes:

  BL> Uri Guttman wrote:
  >> i think you mean something more like
  >> this:
  >> 
  >> @results = map { m/(.*)<suffix>.*/ ? $1 : () } @res; 


  BL> You don't need the ?:. Just

  BL> 	@results = map { m/(.*)<suffix>.*/} @res; 

  BL> will do, as /.../ returns an empty list if the match failed. See:

  BL> 	@a = qw(1x a 2y b 3z c);
  BL> 	@b = map /(\d+)/, @a;
  BL> 	($\, $,) = ("\n", "+");
  BL> 	print @b;
  --> 
  BL> 	1+2+3

good point. but even better were the earlier regexes that just extracted
the strings. doing a split and then a match on each element is long
winded.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 28 Nov 2001 20:24:21 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Regular Expression
Message-Id: <Xns9167CF9D67F2Laocooneudoramailcom@62.153.159.134>

"Eric D." <ericd_@hotmail.com> wrote in
news:uS9N7.8535$Ju6.2152860@news20.bellglobal.com: 

> Hi,
> 
> How do you denote the ) character in regular expression so it's seen as
> a ) character and NOT a special character?
> 
> I tried:
> 
> / \Q)\E /
> 
> and
> 
> / \) /
> 
> either works.

yep your right, both work(if the space matches)..happy?
 
> Thanks,
> Eric


Lao


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

Date: Wed, 28 Nov 2001 19:15:23 +0000 (UTC)
From: "Buck Turgidson" <jc_va@hotmail.com>
Subject: Re: Request Regex Help
Message-Id: <e8cbaa12c40d7d594207737cc22306c1.38849@mygate.mailgate.org>

Could "gr", my version of grep, written in Perl, be a Perl script?




"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in message
news:9u129f$sp5$07$1@news.t-online.com...

> On Tue, 27 Nov 2001 21:34:04 +0000 (UTC), Buck Turgidson wrote:
> 
> [...]
> 
> > Here is my perl grep script, but it is not capturing what I want, it's getting
> > them anyway.  Can someone spot my error?
> > 
> > gr "#Include|#include\w'+[A-Z]'" *.*
> 
> This is no Perl script.
> 
> Tassilo
> -- 
> Ernest asks Frank how long he has been working for the company.
> 	"Ever since they threatened to fire me."




-- 
Posted from  [65.193.99.4] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: Wed, 28 Nov 2001 21:09:00 GMT
From: Nan Wang <nwang@shell3.shore.net>
Subject: Script works in CLI, but not GUI
Message-Id: <MncN7.30$df.3695@news.shore.net>


I'm using PERL 5.001 with NT 4.  I wrote a simple test script called test.bat,
it looks like:

@rem = '--*-Perl-*--
@echo off
perl -w -S "%0" %*
goto endofperl
@rem ';

print "testing\n";
$x=<STDIN>;

__END__
:endofperl

When I ran it from a DOS prompt it works fine, but if I double click it in
Windows Explorer I get a message saying "Cannot execute c:\test.bat" or 
something like that.  Perl.exe is in my path, and using the full path of
perl.exe doesn't help either.  Has anyone seen anything like this?

Thanks a lot.


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

Date: 28 Nov 2001 18:54:21 +0000
From: nobull@mail.com
Subject: Re: syswrite on closed socket?
Message-Id: <u9g06yybdu.fsf@wcl-l.bham.ac.uk>

winter7@e-mailanywhere.com (winter7) writes:

> my server program hangs when trying to syswrite on closed socket.

I suspect this is untrue.
 
> client usally send message before terminate so that server can delete
> client from client list. but when client terminate abnormally, server
> doesn't recognize and hangs when syswrite to this client.

You are not talking out a closed socket.  You are talking about a
socket the peer of which is closed.

I suspect you are wrong about this anyhow.  I suspect that the client
has forked (or has been created by forking) since the socket was
opened and that the branch of the fork is holding the socket open.
 
> how do I overcome this problem?

If I've guessed right, close unwanted file handles after forking.

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


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

Date: 28 Nov 2001 19:20:37 +0000
From: nobull@mail.com
Subject: Re: taint problems
Message-Id: <u9adx6ya62.fsf@wcl-l.bham.ac.uk>

mark grimshaw <m.grimshaw@salford.ac.uk> writes:

>         if(!open(FILE, ">online/$username"))            ##### offending

> $username is also picked up from
> within the script by reading the value from a database.
> 
> Any solutions to this?

Have you tried untainting $username in the usual way (see
perlsec/"Laundering and Detecting Tainted Data")?

Do you know if the database interface you are claims that it returns
untainted data?  DBI, for example, returns untaineded data by default.


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


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

Date: Wed, 28 Nov 2001 16:10:08 -0500
From: Dennis Marti <dennis_marti@yahoo.com>
Subject: Re: Unix dictionary lookups in perl
Message-Id: <dennis_marti-2FC74B.16100828112001@virt-reader.news.rcn.net>

In article <9tunc7$i4j$1@morgoth.sfu.ca>,
 ajdelore@sfu.ca (Anthony Delorenzo) wrote:

> I'm writing a program that needs to check words against the unix
> dictionary file.  It will need to check thousands of words in a single
> execution.  Looking through CPAN, I don't see any native perl modules
> (although please correct me if I've missed any).  So, what is the best
> approach?
> 
> 1 - Use system calls to the unix 'look' command.  Look is very fast, but
> the overhead of thousands of system calls would doubtless be high.
> 2 - Make calls to a C library, if there is one for this purpose.
> 3 - Write some perl code to access the 'words' file directly.

How about comm(1)?

comm selects or reject lines common to two (sorted) files. It's handy 
for things like spell checkers.

Dennis


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

Date: Wed, 28 Nov 2001 16:32:43 -0500
From: "Minh V. Tran" <minh26@hotmail.com>
Subject: Upload table content?
Message-Id: <9u3kjl$rro$1@reznor.larc.nasa.gov>

This is a multi-part message in MIME format.

------=_NextPart_000_0031_01C1782A.4DFA8DB0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

I am looking for hints or websites having information or sample code =
about the problem I am having:
I have a perl-cgi script that runs a query of database and returns the =
result back to the user's browser in table format. I can do this part, =
but I also need to let user able to save and print the data table. The =
user needs to be able to browse the location (directory) where he wants =
to save the data table. Also, the type of the saved file got to be =
either excel or text (doc) because I want to keep the data in table =
format.
So how am I supposed to achieve this goal in perl, cgi? Is there any =
Perl module out there to get this done more easily? I am thinking using =
JavaScript to pop up another window that contains printed version of =
that table so that user can easily save and print the table. Am I on the =
right track?

Any help and suggestions are very appreciated.

Thanks,
Minh
--=20

------=_NextPart_000_0031_01C1782A.4DFA8DB0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4807.2300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>Hi all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>I am looking for hints or websites having information or sample =
code about=20
the problem I am having:</DIV>
<DIV>I have a perl-cgi script that runs a query of database and returns=20
the&nbsp;result&nbsp;back to the user's browser in table format. I can =
do this=20
part, but&nbsp;I also need to let user able to save and print the data =
table.=20
The user needs to be able to browse the location (directory) where he =
wants to=20
save the&nbsp;data table. Also, the type&nbsp;of the saved file got to=20
be&nbsp;either excel or text (doc) because I want to keep the data in =
table=20
format.</DIV>
<DIV>So&nbsp;how am&nbsp;I supposed to&nbsp;achieve this goal in perl, =
cgi? Is=20
there any Perl module out there to get this done more easily? I am =
thinking=20
using&nbsp;JavaScript to&nbsp;pop up another&nbsp;window&nbsp;that =
contains=20
printed version of that table so that user can easily save&nbsp;and =
print the=20
table. Am I on the right track?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Any help and suggestions are very appreciated.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks,</DIV>
<DIV>Minh</DIV>
<DIV>--&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0031_01C1782A.4DFA8DB0--



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

Date: Wed, 28 Nov 2001 13:46:16 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Using CGI.pm to obtain a list of params - Eureka!
Message-Id: <9u3f1a$ain$1@slb6.atl.mindspring.net>

"William Alexander Segraves" <wsegrave@mindspring.com> wrote in message
news:9u363r$h9v$1@slb4.atl.mindspring.net...
> "Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
> news:3C047DF7.CE872B77@earthlink.net...
> > > Suppose each generation has variable names, e.g.,
> > [snip]
> > > Name_G1
> > > Address_G1
> > > ...
> > > Name_G12
> > > Address_G12
> >
>
> > There's no need to do that ugly series of s/// things you suggest.
> > And if one *were* doing something like that, it would be done as:
> >    s/G(\d+)$/$1 + 1/e;
> > which would do all those changes with just a single substitution.
>
> Actually, this doesn't work, as the variable names may be embedded
somewhere
> in the name-value pair that has not been packed yet, rather than at the
end,
> as suggested by the above code. Changing the code to:
>
>     s/G(\d+)+/$1 + 1/e;
>
> causes all instances to be matched and replaced; but the "G" is dropped in
> the replacements, causing the following corruptions of the variable names:
>
> Name_1
> Address_1
> ...
> Name_12
> Address_12
>
> Except for the problem with the replacement dropping the "G", the modified
> substitution has the desired effect, as a generation identifier in the
> variable name may appear anywhere in a name-value pair.
>
> IMO, your approach has great promise, once I solve the problem with the
> dropped "G" in the replacement.
>
> Thanks for your suggestions, Benjamin.

Problem solved. While Benjamin's suggestion didn't work, he provided
sufficient challenge for me to get rid of the "ugly series of s/// things"
that I was able to craft a solution.

BTW, the "ugly series of s/// things" were actually individual lines of code
that were intended as code to move one generation at a time downward by one.
That's no longer necessary, as the following "ugly instance of a s/// thing"
;-) code works for all of them:

   s/(G)(\d+)+/$1,sprintf($1.($2+1))/e;

Many thanks to Jon Bell, Alan Flavell, and Benjamin Goldberg for sharing
their expertise. If you see any possible improvement on this, please let us
know.

Bill Segraves
Auburn, AL





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

Date: Wed, 28 Nov 2001 20:29:48 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: Using CGI.pm to obtain a list of params - Eureka!
Message-Id: <0PbN7.61141$YD.5418982@news2.aus1.giganews.com>

"William Alexander Segraves" <wsegrave@mindspring.com> wrote in message
news:9u3f1a$ain$1@slb6.atl.mindspring.net...

> > > Name_G1
> > > Address_G1
> > > ...
> > > Name_G12
> > > Address_G12

> > as suggested by the above code. Changing the code to:
> >
> >     s/G(\d+)+/$1 + 1/e;
> >
> > causes all instances to be matched and replaced; but the "G" is
> > dropped in the replacements, causing the following corruptions
> of the variable names:
> >
> > Name_1
> > Address_1
> > ...
> > Name_12
> > Address_12
>
> BTW, the "ugly series of s/// things" were actually individual lines of
> code that were intended as code to move one generation at a time
> downward by one. That's no longer necessary, as the following
> "ugly instance of a s/// thing" ;-) code works for all of them:
>
>    s/(G)(\d+)+/$1,sprintf($1.($2+1))/e;

Whatever are you doing?? What's with the + behind $2? The + behind \d
already ensures you grab the digits as greedy as can be (and that there
needs to be at least one digit). So, drop the cargo +. Then do:

s/G(\d+)/"G".($1 + 1)/e;

Too bad you can't use ++$1, be it for good reasons, of course. :)

- Mark




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

Date: Wed, 28 Nov 2001 15:33:27 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Using CGI.pm to obtain a list of params - Eureka!
Message-Id: <9u3lb3$ej1$1@slb6.atl.mindspring.net>

"Mark" <admin@asarian-host.net> wrote in message
news:0PbN7.61141$YD.5418982@news2.aus1.giganews.com...
> >    s/(G)(\d+)+/$1,sprintf($1.($2+1))/e;
>
> Whatever are you doing?? What's with the + behind $2?

It adds 1 to the (current) value of $2 each time there's a match on the
PATTERN.

> The + behind \d
> already ensures you grab the digits as greedy as can be (and that there
> needs to be at least one digit). So, drop the cargo +. Then do:
>
> s/G(\d+)/"G".($1 + 1)/e;
>

Mark, thanks for your suggestions; but your code doesn't perform the
intended function. OTOH, dropping the "cargo +", as you put it, and adding a
"g" to make the REPLACEMENTs global makes my code work as intended:

   s/(G)(\d+)/$1,sprintf($1.($2+1))/ge;

Note: The intent is for ALL instances of the names, as well as values, to
enjoy the shift by one generation, in every place where the generation
number is cited.

Bill Segraves
Auburn, AL






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

Date: Wed, 28 Nov 2001 15:57:10 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Using CGI.pm to obtain a list of params - Oops!
Message-Id: <9u3mr4$3di$1@slb7.atl.mindspring.net>

"William Alexander Segraves" <wsegrave@mindspring.com> wrote in message
news:...

>    s/(G)(\d+)/$1,sprintf($1.($2+1))/ge;

Mea culpa! Out, gremlins! I wrote the above when I should have written:

   s/(G)(\d+)/sprintf($1.($2+1))/ge;

Thanks again to Alan, Benjamin, Jon, and Mark for their excellent
suggestions.

Bill Segraves
Auburn, AL

P.S. Unless someone sees a more concise way to do the above s///, let's end
this "off subject" tangent from the original thread. I'm moving on to a
version of the program that uses CGI.pm. With the suggestions y'all have
contributed, the end result should be much better than it would have been
otherwise.





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

Date: Wed, 28 Nov 2001 22:40:48 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Using CGI.pm to obtain a list of params - Oops!
Message-Id: <x7y9kq5xhq.fsf@home.sysarch.com>

>>>>> "WAS" == William Alexander Segraves <wsegrave@mindspring.com> writes:

  WAS> "William Alexander Segraves" <wsegrave@mindspring.com> wrote in message
  WAS> news:...

  >> s/(G)(\d+)/$1,sprintf($1.($2+1))/ge;

  WAS> Mea culpa! Out, gremlins! I wrote the above when I should have written:

  WAS>    s/(G)(\d+)/sprintf($1.($2+1))/ge;

that sprintf has no arguments other than the format string so it us
useless. a simple $1 . ($2 + 1) will do.

also why even grab the G? grabbing a fixed string makes little sense as
it has to do an extra copy. it may make life a little nicer in defining
the grab part but you could just remove the () and put a G in the
replacement string.

	  s/G(\d+)/'G'.($1+1)/ge;

  WAS> P.S. Unless someone sees a more concise way to do the above s///,
  WAS> let's end this "off subject" tangent from the original
  WAS> thread. I'm moving on to a version of the program that uses
  WAS> CGI.pm. With the suggestions y'all have contributed, the end
  WAS> result should be much better than it would have been otherwise.

was that more concise?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 28 Nov 2001 15:36:59 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Why isn't grep an l-valued function?
Message-Id: <m3667u4opg.fsf@mumonkan.sunstarsys.com>


  @a = 1..4;
  grep( $_ % 2, @a ) = "a".."z";

~>Can't modify grep iterator in scalar assignment ...

Why is this illegal?  I know it's easy to convert that
into a real slice:

  @a[  grep $a[$_] % 2, 0 .. $#a  ] = "a" .. "z";

~> @a = ("a", 2, "b", 4)

I'm just wondering if there is a problem with making grep
work just like substr() does for scalars.

Thanks.
-- 
Joe Schaefer




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

Date: Wed, 28 Nov 2001 16:54:06 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Why isn't grep an l-valued function?
Message-Id: <comdog-EEC109.16540628112001@news.panix.com>

In article <m3667u4opg.fsf@mumonkan.sunstarsys.com>, Joe Schaefer 
<joe+usenet@sunstarsys.com> wrote:

>   @a = 1..4;
>   grep( $_ % 2, @a ) = "a".."z";
> 
> ~>Can't modify grep iterator in scalar assignment ...

what do you think grep does?


> Why is this illegal?  I know it's easy to convert that
> into a real slice:

>   @a[  grep $a[$_] % 2, 0 .. $#a  ] = "a" .. "z";

in this case, grep returns indices to @a because the list
over which it iterates is a list of indices.  the replacement
of elements is done by the array slice, not grep.

> ~> @a = ("a", 2, "b", 4)


> I'm just wondering if there is a problem with making grep
> work just like substr() does for scalars.

grep isn't like substr.  perhaps you wanted splice().

-- 
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

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.  

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


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