[11303] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4903 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 16 02:16:21 1999

Date: Mon, 15 Feb 99 23:00:26 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 15 Feb 1999     Volume: 8 Number: 4903

Today's topics:
        /i in regexp kills performance. <zack44@altavista.net>
        ANNOUNCE: pmtools 1.0 release <tchrist@mox.perl.com>
    Re: Can 2 "submit" buttons in 1 form do different thing <waltman@netaxs.com>
        CPAN shell problem <echeng@orbonline.net>
    Re: Creating individual arrays from an array (Tad McClellan)
        DEMO: recursive closures for graph traversal <tchrist@mox.perl.com>
        Finding a hash key based on regexp <zack44@altavista.net>
    Re: HELP stripping NEWLINE character unspam@kj.imediat.com
    Re: HELP stripping NEWLINE character (Sam Holden)
        how to sort by file date with year (Steve .)
    Re: ip address search (David Efflandt)
        joining files (Mark P.)
    Re: joining files (Larry Rosler)
    Re: joining files (Mark P.)
    Re: Making a Subject Index with Perl (Tad McClellan)
    Re: newbie question, basepath (Tad McClellan)
    Re: Parsing (Larry Rosler)
        Perl and SQL consultant required. (Adam Thyer)
    Re: perl script (Tad McClellan)
        problem: NYTimes access via LWP / UserAgent newsmf@bigfoot.com
        Redirectiong STDERR <jalilf@home.com>
    Re: REGEX $1, $2 ... array? (Abigail)
    Re: REGEX $1, $2 ... array? (Ilya Zakharevich)
    Re: REGEX $1, $2 ... array? (Ilya Zakharevich)
    Re: REGEX $1, $2 ... array? ptimmins@netserv.unmc.edu
    Re: SRC: pmexp - show a module's exports <jdf@pobox.com>
    Re: String Compare (Tad McClellan)
        Term::ReadKey fail when perl is called from C program <mguthrie@IPivot.com>
        Vital parts of $1 missing <admin@asarian-host.org>
    Re: Vital parts of $1 missing <ebohlman@netcom.com>
    Re: Vital parts of $1 missing (Sam Holden)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Tue, 16 Feb 1999 01:51:26 -0500
From: Zack <zack44@altavista.net>
Subject: /i in regexp kills performance.
Message-Id: <36C9156E.7A1DA5D5@altavista.net>

I noticed this in doing some search timing.

Iterating through a file, looking for matches.....20,000 entries:

	### Takes over 19 seconds to complete
	if ($LINE =~ /(test)/i) { print "Match\n"; }

	### Takes only 3 seconds to complete.
	if ($LINE =~ /(test)/) { print "Match\n"; }

WOW.  Is this a bug in perl?


John


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

Date: 15 Feb 1999 18:27:42 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: ANNOUNCE: pmtools 1.0 release
Message-Id: <7aakth$229$1@nntp.Stanford.EDU>

The pmwb stuff, which I could never spell, has been renamed "pmtools",
and is now available with a real Makefile.PL and manpages.

    http://mox.perl.com/misc/pmtools-1.00.tar.gz

I'm not sure about getting it to CPAN -- it is, after all, real tools,
not silly modules. :-)

--tom
-- 
"All things are possible, but not all expedient."  (in life, UNIX, and perl) -me


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

Date: 15 Feb 1999 21:54:07 -0500
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: Can 2 "submit" buttons in 1 form do different things?
Message-Id: <m3pv7bawj4.fsf@netaxs.com>

"Pamela Schultz" <vikette@earthlink.net> writes:

> Can I have 2 submit buttons in the same form that do different stuff? Can I
> somehow pass to the perl script which button is pressed by the user? Thanks
> for your help!

Absolutely!  You need to give your two submit buttons different names,
then the CGI script can look at their names to decide what to do.

Here's a simple example that shows how...

HTML
----
<html>
<head>
<title>Perl Subroutine Test</title>
</head>
<body>
This is a test to show how to call different Perl subroutines inside a
CGI script, depending on which button is pressed.  Click one of these
buttons, and I'll call a routine to tell you which you pressed.
<p>
<form action=cgi-bin/perlsub.cgi>
<input type=submit name=button1 value='Button 1'>
<input type=submit name=button2 value='Button 2'>
</form>
</html>

perlsub.cgi (gets called by the form above)
-------------------------------------------
#!/usr/bin/perl -w
use diagnostics;
use strict;
use CGI qw(:standard);

print header, start_html;

if    (param('button1')) { &button1; }
elsif (param('button2')) { &button2; }

print end_html;

sub button1 { print "You pressed button 1"; }

sub button2 { print "You pressed button 2"; }



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

Date: Tue, 16 Feb 1999 02:58:10 +0000
From: Edmond Cheng <echeng@orbonline.net>
Subject: CPAN shell problem
Message-Id: <36C8DEC1.BCFE2538@orbonline.net>

I tried to install the Perl Modules using the CPAN.  I invoked the
CPAN shell with the command:

%perl -CPAN -eshell

Then a number of configuration questions were asked.  For the URL of
CPAN site question, it could not find the mirror site.  The following is
my answer  to the question:
=======================================================================

We need to know the URL of your favorite CPAN site.
Please enter it here:  ftp.crc.ca

Testing "ftp.crc.ca" ...
Please check, if the URLs I found in your configuration file
(ftp.crc.ca)
are valid. The urllist can be edited. E.g. with ``o conf urllist push
ftp://myurl/''

Cannot fetch MIRRORED.BY

ftp.crc.ca doesn't seem to work. Keep it in the list? [n]
=========================================================================



I am using Redhat 5.1, perl 5.004_004 and ADSL for my Internet
connection (which is the proxy server)

Thanks for any help

Edmond Cheng



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

Date: Tue, 16 Feb 1999 00:41:05 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Creating individual arrays from an array
Message-Id: <1u3ba7.1re.ln@magna.metronet.com>

lchuck@home.com wrote:
: Sorry about the title of the message.  What I'm looking to do is to take an
: array of values (numbers, words, etc) and create an array for each of the
: values in the initial array.  Example:

: @furniture=("chair", "table", "couch");

: I would like to write a snippet of code that could take each item in the
: @furniture array and create seperate arrays, called @chair, @table, and
: @couch.


   That is called a "Symbolic reference". They are described in
   the perlref.pod man page that came with your perl.


: I have attempted to do this, but can't get it to quite work out correctly.  


   You really should not do this.

   There is nearly always a better way than using symbolic references
   in modern perls.

   A hash of arrays data structure would do the trick much more
   safely.  (sym refs are dangerous)

   Below I'll show you how to get what you want without resorting
   to sym refs.


: email me, as I don't get many chances to look through newsgroups.  


   Oh.

   Never mind.

   If you can't be bothered to come back here for the answer,
   the I can't be bothered to give you one.

   Sorry.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 15 Feb 1999 20:18:35 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: DEMO: recursive closures for graph traversal
Message-Id: <7aao4k$2th$1@nntp.Stanford.EDU>

I was trying to come up with a way of writing functions that work like
map{} or grep{}, so that the function would be applied to each of a
bunch of things, with $_ holding the current thing each time.

For example, suppose you had a network of nodes representing
a house, or a dungeon.  You might want to do something like
this:

    graph_walk { print $_->{VALUE}, "\n" } $kitchen;

In graph traversal, you have to keep track of nodes visited,
so you don't just keep running around the house in circles.
I wanted to do this without having an extra helper function
and a local(%seen) or an extra argument.  So I pulled something
out with recursive closures.

One thing that's interesting here is not the use of recursive
closures, but how tremendously easier it is to build fancy data
structures in Perl than in something like C, C++, or Java.
You don't need classes.  You don't need objects.  You don't
need fancy allocators.  It just all falls out.

The fact that a graph is circular means that for garbage you would
need to cloak it in a blessed non-selfreferential object box with 
a destructor to sever the links if you cared not to leak.

But it's still darned easy.  Think of the pain of doing this in C.

--tom


# recursive closure demo for a graph traversal

sub graph_walk (&$) 
{
    my $nodefunc = shift;
    local $_     = shift;  	# nodefunc wants this here
    my %seen     = ();
    my $walker;

    $walker = sub { 
	local $_     = shift;   # nodefunc wants this here
	return if $seen{$_}++;
	$nodefunc->();  	# this will use $_ 
	for my $neighbor (@{$_->{LINKS}}) { 
	    $walker->($neighbor);  
	}
    };

    $walker->($_);
}

sub add_node {
    my ($oldnode, $newnode) = @_;
    push @{ $oldnode->{LINKS} }, $newnode;
    push @{ $newnode->{LINKS} }, $oldnode;  # both ways
    return $newnode;
} 

sub add_value {
    my ($oldnode, $value) = @_;
    my $newnode = {
	VALUE => $value,
	LINKS => [],
    };
    return add_node($oldnode, $newnode);
} 

$foyer = {
    VALUE => "Foyer",
    LINKS => [],
};

$hall    = add_value($foyer, "Hallway");
$bedroom = add_value($hall, "Bedroom");
           add_value($bedroom, "Bathroom");
$kitchen = add_value($hall, "Kitchen");
$living  = add_value($hall, "Living Room");
           add_node($kitchen, $living);

print "Starting from foyer:\n";
graph_walk { print $_->{VALUE}, "\n" } $foyer;

print "\nStarting from kitchen:\n";
graph_walk { print $_->{VALUE}, "\n" } $kitchen;

exit;

__END__

-- 
Emacs is a fine operating system, but I still prefer UNIX. -me


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

Date: Tue, 16 Feb 1999 01:49:07 -0500
From: Zack <zack44@altavista.net>
Subject: Finding a hash key based on regexp
Message-Id: <36C914E3.CE873279@altavista.net>

Is it possible to find a matching hash key without using 
   while ( ($key,$value) = each %hash ) {
   }

I'd love for there to be a way to do a find on the key using a regexp ....
ie:
   if (exists $hash{/(whatever)/} ) ...

I know that syntax is never gonna work, but is there some other similar way?

The tied hash I'm working with has 72,000 keys (and more being added).  Searches are starting to bog down a bit.


(BTW, this is a follow up to my earlier questions about searching large text files.  I've moved to the DB_File method, and am very happy with the speed gains so far.  Thanks all)


Z-


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

Date: Tue, 16 Feb 1999 01:29:47 GMT
From: unspam@kj.imediat.com
Subject: Re: HELP stripping NEWLINE character
Message-Id: <7aahm2$i43$1@nnrp1.dejanews.com>

In article <36C5860A.54483F5@tampabay.rr.com>,
  saij <saij@tampabay.rr.com> wrote:
> I am using s/\n/<br>/sg;
>
> Why does it leve the newline characters in there??

	Don't quote me on it, but I believe the problem is this:

	The final \n is considered the record seperator, and is not seen by any REs.
One quick fix I can think of would be to:

chomp($_);
$_ = join("", $_, "<br>");

	Probably not the most efficient, but you'll surely get the job done.

		Cheers,

			~kj

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 16 Feb 1999 02:52:35 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: HELP stripping NEWLINE character
Message-Id: <slrn7chnbj.pbg.sholden@pgrad.cs.usyd.edu.au>

On Tue, 16 Feb 1999 01:29:47 GMT, unspam@kj.imediat.com wrote:
>In article <36C5860A.54483F5@tampabay.rr.com>,
>  saij <saij@tampabay.rr.com> wrote:
>> I am using s/\n/<br>/sg;
>>
>> Why does it leve the newline characters in there??

It doesn't....

>
>	Don't quote me on it, but I believe the problem is this:
>
>	The final \n is considered the record seperator, and is not seen by any REs.

If you aren't sure then at least do a simple test before making such global
announcements about this non-existant record seperator.

>$_ = join("", $_, "<br>");

Anything wrong with $_.='<br>' ?????

-- 
Sam

People get annoyed when you try to debug them.
	--Larry Wall


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

Date: Tue, 16 Feb 1999 06:48:16 GMT
From: syarbrou@nospam.enteract.com (Steve .)
Subject: how to sort by file date with year
Message-Id: <36c91404.39026059@news.enteract.com>

I have a list of files with the year in it.  I want to sort from
newest to oldest.  Thought of a system call with a reverse listing,
but didn't work, because it doesn't account for the year the way I
want.  Basically it looks like this:
 
PC122198 
PC010799

Linux/UNIX thinks that 122198 is newer because technically it's a
larger number.  How would you do a sort so that it sets the second
file as the newer one in the list? Thanks.  By the way, this sort
would be done on a large group of files.

Steve


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

Date: 16 Feb 1999 02:04:13 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: ip address search
Message-Id: <slrn7chkf5.fq.efflandt@efflandt.xnet.com>

On Mon, 15 Feb 1999 12:44:01 -0800, Roger Kaye <kayer@wou.edu> wrote:
>I'm a newbie and trying to write a script on a unix server to poll ip
>address within
>a given range to test if they ping. Then I need to test each connection
>to see if any are set up as Web servers.

http://www.xnet.com/~efflandt/pub/wwwpost/ look for 'wwwtest'.  It opens a
socket and does a HEAD request to see if the server is responding.  If
unsuccessful, it will tell you at what point if failed (for example, if it
cannot connect to the machine at all, or if it can connect, but the
request timed out).

-- 
David Efflandt    efflandt@xnet.com
http://www.xnet.com/~efflandt/


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

Date: Tue, 16 Feb 1999 02:26:28 GMT
From: mag@imchat.com (Mark P.)
Subject: joining files
Message-Id: <36c8d673.1123769344@news.ionet.net>

I'm trying to join a list of files but I'm stuck on getting them to
print to a new filehandle. Here's what I have so far.

  opendir (COP, "$datadir") || die $!;
@filenames = grep (/\.txt$/i,readdir(COP));
closedir (COP);

	   open(DATA, ">>faq.txt") || die $!;
	while (<DATA>) {

 foreach $file (@filenames)
     {
      open(FILE, "<$file") || die $!;
	print DATA <FILE>;
	print DATA "\n";
close(FILE);
		}
	     }

close(DATA);

	I just get a blank faq.txt when I execute the program from
telnet.




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

Date: Mon, 15 Feb 1999 19:31:28 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: joining files
Message-Id: <MPG.113286662de27706989a43@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36c8d673.1123769344@news.ionet.net> on Tue, 16 Feb 1999 
02:26:28 GMT, Mark P. <mag@imchat.com> says...
+ I'm trying to join a list of files but I'm stuck on getting them to
+ print to a new filehandle. Here's what I have so far.
+ 
+   opendir (COP, "$datadir") || die $!;
+ @filenames = grep (/\.txt$/i,readdir(COP));
+ closedir (COP);
+ 
+ 	   open(DATA, ">>faq.txt") || die $!;
+ 	while (<DATA>) {

What is this loop?  You are trying to read from a file you have opened 
to write.  The read fails, the loop exits, and your output file is 
empty.
 
+  foreach $file (@filenames)
+      {
+       open(FILE, "<$file") || die $!;
+ 	print DATA <FILE>;
+ 	print DATA "\n";
+ close(FILE);
+ 		}
+ 	     }
+ 
+ close(DATA);
+ 
+ 	I just get a blank faq.txt when I execute the program from
+ telnet.

No surprise at all!  Kill the loop, and it looks as if everything will 
fly.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 16 Feb 1999 03:50:16 GMT
From: mag@imchat.com (Mark P.)
Subject: Re: joining files
Message-Id: <36c8eaab.1128945127@news.ionet.net>

	Thanks. I killed the loop and it worked perfectly. We're
learnin here. :-)

>+ 	   open(DATA, ">>faq.txt") || die $!;
>+ 	while (<DATA>) {
>
>What is this loop?  You are trying to read from a file you have opened 
>to write.  The read fails, the loop exits, and your output file is 
>empty.
> 
>+  foreach $file (@filenames)
>+      {
>+       open(FILE, "<$file") || die $!;
>+ 	print DATA <FILE>;
>+ 	print DATA "\n";
>+ close(FILE);
>+ 		}
>+ 	     }
>+ 
>+ close(DATA);
>+ 
>+ 	I just get a blank faq.txt when I execute the program from
>+ telnet.
>
>No surprise at all!  Kill the loop, and it looks as if everything will 
>fly.
>
>-- 
>(Just Another Larry) Rosler
>Hewlett-Packard Company
>http://www.hpl.hp.com/personal/Larry_Rosler/
>lr@hpl.hp.com



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

Date: Tue, 16 Feb 1999 00:23:21 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Making a Subject Index with Perl
Message-Id: <ps2ba7.1re.ln@magna.metronet.com>

Jonathan Eaton (jeaton@tamworth.u-net.com) wrote:

: I have a flat file of book records in which each title may have one or more
: subject terms (delimited by a slash), as follows:

: Title  |  Date  |  Subject Term(s)

: I want to generate an alphabetically sorted subject index as follows (using
: above as example)

: ACCOUNTING
:     Finance for Accountants

: FINANCE
:     Beginner's Course in Finance
:     Finance for Accountants
:     Marketing for Financial Services

: MARKETING
:     Marketing for Financial Services


: I understand how to parse each record, to split the subject term field to
: get individual terms, and am familiar with hashes, but can't see how best to
: achieve the one-to-many relationship between subject term and title, and
: then how to ensure I get a correctly keyed sort on title within subject
: term.


   A hash of arrays is called for here.

   You example data was already sorted by title, so I scrambled
   them to ensure that the sort() is sorting.

----------------------
#!/usr/bin/perl -w
use strict;

my %lib;

while (<DATA>) {
   chomp;
   my($title, $year, $subjects) = split /\|/;
   foreach my $subject ( split m#/#, $subjects ) {
      push @{$lib{$subject}}, $title;
   }
}

foreach my $subject (sort keys %lib) {
   print "$subject\n";
   foreach my $title ( sort @{$lib{$subject}}) {
      print "   $title\n";
   }
}

__DATA__
Marketing for Financial Services|1997|FINANCE/MARKETING
Beginner's Course in Finance|1998|FINANCE
Finance for Accountants|1995|FINANCE/ACCOUNTANCY
----------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 16 Feb 1999 00:34:50 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie question, basepath
Message-Id: <ai3ba7.1re.ln@magna.metronet.com>

weasel (lost_ark@yahoo.com) wrote:
: i've recently changed providers, from a unix to nt host.  my script
: needs a new basepath, can it be formatted as such :

: $basepath = 'D:\Inetpub\wwwroot\102133\q1j8tlte\';


   What happened when you tried it?


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Mon, 15 Feb 1999 19:24:18 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Parsing
Message-Id: <MPG.113284b91811fbae989a42@nntp.hpl.hp.com>

In article <Pine.A41.4.02.9902151805330.36014-
100000@ginger.libs.uga.edu> on Mon, 15 Feb 1999 18:16:12 -0500, Brad 
Baxter <bmb@ginger.libs.uga.edu> says...
> On Mon, 15 Feb 1999, Tom Renic wrote:
> >                # The problem begins when I get to the $OfficeAddress
> > variable, since an address has usually more than one
> >                # line, seperated by enter characters. What I would like
> > to do is replace the enter strokes with a comma.
> 
> Try 'split' and 'join':
 ...
>     join( ",", split( /\n/, $OfficeAddress ) ),

That is painfully slow and complicated compared to 'tr':

    $OfficeAddress =~ tr/\n/,/;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 16 Feb 1999 05:53:21 GMT
From: adam@promethean.com.au (Adam Thyer)
Subject: Perl and SQL consultant required.
Message-Id: <7aau2i$stc$1@reader1.reader.news.ozemail.net>

Hi all

I have a project for an *affordable* and experienced consultant who can write 
SQL (ideally MySQL), CGI and Perl5 for a Web site back-end on an Apache server 
running Redhat Linux. If you're interested, please send your hourly rate 
(US$), a detailed resume, URLs of previous work and referees to 
adam@promethean.com.au. I'll then send a detailed brief to suitable applicants 
so that they can submit a quotation. If I'm happy with his/her work, the 
successful bidder may also receive additional commissions on an ongoing basis.

Cheers :)

Adam Thyer



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

Date: Tue, 16 Feb 1999 00:28:17 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl script
Message-Id: <163ba7.1re.ln@magna.metronet.com>

Abukar Mohamed (abukar@insidewire.com) wrote:

: I am developing a scripts that writes a cookie .


   Perl does not have anything called a "cookie".

   I think you have found the wrong newsgroup.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 16 Feb 1999 05:29:18 GMT
From: newsmf@bigfoot.com
Subject: problem: NYTimes access via LWP / UserAgent
Message-Id: <7aavn6$ti5$1@nnrp1.dejanews.com>

Hi there -

I wrote a little perl program that fetches a NYT page for me (the pages work
with passwords; accessing them with a browser, they display a "first time
user" page if no password is supplied of if there's no cookie, I guess).

My problem: sometimes it gets the real page, sometimes it gets the page for
first time users. I'm really confused because the behavior seems quite random.

Can anyone help?

Thanks for helping and cheers from South Beach,


Marc.


Here's the code:


#!/usr/local/bin/perl


require "httools.pl";
require "cgi-lib.pl";
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;

$url= "http://www.nytimes.com/yr/mo/day/news/world/";

$userid ="231q7";
$password= "032e4";

$ua = new LWP::UserAgent;

$req = new HTTP::Request 'GET',"$url" || die "$!";
$ua->agent('Mozilla/4.03');
$req->authorization_basic($userid, $password);
$res = $ua->request($req) || die "$!";
&header;
print $res->content if $res->is_success;

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 16 Feb 1999 02:43:08 GMT
From: "Jalil Feghhi" <jalilf@home.com>
Subject: Redirectiong STDERR
Message-Id: <0X4y2.6766$yv3.1559@news.rdc1.sfba.home.com>

I would like to redirect STDERR to a file. How should I do that?

Thanks,

-Jalil





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

Date: 16 Feb 1999 03:43:03 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: REGEX $1, $2 ... array?
Message-Id: <7aapg7$m6m$1@client2.news.psi.net>

Ilya Zakharevich (ilya@math.ohio-state.edu) wrote on MCMXCV September
MCMXCIII in <URL:news:7aaeb7$m9l$1@mathserv.mps.ohio-state.edu>:
,, [A complimentary Cc of this posting was sent to William H. Asquith
,, <asquith@macconnect.com>],
,, who wrote in article <7aa61j$8tf@enews1.newsguy.com>:
,, > Ilya and Larry, Thanks.
,, > 
,, > I have not heard of these (@+ and @-) before, will check up on this.  They
,, > are not mentioned in Perl 5.005 Pocket Reference.  They must be very new?
,, 
,, I do not remember when they made it into Perl.  Try 
,, 
,,   perldoc perlvar
,, 
,, (due to the fact that 5.005_02 is useless on Solaris, we have only
,, 5.005_54 installed.  Trying 5.005_02 gives


5.005_02 works very well on Solaris. You must have a broken install.
However:

$ perl -wle 'print "$^O: $]"; $_ = "foo bar fez"; /(bar)/; print "@+\n@-"'
solaris: 5.00502
@+
@-
$

I would say, @+ and @- are not special in Perl. Perhaps in certain
development releases, but those are not Perl. Development releases at
best show how a Perl-to-be might look like.



Abigail
-- 
perl -wleprint -eqq-@{[ -eqw\\\\- -eJust -eanother -ePerl -eHacker -e\\\\-]}-


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

Date: 16 Feb 1999 04:24:12 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: REGEX $1, $2 ... array?
Message-Id: <7aartc$pq3$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Abigail
<abigail@fnx.com>],
who wrote in article <7aapg7$m6m$1@client2.news.psi.net>:
> 5.005_02 works very well on Solaris. 

Get real!  Do not pretend you do not read p5p.  5.00502's h2ph is
useless (however 5.00554's one is not much better - I hope 5.00555
will fix it - though I do not remember seeing a patch for __sparc__
being undefined...).  Plus numerous other bugs not fixed in 5.00502...

> However:
> 
> $ perl -wle 'print "$^O: $]"; $_ = "foo bar fez"; /(bar)/; print "@+\n@-"'
> solaris: 5.00502
> @+
> @-

All these shows is that you do not know how Perl's quoting works:

  > perl -wle "@{','} = (1,2,3); print qq(@, @{','})"
  @, 1 2 3

> $
> 
> I would say, @+ and @- are not special in Perl. Perhaps in certain
> development releases, but those are not Perl.

Currently the only useful versions of Perl 5.005 are _53 and more.

Ilya


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

Date: 16 Feb 1999 04:34:54 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: REGEX $1, $2 ... array?
Message-Id: <7aashe$pui$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Abigail
<abigail@fnx.com>],
who wrote in article <7aapg7$m6m$1@client2.news.psi.net>:
> $ perl -wle 'print "$^O: $]"; $_ = "foo bar fez"; /(bar)/; print "@+\n@-"'
> solaris: 5.00502
> @+
> @-
> $

Bah!  Forgot to mention: it is not in 5.00502 indeed.  Even if you use
@{'-'} in strings ;-).

Ilya


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

Date: Tue, 16 Feb 1999 06:00:49 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: REGEX $1, $2 ... array?
Message-Id: <7ab1if$v0k$1@nnrp1.dejanews.com>

In article <7a9mkp$12c@enews2.newsguy.com>,
  "William H. Asquith" <asquith@macconnect.com> wrote:

> Why isn't there a special array that contains
> $1, $2, $3, etc . . . from application of a regex.
> This would really make things easier.
>

$_ = "Why isn't there a special array";
@array = /^(.*?t) ([^s]+) (.*?l) (.+)/;
foreach (@array) { print "$_\n"; }

which is straight-forward enough, but starts getting to be "not to
terribly useful" (to me :) as your capturing parentheses nest:

$_ = "Why isn't there a special array";
@array = /^(((.*?t) ([^s]+)) ((.*?l) (.+)))/;
foreach (@array) { print "$_\n"; }

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 16 Feb 1999 01:55:31 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: SRC: pmexp - show a module's exports
Message-Id: <m36792rg64.fsf@joshua.panix.com>

Tom Christiansen <tchrist@mox.perl.com> writes:

> #!/usr/bin/env perl
[snip]
> BEGIN { $^W = 1 }

Why not 

  #!/usr/bin/env perl -w

which is documented to work (at least in my neck of the unix-like
woods)?

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Tue, 16 Feb 1999 00:33:51 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: String Compare
Message-Id: <fg3ba7.1re.ln@magna.metronet.com>

Paul J. Sala (psala@btv.ibm.com) wrote:
: I'm trying to construct a REGX that will determine if
: a string contains a character other than 
: these: a-z A-Z 0-9 @ . _ -

   if ( $MyStr =~ /[^\w@._-]/ )
      { print "'$MyStr' contains bad chars\n" }
   else
      { print "'$MyStr' is hunky dokey\n" }


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 16 Feb 1999 02:24:48 GMT
From: Mario Guthrie <mguthrie@IPivot.com>
Subject: Term::ReadKey fail when perl is called from C program
Message-Id: <36C82E19.17C35ED@IPivot.com>

Help!!!

I've written a simple perl program that uses the Term::ReadKey module
and it works fine. When I call
my oerl program from a C program it prints the following error:

Can't load
'/usr/libdata/perl5/site_perl/i386-bsdos/auto/Term/ReadKey/ReadKey.o'
for module Term::ReadKey: can't resolve undefined symbols: No such file
or directory at /usr/libdata/perl5/DynaLoader.pm line 140.

Does anyone have any ideas to help me?

Thanks





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

Date: Tue, 16 Feb 1999 06:06:08 +0100
From: Mark <admin@asarian-host.org>
Subject: Vital parts of $1 missing
Message-Id: <199902160506.WAA06750@asarian-host.org>

I know enough not to call "bug" on every encounter that escapes me, but today I
found a quirk that in the absence of my better judgement would probably qualify
as such. The oddest thing ever. I use Perl 5.005. Imagine I had the following
domains defined:

$sites{'vtdomains'} = 'domain_one.org'.
    '|domain_two.org|domain_three.org'.
    '|domain_four.org';

Suppose also that I have stored someone's bare email-address in $from. Now I am
gonna check whether this user belongs to one of the above domains:

$whoami = $1 if ($from =~ /([\w\.\+\-]+\@$sites{'vtdomains'})/i);

Fair enough, right? Everything goes okay if the user is from domain_one.org; if
our user is someone@domain_one.org, $whoami will that value accordingly. So far
so good. But now comes the weird part when our user is from, say,
domain_two.org: instead of matching the entire email-address, $whoami becomes
just the domain-name! That is right: if our user is someone@domain_two.org,
$whoami will that value "domain_two.org". Excuse me?? It turns out that
everything within $1 before $sites{'vtdomains'} is being totally ignored! And
when I say totally, I mean totally: if our user is someone@domain_two.org, then

$whoami = $1 if ($from =~ /(totalnonsense\@$sites{'vtdomains'})/i);

wil match too!! That is, $1 will be "domain_two.org". Now, although I think this
very weird behavior on the part of Perl, and certainly when it comes to not even
spewing so much as a warning message to indicate that vital parts of $1 are
discarded, I could try and understand this if it never worked, if someone Perl
could not match these types of variables in a same regexp. That I could swallow.
But I am totally baffled by the fact that $1 contains the exact correct value
when user is of domain_one.org.

Well, I will let history decide whether it really is a bug, or whether it is
just me missing something again. I will assume the latter, for now, but in the
meantime I would welcome suggestions.

Much obliged,

- Mark

        System Administrator Asarian-host.org







--
For more information about this posting service, contact:

help@asarian-host.org    -- for general info about our services
admin@asarian-host.org   -- for the server's administrator
nclark@asarian-host.org  -- for our PR manager
abuse@asarian-host.org   -- for abuse of this posting service

If you wish to get an anonymous account, visit our sign-up page:

http://asarian-host.org/emailform.html


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

Date: Tue, 16 Feb 1999 05:15:19 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Vital parts of $1 missing
Message-Id: <ebohlmanF78ELJ.L9K@netcom.com>

Mark <admin@asarian-host.org> wrote:
: I know enough not to call "bug" on every encounter that escapes me, but today I
: found a quirk that in the absence of my better judgement would probably qualify
: as such. The oddest thing ever. I use Perl 5.005. Imagine I had the following
: domains defined:

: $sites{'vtdomains'} = 'domain_one.org'.
:     '|domain_two.org|domain_three.org'.
:     '|domain_four.org';

: Suppose also that I have stored someone's bare email-address in $from. Now I am
: gonna check whether this user belongs to one of the above domains:

: $whoami = $1 if ($from =~ /([\w\.\+\-]+\@$sites{'vtdomains'})/i);

: Fair enough, right? Everything goes okay if the user is from domain_one.org; if
: our user is someone@domain_one.org, $whoami will that value accordingly. So far
: so good. But now comes the weird part when our user is from, say,
: domain_two.org: instead of matching the entire email-address, $whoami becomes
: just the domain-name! That is right: if our user is someone@domain_two.org,
: $whoami will that value "domain_two.org". Excuse me?? It turns out that
: everything within $1 before $sites{'vtdomains'} is being totally ignored! And
: when I say totally, I mean totally: if our user is someone@domain_two.org, then

Read perlre and see what it has to say about the precedence of the '|' 
operator in regexes.

Perl's doing what you told it to; you just forgot to put "use DWIM" at 
the start of your script.



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

Date: 16 Feb 1999 05:22:13 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Vital parts of $1 missing
Message-Id: <slrn7ci045.squ.sholden@pgrad.cs.usyd.edu.au>

On Tue, 16 Feb 1999 06:06:08 +0100, Mark <admin@asarian-host.org> wrote:
>I know enough not to call "bug" on every encounter that escapes me, but today I
>found a quirk that in the absence of my better judgement would probably qualify
>as such. The oddest thing ever. I use Perl 5.005. Imagine I had the following
>domains defined:
>
>$sites{'vtdomains'} = 'domain_one.org'.
>    '|domain_two.org|domain_three.org'.
>    '|domain_four.org';
>
>Suppose also that I have stored someone's bare email-address in $from. Now I am
>gonna check whether this user belongs to one of the above domains:
>
>$whoami = $1 if ($from =~ /([\w\.\+\-]+\@$sites{'vtdomains'})/i);
>
>Fair enough, right? Everything goes okay if the user is from domain_one.org; if
>our user is someone@domain_one.org, $whoami will that value accordingly. So far
>so good. But now comes the weird part when our user is from, say,
>domain_two.org: instead of matching the entire email-address, $whoami becomes
>just the domain-name! That is right: if our user is someone@domain_two.org,
>$whoami will that value "domain_two.org". Excuse me?? It turns out that
>everything within $1 before $sites{'vtdomains'} is being totally ignored! And
>when I say totally, I mean totally: if our user is someone@domain_two.org, then
>
>$whoami = $1 if ($from =~ /(totalnonsense\@$sites{'vtdomains'})/i);
>
>wil match too!! That is, $1 will be "domain_two.org". Now, although I think this
>very weird behavior on the part of Perl, and certainly when it comes to not even
>spewing so much as a warning message to indicate that vital parts of $1 are
>discarded, I could try and understand this if it never worked, if someone Perl
>could not match these types of variables in a same regexp. That I could swallow.
>But I am totally baffled by the fact that $1 contains the exact correct value
>when user is of domain_one.org.
>
>Well, I will let history decide whether it really is a bug, or whether it is
>just me missing something again. I will assume the latter, for now, but in the
>meantime I would welcome suggestions.

Have you considered what the actual regular expression you are using is?
Have you considered how precedence might work?

What does the following put in $1 if a match succeeds :

/(foo|bar)/

What about :

/(foo_baz|bar)/


What about :

/(foo@baz|bar)/


Your regex is not matching what you expect it to match. 

You coulds try something like :

/([\w\.\+\-]+\@(?:$sites{'vtdomains'}))/i


-- 
Sam

There's no such thing as a simple cache bug.
	--Rob Pike


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". 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". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4903
**************************************

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