[23401] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5619 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 5 14:06:18 2003

Date: Sun, 5 Oct 2003 11:05:10 -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           Sun, 5 Oct 2003     Volume: 10 Number: 5619

Today's topics:
    Re: A couple of matching questions. (AGoodGuyGoneBad)
    Re: Accessing parent objects <email@christoph-haas.de>
    Re: code with style (AGoodGuyGoneBad)
    Re: code with style (Pedro)
    Re: code with style (Roy Johnson)
    Re: code with style <perl@my-header.org>
    Re: examples of sprintf (Tad McClellan)
    Re: fastest count of instances in string? (Roy Johnson)
    Re: fastest count of instances in string? (Roy Johnson)
    Re: fastest count of instances in string? <uri@stemsystems.com>
    Re: fastest count of instances in string? <uri@stemsystems.com>
    Re: fastest count of instances in string? <krahnj@acm.org>
        how to search a specific file on a web server <nospam@peng.nl>
    Re: how to search a specific file on a web server (Tad McClellan)
        pattern matching <nospam@peng.nl>
    Re: pattern matching <perl@my-header.org>
    Re: pattern matching <nospam@peng.nl>
    Re: pattern matching (Tad McClellan)
    Re: regex behavior <abigail@abigail.nl>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 05 Oct 2003 16:20:32 GMT
From: agoodguygonebad@aol.com (AGoodGuyGoneBad)
Subject: Re: A couple of matching questions.
Message-Id: <20031005122032.09783.00000262@mb-m25.aol.com>

>: Q2. I have a string of characters where some repeat and some don't,
>: and an array of characters. The string is only made up of characters
>: from the array.
>: 
>: I need to match the string, at the begining, with
>: a string of repeating characters from the array greater than 4,
>: or a string of non repeating characters within the array,
>: or a string of reversed non repeating characters within the array.
>
>Good golly.
>
>The third case trivially reduces to the second case, so consider them as
>a single problem.
>
>Is there a minimal length requirement for the string of non-repeating
characters?
>
>: I know I can find any repeat with =m/^(.)\1{4,}/;
>: and $+ contains what character it found, and length($&) is how many, (I
>think).
>
>Better to add another set of capturing parentheses and avoid $&.
>
>    m/^((.)\2{4,})/
> 
>: How can I find if there is a match in the forward or reverse strings?
>
>My thinking:
>    1. Construct a string from the array elements, starting with the
>       element that matches the first letter in the target string.
>    2. XOR the string built in step 1 with the target string.
>    3. Count how many null ("\c@") characters occur at the beginning of 
>       the string created in the XOR operation.
>    4. Pluck that many characters from the beginning of the target 
>       string.
>    5. Reverse the array; perform the first above steps again.
>
>As in,
>
>    sub bar {
>        my($str) = @_;
>        my @array = qw( a  b  c  d  g );
>        my @matches;
>        my $c = substr($str, 0, 1);
>        for(1, 2) {
>            my $mask;
>            for( 0..$#array ) {
>               next unless $array[$_] eq $c;
>               $mask = join '', @array[ $_ .. $#array ];
>               last;
>            }
>            my($nulls) = ($mask^$str) =~ /^(\c@*)/;
>            push @matches, substr($str, 0, length $nulls);
>            @array = reverse @array;
>        }
>        return @matches;
>    }
>
>: short examples
>: ie for @array like @array=('a','b','c','d','g');
>
>Are the elements of @array guaranteed to be sorted in ascending order?
>Is @array guaranteed to have no duplicated elements?
> 
>: $forward=join('',@array);
>: $reverse=join('', sort {$b <=> $a} @array);
>
>Reversing a list of items is more easily done with the reverse()
>function.
> 
>: I've been trying to use matches, and tring to avoid
>: long loops using substrings.
>
>Is there a reason to avoid them?

After thinking about it, the forward, reverse could loop.
So abcdg for c forward becomes cdgab
c rev becomes cbagd

To answer your other qestions, I'm looking for a length >3
array is sorted with no duplicates.
I needed the sort earlier but not at this point, my mistake.

Thanks to all, the code looks great.



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

Date: Sun, 05 Oct 2003 17:44:01 +0200
From: Christoph Haas <email@christoph-haas.de>
Subject: Re: Accessing parent objects
Message-Id: <blpe80$ek2ie$1@ID-164271.news.uni-berlin.de>

Update... (argh, Mozilla ate my first reply)

I just came across a nice tutorial on variable scopes at
http://perl.plover.com/FAQs/Namespaces.html.en#The_Current_Package
which describes very clearly how lexicals and packages work.

I'm now convinced that the best way is declaring global variables
in the main package and then just refer to them via $main::parent
(or short: $::parent) from within the "child" objects from the
"Child" package.

If other have fresh ideas - let me know.

  Christoph





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

Date: 05 Oct 2003 15:59:24 GMT
From: agoodguygonebad@aol.com (AGoodGuyGoneBad)
Subject: Re: code with style
Message-Id: <20031005115924.09783.00000261@mb-m25.aol.com>

>Hi all,
>
>I was trying to calculate the max number of variations of the columns on
>an array.

Do you mean the number of permutations ?
http://mathforum.org/dr.math/faq/faq.comb.perm.html
usually written as 3!, 4!, 5! etc.
ie an array of 3 is 6
123
132
213
231
312
321
4 is 24
5 is 120

otherwise, the number is the max number an element can be to the power of the
number of columns.
5^5, or 5**5 in perl.
16^2 =256 or 00 to FF
4^4 = 256 

Steve
HTH



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

Date: Sun, 05 Oct 2003 17:30:51 +0100
From: pedro.fabre.NO-SPAM@gen.gu.se (Pedro)
Subject: Re: code with style
Message-Id: <pedro.fabre.NO-SPAM-0510031730510001@192.168.0.5>

In article <20031005115924.09783.00000261@mb-m25.aol.com>,
agoodguygonebad@aol.com (AGoodGuyGoneBad) wrote:

> >Hi all,
> >
> >I was trying to calculate the max number of variations of the columns on
> >an array.
> 
> Do you mean the number of permutations ?
No I don't.

from my example

my @a = (
         [qw/1 2 3 4 5/],
         [qw/2 2 3 2 4/],
         [qw/3 1 2 4 5/]
     );

the first column have 3 different values (1,2,3), the second 2 (2,1), two
also for the third one (3,2)... On this example, the column which presents
more variations is the first one with 3.

So the score of the matrix is 3 for this example.

Clear now?


The code does what it has to do, My question if focussed about my style
more than about the result of the code which works fine.

Cheers
P


> http://mathforum.org/dr.math/faq/faq.comb.perm.html
> usually written as 3!, 4!, 5! etc.
> ie an array of 3 is 6
> 123
> 132
> 213
> 231
> 312
> 321
> 4 is 24
> 5 is 120
> 
> otherwise, the number is the max number an element can be to the power of the
> number of columns.
> 5^5, or 5**5 in perl.
> 16^2 =256 or 00 to FF
> 4^4 = 256 
> 
> Steve
> HTH


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

Date: 5 Oct 2003 09:33:01 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: code with style
Message-Id: <3ee08638.0310050833.428341b0@posting.google.com>

pedro.fabre.NO-SPAM@gen.gu.se (Pedro) wrote in message news:<pedro.fabre.NO-SPAM-0510031532170001@192.168.0.5>...
[...]
> I am not fully convinced with my style, and I guess this can be done in a
> simpler way.
> 
> use strict;
> 
> my @a = (
>          [qw/1 2 3 4 5/],
>          [qw/2 2 3 2 4/],
>          [qw/3 1 2 4 5/]
>      );
> 
> my $var = maximum_multiplicity(\@a);
> 
> print "$var\n";
> 
> sub maximum_multiplicity{
> 
>     my ($a_ref)= @_;
>     
>     my $mm=0;    # maximum multiplicity
>     my $length = @{ @$a_ref[0]};    #length of the row
>  
>     for (my $i = 0; $i<$length;$i++){
> 
>         my %var=();
> 
>         for my $r (0..$#$a_ref){
> 
>             $var{ $a_ref->[$r][$i] } =1;  # new key for every new variation
>             my @al = keys %var;           # store var in array
> 
>             # if the number of var for this column is
>             # greater than before set $m value as var number
>             $mm= scalar @al if (scalar @al >$mm);
> 
>         }
>     }
> 
>     return $mm;
> }

Use a scalar $al instead of @al. keys %var will return the number of
keys into a scalar, and that's all you're using it for. Your outer
loop could also be
for my $i (0..$length)

I'm not sure I understand your intent, but it looks like you're really
just using %var to determine whether you've seen a variation before.
The body of your inner loop could probably be
++$mm unless $seen{$a_ref->[$r][$i]}++;


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

Date: Sun, 05 Oct 2003 18:36:56 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: code with style
Message-Id: <lch0ov88jujq6mq18cunu7t8rgcgu0t4s0@4ax.com>

X-Ftn-To: Pedro 

pedro.fabre.NO-SPAM@gen.gu.se (Pedro) wrote:
>I am not fully convinced with my style, and I guess this can be done in a
>simpler way.
>
>Any suggestion?

Hope it does same thing,

sub maximum_multiplicity {

    my ($a_ref) = @_;

    my $mm = 0;    # maximum multiplicity
    my $length = $#{ ${$a_ref}[0] }; #length of the row

    for my $i (0 .. $length) {

        my %seen = map { $a_ref->[$_][$i] => 1 } 0 .. $#{$a_ref};
        my $al = keys %seen;
        $mm = $al if $al > $mm;
    }
    return $mm;
}


-- 
Matija


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

Date: Sun, 5 Oct 2003 11:53:42 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: examples of sprintf
Message-Id: <slrnbo0j4m.dra.tadmc@magna.augustmail.com>

Mike Flannigan <mikeflan@earthlink.net> wrote:

> Perl documentation is short on
> examples.  


huh?


> The sprintf function is the one I'd most
> like to see examples included in the documentation.


   perldoc -f sprintf


I count only 38 examples there. We need more?


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


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

Date: 5 Oct 2003 09:16:52 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: fastest count of instances in string?
Message-Id: <3ee08638.0310050816.411cd599@posting.google.com>

Uri Guttman <uri@stemsystems.com> wrote in message news:<x74qyonwyb.fsf@mail.sysarch.com>...
> >>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
> 
>   RJ> sub str {
>   RJ>     my ($str, $tr_chars) = @_;
>   RJ>     $str=~s/$tr_chars//g;
>   RJ> }
> 
> that still doesn't do anything useful. how many times do you have to be
> told that?

How many times do you imagine you have told me that? Can you explain
why the output of the program is "There are 4 of them." when the str
function is called?

>   RJ> sub tr_chars {
>   RJ>    my ( $str, $tr_chars ) = @_;
>   RJ>    $tr_subs{ $tr_chars } ||= eval 'sub { $str=~tr/$tr_chars// }' ;
> 
> and that doesn't interpolate $tr_chars either as it is in single quotes.
> it may still works as it has an 'a' in '$tr_chars' but it is slower than
> just having 'a' in there.

Yep. I need to protect $str from interpolation, but not $tr_chars:
   $tr_subs{ $tr_chars } ||= eval "sub { \$str=~tr/$tr_chars// }" ;
The timing is not noticeably affected.

> this is going nowhere slowly.

Then ignore me. I supplied code, you supplied complaints. I won't feel
guilty for not being perfect. If you don't want to deal with lesser
mortals, don't.


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

Date: 5 Oct 2003 09:23:24 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: fastest count of instances in string?
Message-Id: <3ee08638.0310050823.67962f0c@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbnunfg.52v.tadmc@magna.augustmail.com>...
> Roy Johnson <rjohnson@shell.com> wrote:
> 
> > In much the same way that
> >   "$stupid"
> > is the same as
> >   $stupid
> 
> 
> But they are not the same!
> 
>    perldoc -q vars

Ok, mea culpa. For string values of $stupid, they are the same.


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

Date: Sun, 05 Oct 2003 17:17:10 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: fastest count of instances in string?
Message-Id: <x78ynzmwo9.fsf@mail.sysarch.com>

>>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:

  RJ> Uri Guttman <uri@stemsystems.com> wrote in message news:<x74qyonwyb.fsf@mail.sysarch.com>...
  >> >>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
  >> 
  RJ> sub str {
  RJ> my ($str, $tr_chars) = @_;
  RJ> $str=~s/$tr_chars//g;
  RJ> }
  >> 
  >> that still doesn't do anything useful. how many times do you have to be
  >> told that?

  RJ> How many times do you imagine you have told me that? Can you explain
  RJ> why the output of the program is "There are 4 of them." when the str
  RJ> function is called?

have you rtfm'ed about this? the relevant section was posted in this
thread. tr/// DOES NOT INTERPOLATE. 

the actual string in the tr/// happens to HAVE an 'a' in it. so it will
count a's as well as '$' and 't' the rest of '$tr_chars'


  RJ> sub tr_chars {
  RJ> my ( $str, $tr_chars ) = @_;
  RJ> $tr_subs{ $tr_chars } ||= eval 'sub { $str=~tr/$tr_chars// }' ;

same here. the single quotes won't interpolate either. 

  RJ> Yep. I need to protect $str from interpolation, but not $tr_chars:
  RJ>    $tr_subs{ $tr_chars } ||= eval "sub { \$str=~tr/$tr_chars// }" ;
  RJ> The timing is not noticeably affected.

but this is CORRECT now. i wasn't concerned about speed.

try the original and the str sub with data that contains any other chars
in '$tr_chars' beyond 'a'. see what the count is then.

  >> this is going nowhere slowly.

  RJ> Then ignore me. I supplied code, you supplied complaints. I won't feel
  RJ> guilty for not being perfect. If you don't want to deal with lesser
  RJ> mortals, don't.

i deal with all sorts provided they listen and learn. when you have been
told multiple times that tr/// doesn't interpolate and you still attempt
it then you are not listening. you did listen and learn about the
eval. now try to listen and learn about proper testing. use better data
input and try to break the code. that is one aspect of proper
testing. note that moronzilla is infamous (among other things) for
posting test cases that don't drive the code well. the data she provides
is almost always best case and will produce good results. but anything
else will fail and she fails to see that. she has done that many times
and refuses to listen or learn. don't you become like that.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sun, 05 Oct 2003 17:18:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: fastest count of instances in string?
Message-Id: <x765j3mwmv.fsf@mail.sysarch.com>

>>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:

  RJ> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbnunfg.52v.tadmc@magna.augustmail.com>...
  >> Roy Johnson <rjohnson@shell.com> wrote:
  >> 
  >> > In much the same way that
  >> >   "$stupid"
  >> > is the same as
  >> >   $stupid
  >> 
  >> 
  >> But they are not the same!
  >> 
  >> perldoc -q vars

  RJ> Ok, mea culpa. For string values of $stupid, they are the same.

and you can't guarantee that. they are different and "$string" is almost
always wrong. 

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sun, 05 Oct 2003 17:41:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: fastest count of instances in string?
Message-Id: <3F805799.76DE0A3C@acm.org>

Roy Johnson wrote:
> 
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbnunfg.52v.tadmc@magna.augustmail.com>...
> > Roy Johnson <rjohnson@shell.com> wrote:
> >
> > > In much the same way that
> > >   "$stupid"
> > > is the same as
> > >   $stupid
> >
> > But they are not the same!
> >
> >    perldoc -q vars
> 
> Ok, mea culpa. For string values of $stupid, they are the same.

If the value in $stupid is already a string why would you need to quote
the variable?


John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 5 Oct 2003 16:44:45 +0100
From: "news.wanadoo.es" <nospam@peng.nl>
Subject: how to search a specific file on a web server
Message-Id: <Y4Xfb.6804$Hd.810924@news-reader.eresmas.com>

Hi,

from my site, I'd like to search the
http://sohowww.nascom.nasa.gov/data/realtime/javagif/gifs_thumb/ directory
for the latest .gif file. (and copy that one).

What's the best method of achieving this?

In other words: what do I need to learn.

Is lwp:simple any good for this?

Thanks,

Lex




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

Date: Sun, 5 Oct 2003 12:37:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to search a specific file on a web server
Message-Id: <slrnbo0lls.dra.tadmc@magna.augustmail.com>

news.wanadoo.es <nospam@peng.nl> wrote:
> Hi,
> 
> from my site, I'd like to search the
> http://sohowww.nascom.nasa.gov/data/realtime/javagif/gifs_thumb/ directory
> for the latest .gif file. (and copy that one).
> 
> What's the best method of achieving this?


There is no method for achieving that. HTTP does not give you
access to directories or files, it gives you access to resources
(the "R" in "URL").


But you _can_ extract the links, and return the latest one assuming
that the date/time is always encoded in the resource's name:

-----------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use HTML::LinkExtor;

my $html = get 'http://sohowww.nascom.nasa.gov/data/realtime/javagif/gifs_thumb/
';

my $le = HTML::LinkExtor->new();
$le->parse($html);

my $latest = '';
foreach my $link ( $le->links ) {
   my($tag, %attrs) = @$link;
   next unless $attrs{href} =~ /\.gif$/;
   $latest = $attrs{href} if $attrs{href} gt $latest;
}

print "$latest is the latest file\n";
-----------------------------------------


or, you _can_ return the second-to-last link on the page:

-----------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use HTML::LinkExtor;

my $html = get 'http://sohowww.nascom.nasa.gov/data/realtime/javagif/gifs_thumb/
';

my $le = HTML::LinkExtor->new();
$le->parse($html);

my($tag, %attrs) = @{ ( $le->links )[-2] };
print "$attrs{href} is the latest file\n";
-----------------------------------------


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


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

Date: Sun, 5 Oct 2003 17:20:08 +0100
From: "Lex" <nospam@peng.nl>
Subject: pattern matching
Message-Id: <8CXfb.6810$Hd.811961@news-reader.eresmas.com>

Hi,

I've got a text file, database looking like:

ID|word|plural|synonym|meaning

now 268 records. (specialised dictionary)

When somebody looks up a word, it checks for a match in word or plural or
synonym.
(sofar I can even do it...)

However, what I'd want as well that as soon as 'meaning' is shown to the
user, (normally a few phrases) every word in it should be checked to see if
it's in any of the word, plural or synonym fields of all the (other)
records. (so I can link it to that record)

What's the best way of doing that? Any examples?

Thanks,

Lex




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

Date: Sun, 05 Oct 2003 18:45:28 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: pattern matching
Message-Id: <l9i0ovs8jqp6ifssev91fd7epnldskpkvh@4ax.com>

X-Ftn-To: Lex 

"Lex" <nospam@peng.nl> wrote:
>However, what I'd want as well that as soon as 'meaning' is shown to the
>user, (normally a few phrases) every word in it should be checked to see if
>it's in any of the word, plural or synonym fields of all the (other)
>records. (so I can link it to that record)
>
>What's the best way of doing that? Any examples?

my %winfo;
for my $word (split /\s+/, $meaning) {
  @winfo{qw/id plural synonym meaning/} = sub_id($word);
}

sub_id returns to you values for given $word, and $meaning is already
retrieved meaning for initial word.



-- 
Matija


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

Date: Sun, 5 Oct 2003 18:17:59 +0100
From: "Lex" <nospam@peng.nl>
Subject: Re: pattern matching
Message-Id: <msYfb.6815$Hd.813185@news-reader.eresmas.com>

"Matija Papec" <perl@my-header.org> wrote in message
news:l9i0ovs8jqp6ifssev91fd7epnldskpkvh@4ax.com...

>
> my %winfo;
> for my $word (split /\s+/, $meaning) {
>   @winfo{qw/id plural synonym meaning/} = sub_id($word);
> }
>
> sub_id returns to you values for given $word, and $meaning is already
> retrieved meaning for initial word.

Hi  Matija,

thanks for the reply. I'm a newbie and trying to see what exaclty happens
with what you wrote.

for my $word (split /\s+/, $meaning) {     # every single word in $meaning
  @winfo{qw/id plural synonym meaning/} = sub_id($word);

Shouldn't that be @winfo{qw/word plural synonym/} = sub_id($word);
Might well be that I don't understand what's going on here...

I think I didn't write down well what I'd like to happen or that I just
don't understand what you wrote.

I'll retry explaining what it is I'd like to happen:

flatfile database, somebody asks the meaning of a word.
The meaning is shown
But before that, every word in meaning is checked if it isn't in any of the
word, synonym or plural fields of all other records. If it is, I can make a
link of that particular word in meaning so people can look up the meaning of
that word as well.

To give an example:

db:
1|stove|stoves|heater|a thing to warm up a room
2|room|rooms|chamber|part of a building, often equiped wit a stove

Now, if somebody looks up the word stove the result would be:
stove: a thing to warm up a room
in which the word 'room' would link to a subroutine to show the meaning of
'room' (and when people would click on it, they'd see 'room: part of a
building, often equiped wit a stove' where stove would link to ... you get
my drift.

I think that might well be my problem, you do get my drift but I don't get
yours. Excuse me if that is the case. If not I hope I was able to describe
my 'problem' better.

Thanks,

Lex




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

Date: Sun, 5 Oct 2003 11:48:18 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: pattern matching
Message-Id: <slrnbo0iqi.dra.tadmc@magna.augustmail.com>

Lex <nospam@peng.nl> wrote:
> Hi,
> 
> I've got a text file, database looking like:
> 
> ID|word|plural|synonym|meaning
> 
> now 268 records. (specialised dictionary)
> 
> When somebody looks up a word, it checks for a match in word or plural or
> synonym.
> (sofar I can even do it...)
> 
> However, what I'd want as well that as soon as 'meaning' is shown to the
> user, (normally a few phrases) every word in it should be checked to see if
> it's in any of the word, plural or synonym fields of all the (other)
> records. (so I can link it to that record)
> 
> What's the best way of doing that? Any examples?


Any example data?

Untested, since I don't want to have to create test data:

   my %xref;
   while ( <DB> ) {
      my($id, $word, $plural, $synonym) = split /\|/;
      @xref{ $word, $plural, $synonym } = ($id, $id, $id);
   }
   ...
   foreach my $word ( $meaning =~ /(\S+)/g ) {
      print "make a link to ID $xref{$word}\n" if exists $xref{$word}
   }


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


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

Date: 05 Oct 2003 17:00:00 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: regex behavior
Message-Id: <slrnbo0jgg.u17.abigail@alexandra.abigail.nl>

Michael P. Broida (michael.p.broida@boeing_oops.com) wrote on
MMMDCLXXXIII September MCMXCIII in <URL:news:3F7B532C.7878A3BB@boeing_oops.com>:
,,  Abigail wrote:
,, > 
,, > Matija Papec (mpapec@yahoo.com) wrote on MMMDCLXXXIII September MCMXCIII
,, > in <URL:news:4bdmnvcb9or2nbm2ne1euvhqp1e64s84g7@4ax.com>:
,, > --
,, > --  I went through perldoc but didn't found similar regex,
,, > --  print join ',', 'a bb ccc dddd' =~ /(\w)+/g;
,, > --
,, > --  the question is, what it exactly matches and why?
,, > 
,, > /(\w)+/ matches a set of consecutive word characters, capturing
,, > the *last* one. //g in list context means, do this as often as
,, > possible (without overlap), returning a list of each of the submatches.
,, > 
,, > So, 'a bb ccc dddd' =~ /(\w)+/g; returns for each substring of
,, > consecutive word characters the last one, resulting in 'a', 'b', 'c' and 'd'.
,,  
,,  	That tests out as you said, so it's MY thinking that's off.  :)
,,  	Hopefully, you can clue me in.  :)
,,  
,,  	I expected it to result in "a,bb,ccc,dddd". Now I realize that
,,  	it's the positioning of the + that causes it to get a single
,,  	character from each group.  If the + is inside the (), it
,,  	prints what I expected.
,,  
,,  	But...  What is causing the original /(\w)+/ to get the LAST
,,  	character from each group instead of the FIRST character from
,,  	each group?


Would you expect:

    $x = $_ for qw /a b c d/
    print $x;

to print 'a' as well?



Abigail
-- 
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/                xor      !@ _?
       exit print                                                  :
            print and push @_ => shift and goto &{(caller (0)) [3]}}
            split // => "KsvQtbuf fbsodpmu\ni flsI "  xor       & _


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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