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

Re: [FWP] duh: A small puzzler



On Fri, Jul 30, 1999 at 04:56:14PM -0700, Vicki Brown wrote:
> People asked for simpler puzzles; here's a small one. Perl gurus 
> can't play (or play quietly while the more lurkers consider :-)
> 
> I did this today; I wasn't thinking... (well, it's Friday after all)
> 
>    # records look like
>    # >12|c2169.2750 CHROMAT_FILE: 12=c2169.2750 PHD_FILE: ...
>    #
>    # I want to get just the c2169.2750 part
> 
>    ($id) = split(/\s+/, $record);
> 
>    $id =~ s/^.*|//;    # remove extraneous stuff before the construct info
> 
> 
> what's wrong? :-}

Well, wouldn't the regex applied to $id be searching for either any number
of non-newline characters at the first of the string or... well, nothing
(a empty string) and replace either of those with nothing?  So wouldn't it
just match the entire $id string and thus $id = ""?  Methinks we lost the
part of the string we wanted to keep with the trash, eh? :)

For extra credit, wouldn't you just backslash the pipe?  Or am I wrong?

Stevie

-- 
In this case, magically means "transparently doing something very
complicated."  You know the old saying -- any technology sufficiently
advanced is indistinguishable from a Perl script.
    -- Programming Perl, 2nd edition, p. 301

PGP signature