[15739] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3152 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 24 18:15:57 2000

Date: Wed, 24 May 2000 15:15:31 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <959206531-v9-i3152@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 24 May 2000     Volume: 9 Number: 3152

Today's topics:
    Re: hashes vs associative arrays (was: Re: Array Questi <rootbeer@redcat.com>
    Re: Help needed with SNPP!!!!!!!!!!!!!! <apage.net[remove]@usa.net>
    Re: How do I extract 2nd and 3rd characters from a stri (Gwyn Judd)
    Re: How to split this ? <aqumsieh@hyperchip.com>
    Re: how to stop strict from whining... <rootbeer@redcat.com>
    Re: LWP::Simple problem <rootbeer@redcat.com>
    Re: LWP::Simple problem <makarand_kulkarni@My-Deja.com>
    Re: Matching Question <jraff@home.com>
    Re: Matching Question <lr@hpl.hp.com>
    Re: my algorythms suck <thepoet1@arcormail.de>
        need help on perl library call.. e_bengal@my-deja.com
    Re: newbie question - relative addressing <rootbeer@redcat.com>
    Re: odd behavior printing after randomizing an array fr <red_orc@my-deja.com>
    Re: odd behavior printing after randomizing an array fr <kiera@nnickee.com>
    Re: odd behavior printing after randomizing an array fr <kiera@nnickee.com>
    Re: odd behavior printing after randomizing an array fr (Gwyn Judd)
        Opensales uses Perl <makarand_kulkarni@My-Deja.com>
    Re: Opensales uses Perl <Tbone@pimpdaddy.com>
    Re: Passing an array to a regexp <lr@hpl.hp.com>
    Re: Passing an array to a regexp (Abigail)
    Re: Passing an array to a regexp <madebeer@igc.apc.org>
    Re: Passing an array to a regexp <lr@hpl.hp.com>
        Perl DBI -- please help <yardeni@hooverco.com>
    Re: Perl DBI -- please help <rootbeer@redcat.com>
    Re: Perl DBI -- please help <jeff@vpservices.com>
        Perl Editor for Linux houseofpain@my-deja.com
    Re: Perl Editor for Linux <rootbeer@redcat.com>
    Re: Perl Editor for Linux <flavell@mail.cern.ch>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 24 May 2000 11:43:16 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: hashes vs associative arrays (was: Re: Array Question)
Message-Id: <Pine.GSO.4.10.10005241137050.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, Peter Lowe wrote:

> I personally think that the phrase associative arrays is a much better
> word to use when learning perl, as it actually tells what you're
> dealing with if you know what an array is, whereas "hash" doesn't
> really tell me much.

Well, if the term "associative array" actually tells you something, go
ahead and say it. But it doesn't seem to tell me anything more than "hash"
does. Either way, once you learn what it is, you probably won't want to
keep using the long and awk-ward term. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 14:46:53 -0400
From: "Zowwie" <apage.net[remove]@usa.net>
Subject: Re: Help needed with SNPP!!!!!!!!!!!!!!
Message-Id: <sio8t3rjo191@corp.supernews.com>

Q: "For example, I want to send a message to my 2 way skytel pager with
multiple choices response, so that skytel user will choose one of the
responses and email it back to me."

A:
See the following SkyTel developer link:
http://www.skytel.com/develop/index.html

The package at Skytel appears to establish a connection via a socket to port
#7777 @ snpp.skytel.com.

As far as the perl module goes... I would assume that you could use any
package or module to obtain the responses so long as it permitted you to
tx/rx your commands.

Good luck.






Mohammad Khan wrote in message <392bff4f$0$18620@wodc7nh1.news.uu.net>...
>Hi,
>      Is there any way to send multi choice responses through Perl SNPP
>module. For example, I want to send a message to my 2 way skytel pager with
>multiple choices response, so that skytel user will choose one of the
>responses and email it back to me.
>
>Thanks.
>
>




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

Date: Wed, 24 May 2000 21:49:11 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: How do I extract 2nd and 3rd characters from a string
Message-Id: <slrn8ir82p.c6l.tjla@thislove.dyndns.org>

I was shocked! How could Tom Briles <sariq@texas.net>
say such a terrible thing:
>Gwyn Judd wrote:
>> umm but doesn't '.' normally match any character except newline? In
>> which case it would match "st" in your given string.
>
>No, it won't.  *Always* test before posting.

look (from the perlre documentation):

  .   Match any character (except newline)

Are you saying it does match newlines? Or something else?

$string = "A\nstring";
($st) = $string =~ /.(..)/;
print $st;

This gives me an output of "tr". Oh whoops now I understand :). Thanks
for being so patient with me.

-- 
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
Planet Claire has pink hair.
All the trees are red.
No one ever dies there.
No one has a head....


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

Date: Wed, 24 May 2000 19:48:49 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: How to split this ?
Message-Id: <7avh03wwym.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


Ilja <billy@arnis-bsl.com> writes:

> In article <8ggk54$1ht$1@news2.kornet.net>,
>   "Moltimer" <moltimer@yahoo.com> wrote:
> 
> > If you give me one more example
> > for getting two values of lets[0] and lets[1] with
> > "A-1_A-2_A-3_much_more_B",
> > I will be happy to learn this.
> >
> >  $lets[0] should be "A-1_A-2_A-3_much_more"
> >  $lets[1] should be "B"
> >
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my $str = 'A-1_A-2_A-3_much_more_B';
> 
> my @lets = $str =~ /(.+)_([^_]+?)$/;
> 
> die "string $str doesn't match\n"  unless @lets;

No need to complicate the regexp that much. Just make use of the
default greediness of the +:

	my @lets = $str =~ /(.+)_(.+)/;

--Ala


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

Date: Wed, 24 May 2000 11:12:45 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: how to stop strict from whining...
Message-Id: <Pine.GSO.4.10.10005241106550.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, peter wrote:

> how can i stop "use strict" from whining about bad code in a module?  

If you're the author (or maintainer) of the module, make it 'strict
compliant'. If you're not, using 'use strict' in your own code shouldn't
affect the module's behavior. If using the module in the proper way causes
warning messages, file a bug report.

Of course, maybe the messages you're seeing mean that there's a real bug
that Perl is trying to warn you about.

> Argument "HASH" isn't numeric in eq at

> Argument "" isn't numeric in eq at

> Use of uninitialized value at

Those aren't from 'use strict'! They almost certainly mean a bug, though.

> ------ here is the offending
> code ----------------------------------------------------
> ---clearly the "==" should be "eq"
> code from /usr/complex/perl/lib/site_perl/5.005/aix/DBD/DB2.pm:
> ...
>         if( ref($attr) == "HASH" )

Yep, that's a bug. Have you filed a bug report? If you include a patch,
that'll be helpful. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 11:19:30 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: LWP::Simple problem
Message-Id: <Pine.GSO.4.10.10005241117230.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, Richard Corfield wrote:

> it seems that I can retrieve pages from within the
> company intranet, but not from outside using this method. 

Smells like a firewall. Do you need to set up LWP to use a proxy, perhaps?
Maybe you didn't need that last week, but maybe you do today. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 11:49:09 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: LWP::Simple problem
Message-Id: <392C2425.C022221E@My-Deja.com>

> OK ..... so I've discovered it's because of the proxy server I'm behind -
> any ideas of how to get round this as painlessly as posssible?

You can set a proxy URL using LWP::UserAgent
read
perldoc  LWP::UserAgent




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

Date: Wed, 24 May 2000 18:56:35 GMT
From: "jraff" <jraff@home.com>
Subject: Re: Matching Question
Message-Id: <DBVW4.83152$R4.508705@news1.rdc1.nj.home.com>

Look at the paren "()" usage in perl RE - /(\d(9))/:
http://www.perl.com/pub/doc/manual/html/pod/perlre.html
http://www.activestate.com/Products/ActivePerl/docs/lib/Pod/perlre.html
Look for "The bracketing construct ( ... ) creates capture buffers"
----------------------------------------
For the start look at "index".
http://www.activestate.com/Products/ActivePerl/docs/lib/Pod/perlfunc.html#it
em_index
(For some reason O'Riley doesn't have it)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
<amerar@my-deja.com> wrote in message news:8ggq3g$d7t$1@nnrp1.deja.com...
> Here is a dumb question.  I need to do a series of pattern matchings.
> For example, I need to search a string for 9 digits in a row, or I need
> to find a pattern of 2 digits, followed by letters FR followed by 5 more
> digits.
>
> Anyhow, upon finding the match, I need to extract the pattern from the
> string.
>
> I can find out whether or not a pattern is in the string as in this
> case:  ($x =~ /\d{9}/)
>
> But how do I extract the string?  I do not even know where the string
> starts.......





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

Date: Wed, 24 May 2000 12:09:51 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Matching Question
Message-Id: <MPG.1395c8d9e452bb8798aace@nntp.hpl.hp.com>

In article <8ggq3g$d7t$1@nnrp1.deja.com> on Wed, 24 May 2000 14:48:22 
GMT, amerar@my-deja.com <amerar@my-deja.com> says...

 ...
 
> Here is a dumb question.

It isn't a dumb question, it is an elementary question.  You need to 
read a tutorial on regular expressions.  I posted a URL earlier today; 
you can find the same URL easily by a web search for 'Perl' and 
'tutorial'.

>                         I need to do a series of pattern matchings.
> For example, I need to search a string for 9 digits in a row, or I need
> to find a pattern of 2 digits, followed by letters FR followed by 5 more
> digits.

Why do you describe that as a series of pattern matchings?  It sounds 
like a choice of alternatives, so the regex alternation operator will be 
involved.

> Anyhow, upon finding the match, I need to extract the pattern from the
> string.
> 
> I can find out whether or not a pattern is in the string as in this
> case:  ($x =~ /\d{9}/)
> 
> But how do I extract the string?  I do not even know where the string
> starts.......

Use capturing parentheses.

> Please cc a copy of amerar@ci.chi.il.us

Please post from that address, or put that address into a Reply-To 
header.

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


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

Date: Wed, 24 May 2000 01:10:26 +0200
From: Christian Winter <thepoet1@arcormail.de>
Subject: Re: my algorythms suck
Message-Id: <253fg8.20e.ln@usenet-autoren.de>

klidge <klidge@mailbox.gr> schrob:
> so i have an index file for a forum i want to create on the web

> i want an algorythm which using the above data can create this output:

> subject 3
>  |->subject 3-1
>    |->subject 3-1-1
>    |->subject 3-1-2
>  |->subject 3-2
>    |->subject 3-2-1

> of course i don't have any problem with the html code.i just can't find
> how can i make perl to do it.i 'm open to ANY suggestions :)

Hi,

I did something similare recently (threading a newsgroup), so
it wasn't hard to adapt the code:

--------------------------------------------------------------
#!/usr/bin/perl -w

use strict;

my %inmsg;

open(IN, "<input.dat") or die $!;
while( <IN> ) {
  chomp;
  my @vals = split /\?/, $_;
  $inmsg{shift @vals} = \@vals;
}
close IN;

my %sorted;
my @top;
my %next;

while( scalar %inmsg ) {
  foreach( keys %inmsg ) {
    my @inarr = @{$inmsg{$_}};
    if( $inarr[1] == 0 ) {
      $sorted{ $_ } = $inmsg{$_};
      push @top, $_;
      delete $inmsg{$_};
    } elsif( defined( $sorted{ $inmsg{$_}->[1] } ) ) {
      $sorted{ $_ } = $inmsg{$_};
      unless( defined( $next{ $inmsg{$_}->[1] } ) ) {
        my @aaa;
        $next{ $inmsg{$_}->[1] } = \@aaa;
      }
      push @{$next{ $inmsg{$_}->[1] }}, $_;
      delete $inmsg{$_};
    }
  }
}

foreach( @top ) {
  recurse($_);
}

exit(0);

sub recurse
{
  my $val = shift;
  my $ind = (@_)?(shift @_):"";
  my $indent = ($ind ne "")?$ind."|->":"";
  print $indent.$sorted{$val}->[2]."\n";
  if( defined( $next{$val} ) ) {
    recurse( $_, $ind."\t" ) foreach( @{$next{$val}} );
  }
}
-----------------------------------------------------------

HTH
Christian


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

Date: Wed, 24 May 2000 21:35:22 GMT
From: e_bengal@my-deja.com
Subject: need help on perl library call..
Message-Id: <8ghhup$42$1@nnrp1.deja.com>

I have been looking for infos on perl library call "shellwords.pl".
I have used it long time ago and forgot how to use it again with
the "require" command. I went to book store and glanced thru' 6/7
books on perl, looking for some examples or detailed explanations !!
Gosh~~, nothing I could find helped me in any of the books !!!!

Can someone please tell me with an example how to use the call.
Also can anyone recommend any good book where it explains with
examples how to use all perl library calls etc. ?

Would appreciate it very much.

Thanks.

FA.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 24 May 2000 11:45:44 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: newbie question - relative addressing
Message-Id: <Pine.GSO.4.10.10005241144230.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, Alan Hood wrote:

> The problem seems to be that I use relative addresses. 

Do you mean file paths relative to the current directory?

Could you be talking about a CGI program? The CGI spec doesn't specify
which directory will be the current working directory when a CGI program
is started.

    http://hoohoo.ncsa.uiuc.edu/cgi/

It may be the root directory, the server's working directory, the home
directory for user nobody, the home directory for root, the directory the
program is stored in, the directory the server is stored in, the base
cgi-bin directory, the /tmp directory, a directory you don't have access
to from the shell, a directory named after an annoying character from
Saturday Night Live, a directory chosen at random, or some other
directory.

A CGI program which uses a relative path before chdir()ing to a
non-relative path is in a state of sin.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 20:11:50 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: odd behavior printing after randomizing an array from STDIN
Message-Id: <8ghd1o$s8c$1@nnrp1.deja.com>

In article
<84BF13308AFA8255.1CFB92267BA562CA.0F5E9952FEF66BDA@lp.airnews.net>,
  kiera@nnickee.com wrote:
> Ok, the basics:  running win98 with ActivePerl (version 5.005_03,
> build 522)
>
> Am working thru the Exercises in "Learning Perl on Win32 Systems" and
> I get to the 3rd exercise in the 3rd chapter:
>
> "Write a program that reads a list of strings and then selects and
> prints a random string from the list."
>
> Easy.
>
> #!perl -w
> srand;
> print "List of strings: ";
> my @b = <STDIN>;
> print "Answer: $b[rand(@b)]";
> #__END__
>
> Right?  Cept.. it didn't print anything.  Not even the word "Answer:".
> No warnings, no nuthin'.  Oh, and that code above is almost character
> for character from the Answer page in the book (I added the -w and the
> my - behavior didn't change when I removed them).
>
> What did change the outcome was adding a \n right before Answer:
> 	print "\nAnswer: $b[rand(@b)]";
>

what part of the bahavior changed?  did it print the expected result?

The code above expects an unspecified number of lines input from STDIN,
and will not continue until EOF is hit.  When I tried this on my NT
machine (also 5.00503 build 522), I entered three lines and closed the
input with a cntrl-z.  This resulted in the printed line with one of my
input lines as the output.

> Ok, so I guess my question is... is this behavior specific to win98?
> Is it because of the ctrl-z needed to stop reading in strings from the
> command window?

probably, since the read from the command window needs to hit EOF before
the script can continue.

> Is this documented anywhere (I've been looking but
> haven't found it yet)?
>
> Why is the sky blue? [0]

This is due to scattering of the incomming light from (mainly) the sun.
scattering is inversely proportional to the (i think fourth power of the
) wavelength of the ligit being scattered.  As a consequence, light with
a longer wavelength (red, infrared) is scattered less than light with a
shorter wavelength (blues, violet, ultraviolet).  This results in the
blue appearance of the sky, and the (sometimes) reddish appearance of
sunsets/sunrises.

>
> TIA
> Kiera
>
> [0] erm.. sorry... just kinda got on a roll there :)
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 24 May 2000 16:23:29 -0500
From: Kiera <kiera@nnickee.com>
Subject: Re: odd behavior printing after randomizing an array from STDIN
Message-Id: <3B96DFD4A2F40F5E.E631EEF6353E4932.51E04B4DCA26A856@lp.airnews.net>

On Wed, 24 May 2000 20:11:50 GMT, someone claiming to be Rodney
Engdahl <red_orc@my-deja.com> said:

>> #!perl -w
>> srand;
>> print "List of strings: ";
>> my @b = <STDIN>;
>> print "Answer: $b[rand(@b)]";
>> #__END__

>> Right?  Cept.. it didn't print anything.  Not even the word "Answer:".
>> No warnings, no nuthin'.  Oh, and that code above is almost character
>> for character from the Answer page in the book (I added the -w and the
>> my - behavior didn't change when I removed them).

>> What did change the outcome was adding a \n right before Answer:
>> 	print "\nAnswer: $b[rand(@b)]";

>what part of the bahavior changed?  did it print the expected result?

yes it did.  sorry if I didn't make that clear the first time  :)

>The code above expects an unspecified number of lines input from STDIN,
>and will not continue until EOF is hit.  When I tried this on my NT
>machine (also 5.00503 build 522), I entered three lines and closed the
>input with a cntrl-z.  This resulted in the printed line with one of my
>input lines as the output.

Oh, I knew I had to ctrl-z ... and I did (after entering a few lines
of text).  The problem was that until I added the \n to the beginning
of the print statement, *nothing* printed after the ctrl-z... the
script just "ended".

>> Ok, so I guess my question is... is this behavior specific to win98?
>> Is it because of the ctrl-z needed to stop reading in strings from the
>> command window?

>probably, since the read from the command window needs to hit EOF before
>the script can continue.

But the command window *did* hit EOF.  If you have access to a win98
box, try it out.  Guess I'm gonna hafta get my E drive's contents
moved to another drive so I can reinstall NT (oh darn :)  and make
this system dual-boot again :)

Kiera



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

Date: Wed, 24 May 2000 16:23:30 -0500
From: Kiera <kiera@nnickee.com>
Subject: Re: odd behavior printing after randomizing an array from STDIN
Message-Id: <555FB029FEC04A33.DA0D93137D63A8D1.CE08CDA9BDD4AA1D@lp.airnews.net>

On 24 May 2000 09:18:58 -0700, someone claiming to be Sue Spence
<sue@pennine.com> said:

>>#!perl -w
>>srand;
>>print "List of strings: "; 
>>my @b = <STDIN>;
>>print "Answer: $b[rand(@b)]";
>>#__END__

>>Right?  Cept.. it didn't print anything.  Not even the word "Answer:".
>>No warnings, no nuthin'.  Oh, and that code above is almost character
>>for character from the Answer page in the book (I added the -w and the
>>my - behavior didn't change when I removed them).

>>What did change the outcome was adding a \n right before Answer:
>>	print "\nAnswer: $b[rand(@b)]";

>>Ok, so I guess my question is... is this behavior specific to win98?

>Maybe.  It seemed "obvious" to me that you should have a "\n" on the end of your
>print statement.  But I tried that on Win98 with ActiveState v5.6 and that
>didn't flush the buffer the way I had expected it to.  Strangely, as you say,
>the only thing that works is to put the newline at the beginning of the print
>string.  Weird.  Works as expected on solaris 5.6 w/perl 5.005_02.

Thank you!  I posted this here hoping that others who had access to a
win98 box would test it.

So far we've had one on NT test it and it worked and two (you and I)
on win98 where it didn't work.  Anybody else?

Kiera



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

Date: Wed, 24 May 2000 22:01:44 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: odd behavior printing after randomizing an array from STDIN
Message-Id: <slrn8ir8qa.c6l.tjla@thislove.dyndns.org>

I was shocked! How could Abigail <abigail@arena-i.com>
say such a terrible thing:
>You can do it in constant space if you may make the assumption the
>strings have at most a certain, pre determined, length.
>
>    perl -nwe '$a = $_ if rand $. < 1; END {print $a}'
>
>The math is simple. Suppose there are N lines on the input. The chance that
>line M will be the line printed is:
>
>         N
>    1   ___   k-1       1   M    1
>    _ * | |   ---   =   - * - == -
>    M   | |    k        M   N    N
>       k=M+1
>
>And that's for all M.

oh that's pretty :).

-- 
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
Human resources are human first, and resources second.
		-- J. Garbers


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

Date: Wed, 24 May 2000 12:56:59 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Opensales uses Perl
Message-Id: <392C340B.AAFFCF63@My-Deja.com>

I thought this might be an interesting read for those always debating
whether Perl is appropriate to do a particular job etc.

From:
http://news.cnet.com/news/0-1007-200-1939586.html?tag=st.ne.1002.tgif.ni

"One unusual aspect of OpenSales is its use of the Perl programming
language for its software. By contrast,
  most large, complex programs are written in languages such as C, C++
or Java, which can be translated
  into compact instructions a chip can understand."

--



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

Date: 24 May 2000 21:39:43 GMT
From: Intergalactic Denizen of Mystery <Tbone@pimpdaddy.com>
Subject: Re: Opensales uses Perl
Message-Id: <8ghi6v$t8q$1@news.enteract.com>

makarand_kulkarni@My-Deja.com writes:
>From:
>http://news.cnet.com/news/0-1007-200-1939586.html?tag=st.ne.1002.tgif.ni
>
>"By contrast, [...] languages such as C, C++ or Java, [...] can be
>translated into compact instructions a chip can understand."

I didn't know CNet published articles with dorky statements like this...



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

Date: Wed, 24 May 2000 12:20:03 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Passing an array to a regexp
Message-Id: <MPG.1395cb3ea58d8c2298aacf@nntp.hpl.hp.com>

In article <959183416.22231@itz.pp.sci.fi> on 24 May 2000 15:58:09 GMT, 
Ilmari Karonen <iltzu@sci.invalid> says...
> In article <392bf388.2052011@news.freeserve.net>, Ben Hambidge wrote:
> >I have the following condition:
> >if ( $x =~ /^[one|two|three|four]/ ) { ...}
> >However, I would like to test for values in an array; for example:
> >@array = ( "one", "two", "three", "four" );
> 
> I presume your real code has () instead of [] in the regexp?
> 
>   my $re = join '|' => map "\Q$_" => @array;
>   if ( $x =~ /^($re)/ ) { ... }

Oof.  You didn't test that.  What do you think would be matched by:

    /^(\Qone|\Qtwo|\Qthree|\Qfour)/

A trailing '$' anchor might be wise, also.

> Remove the 'map "\Q$_" =>' part if you want the array elements to be
> interpreted as regexps.
> 
> Depending on exactly what you're doing, this may or may not be the
> most efficient way, but it should work. 

Here is more required reading on this:

perlfaq4: "How can I tell whether a list or array contains a certain 
element?"

>                                       If you plan to apply the same
> regexp to several values, precompiling it with qr// is recommended.

And on this:

perlfaq6: "How do I efficiently match many regular expressions at once?"

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


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

Date: 24 May 2000 20:10:36 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: Passing an array to a regexp
Message-Id: <8ghcvs$81n$3@news.panix.com>

On Wed, 24 May 2000 12:20:03 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
++ In article <959183416.22231@itz.pp.sci.fi> on 24 May 2000 15:58:09 GMT, 
++ Ilmari Karonen <iltzu@sci.invalid> says...
++ > 
++ >   my $re = join '|' => map "\Q$_" => @array;
++ >   if ( $x =~ /^($re)/ ) { ... }
++ 
++ Oof.  You didn't test that.  What do you think would be matched by:
++ 
++     /^(\Qone|\Qtwo|\Qthree|\Qfour)/

Eh, *you* didn't test that. 

    @array = qw /one two three four/;
    join '|' => map "\Q$_" => @array;

doesn't yield

    "\Qone|\Qtwo|\Qthree|\Qfour"

Instead:

    @array = qw /one two th[re]e four/;
    print join '|' => map "\Q$_" => @array;

gives:

    one|two|th\[re\]e|four


After all, the \Q is interpolated in the "\Q$_", not kept and evalled
in the regex.



Abigail


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

Date: Wed, 24 May 2000 12:03:34 -0700 (PDT)
From: Michael de Beer <madebeer@igc.apc.org>
Subject: Re: Passing an array to a regexp
Message-Id: <APC&1'0'50775de1'0e2@igc.apc.org>

Ben wrote:

>if ( $x =~ /^[one|two|three|four]/ ) { ...}
>
>However, I would like to test for values in an array; for example:
>
>@array = ( "one", "two", "three", "four" );

Two things:
a) I think you have to make a regexp string and use that.
b) what do you want to happen if there are metacharacters in your array?

Here is code does a) and warns about b)

#!/usr/local/bin/perl5 -w
use strict qw(vars);
--------------------------------------------------------------------------
# /^[one|two|three|four]/, or probably using () instead of []
my @array = ( "one", "two", "three", "four", 'zebra$1' );

# warn about any possible metacharacters.  This could be less strict.
my @odd = grep( /\W/, @array);
print "non-alphanumeric character in @odd, regexp could be messed up.\n" 
   if (@odd);

# create a regular expression that looks for any values in the array
my $regexp = '^(' . join('|',@array) . ')';
print "using regexp $regexp\n";

for (qw/two three four five six/) {
  print /$regexp/ ? '' : 'no ', "match on $_\n"
}
__END__



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

Date: Wed, 24 May 2000 14:05:37 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Passing an array to a regexp
Message-Id: <MPG.1395e3fa8d7dde0898aad2@nntp.hpl.hp.com>

In article <8gh47m$63o$2@news.panix.com> on 24 May 2000 17:41:10 GMT, 
Abigail <abigail@arena-i.com> says...
> On Wed, 24 May 2000 15:24:29 GMT,
> Ben Hambidge <newsmay2000@ordinate.co.uk> wrote:
> ++ I have the following condition:
> ++ 
> ++ if ( $x =~ /^[one|two|three|four]/ ) { ...}
> ++ However, I would like to test for values in an array; for example:
> ++ 
> ++ @array = ( "one", "two", "three", "four" );
> ++ 
> ++ Can I now write the regexp to pull out the values of the array
> ++ instead, making the regexp flexible depending on the values in the
> ++ array at the time?

 ...

>     {local $"  = '|';
>      my @array = map {quotemeta} @array;   # Not necessary if no element of
>                                            # @array contains a regex meta char.
>      if ($x =~ /^@array/) { ... }

       if ($x =~ /^(?:@array)$/) { ... }

>     }

But why are we mucking around with regexes, when this should be a 
classic hash lookup?  I already gave the FAQ reference.

      my %array;
      @array{@array} = ();

      if (exists $array{$x}) { ... }

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


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

Date: Wed, 24 May 2000 14:29:58 -0500
From: "Tal Yardeni" <yardeni@hooverco.com>
Subject: Perl DBI -- please help
Message-Id: <9%VW4.98$a3.457355@sol.pdnt.net>

I have the Perl DBI module installed on my web server (I followed the
instructions to the letter on
http://forteviot.symbolstone.org/cgi/dbi/moduledump?module=DBI) yet I am
getting an error message when trying to use DBI to connect to any data
source:

 ./getdb.cgi
Content-type: text/html

Can't locate Win32/OLE.pm in @INC (@INC contains:
/usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 .
/usr/lib/perl5/site_perl/5.005/i386-linux) at
/usr/lib/perl5/site_perl/5.005/i386-linux/DBD/ADO.pm line 68.

This looks like there is an error in the ADO.pm script.

Apart from running:
make
make test ( no errors came up here)
make install

is there anything else I need to do to get this module to work?

The server I am trying to run my script on is an x86 running Linux 2.2.14
(Red Hat 6.2).

Thanks.





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

Date: Wed, 24 May 2000 12:39:03 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl DBI -- please help
Message-Id: <Pine.GSO.4.10.10005241237450.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, Tal Yardeni wrote:

> Can't locate Win32/OLE.pm in @INC (@INC contains:

Do you have that module properly installed? (Hint: No. :-)

> The server I am trying to run my script on is an x86 running Linux 2.2.14
> (Red Hat 6.2).

That doesn't sound like a machine which should be running Win32 modules.
Is that what you're trying to do?

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/




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

Date: Wed, 24 May 2000 13:07:43 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Perl DBI -- please help
Message-Id: <392C368F.9DC0DC3A@vpservices.com>

Tal Yardeni wrote:
> 
> I have the Perl DBI module installed on my web server
>
> [snip]
>
> Can't locate Win32/OLE.pm in @INC (@INC contains:
>
> [snip]
>
> The server I am trying to run my script on is an x86 running Linux 2.2.14
> (Red Hat 6.2).

Win32/OLE.pm is a module specific to windoze, you can't run it on
Linux.  And in any case, it has nothing to do with DBI.  You need to get
DBI and the DBD that is appropriate for whatever database you are
running on Linux.

-- 
Jeff


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

Date: Wed, 24 May 2000 19:29:12 GMT
From: houseofpain@my-deja.com
Subject: Perl Editor for Linux
Message-Id: <8ghahj$qbt$1@nnrp1.deja.com>

Can anyone recomend a good Perl Editor for Linux.  Someting i can use
to trace through my code.


Thanks,
HOP


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 24 May 2000 13:23:34 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl Editor for Linux
Message-Id: <Pine.GSO.4.10.10005241320270.14618-100000@user2.teleport.com>

On Wed, 24 May 2000 houseofpain@my-deja.com wrote:

> Can anyone recomend a good Perl Editor for Linux.  

Use the same editor you use for C. If you're not sure which one, start a
religious war. :-)

> Someting i can use to trace through my code.

Editors edit. Debuggers trace through code. Right?

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 22:51:48 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl Editor for Linux
Message-Id: <Pine.GHP.4.21.0005242250010.8380-100000@hpplus01.cern.ch>

On Wed, 24 May 2000, Tom Phoenix wrote:

> Editors edit. Debuggers trace through code. Right?

I think emacs does both, makes coffee and toast too.

I'm afraid I never caught that particular religion (aside from
occasionally running emacs-w3 as a web browser).



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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3152
**************************************


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