Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: An Elegance Question

by plaid (Chaplain)
on Apr 13, 2000 at 22:30 UTC ( #7501=note: print w/replies, xml ) Need Help??


in reply to An Elegance Question

Instead of using variables such as $noun1, $noun2, etc., you might want to consider encapsulating the values in a hash ($hash{noun1}, $hash{noun2}, etc.) when reading them in. This would first of all keep your namespace cleaner, and secondly, would allow the foreach loop to be rewritten as
foreach (@story) { s/\[(.*?)\]/$hash{$1}/g; print; }
or, for more fun
map { s/\[(.*?)\]/$hash{$1}/g; print } (@story);
The same effect could be achieved with the variable names you're reading into now, but would require the use of symbolic references, the use of which would probably get you dragged out into the street and shot here:)

Replies are listed 'Best First'.
RE: Re: An Elegance Question
by Simplicus (Monk) on Apr 13, 2000 at 22:39 UTC
    Very cool. Thank you! S-

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-05-22 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?