[13153] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 563 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 17 05:07:17 1999

Date: Tue, 17 Aug 1999 02:05:11 -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           Tue, 17 Aug 1999     Volume: 9 Number: 563

Today's topics:
    Re: <== importing hash symbols from one package to anot (Abigail)
    Re: <== importing hash symbols from one package to anot (Bart Lateur)
    Re: Array, Subroutine question (Bart Lateur)
    Re: automatic text formatting for 80 chars a line (Abigail)
        Calling all PERL & DBI gurus <geoff@brainstorm.net.au>
    Re: Counting lines of block of text (Abigail)
    Re: Creating hotlinks out of plain URLs in Perl. <sunfox@sunwerx.com>
    Re: Creating hotlinks out of plain URLs in Perl. (Abigail)
        dynamic random image CGI script needed (David Ford)
    Re: dynamic random image CGI script needed (Sam Holden)
    Re: HARASSMENT -- Monthly Autoemail (John Stanley)
    Re: how can i switch to perl5 (Bart Lateur)
    Re: How to view code as text in working cgi script (Bart Lateur)
    Re: Matching more than one item on a line?? (Eric Bohlman)
    Re: Matching more than one item on a line?? <monty@primenet.com>
    Re: mod (%) in PERL (Abigail)
        NEED HELP!! <andrew_dieckman@amdahl.com>
    Re: NEED HELP!! (elephant)
        PERL & EXCEL <kilimount@earthling.net>
    Re: Perl Services (Abigail)
        Personal Start Page With Cookie login system twafa@earthlink.net
        Running a perl process as service under Win NT <stefan.schulze@wildner.de>
        serial port / ioctl <brekevel@worldonline.nl>
        SWIG for Win32... <vincent.cheminot@wanadoo.fr>
    Re: unpacking - help (Bart Lateur)
    Re: Why It's Cool To Make Fun Of Bad Code <uri@sysarch.com>
    Re: Why It's Cool To Make Fun Of Bad Code (Andrew Johnson)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: 17 Aug 1999 01:08:03 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: <== importing hash symbols from one package to another ==>
Message-Id: <slrn7rhv40.9e1.abigail@alexandra.delanet.com>

Kevin Howe (khowe@performance-net.com) wrote on MMCLXXVI September
MCMXCIII in <URL:news:DpZt3.45883$5r2.95506@tor-nn1.netcom.ca>:
~~ I'd like to thank everyone for being so helpful, my module is working well
~~ using the sub import{} method. I am left with lingering questions about
~~ Exporter though. I've read it's documentation many times, I've tried many
~~ different things, but I still could not properly export the hashes using
~~ Exporter. Can anyone prove that Exporter can actually do this?
~~ 

#!/opt/perl/bin/perl -w

package Furby;

use vars qw /@ISA @EXPORT @EXPORT_OK %hash/;
use Exporter;

@ISA       = qw /Exporter/;
@EXPORT    = qw /%hash/;
@EXPORT_OK = qw //;

%hash = (blue   =>  'apple',
         green  =>  'refridgerator',
         red    =>  'dolphin');


package Pooky;

Furby -> import;

while (my ($colour, $object) = each %hash) {
    print "A $colour $object.\n";
}


keys %hash;  # Keep -w happy.


__END__
A blue apple.
A green refridgerator.
A red dolphin.



Abigail
-- 
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
 |perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
 |perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
 |perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Tue, 17 Aug 1999 08:41:23 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: <== importing hash symbols from one package to another ==>
Message-Id: <37bd1cbf.6682285@news.skynet.be>

Eric Bohlman wrote:

>Your hash isn't called 'hash'.  It's called '%hash'.  Try exporting it 
>based on what it's called :)

No, actually, it *IS* called "hash". Otherwise, how would you be able to
access elements from the hash through $hash{$key} or @hash{@keys}?

You can check the entries in the stash too, as if it was a hash:

	use one;
	$, = " ";
	print keys %one::;
->
	EXPORT import hash EXPORT_FAIL ISA
	              ^^^^

All this pedantia serves only one purpose: to point out that the docs
for Exporter should be a bit more clear.

	Bart.


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

Date: Tue, 17 Aug 1999 08:40:57 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Array, Subroutine question
Message-Id: <37c01fc8.7459089@news.skynet.be>

Ronald J Kimball wrote:

>Did you try it both ways?

No I hadn't. Now I have. I was right.

This works:

  sub shift2 (\@) {
	return splice(@{$_[0]}, 0, 2);
  }
  @friends = qw(Peter Paul Mary Jim Tim);
  ($this, $that) = shift2(@friends);
  ($\,$,) = ("\n",', ');
  print $this,$that;
  print @friends;

->
  Peter, Paul
  Mary, Jim, Tim

This doesn't:

  @friends = qw(Peter Paul Mary Jim Tim);
  ($this, $that) = shift2(@friends);
  ($\,$,) = ("\n",', ');
  print $this,$that;
  print @friends;

  sub shift2 (\@) {
	return splice(@{$_[0]}, 0, 2);
  }

->
  Use of uninitialized value at test.pl line 5.
  Use of uninitialized value at test.pl line 5.
  ,
  Peter, Paul, Mary, Jim, Tim


Putting

  sub shift2 (\@);

at the front of the script makes it work again.

>Doesn't matter, because the subroutine is being called with parentheses
>around the arguments, which tells perl that it is, indeed, a subroutine
>call.  It happily assumes that the subroutine will be declared later in
>the compilation process.  If it isn't, you get a runtime error.

It doesn't matter that it compiles. If the sub definition follows, Perl
doesn't know about the *prototypes*. Prototypes make the compiler work
in a different way, with regards to the prototyped subs. So although it
will compile, it will not compile into the same functionality. That's
why it fails (at runtime).

BTW Putting the sub definitions in a module, and "use"-ing it at the
front of the script, puts the sub definitions at the front of the script
too, so it will compile correctly then, too.

	Bart.


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

Date: 17 Aug 1999 01:41:22 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: automatic text formatting for 80 chars a line
Message-Id: <slrn7ri12g.9e1.abigail@alexandra.delanet.com>

Michael Scheferhoff (m.scheferhoff@gmx.de) wrote on MMCLXXVI September
MCMXCIII in <URL:news:37B7FD51.7F4F8A76@gmx.de>:
~~ 
~~ does anybody know how to format a text so that I have 80 characters in a
~~ line. Is there a command for this?


    $text =~ s/\n+//g;
    $text =~ s/.{80}/\n/g;


HTH. HAND.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Tue, 17 Aug 1999 18:59:14 +0000
From: "Geoffrey Toogood" <geoff@brainstorm.net.au>
Subject: Calling all PERL & DBI gurus
Message-Id: <37b923fd@grissom>

Hi there,

Learning PERL by yourself and you can only get so far. I am having problems
with a script and I know there is probably an easy way to do what I want to
do, so if any of you PERL Gurus want to tell a PERL Wannabe how to do this I
will be very greatfull. I have tried working it out myself but If someone
can tell me and save me the head ache??!!

Info on Setup:
Server : Apache 1.3
Perl 5 installed
Using DBI
Using DBI::ODBC
etc,etc.

I have got my script getting data from my Mircosoft Access Database "test",
and presenting it to the browser via HTML. 

**********
Here is the code I am using:

use DBI;
print "Content-Type: text/html\n";
print "Pragma: no-cache\n\n";
print "<HTML>\n";
$dbh = DBI->connect('dbi:ODBC:test', '', '');
$sth = $dbh->prepare( "SELECT * FROM table WHERE name = ?" );
$sth->bind_param(1, "wally");
$sth->execute;
$counter = 0;
while ( @row = $sth->fetchrow) {
&count;
print "<BODY>ID:$row[0].<br> EMAIL:$row[1].<br> NAME:$row[2].<br><br>\n";
}
print "</BODY>\n</HTML>";
exit;
sub count {
if ($counter < 20)
{$counter = $counter + 1;
print "$counter";
}else{
print ('next 20 choices');
exit;
}
}

***********

Suppose this returns 40 people with the name "Wally" but only prints out 20
before "next 20 choices".
If I then somehow make the  URL for "next 20 choices" :
<A HREF="/cgi-bin/whatever.pl?Next20=somevariable"> next 20 choices </A>.
Then use the GET method to send this to the QUERY_STRING for whatever.pl
which sets the value to a $scalar and then processes it. 

HERE COMES THE QUESTION:

How do I retrieve the next 20 rows from the database where I left off in the
other Script? (ie. retrieve  rows 20-40 from my SELECT query to the
database.)

Do I create some kind of reference to an aray or something? 

AM I ON THE RIGHT TRACK?!!

If you could help me out or point me to someone or article who/that could, I
would appreciate it.

CHEERS
Geoff






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

Date: 17 Aug 1999 01:45:31 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Counting lines of block of text
Message-Id: <slrn7ri1a7.9e1.abigail@alexandra.delanet.com>

D. Stuart (dstu@u.washington.edu) wrote on MMCLXXVI September MCMXCIII in
<URL:news:Pine.A41.4.10.9908161246230.40420-100000@vergil01.u.washington.edu>:
__ 
__ I am a novice perl user, so my problem is probably elementary.
__ 
__ I have a program that returns a block of text. 
__ Currently I am assigning that to an array "@text".  I'd like to be able to
__ count the number of lines of text that I have.  I know how to do this when
__ reading in a file... but not when it isn't a file.  


do {my $nol = 0; map {$nol += y/\n//} @text; $nol};



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");


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Tue, 17 Aug 1999 06:55:04 GMT
From: "Sunfox" <sunfox@sunwerx.com>
Subject: Re: Creating hotlinks out of plain URLs in Perl.
Message-Id: <cH7u3.113291$U42.175667@news1.rdc1.bc.home.com>

Abigail wrote in message ...
>
>Well, the ultimate goal was RFC compliance. By the time the program was
>written, RFC 1738 was the current standard. That standard was sane and
>did not allow `~' as a character. Hence, my regex will not allow `~' as a
>character. RFC 2396 however, allows `~'. A trivial fix allows `~' as well;
>in the code I posted that generates the regex, take `~' out of the
$national
>character equivalence class, and add it to $extra.


<SNIP>

You are the man! I really mean it, this code you've posted is useful to more
people than you may thing. Plus, your patch works perfectly. One question:
in testing this on my database containing numerous URLs, one that seems to
catch it is anything with a =/ in the URL. For instance,
http://www.domain.com?file=/www/index.html Everything up to file= works, but
from /www onwards is ignored. I'm assuming this is a big RFC no-no, but is
there a way to patch it?

- Sunfox




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

Date: 17 Aug 1999 02:51:26 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Creating hotlinks out of plain URLs in Perl.
Message-Id: <slrn7ri55r.9e1.abigail@alexandra.delanet.com>

Sunfox (sunfox@sunwerx.com) wrote on MMCLXXVII September MCMXCIII in
<URL:news:cH7u3.113291$U42.175667@news1.rdc1.bc.home.com>:
 .. 
 .. You are the man! I really mean it, this code you've posted is useful to more
 .. people than you may thing. Plus, your patch works perfectly. One question:
 .. in testing this on my database containing numerous URLs, one that seems to
 .. catch it is anything with a =/ in the URL. For instance,
 .. http://www.domain.com?file=/www/index.html Everything up to file= works, but
 .. from /www onwards is ignored. I'm assuming this is a big RFC no-no, but is
 .. there a way to patch it?


It stops after the = because RFC 1738 says /'s are not allowed in the 
query path. They aren't allowed because /'s are special in URLs.

Given a document with absolute URL:
    http://www.spam.com/eggs?file=/ham/index.html
a relative URL of "bacon?file=/hash/index.html" would be:
    http://www.spam.com/eggs?file=/ham/bacon?file=/hash/index.html
which of course, is an illegal URL.

And while RFC 2396 updates RFC 1738, it doesn't obsolete it. For http
URIs, RFC 1738 is still the definite source. Glansing in RFC 2396, I
get the impression that RFC 2396 leaves the possibility open for schemes
to allow / in a query path. But it doesn't say anything about any scheme
in particular. So, assume / is not allowed.

You can of course modify the $search variable in the program. However,
it would be better to fix your data and replace the /'s with %2F.



Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 16 Aug 1999 23:10:56 PDT
From: davidlee@wavenet.com (David Ford)
Subject: dynamic random image CGI script needed
Message-Id: <davidlee-1608992253150001@ts005d30.lax-ca.concentric.net>

Hello,

I need a CGI script that calls up a random image on a WWW page each time
it is hit or re-loaded.  It must not freeze or crash older browsers and
must overcome Netscape's tendency to only re-load the cache (instead of
actually re-loading the page) upon hitting the re-load button.

For an example of how I want for this to work, go to Food.com and re-load
the page a few times.  See the picture that changes?  That is the model.

Thanks,
David


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

Date: 17 Aug 1999 06:17:16 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: dynamic random image CGI script needed
Message-Id: <slrn7rhvkb.s63.sholden@pgrad.cs.usyd.edu.au>

On 16 Aug 1999 23:10:56 PDT, David Ford <davidlee@wavenet.com> wrote:
>Hello,
>
>I need a CGI script that calls up a random image on a WWW page each time
>it is hit or re-loaded.  It must not freeze or crash older browsers and
>must overcome Netscape's tendency to only re-load the cache (instead of
>actually re-loading the page) upon hitting the re-load button.
>
>For an example of how I want for this to work, go to Food.com and re-load
>the page a few times.  See the picture that changes?  That is the model.

Why don't you ask on a group that actually is about CGI instead of a
random programming group. I would suggest trying in a newsgroup with the
string 'cgi' somewhere in the name, and maybe even 'www'.

But if you must ask in a programming language group then I suggest
comp.lang.python since they keep claiming that python is much easier than
perl. 

So go and ask them.

-- 
Sam

the Emacs editor is horrible
	--Linus Torvalds


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

Date: 17 Aug 1999 06:34:17 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: HARASSMENT -- Monthly Autoemail
Message-Id: <7pavp9$8ot$1@news.NERO.NET>

In article <37b8dedf.30141037@news.erols.com>,
Dave Salovesh <darsal@erols.com> wrote:
>Please, point me to a netiquette guide, your AUP, your TOS, a FAQ,
>something, just one well distributed source which says that posting to
>Usenet does not solicit, does not permit, email replies - just so I can
>understand your point of view.  

No, Dave, you have it backwards. If you want to prove I am wrong, then
you show me the document I signed that says I must accept email in
response to USENET postings. You show me something besides someone
else's opinion that I must accept such email. 

I don't care if you understand my point of view. All you need to do is
understand that your opinion is nothing more than that, and that if you
want to act as if posting to USENET is soliciting email comments to what
you post, that's fine. Just don't force that opinion on others who have
made it clear that they do not believe the same thing.

Do not tell others that they must accept such email or stop posting to
USENET. That is what the person who is complaining about monthly email
from Tom is being told. 

>But every source I've ever read with an opinion on the subject

Keyword: opinion. 

>explicitly suggests that there are situations where replies to Usenet
>posts should be sent via email.

So, since there are "situations" were some people think replies should
be sent by email, you believe that every article posted is a
solicitation for email. Notice that even you did not say "must be
accepted", just "should be sent". 

And, just to clear this up, the mail being discussed is not a response
to a question posted to USENET, it is a monthly email expressing the
sender's opinion of how articles should be formatted.

>If it's simply your view about what you like to see, then that's fine.

Thank you so much for granting me the right to have an opinion. 

>As to your point about UCE, IMNSHO UCE is not objectionable just because
>it's U, or just because it's C, but because the U and the C come
>together.  

But you have told me it is not unsolicited, thus it is not U at all. There
goes the "U and C come together" excuse for objecting to spam.

>There's a gray area in there, where motives and other factors
>must be considered, but as long as it's a personal contact in response
>to a Usenet post, it doesn't deserve to be called UCE.

That's right. That is the logical conclusion to the claim that posting
to USENET is solicitation for email. "I saw you posting to x.y.z and
thought you might be interested in this..." is sufficient defense to the
charge of spamming.



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

Date: Tue, 17 Aug 1999 08:41:26 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: how can i switch to perl5
Message-Id: <37be1ec9.7204127@news.skynet.be>

bishar fambrough wrote:

>i'm a pretty decent perl 4 programmner, but i need to make the switch
>to perl 5 in a hurry.  can anyone give me some pointers as to the
>fastest and most painless way this can be achieved?

Just do it. Virtually everything that worked under Perl4 will work under
Perl5. The most known pitfall is that you have to precede '@' in double
quotish strings with a backslash, if you want it literally. If the
compiler doesn't recognize the array name, it will complain.

Ok in Perl4 but not in Perl5:

	$_ = "My e-mail address is bart@mediamind.be.";

Ok in Perl5:

	$_ = "My e-mail address is bart\@mediamind.be.";

	Bart.


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

Date: Tue, 17 Aug 1999 08:41:16 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: How to view code as text in working cgi script
Message-Id: <37ba1642.5022012@news.skynet.be>

Warren Bell wrote:

>> No, you cannot steal CGI programs that way.
>
>I wasn't planning on it.

Funny that people talk about "stealing code". The same people that say
that you may not hide the source for your scripts.

>You should really get a little more info before accusing someone.  Just
>because I want to SEE the code doesn't mean I'm going to steal it.  And
>who's to say I'm not doing some sort of experiment and the script in
>question is on my own server.

Do it through FTP. Or build in an option in the script, so that with one
particular input parameter, the script shows itself.

	if ($ENV{PATH_INFO} and $ENV{PATH_INFO} =~ m[^/pencil]) {
		print "Content-type: text/plain\n\n";
		open 0; # this opens $0, i.e. the script itself
		print <0>;
		exit;
	}

Call it as

	http://your.server.com/path/to/script.cgi/pencil.txt

(where "script.cgi" is the script's name)
	Bart.


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

Date: 17 Aug 1999 06:37:58 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Matching more than one item on a line??
Message-Id: <7pb006$58l@dfw-ixnews5.ix.netcom.com>

Jim Bell (bellj@nospamnycap.rr.com) wrote:
: All I'm trying to do is to read through one file line by line, identifying
: all instances of a particular text string.  When found, I want to write the
: text string to another file.  This code below works, BUT if a line contains
: more than one instance of the searched-for string, only the first instance
: is identified. The identified string begins and ends properly; it's not
: including all characters to the end of the line--so that's not the problem.
: 
: One passage in the book seems to suggest that this is how matches work
: (always stop at first match), but if so I haven't seen anything that
: explains the best way to compensate.  I'm guessing  the problem is that
: after matching the first string, my code is immediately moving to process
: the next line; but don't know if I need to change the search expression or
: modify the looping process. Again, thanks for any input!

Your guess is correct.

: open (INFILE, 'c:\mydocu~1\session.txt') or die "Can't read SESSION.TXT:
: $!\n";
: open (OUTFILE, '>c:\mydocu~1\test.txt') or die "Can't open file: $!\n";
: while (<INFILE>) {
: if (/((A|S)\.\d{1,5}\-?\w{0,1})/) {

Change that 'if' to a 'while' and stick a 'g' on the end of that match.
perldoc perlre to find out how the g modifier works.

: print OUTFILE "$1\n";
: }
: }
: close OUTFILE;


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

Date: 17 Aug 1999 06:46:09 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: Matching more than one item on a line??
Message-Id: <7pb0fh$cuc$2@nnrp02.primenet.com>

Jim Bell <bellj@nospamnycap.rr.com> wrote:
> Hi, I'm a non-programmer...

No you're not.

> ...who's trying to get started with Perl and has run
> into a head-scratching dead-end with my first practical project. I've read
> through the appropriate sections of my Perl book (no, I don't have the
> O'Reilly bibles, but they're next on my shopping list) and looked through as
> much material online as I could before posting here, but either missed the
> answer or didn't recognize it when it was in front of me. I'm hoping
> someone can give me a gentle shove in the right direction!
>
> All I'm trying to do is to read through one file line by line, identifying
> all instances of a particular text string. When found, I want to write the
> text string to another file. This code below works, BUT if a line contains
> more than one instance of the searched-for string, only the first instance
> is identified. The identified string begins and ends properly; it's not
> including all characters to the end of the line--so that's not the problem.
>
> One passage in the book seems to suggest that this is how matches work
> (always stop at first match), but if so I haven't seen anything that
> explains the best way to compensate. I'm guessing the problem is that
> after matching the first string, my code is immediately moving to process
> the next line; but don't know if I need to change the search expression or
> modify the looping process. Again, thanks for any input!
>
> SAMPLE PROG===
> open (INFILE, 'c:\mydocu~1\session.txt') or die "Can't read SESSION.TXT:
> $!\n";
> open (OUTFILE, '>c:\mydocu~1\test.txt') or die "Can't open file: $!\n";
> while (<INFILE>) {
> if (/((A|S)\.\d{1,5}\-?\w{0,1})/) {
> print OUTFILE "$1\n";
> }
> }
> close OUTFILE;
>
> SAMPLE DATA===
> Asd Fsd sdfsdf  A.100  sd sadfasd fsad    #returns A.100, works fine
> Sdsdf dfsd sd  S.223-B sdfsd sadfsdf d    #returns S.223-B, works fine
> A.323 sdasd sadfsadfasd fasd fsda fsad    #returns A.323, works fine
> sdfasdf  S.3234-A  sdfsdf   S.200 sdfd    #returns S.3234-A, but not S.200

Use "while (m//g)" instead of "if (m//)" to iterate over global
matches.

------------8<----------------------8<------------
#!/usr/local/bin/perl -w

while (<DATA>) {
    print "$1\n" while m/([AS]\.\d{1,5}(-\w)?)/g;
}

__DATA__
Asd Fsd sdfsdf  A.100  sd sadfasd fsad
Sdsdf dfsd sd  S.223-B sdfsd sadfsdf d
A.323 sdasd sadfsadfasd fasd fsda fsad
sdfasdf  S.3234-A  sdfsdf   S.200 sdfd
------------8<----------------------8<------------

The script above produces this output:

A.100
S.223-B
A.323
S.3234-A
S.200

This

    print "$1\n" while m/([AS]\.\d{1,5}(?:-\w)?)/g;

is functionally the same as this

    while (m/([AS]\.\d{1,5}(?:-\w)?)/g) {
        print "$1\n";
    }

Note the changes I made to your regular expression pattern:

    What you posted: ((A|S)\.\d{1,5}\-?\w{0,1})
    My revision:      ([AS]\.\d{1,5}(?:-\w)?)

For single-character alternatives ("this character or that character"),
use character classes, not alternation. Conversely, if you want to
optionally match a multiple-character substring (i.e., exactly zero
or one time), use the question mark quantifier with non-capturing
parentheses. The regular expression you posted would successfully
match both of these eight-character substrings

    A.12345-
    S.123456

in this line of input

    begin foo A.12345- bar S.123456 end

Just a suggestion: Apply the terse style of my answer to your next
comp.lang.perl.misc inquiry.

-- 
Jim Monty
monty@primenet.com
Tempe, Arizona USA


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

Date: 17 Aug 1999 01:47:23 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: mod (%) in PERL
Message-Id: <slrn7ri1dp.9e1.abigail@alexandra.delanet.com>

Linda Minnich (lin.minnich@usa.net) wrote on MMCLXXVI September MCMXCIII
in <URL:news:37b810dd.4090938@nntp.lucent.com>:
-- IS it possible to do a mod function like in C++  represented by the
-- percentage sign : %  in PERL? 


Nah, who would ever want that?

(What's PERL? Perl Emacs Random Locator?)



Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Mon, 16 Aug 1999 10:42:52 -0700
From: Andrew Dieckman <andrew_dieckman@amdahl.com>
Subject: NEED HELP!!
Message-Id: <37B84D9C.F8EE581E@amdahl.com>

I am calling an executable with a perl program, and one of the options
for the executable is to enter an IP address.
Whenever I enter the IP adress, the perl script fails.  I believe it is
because of the . in the IP adress.
Any ideas on how to solve this.

ex of command run
@dir = `stcmd list /p ....@255.255.255.255 ...`;




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

Date: Tue, 17 Aug 1999 18:59:36 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: NEED HELP!!
Message-Id: <MPG.1223cf85b1a950d2989c3d@news-server>

Andrew Dieckman writes ..
>Whenever I enter the IP adress, the perl script fails.  I believe it is
>because of the . in the IP adress.

it's not the period it's the '@' .. you have to escape it otherwise Perl 
tries to interpret it as an array

>@dir = `stcmd list /p ....@255.255.255.255 ...`;

  @dir = `stcmd list /p ....\@255.255.255.255 ...`;

alternatively (assuming no interpolation is required and there are no 
single quotes anywhere in your command string

  @dir = qx'stcmd list /p ....@255.255.255.255 ...';

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Tue, 17 Aug 1999 10:41:38 +0200
From: kilimount <kilimount@earthling.net>
Subject: PERL & EXCEL
Message-Id: <37B92041.236CE5A0@earthling.net>

I've been trying this code under windows NT, but being a very early
beginner in Perl, I cannot figure out what's wrong.
If ever someone could spend a little time to check it out, That'd be
cool :o)
Here's the code :

use OLE;

                       $xlfile ="c:\\filename.xls";

                       ##### OLE - Excel Connection

                       # Create OLE object - Excel Application Pointer
                       $xl_app = CreateObject OLE 'Excel.Application' ||

die $!;

                       # Set Application Visibility
                       # 0 = Not Visible
                       # 1 = Visible
                       $xl_app->{'Visible'} = 0;

                       # Open Excel File
                       $workbook = $xl_app->Workbooks->Open($xlfile);

                       # setup active worksheet
                       $worksheet = $workbook->Worksheets(1);

                       # retrieve value from worksheet
                       $cellA1 = $worksheet->Range("A1")->{'Value'};
                       $cellB1 = $worksheet->Range("B1")->{'Value'};

                       # Close It Up
                       $xl_app->ActiveWorkbook->Close(0);
                       $xl_app->Quit();

Perl Builder's debugger is returning this line :
Can't call method "Worksheets" without a package or object reference at
script line 19.
Thanx in advance for your help,

Kili.





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

Date: 17 Aug 1999 01:30:26 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl Services
Message-Id: <slrn7ri0e0.9e1.abigail@alexandra.delanet.com>

Elaine -HFB- Ashton (elaine@chaos.wustl.edu) wrote on MMCLXXVI September
MCMXCIII in <URL:news:37B89DB8.B89910C6@chaos.wustl.edu>:
--
-- Well, we have the choice of bitching about MW or creating something
-- within the community to promote good CGI code. I think that is worth a
-- bit of work to build.

There's another approach, which is more in my lane. Do neither. I hardly
bitch about MW, and I absolute hate writing CGI programs. I'd rather
have Matt writing them, then that I write them myself. ;-)

I mean, there are so much more interesting areas where we can write
programs for. Bagpipe maintenance and catalogues for instance.



Abigail
-- 
perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Tue, 17 Aug 1999 07:22:09 GMT
From: twafa@earthlink.net
Subject: Personal Start Page With Cookie login system
Message-Id: <7pb2ir$geg$1@nnrp1.deja.com>

I am in the process of developing a Personal Start Page with a
registration system which will store information on a user, (ie email
address, survey info, name, address, etc..) I wanted to integrate this
with a cookie such that the user won't have to ksyeep logging in over
and
over.  I am having trouble figuring out how to implement this
registration system, especially writing the registration information to
a file on the server end, while at the same time sending a cookie to
the users machine.

If anyone is experienced at all with these registration type systems,
please contact me.  Any open source code regarding a similar setup
would be greatly appreciated, as I am more into tweaking then actually
coding.

The best way I would describe this system is similar to the
registration system on Dejanews.com or my.yahoo.com . Please post any
or all information regarding a system like this or email me.

Thanks for any help.

Tawab Wafa
Afghanistan News Service


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Tue, 17 Aug 1999 10:57:53 +0200
From: "Stefan Schulze" <stefan.schulze@wildner.de>
Subject: Running a perl process as service under Win NT
Message-Id: <37b9236b.0@news.touch.net>

I just wrote a small tcp/ip-server that handles access to a custom database
over
the net. Now i'm planning to run the script as a service under Windows NT
4.0.
Anyone out there who tried/did this? Is there a handy module to accomplish
this task?

Thanks in advance

Stefan Schulze

Wildner Trainingssysteme GmbH





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

Date: Tue, 17 Aug 1999 10:46:17 +0200
From: "F. Brekeveld" <brekevel@worldonline.nl>
Subject: serial port / ioctl
Message-Id: <37B92159.30202CEA@worldonline.nl>

Hi,

I need to do some serial port programming and therefore need to use
ioctl.

I have a RedHat 5.2 Linux machine, with standard perl 5.004.. installed.
Now when I execute a perl-script containing a piece of example code from
the O'Reilly  book I get an error.

require "ioctl.ph";
$getp = &TIOCGETP or die "....";
 ...

The second line generates the error:
Undefined subroutine &main::TIOCGETP called at ./xxx.pl line 18

What to do about this ?

A find /usr -name "ioctl.ph" -print delivers:

/usr/lib/perl5/i386-linux/5.00404/asm/ioctl.ph
/usr/lib/perl5/i386-linux/5.00404/linux/ioctl.ph
/usr/lib/perl5/i386-linux/5.00404/sys/ioctl.ph

Any suggestions ?

Thanks,

Feite Brekeveld



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

Date: Tue, 17 Aug 1999 10:39:38 +0100
From: "Vincent" <vincent.cheminot@wanadoo.fr>
Subject: SWIG for Win32...
Message-Id: <7pb79q$42g$1@wanadoo.fr>

Hi,

I would like to use 3 functions from a small C library in Perl
with help of SWIG. The executable for this tool is not directly
available for Win32. Does anyone have a pre-compiled version
for me ?

Thanx in advance for your help,

Vincent.





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

Date: Tue, 17 Aug 1999 08:41:19 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: unpacking - help
Message-Id: <37bc1c24.6527946@news.skynet.be>

Rockett Crawford wrote:

>When I used substr I pulled this string out:
>"Win32::OLE=HASH(0x1aa1718)"
>
>Does this mean that the real string is elsewhere?
>If so, how can I get it into a string variable?

It means that you stringified the object. You must either dereference,
through a method call designed for that (recommended), or hack it, and
access the field directly through hash methods (NOT recommended, but the
fact that it works is interesting :-).

	Bart.


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

Date: 17 Aug 1999 03:11:13 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Why It's Cool To Make Fun Of Bad Code
Message-Id: <x7wvuuzxta.fsf@home.sysarch.com>

>>>>> "JM" == Jim Monty <monty@primenet.com> writes:

  JM> Uri Guttman <uri@sysarch.com> wrote:

  JM> My workaround (which, by the way, I am *not* pleased with) was to
  JM> use Text::Tabs::unexpand on the wrapped text. I used *two* modules
  JM> where, frankly, I would have prefered to use none. I know all about
  JM> code reuse and not reinventing the wheel; if I didn't, I might have
  JM> written the script in awk. But I don't think I should have had to
  JM> use two modules to accomplish what I'm pretty sure can be done in
  JM> a single, skillfully-written s/// operation. (I wasn't doing general
  JM> reformatting of multiple, variable-length lines of text. I was
  JM> simply breaking single lines of text that I *knew* exceeded some
  JM> length limitation into two or more lines that did not exceed that
  JM> limitation, and were also indented.)

a simpler workaround would be to use no indent at all and then a simple
regex or substr on each line to indent. very easy.

there are at least 2 other modules that do wrapping, Text::NWrap and
Text::Format. maybe they do what you want.

  JM> I do appreciate the spirit in which you make this suggestion: Perl
  JM> is open source software that is freely supported (and supported
  JM> for free) by its user community. But you must have read my comment
  JM> that this was the first time I had ever used a module in a Perl
  JM> script, and you cannot have failed to grasp the gist of my rant.
  JM> Do you really want *me* to patch Text::Wrap? I'm not one of the
  JM> few Perl experts who, like you, are qualified to maintain the
  JM> language and its peripherals. I'm one of the (usually) silent
  JM> majority who just use Perl (or awk, or Korn shell, or Visual Basic,
  JM> or whatever) to help keep themselves gainfully employed, at least
  JM> until this damn Information Age blows over.

i don't have sympathy for this attitude. do you constantly want to
reinvent the wheel? are all your perl scripts totally written from
scratch with no shared code? i find that hard to believe. there are many
very high quality modules in cpan and you should learn to explore and
use them. being scared of them is worse than running across a bug in
them. as for maintaining the language, even reporting your problems to
the author of the module helps. Text::Wrap mentioned the help he got
from various people and included the fix for the die problem. so you
have to at least let them improve things. you didn't even have the
latest version. and did you post your problem in c.l.p.modules? i bet
someone else has had the tab problem and could have told you about a
fix.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Tue, 17 Aug 1999 07:25:53 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Why It's Cool To Make Fun Of Bad Code
Message-Id: <588u3.3804$dr6.89874@news1.rdc2.on.home.com>

In article <x7wvuuzxta.fsf@home.sysarch.com>,
 Uri Guttman <uri@sysarch.com> wrote:
[snip] 
! i don't have sympathy for this attitude. do you constantly want to
! reinvent the wheel? are all your perl scripts totally written from
! scratch with no shared code? i find that hard to believe. there are many

and, to paraphrase Arthur C. C. (I think) --- if you want to make a
Text::Wrap from scratch, first you have to invent the universe.

andrew 

      


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu. 

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


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