[22314] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4535 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 10 18:31:53 2003

Date: Mon, 10 Feb 2003 15:31:31 -0800 (PST)
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, 10 Feb 2003     Volume: 10 Number: 4535

Today's topics:
        How to compare two arrays (Francesco Moi)
    Re: How to compare two arrays <mothra@nowhereatall.com>
    Re: How to compare two arrays <spamtrap@nowhere.com>
    Re: How to compare two arrays <mothra@nowhereatall.com>
    Re: How to compare two arrays <mpapec@yahoo.com>
        How to prevent resolving variables (Jason Chen)
    Re: How to prevent resolving variables <usenet@dwall.fastmail.fm>
    Re: I'm just not getting it... FAQ5 <krahnj@acm.org>
        Installation of perl modules (Lisa Koma)
    Re: Installation of perl modules <noreply@gunnar.cc>
    Re: Installation of perl modules (Stefan Adams)
        Installing new modules <brian.smart@blueyonder.co.uk>
    Re: Installing new modules <ajglist@izzy.net>
    Re: Installing new modules (Tad McClellan)
    Re: Installing new modules (Chas Friedman)
        iterator in for loop (squillion)
    Re: iterator in for loop <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: iterator in for loop <ubl@schaffhausen.de>
    Re: iterator in for loop <mpapec@yahoo.com>
    Re: iterator in for loop <bigj@kamelfreund.de>
    Re: LWP multipart/form-data with content NOT from file <peakpeek@purethought.com>
    Re: LWP multipart/form-data with content NOT from file <peakpeek@purethought.com>
    Re: LWP multipart/form-data with content NOT from file <richard@zync.co.uk>
        matching with [ <zahm@uiuc.edu>
    Re: matching with [ <thepoet@nexgo.de>
    Re: matching with [ <zahm@uiuc.edu>
    Re: matching with [ <flavell@mail.cern.ch>
    Re: matching with [ <me@privacy.net>
    Re: matching with [ <zahm@uiuc.edu>
    Re: matching with [ (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 7 Feb 2003 12:30:58 -0800
From: francescomoi@europe.com (Francesco Moi)
Subject: How to compare two arrays
Message-Id: <5b829932.0302071230.17619b3@posting.google.com>

Hello.

I've got two arrays:
@array1 = ('foo1' 'foo2' 'foo3')
@array2 = ('foo2' 'foo7' 'foo9')

And I want to get the matching elements of both arrays.

Is there any function? Thank you very much.


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

Date: Fri, 7 Feb 2003 12:47:57 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: How to compare two arrays
Message-Id: <3e4419f0$1@usenet.ugs.com>


"Francesco Moi" <francescomoi@europe.com> wrote in message
news:5b829932.0302071230.17619b3@posting.google.com...
> Hello.
>
> I've got two arrays:
> @array1 = ('foo1' 'foo2' 'foo3')
> @array2 = ('foo2' 'foo7' 'foo9')
>
> And I want to get the matching elements of both arrays.
>
> Is there any function? Thank you very much.

use strict;
use warnings;
my @array1 = qw(foo1 foo2 foo3);
my @array2 = qw(foo2 foo7 foo9);
my %union;
my %isect;
foreach my $e (@array1, @array2) { $union{$e}++ && $isect{$e}++ }

my @union = keys %union;
my @isect = keys %isect;

Mothra

print @isect;




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

Date: Fri, 07 Feb 2003 20:46:22 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: How to compare two arrays
Message-Id: <ho684vgi6h5qainhfi4a81ij06g810o1n4@4ax.com>

On 7 Feb 2003 12:30:58 -0800, francescomoi@europe.com (Francesco Moi)
wrote:

>Hello.
>
>I've got two arrays:
>@array1 = ('foo1' 'foo2' 'foo3')
>@array2 = ('foo2' 'foo7' 'foo9')
>
>And I want to get the matching elements of both arrays.
>
>Is there any function? Thank you very much.

perldoc perlfaq4

"How do I compute the difference of two arrays? How do I compute the
intersection of two arrays?"

hth



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

Date: Fri, 7 Feb 2003 12:50:14 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: How to compare two arrays
Message-Id: <3e441a79$1@usenet.ugs.com>


"Mothra" <mothra@nowhereatall.com> wrote in message
news:3e4419f0$1@usenet.ugs.com...
>
> "Francesco Moi" <francescomoi@europe.com> wrote in message
> news:5b829932.0302071230.17619b3@posting.google.com...
> > Hello.
> >
> > I've got two arrays:
> > @array1 = ('foo1' 'foo2' 'foo3')
> > @array2 = ('foo2' 'foo7' 'foo9')
> >
> > And I want to get the matching elements of both arrays.
> >
> > Is there any function? Thank you very much.
>
> use strict;
> use warnings;
> my @array1 = qw(foo1 foo2 foo3);
> my @array2 = qw(foo2 foo7 foo9);
> my %union;
> my %isect;
> foreach my $e (@array1, @array2) { $union{$e}++ && $isect{$e}++ }
>
> my @union = keys %union;
> my @isect = keys %isect;
>
> Mothra
>
> print @isect;
ops!!
should be

print @isect;

-------end script-------

Mothra







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

Date: Sat, 08 Feb 2003 11:22:50 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: How to compare two arrays
Message-Id: <hdm94vsk7ia4lm20aq1kuj0ge5o6inblko@4ax.com>

X-Ftn-To: Mothra 

"Mothra" <mothra@nowhereatall.com> wrote:
>> @array2 = ('foo2' 'foo7' 'foo9')
>>
>> And I want to get the matching elements of both arrays.
>>
>> Is there any function? Thank you very much.
>
>use strict;
>use warnings;
>my @array1 = qw(foo1 foo2 foo3);
>my @array2 = qw(foo2 foo7 foo9);
>my %union;
>my %isect;
>foreach my $e (@array1, @array2) { $union{$e}++ && $isect{$e}++ }

Two for loops are better when you're dealing with repeating elements
i.e. my @array1 = qw(foo1 foo2 foo3 foo1);



-- 
Matija


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

Date: 10 Feb 2003 11:58:54 -0800
From: jason4chen@yahoo.com (Jason Chen)
Subject: How to prevent resolving variables
Message-Id: <508693ba.0302101158.7433c5d3@posting.google.com>

I have a script to check log files and print out filename,linenumber,
and any lines with 'error' in it. This single line command works at
command prompt:

perl -w -e 
    'while(<>){print $ARGV ,":", sprintf("%4.4d",$.) ,":", $_ if
/error/i ;}'
    /u/temp/*.log;


But, if I run it inside a perl script, $ARGV and $. do not get
resolved:

      @output=(); 
      
      ...

      push @output,`perl -w -e 'while(<>){print $ARGV ,":", 
            sprintf("%4.4d",$.) ,":", $_ if /error/i ;}'
/u/temp/*.log`;

      print @output;


Obviously, $ARGV and $. get resolved before it should be. Adding
Escape before
$ sign does not work.

Any help is appreciated,

Jason


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

Date: Mon, 10 Feb 2003 21:47:09 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: How to prevent resolving variables
Message-Id: <Xns931EAAC1BEB89dkwwashere@216.168.3.30>

Jason Chen <jason4chen@yahoo.com> wrote on 10 Feb 2003:

> But, if I run it inside a perl script, $ARGV and $. do not get
> resolved:
> 
>       @output=(); 
>       
>       ...
> 
>       push @output,`perl -w -e 'while(<>){print $ARGV ,":", 
>             sprintf("%4.4d",$.) ,":", $_ if /error/i ;}'
> /u/temp/*.log`;
> 
>       print @output;

Why are you running perl from within a perl program?  Just use the 
code you have and put what you want in @ARGV.


    use strict;
    use warnings;
    @ARGV = glob "/u/temp/*.log";
    while(<>) {
        print "$ARGV:", sprintf("%4.4d",$.), ":$_" if /error/i ;
    }


-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Fri, 07 Feb 2003 18:54:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: I'm just not getting it... FAQ5
Message-Id: <3E4400DF.F59EC650@acm.org>

rab wrote:
> 
> "John W. Krahn" <krahnj@acm.org> wrote in message news:<3E42F63B.F60D4A19@acm.org>...
> > rab wrote:
> > > > > I'm hitting a wall on how to match the pattern (grok-3.+) and delete
> > > those lines containing it, while simultaneously replacing those lines
> > > in that same place in the file with the new grok-3 modified single
> > > line.
> >
> > perl -i.bak -0777pe's/(^grok-3.*\n)+/grok-3 NEW TEXT HERE\n/m' yourfile
> 
> John...thanks for the suggestion.   Since there were three lines
> containing "grok-3" in the original file, the new line was inserted 3
> times with this construct.   Any ideas how to delete all three of the
> original lines while only replacing them with one line, one time?

That will work if all the "grok-3" lines are contiguous.
This may work better.  :-)

perl -i.bak -0777pe's/^grok-3.*?(?=^grok-[^3])/grok-3 NEW TEXT HERE\n/sm' yourfile



John
-- 
use Perl;
program
fulfillment


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

Date: 10 Feb 2003 11:43:25 -0800
From: zsh99@yahoo.com (Lisa Koma)
Subject: Installation of perl modules
Message-Id: <d011d382.0302101143.17fe018@posting.google.com>

The question is, I have a server with two installations of perl
One is locally installed /usr/local/perl and the other is auot-mounted from 
another server /users/perl

When I install a module, how do I tell it which perl it should add the
module to? Is there a global parameter that need to be set or ..how does
the makefile find the perl installation  ??


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

Date: Mon, 10 Feb 2003 20:29:08 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Installation of perl modules
Message-Id: <oYT1a.10477$LY2.624390@newsc.telia.net>

Lisa Koma wrote:
> When I install a module, how do I tell it which perl it should add the 
> module to?

I think that the ongoing thread "Installing new modules" in this group 
covers your question.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 10 Feb 2003 14:22:47 -0800
From: stefan@borgia.com (Stefan Adams)
Subject: Re: Installation of perl modules
Message-Id: <dcc927de.0302101422.5172ee07@posting.google.com>

zsh99@yahoo.com (Lisa Koma) wrote in message news:<d011d382.0302101143.17fe018@posting.google.com>...
> The question is, I have a server with two installations of perl
> One is locally installed /usr/local/perl and the other is auot-mounted from 
> another server /users/perl
> 
> When I install a module, how do I tell it which perl it should add the
> module to? Is there a global parameter that need to be set or ..how does
> the makefile find the perl installation  ??

I believe that is determined by the perl executable when you call the Makefile.PL.

/users/perl/bin/perl Makefile.PL would install the Module to that instance.
/usr/local/perl/bin/perl Makefile.PL would install the Module to that instance.


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

Date: Sun, 9 Feb 2003 19:12:20 -0000
From: "Brian Smart" <brian.smart@blueyonder.co.uk>
Subject: Installing new modules
Message-Id: <zBx1a.99$lk6.50@news-binary.blueyonder.co.uk>

Hi,
I have been trying to install a new module but am unsure how to go about it.
I have read everything I can, but the more I read, the more I get confused.
I may be trying to do the wrong thing completely.
I want to create a perl script on my web site that requires a module which
is not part of the core perl loaded on the web server.
Could somebody explain exactly what to do to install a module presumably in
my web space that a script can then use along with the perl modules loaded
on the server. Any module would do if a script could be provided that would
demonstrate that the module is working.

If I can overcome this first hurdle, I am sure I can make good progress.

Thanks for any help you are able to give.

Regards

Brian Smart





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

Date: Sun, 09 Feb 2003 19:19:41 GMT
From: Alan Gutierrez <ajglist@izzy.net>
Subject: Re: Installing new modules
Message-Id: <hRx1a.15738$tQ1.1115107@news2.east.cox.net>

Brian Smart wrote:

>  Any module would do if a script could be provided that would
>  demonstrate that the module is working.
> 
> If I can overcome this first hurdle, I am sure I can make good
> progress.

# Source of AModule.pm

package AModule;

sub hello { print "Hello, World" }

1;
__END__

#!/usr/bin/perl

use lib '/home/bsmart/lib';
use AModule;

print "Content-Type: text/plain\n\n";
print &AModule::hello, "\n";

__END__

Assumes that your home directroy is /home/bsmart and that you place
AModule.pm in /home/bsmart/lib.

This is untested, sorry. Hope it helps.

-- 
Alan Gutierrez - ajglist@izzy.net


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

Date: Sun, 9 Feb 2003 14:23:00 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Installing new modules
Message-Id: <slrnb4de54.fm.tadmc@magna.augustmail.com>

Brian Smart <brian.smart@blueyonder.co.uk> wrote:

> I have been trying to install a new module but am unsure how to go about it.


Once you have downloaded and unpacked the module, you type
only four things.

What does "new module" mean?

One that you just wrote, or one that you just downloaded from CPAN?

If you want to write your very own module, then:

   perldoc -q module

      "How do I create a module?"

I will assume you mean a CPAN module.


> I have read everything I can, but the more I read, the more I get confused.


What is it that you have read?

If it is the standard docs that come with Perl, then we need to
fix them so that they are less confusing. What part were you
confused by?

If it is not the standard docs, then we don't care if they are
correct or not (so you should probably be looking at the std
docs...)


> Could somebody explain exactly what to do to install a module 


   perldoc -q install

      "How do I install a module from CPAN?"


lists the 4 commands that are used to install a module.

   perl Makefile.PL
   make
   make test
   make install


> presumably in
> my web space 


If you do not have root permission on the web server, then:

   perldoc -q module

      "How do I keep my own module/library directory?"

Tells you do change one of The Four Commands above, and 
either add an env var or add a "use lib" line to your program.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 10 Feb 2003 19:51:42 +0000 (UTC)
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: Installing new modules
Message-Id: <b28vse$pp2$1@geraldo.cc.utexas.edu>



__________
Tad wrote:
 ....
>   perldoc -q module
>
>      "How do I keep my own module/library directory?"
>
>Tells you do change one of The Four Commands above, and 
>either add an env var or add a "use lib" line to your program.
 ....

 Something that's confused me for some time: I've seen recommendations
in various texts to use 

perl Makefile.PL PREFIX=... and sometimes just(!) perl Makefile.PL LIB=...

when installing in a local (i.e. not the standard) directory.
In fact, it seems that the PREFIX=... version usually seems to be the one
that is satisfactory, and the LIB=... isn't what is wanted
but in a few cases I seem to recall that I needed to use both the PREFIX=... and LIB=... together in the command to use the resulting Makefile without 
errors/problems. To understand the difference, I tried various combinations
and compared the resulting Makefiles, and there certainly was a difference, but
the effect of the differences was hard to understand - Makefiles produced
by Makefile.PL tend to be rather long and difficult (for me) to read.

 Do you know what the effect of each of these settings is and when the LIB=
is useful? 
 (Note: I do realize that "use lib" is something different and often
necessary when using modules located in nonstandard places.)
 Thanks for any comments or info!
                       chas




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

Date: 10 Feb 2003 06:03:46 -0800
From: squillion@hotmail.com (squillion)
Subject: iterator in for loop
Message-Id: <81016f2d.0302100603.75d1b98b@posting.google.com>

hi

how do i tell which iteration i'm on within a for loop?

i can do

for (my $i=0;$i<@array;$i++) {
  print "iteration #: $i item: $array[$i]\n";
}

but i don't like that C-style idiom.  what i need is a system variable
$X to tell me which item i'm on, like:

print "iteration #: $X item: $_\n" for @array;

please could someone hack into the perl source code and add this
feature for me and email me the recompiled perl binary.

TIA


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

Date: Mon, 10 Feb 2003 14:05:07 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: iterator in for loop
Message-Id: <Xns931E98CDBEAE5elhber1lidotechnet@62.89.127.66>

squillion wrote:

> hi
> 
> how do i tell which iteration i'm on within a for loop?
> 
> i can do
> 
> for (my $i=0;$i<@array;$i++) {
>   print "iteration #: $i item: $array[$i]\n";
> }
> 
> but i don't like that C-style idiom.  what i need is a system variable
> $X to tell me which item i'm on, like:
> 
> print "iteration #: $X item: $_\n" for @array;
> 
> please could someone hack into the perl source code and add this
> feature for me and email me the recompiled perl binary.


Sure, I'll do it. Can I pleeeease give you a foot massage while you wait?


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Mon, 10 Feb 2003 15:28:50 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: iterator in for loop
Message-Id: <b28g6f$7ad$1@news.dtag.de>

squillion wrote:
> hi
> 
> how do i tell which iteration i'm on within a for loop?
> 
> i can do
> 
> for (my $i=0;$i<@array;$i++) {
>   print "iteration #: $i item: $array[$i]\n";
> }
> 
> but i don't like that C-style idiom.  what i need is a system variable
> $X to tell me which item i'm on, like:
> 
> print "iteration #: $X item: $_\n" for @array;
> 
> please could someone hack into the perl source code and add this
> feature for me and email me the recompiled perl binary.

Sure, do you want it thread safe, with or without dressing?
Oh, you forgot to mention your OS and architecture. I'm afraid I can't 
help you then.

->malte



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

Date: Mon, 10 Feb 2003 18:52:21 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: iterator in for loop
Message-Id: <cjof4vgb9a28qi7cm2ih18m500lv71nij4@4ax.com>

X-Ftn-To: squillion 

squillion@hotmail.com (squillion) wrote:
>how do i tell which iteration i'm on within a for loop?
>
>i can do
>
>for (my $i=0;$i<@array;$i++) {
>  print "iteration #: $i item: $array[$i]\n";
>}
>
>but i don't like that C-style idiom.  what i need is a system variable
>$X to tell me which item i'm on, like:
>
>print "iteration #: $X item: $_\n" for @array;

my $X = 0;
print "iteration #: @{[$X++]} item: $_\n" for @array;

>please could someone hack into the perl source code and add this
>feature for me and email me the recompiled perl binary.

Well, I would send it you but I guess you already have dozen of them by now.



-- 
Matija


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

Date: Mon, 10 Feb 2003 17:52:45 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: iterator in for loop
Message-Id: <pan.2003.02.10.16.52.33.738606@kamelfreund.de>

On Mon, 10 Feb 2003 06:03:46 -0800, squillion wrote:

> for (my $i=0;$i<@array;$i++) {
>   print "iteration #: $i item: $array[$i]\n";
> }
> 
> but i don't like that C-style idiom.  what i need is a system variable
> $X to tell me which item i'm on, like:
> 
> print "iteration #: $X item: $_\n" for @array;

I don't like the C idiom too.
Normally, I use the simple workaround:

print "iteration $_: $array[$_} item\n" for (0 .. $#array);

(And sometimes, if I'm really scared of confused programmers,
 I replace 0 with $[ :-))

> please could someone hack into the perl source code and add this
> feature for me and email me the recompiled perl binary.

And could this guy send me also the lottery numbers of next week.

I would suggest you, too wake up or wait till Perl 6 :D


Cheerio,
Janek


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

Date: Sat, 08 Feb 2003 05:37:15 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: LWP multipart/form-data with content NOT from file
Message-Id: <u6594vsb9c2l1bpp6c1rg6tpf1tcs8o8r9@4ax.com>

On Thu, 06 Feb 2003 23:51:53 +0000, in comp.lang.perl.misc, "Richard Gration" <richard@zync.co.uk> wrote:

>It says in the docs for HTTP::Request::Common that you can generate a
>Request Object thusly:
>
>POST 'http://some.url.tld/cgi-bin/some_old_rot.cgi'
>	Content_Type	=>	'form-data',
>	Content			=> 	[
>		thing		=>	whatsit,
>		foo			=>	bar,
>		myfile		=>	[$file,$filename]
>	];
>
>The array ref which is the last entry in the Content list specifies the
>file upload bit of the POST.
>
>It also says in the docs that you should "Use an "undef" as $file value
>if you want to specify the content directly." But it never mentions
>how to do this (specify the content directly). Now obviously I can roll
>my own multipart/form-data content, but that's not the point!
>
>Does anyone know how to set the content for the file upload bit?

I haven't had time to try this, but a quick look at the
documentation and the code suggests something ...

The documentation says a little more than you have quoted:

  If one of the values in the $form_ref is an array
  reference, then it is treated as a file part
  specification with the following interpretation:
    [ $file, $filename, Header => Value... ]

and the code in the module appears to handle the special
case of a Header called Content ...
  if ($h->header("Content")) {
      $content = $h->header("Content");
      $h->remove_header("Content");
  }

So you might try this:
  myfile => [ undef, $filename, Content => $file_contents ]

-- 
Sharon


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

Date: Sat, 08 Feb 2003 06:24:22 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: LWP multipart/form-data with content NOT from file
Message-Id: <id894vcig0bt0pb08o7a9c742t5p5vp113@4ax.com>

On Sat, 08 Feb 2003 05:37:15 +0000, in comp.lang.perl.misc, Sharon Grant <peakpeek@purethought.com> wrote:

>On Thu, 06 Feb 2003 23:51:53 +0000, in comp.lang.perl.misc, "Richard Gration" <richard@zync.co.uk> wrote:
>
>>It says in the docs for HTTP::Request::Common that you can generate a
>>Request Object thusly:
>>
>>POST 'http://some.url.tld/cgi-bin/some_old_rot.cgi'
>>	Content_Type	=>	'form-data',
>>	Content			=> 	[
>>		thing		=>	whatsit,
>>		foo			=>	bar,
>>		myfile		=>	[$file,$filename]
>>	];
>>
>>The array ref which is the last entry in the Content list specifies the
>>file upload bit of the POST.
>>
>>It also says in the docs that you should "Use an "undef" as $file value
>>if you want to specify the content directly." But it never mentions
>>how to do this (specify the content directly)
>>
>>Does anyone know how to set the content for the file upload bit?

>you might try this:
>  myfile => [ undef, $filename, Content => $file_contents ]

I found some time to test this. It worked



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

Date: Mon, 10 Feb 2003 18:09:03 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: LWP multipart/form-data with content NOT from file
Message-Id: <20030210.180903.213975407.20961@richg.zync>

> It worked


You BEAUTY!! (In the australian sense :-) ) Thank you very much! I
actually spent a while poring over the source, but couldn't see this
solution. Thank you again

Rich


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Fri, 7 Feb 2003 13:21:32 -0600
From: "Robert Zahm" <zahm@uiuc.edu>
Subject: matching with [
Message-Id: <uET0a.20224$Vf3.220531@vixen.cso.uiuc.edu>

I'm trying to match a string which contains a left bracket but not a right
bracket.  For example:

$pattern = "junk[junk";
$someString =~ /$pattern/;

This gives me an error when I try to run it because of the left unclosed
bracket in $pattern.  Does anybody know if there is a way around this short
of either closing the bracket or removing it (which is tough because
s/[/other/ won't work either) by hand?  Is there a way to force $pattern
into a string or something?  I think the problem is that $pattern is
interpreted as a regular expression, for which an unclosed bracket is not
proper form.  Any suggestions?  Thanks.

Rob




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

Date: Fri, 7 Feb 2003 20:51:20 +0100
From: "Christian Winter" <thepoet@nexgo.de>
Subject: Re: matching with [
Message-Id: <3e440d2e$0$9352$9b4e6d93@newsread2.arcor-online.net>

"Robert Zahm" <zahm@uiuc.edu> schrieb:
> I'm trying to match a string which contains a left bracket but not a right
> bracket.  For example:
>
> $pattern = "junk[junk";
> $someString =~ /$pattern/;
>
> This gives me an error when I try to run it because of the left unclosed
> bracket in $pattern. [...]

Hi,

just use \Q like 'perldoc perlre' suggests:
=citation
 \Q          quote (disable) pattern metacharacters till \E
=cut

thatfor
$someString =~ /\Q$pattern/;
should work.

Best also have a look at 'perldoc -f quotemeta'.

HTH
-Christian



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

Date: Fri, 7 Feb 2003 14:57:13 -0600
From: "Robert Zahm" <zahm@uiuc.edu>
Subject: Re: matching with [
Message-Id: <33V0a.20262$Vf3.221249@vixen.cso.uiuc.edu>

Thanks a bunch, this looks very helpful!

Rob




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

Date: Sat, 8 Feb 2003 01:41:45 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: matching with [
Message-Id: <Pine.LNX.4.53.0302080139480.26093@lxplus088.cern.ch>

On Feb 7, Robert Zahm inscribed on the eternal scroll:

> Thanks a bunch, this looks very helpful!

What can the readers learn from your experience?  A summary would be
appreciated, as fair recompense for the effort which the 'bunch' put
into this community pot.


-- 
           Manchmal denke ich, ich brauche die ganzen schicken, neuen
           Brauser nur, um mich besser gegen den Autor zu wehren...
                                          - Sybille Kahl on dciwam


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

Date: Sat, 8 Feb 2003 12:37:29 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: matching with [
Message-Id: <b21n0r$188arj$1@ID-172104.news.dfncis.de>


"Robert Zahm" <zahm@uiuc.edu> wrote in message
news:33V0a.20262$Vf3.221249@vixen.cso.uiuc.edu...
> Thanks a bunch, this looks very helpful!

And "this" is.....????




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

Date: Sun, 9 Feb 2003 00:33:02 -0600
From: "Robert Zahm" <zahm@uiuc.edu>
Subject: Re: matching with [
Message-Id: <4Am1a.20656$Vf3.227196@vixen.cso.uiuc.edu>

> And "this" is.....????
My bad for trimming the post, I just figured anybody interested in
the answer would look at the message I replied to.  I haven't had a
chance to try it out yet, and just wanted to say thanks to the guy
who posted to help me out.

Rob
ps, here's the message below

> I'm trying to match a string which contains a left bracket but not
a right
> bracket.  For example:
>
> $pattern = "junk[junk";
> $someString =~ /$pattern/;
>
> This gives me an error when I try to run it because of the left
unclosed
> bracket in $pattern. [...]

Hi,

just use \Q like 'perldoc perlre' suggests:
=citation
 \Q          quote (disable) pattern metacharacters till \E
=cut

thatfor
$someString =~ /\Q$pattern/;
should work.

Best also have a look at 'perldoc -f quotemeta'.

HTH
-Christian




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

Date: Sun, 9 Feb 2003 07:45:05 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: matching with [
Message-Id: <slrnb4cmr1.u3s.tadmc@magna.augustmail.com>

Robert Zahm <zahm@uiuc.edu> wrote:

Some nameless Usenaut wrote:

>> And "this" is.....????

> My bad for trimming the post, 


And for not providing an attribution.

Please learn the accepted conventions for how to compose followups:

   http://web.presby.edu/~nnqadmin/nnq/nquote.html


> I just figured anybody interested in
> the answer would look at the message I replied to.


What if the message you replied to had not been received yet?

Your followup may arrive _before_ the message you are replying to.

In fact, the message you are replying to may *never* arrive,
news is not totally reliable.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 4535
***************************************


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