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

Re: [FWP] Real World Perl



On Fri, Mar 23, 2001 at 10:45:32AM +0200, Ilmari Karonen wrote:
> 
> On Wed, 21 Mar 2001, Vicki Brown wrote:
> > 
> >     if ( $year < 100 ) {
> >         $cc = 19;
> >       }
> >     else {
> >        $cc = 20;
> >        $year = $year - 100;
> >        $year = "0" . $year if length($year) < 2;
> >       }
> 
> This being the Fun With Perl list, I can only presume that the "fun"
> part, at least for the rest of us, is the ability to press D and have
> the ugliness just vanish, instead of having to maintain it?
> 
> That still leaves open the question of how exactly it is fun for you.
> Of course, there is a certain amount of satisfaction involved in
> replacing such code with something sane, but it usually evaporates
> rather quickly once one happens to think about the actual significance
> of having removed 20 lines of bogosity from a 20000 line project.

Those of us who have been on this mailing list since its inception know
that Vicki's original intent in founding the list was to share bits of Perl
code like this, where the puzzle is to figure out what they're supposed to
do, why they work, and what a good way to do it would have been.

It's true that the list now focuses more on challenges and Perl golf, but
these code snippets are still fun as well.  I'm rather put off by the
implication that Vicki's posting to her own mailing list doesn't qualify as
being fun.

Ronald


----- Forwarded message from Vicki Brown <vlb@cfcl.com> -----

Date: Sun, 6 Jun 1999 10:57:44 -0700
To: fwp@cfcl.com
From: Vicki Brown <vlb@cfcl.com>
Subject: [Fun With Perl] Welcome to Fun With Perl
Reply-To: Vicki Brown <vlb@cfcl.com>

Welcome. We now bring you the first installment of Fun With Perl. 
(Some folks have seen some of this already. Sorry for any repeats)

About a year ago, I started to collect little bits of Perl code that 
I thought were worthy of mention (or at least of saving) for some 
reason ("worthy" here means _I_  thought so).  Maybe they're bits 
that could someday go into a Perl puzzle book or exercise article, 
or... maybe they're things I would have done  differently, or... 
maybe they are examples of a form that could be called "What is wrong 
with this picture?".  Maybe they are just a set of examples that 
prove There Is More Than One Way To Do It.

In essence, "Fun With Perl" is things I thought were worth mentioning 
to Perlish friends I think would get a kick out of them.

Please send me anything you run across that qualifies as Fun With 
Perl; I'm collecting :-)  If you send one, I'd like: the setup 
(what's the problem), the given solution, your alternate solution(s) 
where applicable, any appropriate description of what's wrong or why 
this is interesting...

When I save these, I have been trying to save them as Perl code... so 
my comments about what's going on are set as Perl comments. Not a 
requirement, of course, but it seems to work. (This note isn't done 
that way, of course)

Here, to start things off, is one of my favorite lines from much code 
at my previous company:

    system("date | perl -p -e 'chop' >> $times");

I really love this one :-)
No comment required here, I think... (if you want one, let me know)


One of my friends has suggested that I post the collection to the 
list gradually, so that's what I'll do.

Here's the one I ran into back in January:

# Setup: The programmer is reading from a file where records contain multiple
# lines. He wishes to tack the current input line onto the end of a string he's
# building up. The string is stored in the variable $str.

#Code:
          $str = join($_, $str, "");

# What is wrong with this picture?  (by the way, it does work...)

# Solution 1:
          $str = join("", $str, $_);  # the syntax for join was inside-out!

# Solution 2:
          $str = $str . $_;
 
# Solution 3:
          $str = "$str$_";


# For extra credit: how come the original code actually worked?

- Vicki
-- --
        |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
  ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
       |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
      '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.org

==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org

----- End forwarded message -----

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