[24204] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6396 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 13 14:11:07 2004

Date: Tue, 13 Apr 2004 11:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 13 Apr 2004     Volume: 10 Number: 6396

Today's topics:
    Re: need to find word, and comment out next 5 lines <wherrera@lynxview.com>
    Re: need to find word, and comment out next 5 lines <xx087@freenet.carleton.ca>
    Re: need to find word, and comment out next 5 lines <perl@my-header.org>
    Re: need to find word, and comment out next 5 lines <perl@my-header.org>
    Re: Newbie Question... <tadmc@augustmail.com>
    Re: PERL web addressing <ssadale@nospam.yahoo.com>
    Re: perldoc incompetence: perlre /s <bik.mido@tiscalinet.it>
    Re: perldoc incompetence: perlre /s <bik.mido@tiscalinet.it>
    Re: perldoc incompetence: perlre /s <vetro@online.no>
        Populating/Sorting Hases <georgekinley@hotmail.com>
    Re: Populating/Sorting Hases <tore@aursand.no>
    Re: Populating/Sorting Hases <xxala_qumsiehxx@xxyahooxx.com>
    Re: Populating/Sorting Hases <nobull@mail.com>
        Reading input from files and directories in the command <a24061@yahoo.munged>
    Re: Reading input from files and directories in the com <ittyspam@yahoo.com>
    Re: the code for bbs 3 <robin @ infusedlight.net>
    Re: Tough (for me) regex case <matthew.garrish@sympatico.ca>
    Re: Tough (for me) regex case <tadmc@augustmail.com>
    Re: Tough (for me) regex case <tadmc@augustmail.com>
    Re: Tough (for me) regex case <tadmc@augustmail.com>
    Re: Why are arrays and hashes this way? <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 13 Apr 2004 07:41:07 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: need to find word, and comment out next 5 lines
Message-Id: <6Yadnc_GJ9lscObd4p2dnA@adelphia.com>

joe shaboo wrote:
> Hi,
> 
> I'm new to perl.
> 
> I need to find a line in my named.conf file, and comment out the next
> five lines.
> 
> example
> 
> zone "mydomain.com" {
>     type master;
>     file "path/to/zone"
>     notify yes;
> }
> 
> what I'd like to do
> 
> // Domain commented out by `finger `logname` | grep real | awk '{print
> $7" "$8}'` on date.
> // zone "mydomain.com"
> //       type master;
> //       file "path/to/zone"
> //       notify yes;
> //}
> 
> Can someone please first, tell me can I embed system commands as I've
> done?
> 

Yes, but of course you don't embed them in the data file, you use the ` 
   ` or qx/  / stuff in perl.

> and, lastly, how can I do this using Perl? I know it must be very
> easy, but I just am not familiar enough with the language to do this.
> 

untested and unfinished:
#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;

my $fname = 'named.conf';
my @filelines;

tie @filelines, 'Tie::File', $fname or die "cannot open and tie $fname: $!";

foreach my $line (@filelines) {
   # check for the first match that fits
   if ($line =~ /zone \"mydomain.com\" \{/) {
     ... note: the many quote types here may need better escaping
     my $namelabel = `finger \`logname\` | grep real | awk '{print $7" 
"$8}'`
     ....
     ...here you replace the lines you need to change...
     last;
   }
}



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

Date: 13 Apr 2004 13:41:00 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: need to find word, and comment out next 5 lines
Message-Id: <slrnc7nrfc.stu.xx087@smeagol.ncf.ca>

joe shaboo <jshaboo@hotmail.com> wrote:
[...]
>  example
>  
>  zone "mydomain.com" {
>      type master;
>      file "path/to/zone"
>      notify yes;
>  }
>  
>  what I'd like to do
>  
>  // Domain commented out by `finger `logname` | grep real | awk '{print
>  $7" "$8}'` on date.
>  // zone "mydomain.com"
>  //       type master;
>  //       file "path/to/zone"
>  //       notify yes;
>  //}

Here's one approach:

    #!/usr/local/bin/perl
    use strict;
    use warnings;

    my $re = qr{domain2};
    my $commenting = 0;

    while (<DATA>) {
        if (/$re/) {
            $commenting = 1;
            print "// some useful comment\n";
        }
        print "//" if $commenting;
        print;
        $commenting = 0 if /^\s*}/;
    }
    exit;

    __DATA__
    zone "domain1.com" {
        type master;
        file "path/to/zone"
        notify yes;
    }
    zone "domain2.com" {
        type master;
        file "path/to/zone"
        notify yes;
    }
    zone "domain3.com" {
        type master;
        file "path/to/zone"
        notify yes;
    }


-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Tue, 13 Apr 2004 16:32:12 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: need to find word, and comment out next 5 lines
Message-Id: <b1un70ph5epn81v60o7ufv9kpti08qj1ui@4ax.com>

X-Ftn-To: joe shaboo 

jshaboo@hotmail.com (joe shaboo) wrote:
>zone "mydomain.com" {
>    type master;
>    file "path/to/zone"
>    notify yes;
>}
>
>what I'd like to do
>
>// Domain commented out by `finger `logname` | grep real | awk '{print
>$7" "$8}'` on date.
>// zone "mydomain.com"
>//       type master;
>//       file "path/to/zone"
>//       notify yes;
>//}
>
>Can someone please first, tell me can I embed system commands as I've
>done?
>
>and, lastly, how can I do this using Perl? I know it must be very
>easy, but I just am not familiar enough with the language to do this.

I would slurp complete named.conf in $conf and then

#untested
my $zonematch = qr/mydomain\.com/;
$conf =~ s[^(\s*zone\s+".+?"\s*{.+?})][

  my $zone = $1;
  $zone =~ s!^!//!gm if $zone =~ /$zonematch/;
  $zone;
]igesm;



-- 
Matija


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

Date: Tue, 13 Apr 2004 16:37:33 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: need to find word, and comment out next 5 lines
Message-Id: <3mun705vrqqhgadfdfd967ishpk8qcjj0q@4ax.com>

X-Ftn-To: Matija Papec 

Matija Papec <perl@my-header.org> wrote:
>>and, lastly, how can I do this using Perl? I know it must be very
>>easy, but I just am not familiar enough with the language to do this.
>
>I would slurp complete named.conf in $conf and then
>
>#untested
>my $zonematch = qr/mydomain\.com/;
>$conf =~ s[^(\s*zone\s+".+?"\s*{.+?})][
>
>  my $zone = $1;
>  $zone =~ s!^!//!gm if $zone =~ /$zonematch/;
>  $zone;
>]igesm;

or better yet,

#untested
my $zonematch = 'mydomain.com';
$conf =~ s[^(\s*zone\s+"(.+?)"\s*{.+?})][

  my ($zone, $domain) = ($1, $2);
  $zone =~ s!^!//!gm if $domain eq $zonematch;
  $zone;
]igesm;



-- 
Matija


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

Date: Tue, 13 Apr 2004 12:27:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Newbie Question...
Message-Id: <slrnc7o8oq.8am.tadmc@magna.augustmail.com>

EddieJ <eddiejones64@hotmail.com> wrote:
> Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040412121432.X27629@dishwasher.cs.rpi.edu>...
>> 
>> Why are you bothering with this?  If the files exist when you try to open
>> them for writing, they are automatically clobbered.
> 
> Oh, okay didnt realise that. 


You should read the documentation for the functions that you use.


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


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

Date: Tue, 13 Apr 2004 10:27:30 -0400
From: "Dale" <ssadale@nospam.yahoo.com>
Subject: Re: PERL web addressing
Message-Id: <xqmdnc0Po_bwZObd4p2dnA@inoc.net>

Thanks Guys
It looks like "extra path information" was what I needed. The server I'm
working with is configured to see the program name and pass the extra info
so I'm off and running.
Thanks again
Dale


"l v" <lv@aol.com> wrote in message
news:eIIec.178$Ho2.5236@dfw-read.news.verio.net...
> ssadale#nospam#yahoo.com wrote:
> > That would be a great approach and I'm familiar with settng up IIS to
handle
> > vertual vs physical paths. Unfortunately I'm not terribly well versed in
> > Apache server administration and the site I'm working on is hosted by an
ISP
> > with their own views on how a site/server should be configured. When I
saw
> > the default.pl/folder addressing scheme I figured it was a PERL module
or
> > method I was unfamiliar with responsible for requesting and serving the
> > appropriate file(s). I'm being asked to provide "secure" (login) access
to a
> > variety of file types hosted on a remote server and .htaccess is
fighting me
> > on this server. This approach, combined with session cookies seemed
workable
> > since it effectively hides the file path and name. So far every attempt
I've
> > made to request a file from the site I stumbled on has been met with
> > scripted access; I'm a  little impresssed and am curious how they're do
it.
> > the domain is softwingflight.com (my favorite hobby) I haven't checked
the
> > domain registration or service provider yet, just curious about a
different
> > technique.
> >
> > Thanks for the feedback
> > Dale
> >
> >
> > "Tore Aursand" <tore@aursand.no> wrote in message
> > news:pan.2004.04.12.23.45.15.319295@aursand.no...
> >
> >>On Mon, 12 Apr 2004 15:27:52 -0400, Dale wrote:
> >>
> >>>Anyway, the site in question has all of its links and addresses in the
> >>>form of blah.com/index.pl/[some folder] There are no page or file type
> >>>references visible in either the address bar or status bar and the
> >>>source code in the browser is in the same format. I've seen many sites
> >>>that use a querystring to reference the requested file and process the
> >>>request through a script but never this method.
> >>
> >>Why not use a Apache handler to do the job?  It's even more
professional;
> >>
> >>  http://www.blah.com/some/path/goes/here/
> >>
> >>Of course, '/some/path/goes/here/' doesn't exist, but the Apache handler
> >>has been set up to handle all requests so that it's able to convert that
> >>path to something more useful internally (ie. lookup the path string in
a
> >>database or something like that).
> >>
> >>For more information:
> >>
> >>  http://perl.apache.org/
> >>
> >>
> >>--
> >>Tore Aursand <tore@aursand.no>
> >>"Omit needless words. Vigorous writing is concise. A sentence should
> >> contain no unnecessary words, a paragraph no unnecessary sentences,
> >> for the same reason that a drawing should have no unnecessary lines
> >> and a machine no unnecessary parts." -- William Strunk Jr.
> >
> >
> >
>
> Perhaps http://www.oreilly.com/openbook/cgi/ch02_04.html will get you
> started.
>
> Len
>




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

Date: Tue, 13 Apr 2004 17:25:53 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <p7vn70lfso10v46o2b1e19i7hp5le49hbr@4ax.com>

On 11 Apr 2004 19:59:03 -0700, xah@xahlee.org (Xah Lee) wrote:

>today i'm writing some perl code involving regex. I wanted to find out
[snip]
>Fucking no mention of it. Fuck Perl and fuck Perl coders.

Am I the only one seeing the contradiction?!?


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Tue, 13 Apr 2004 17:25:53 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <edvn70psp4tdfru4v0iofiuudtchjhb9ut@4ax.com>

On 11 Apr 2004 19:59:03 -0700, xah@xahlee.org (Xah Lee) wrote:

>today i'm writing some perl code involving regex. I wanted to find out
>exactly what is /s (whitespace) is defined. So i did "perldoc -t
>perlre".
>
>Fucking no mention of it. Fuck Perl and fuck Perl coders.

Well, maybe because it's \s?!?


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Tue, 13 Apr 2004 17:34:18 +0200
From: Vetle Roeim <vetro@online.no>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <m3brlvhoxx.fsf@quimby.dirtyhack.org>

* Michele Dondi
> On 11 Apr 2004 19:59:03 -0700, xah@xahlee.org (Xah Lee) wrote:
>
>>today i'm writing some perl code involving regex. I wanted to find out
> [snip]
>>Fucking no mention of it. Fuck Perl and fuck Perl coders.
>
> Am I the only one seeing the contradiction?!?

  What he does in the privacy of his own home is none of our business.
  ;-)


-- 
#!/usr/bin/vr


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

Date: Tue, 13 Apr 2004 13:15:50 GMT
From: "George Kinley" <georgekinley@hotmail.com>
Subject: Populating/Sorting Hases
Message-Id: <aKRec.13701$k4.280426@news1.nokia.com>

Hi,
I am populating a Hash as follows
$HASH{$HASHKEY}{$Feature}{$i}=@FeatureTestCase[$i];
Where
HASH=%HASH
$HASHKEY=Numeric Incremented by 1 when Feature Changes
$Feature=Is String
$i= is Numeric Incremented by 1 when FeatureTestCase Changes

So in the end we have have HASH like this
%HASH=({1=>{'ABC'=>{1=>'X',2=>'Y'}})

Now During the Populating , when FeatureTestCase[$i] crosses 10 , The
Position 2  from $HASH{HASHKEY}{$Feature}{2} is replaces by
$HASH{HASHKEY}{$Feature}{10}  is and 3 by $HASH{HASHKEY}{$Feature}{11} and
so on , why  that happens may be "Random filling"


Second query is
When I try to Sort as
{
$FeatureNameKeyIdx =$HASH{$HASHKEY}{$Feature};
foreach  my $TestCase (sort (keys %$FeatureNameKeyIdx))

}

I get output as

(1)     T1_REG_
(10)    T2_PRO_   (Why is this not sorted )
(2)     T3_REG_
(3)     T4_REG_
(4)     T5_PRO_
(5)     T6_PRO_
(6)     T7_REG_
(7)     T8_PRO_
(8)     T9_PRO_
(9)     T10_PRO_





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

Date: Tue, 13 Apr 2004 15:54:26 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Populating/Sorting Hases
Message-Id: <pan.2004.04.13.13.52.30.668080@aursand.no>

On Tue, 13 Apr 2004 13:15:50 +0000, George Kinley wrote:
> When I try to Sort as
> {
> $FeatureNameKeyIdx =$HASH{$HASHKEY}{$Feature};
> foreach  my $TestCase (sort (keys %$FeatureNameKeyIdx))
> 
> }
> 
> I get output as
> 
> (1)     T1_REG_
> (10)    T2_PRO_   (Why is this not sorted )
> (2)     T3_REG_
> (3)     T4_REG_
> [...]

If you've read the documentation for the 'sort' function you would have
noticed that 'sort' defaults to sort in string comparison order.

In your case, you have to create a sorted list of keys (and sort them in
numerical order):

  my @sorted_keys = sort { $a <=> $b } keys %˝FeatureNameKeyIdx;
  foreach ( @sorted_keys ) {
      # ...
  }

Please read the documentation for more information:

  perldoc -f sort
  perldoc -q sort


-- 
Tore Aursand <tore@aursand.no>
"When you love someone, all your saved-up wishes start coming out." --
 Elizabeth Bowen


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

Date: Tue, 13 Apr 2004 15:56:07 GMT
From: Ala Qumsieh <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: Populating/Sorting Hases
Message-Id: <r4Uec.22161$nP7.19519@newssvr27.news.prodigy.com>

George Kinley wrote:
> Hi,
> I am populating a Hash as follows
> $HASH{$HASHKEY}{$Feature}{$i}=@FeatureTestCase[$i];
> Where
> HASH=%HASH
> $HASHKEY=Numeric Incremented by 1 when Feature Changes
> $Feature=Is String
> $i= is Numeric Incremented by 1 when FeatureTestCase Changes

Whenever I have consecutive numeric integers, I think arrays:

   $HASH[$HASHKEY]{$Feature}[$i] = $FeatureTestCase[$i];

They're faster and easier to work with. Of course this is not a hash 
anymore, but an array of hashes of arrays, so you might want to change 
the name of %HASH to something else.

This way you don't have to sort:

> When I try to Sort as
> {
> $FeatureNameKeyIdx =$HASH{$HASHKEY}{$Feature};
> foreach  my $TestCase (sort (keys %$FeatureNameKeyIdx))

[untested]:

   $FeatureNameKeyIdx = $HASH[$HASHKEY]{$Feature};
   for my $TestCase (0 .. $#$FeatureNameKeyIdx) {
     ....
   }

--Ala



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

Date: 13 Apr 2004 17:43:45 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Populating/Sorting Hases
Message-Id: <u9llkz4ym6.fsf@wcl-l.bham.ac.uk>

"George Kinley" <georgekinley@hotmail.com> writes:

> I am populating a Hash as follows
> $HASH{$HASHKEY}{$Feature}{$i}=@FeatureTestCase[$i];

In that case you should enable warnings.

> Where
> HASH=%HASH
> $HASHKEY=Numeric Incremented by 1 when Feature Changes
> $Feature=Is String
> $i= is Numeric Incremented by 1 when FeatureTestCase Changes
> 
> So in the end we have have HASH like this
> %HASH=({1=>{'ABC'=>{1=>'X',2=>'Y'}})

You should always use the most natural represtation of your data
unless there is a reason to do otherwise.

Since $HASHKEY and $i appear to be simple counters with no gaps then
it would be more appropriate use arrays.
 
  $HASH[$HASHKEY]{$Feature}=\@FeatureTestCase;

Or if you want to change @FeatureTestCase subsquently without changing
the what's pointed to in the structure then you need to make a copy:

  $HASH[$HASHKEY]{$Feature}=[@FeatureTestCase];

Note: if @FeatureTestCase is correctly scoped then it is unlikely that
you will need to make a copy.

So in the end we have have an ARRAY (confusingly named @HASH) like:

@HASH=(undef,{'ABC'=>[undef,'X',Y']})

Of course if $HASHKEY and $i can be made to start at 0 rather than 1
(as would be natural in Perl) this simplifies to

@HASH=({'ABC'=>['X',Y']})

Note that you don't acutally need to maintain $HASHKEY just to append
to @HASH or access the last element, you can do that more simply with
push or negative subscripts.

Hang on.  I've just realised that you said "$HASHKEY=Numeric
Incremented by 1 when Feature Changes". So this means that it is
unnatural for $Feature to be a hash subscript.

push @HASH => { FEATURE => $Feature, TestCase => \@FeatureTestCase };

@HASH=({ Feature => 'ABC', TestCase =>['X',Y']})

> Now During the Populating , when FeatureTestCase[$i] crosses 10 , The
> Position 2  from $HASH{HASHKEY}{$Feature}{2} is replaces by
> $HASH{HASHKEY}{$Feature}{10}  is and 3 by $HASH{HASHKEY}{$Feature}{11} and
> so on , why  that happens may be "Random filling"
> 
> 
> Second query is [...]

Second?  You haven't asked a first yet.

Was the question "why does is the data I put in a hash undordered?"?
That would be beacuse hashes are (conceptually) undordered.

> When I try to Sort as
> {
> $FeatureNameKeyIdx =$HASH{$HASHKEY}{$Feature};
> foreach  my $TestCase (sort (keys %$FeatureNameKeyIdx))
> 
> }
> 
> I get output as
> 
> (1)     T1_REG_
> (10)    T2_PRO_   (Why is this not sorted )
> (2)     T3_REG_

That is correct, the string '10' comes between '1' and '2'. 


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


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

Date: Tue, 13 Apr 2004 15:26:11 GMT
From: Adam <a24061@yahoo.munged>
Subject: Reading input from files and directories in the command line arguments (like grep -R).
Message-Id: <nETec.2640$LI5.25005241@news-text.cableinet.net>

A fairly normal thing to do in Perl is to read input from the files
named in the command arguments and process line by line.
        while (<>) { process($_) ; }

But I want to recurse down directories the way grep -R works.  So far
I've come up with this:

while (@ARGV>0) {
    $filename = shift(@ARGV);
    print ($filename);
    
    if ( -d $filename ) {
        @list = `ls $filename` ;
        @list1 = map {chomp; $_ = $filename . "/" . $_ } @list ;
        unshift(@ARGV, @list1) ;
    }

    elsif ( -e $filename ) {
        open(INPUTFILE, $filename) ;
        while($line = <INPUTFILE>) {
            process($line) ;
        }
        close(INPUTFILE) ;
    }
}


It works but I can't believe it's the best way to do it.  Any better
suggestions?



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

Date: Tue, 13 Apr 2004 11:49:16 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Reading input from files and directories in the command line arguments (like grep -R).
Message-Id: <20040413113651.K27629@dishwasher.cs.rpi.edu>

On Tue, 13 Apr 2004, Adam wrote:

> A fairly normal thing to do in Perl is to read input from the files
> named in the command arguments and process line by line.
>         while (<>) { process($_) ; }
>
> But I want to recurse down directories the way grep -R works.  So far
> I've come up with this:
>
> while (@ARGV>0) {
>     $filename = shift(@ARGV);
>     print ($filename);
>
>     if ( -d $filename ) {
>         @list = `ls $filename` ;
>         @list1 = map {chomp; $_ = $filename . "/" . $_ } @list ;
>         unshift(@ARGV, @list1) ;
>     }
>
>     elsif ( -e $filename ) {
>         open(INPUTFILE, $filename) ;
>         while($line = <INPUTFILE>) {
>             process($line) ;
>         }
>         close(INPUTFILE) ;
>     }
> }
>
>
> It works but I can't believe it's the best way to do it.  Any better
> suggestions?
>

Use the standard File::Find module:

#!/usr/bin/perl
use strict;
use warnings;
use File::Find;

sub wanted {
  if (-f){
    open INPUT, $_ or die "Cannot open $File::Find::name: $!";
    while (<INPUT>){
      # process $_;
    }
    close INPUT;
  }
}

find(\&wanted, @ARGV);
__END__

read `perldoc File::Find` for more info

Paul Lalli


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

Date: Tue, 13 Apr 2004 10:54:39 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: the code for bbs 3
Message-Id: <c5hanf$7cl$1@reader2.nmix.net>

can someone point out a security hole? Or did I come to the wrong place?
-Robin





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

Date: Tue, 13 Apr 2004 10:50:50 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Tough (for me) regex case
Message-Id: <d7Tec.4895$vF3.898850@news20.bellglobal.com>


"Rob Perkins" <rob_perkins@hotmail.com> wrote in message
news:qf1n70t24p89rh6psavllgkp9tbdhjqu32@4ax.com...
>
> Who's wrong? You'll doubtless say Microsoft did it wrong, I'm sure,
> since you seem to care about believing that they can't do it right.
>

They do many things wrong, but that's not my point. Regular expressions are
*largely* the same between implementations, but each language has its own
idiosyncracies you have to be aware of. I'll give you a quick breakdown of
why the quotes *shouldn't* be captured:

/(?<!")"(?!")(.*?)(?<!")"(?!")/

(?<!")"(?!") -- find a quote that isn't preceded or followed by a quote (see
the perlre documentation). Note that the quotation mark is not in parens,
and so should *not* be captured by the regex (which was my point from the
outset).

(.*?)(?<!")"(?!") -- Now do a non-greedy match of everything up to the next
quotation mark that is not preceded or followed by a quotation mark. Again,
this final quotation mark is not part of the match pattern, so it should
*not* be included in the match (your match is everything (.*?) between the
quotation marks).

Does it make a little more sense now why Microsoft's implementation is
wrong?

Matt




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

Date: Tue, 13 Apr 2004 09:52:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Tough (for me) regex case
Message-Id: <slrnc7nvm2.8am.tadmc@magna.augustmail.com>

Rob Perkins <rob_perkins@hotmail.com> wrote:

> I had *no idea* that there were different implementations of "regular
> expressions". The name belies the very idea of differing
> implementations.


> Well, for what it's worth, I ran the code through ActivePerl, with the
> results you predicted. It seems to me reading the regex that if Perl's
> evaluator strips the surrounding quotes, 


It does not "strip the surrounding quotes", they are still there
in the original string where they always were.

It "fails to match the surrounding quotes".

m//g in a list context returns a list of the memories in the pattern.
The pattern had no memories that would match the leading/trailing quotes.


> it's *wrong*, since nothing
> in that regex should consume the character, 


There is no "consuming" going on, only "matching" (or not matching).


> and ALL implementations
> should give the same match, IMO.


Every operator in every language must mean the same thing?

That's too limiting to be widely adopted I'm afraid.


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


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

Date: Tue, 13 Apr 2004 10:00:15 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Tough (for me) regex case
Message-Id: <slrnc7o03v.8am.tadmc@magna.augustmail.com>

Rob Perkins <rob_perkins@hotmail.com> wrote:


> Chris Sells' RegexDesigner.NET shows that with that input string and
> that regex, the quotemarks are sucked up in the match. 


Different languages have different behaviors. Get used to it.


> Of course, if you'd rather be dogmatic about it, I guess I'll have to
> leave you alone, and slink away with my question unanswered. 


It is "pragmatic" rather than "dogmatic".

Since different languages have different behaviors, it is kinda
required that the particular language be known in order to
provide a useable answer.

If you ask for an answer in Perl, but hope to really use some
other language, then it is up to YOU to translate it. We speak
Perl here in the Perl newsgroup.

If you can't be bothered with doing the translation, then don't
ask in other-language newsgroups.


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


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

Date: Tue, 13 Apr 2004 12:23:46 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Tough (for me) regex case
Message-Id: <slrnc7o8h2.8am.tadmc@magna.augustmail.com>

Rob Perkins <rob_perkins@hotmail.com> wrote:

> I had *no idea* that there were different implementations of "regular
> expressions". The name belies the very idea of differing
> implementations.


Then you misunderstand the use of the word "regular" here.

It has a precise mathematical meaning, as in "regular language",
"regular grammar", etc.

   http://en.wikipedia.org/wiki/Regular_language


It should also be noted that regexes in Perl no longer meet
the rules to be mathematically "regular". ie. The name is
historical rather than accurate.


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


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

Date: Tue, 13 Apr 2004 17:25:52 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Why are arrays and hashes this way?
Message-Id: <1eun70dugjh1govfe98973opa3a2kf40ol@4ax.com>

On Sun, 11 Apr 2004 15:34:55 +0100, pkent <pkent77tea@yahoo.com.tea>
wrote:

>c) hashes and arrays may contain other hashes or arrays by holding 
>references to them

Definitely correct IMHO (see e.g. my other post in this thread) once
s/may contain/may (fake very nicely to) contain/;


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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