[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] duh: A small puzzler



Brian Matthews wrote:
> John Porter wrote:
> > Jim Monty wrote:
> > > By the way, the plus quantifier in this expression is superfluous:
> > >
> > >     ($id) = split(/\s+/, $record);
> >
> > Only if, as in this case, there are no runs of whitespace longer
> > than one.
>
> However, if a single space is the column separator and columns can be
> empty, then the + isn't just superfluous, it's wrong. Vicki didn't give
> us enough information to say which is correct. Of course, she wasn't asking
> about the split either...

My point was that, in this _specific_ context, it doesn't matter
how many spaces occur between the first and second "words" (continguous
strings of non-space characters) on the line. Vicki is only carving
out the first "word" or "column". It's this that makes the plus
quantifier superfluous here:

$record1 = '>12|c2169.2750 CHROMAT_FILE: 12=c2169.2750 PHD_FILE:';
$record2 = '>12|c2169.2750      CHROMAT_FILE:  12=c2169.2750  PHD_FILE:';
($id1) = split /\s/, $record1;  # $id1 gets '>12|c2169.2750'
($id2) = split /\s/, $record2;  # $id2 gets '>12|c2169.2750'

Same-o, same-o.

-- 
Jim Monty
monty@primenet.com
Tempe, Arizona USA

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe