Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Shifting themes

by mwp (Hermit)
on Jul 28, 2000 at 06:53 UTC ( [id://24792]=poem: print w/replies, xml ) Need Help??

#$ shifting themes, upon first glance # # can the heart and soul really keep # # up with the themes of our lives? $# our @themes = qw( fuel fire flame hot air water earth spirit desire love happiness peace ); our $poem = q( from heart comes soul thus the heart is truly soul for without heart, one cannot have soul and without soul one returns to the heart one soul, one heart no heart, no soul ); while(my $heart = shift @themes and my $soul = shift @themes) { $poem =~ s/heart/$heart/ && $poem =~ s/soul/$soul/ } print $poem; #$ is the theme shifting, # # or does it remain the same? $#

(UPDATE: This doesn't quite capture the grace of osfameron's implementation, but it's a little cleaner than it was before)

Replies are listed 'Best First'.
RE: shifting themes
by osfameron (Hermit) on Jul 31, 2000 at 15:48 UTC
    Just a thought I had about the shifting themes - why not tie the scalars to a shifting array (I knew that book on OO Perl would come in useful for something...)
    Not sure whether that ugly OO code has any place in a perl poem - what do you think?
    # words and concept by alakaboo # Tied OO implementation of shifting themes # by Osfameron (hakim@earthling.net) our @themes = qw( fuel fire flame hot air water earth spirit desire love happiness peace ); tie $heart, 'Theme', \@themes; tie $soul, 'Theme', \@themes; print <<POEM; from $heart comes $soul thus the $heart is truly $soul for without $heart one cannot have $soul and without $soul one returns to the $heart one $soul, one $heart no $heart, no $soul POEM package Theme; sub TIESCALAR { bless @_[1], @_[0] }; sub FETCH { shift @{@_[0]} };
    Update: On thinking about it, it seems churlish not to mention that that the OO book in question is Damian Conway's excellent Object Oriented Perl.

    Cheerio!
    Osfameron

      This is one of those occasions where I wish I could ++ a post twice. :)

      This is an elegant solution to an otherwise inelegant problem. I've been reading about Tie() off and on since I started learning object oriented Perl programming, about two months ago, and this really brings it together for me. Ironic, dontcha think?

      Thanks for the help!!

      Alakaboo
      I am the lurker that spams in the night.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: poem [id://24792]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found