Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: An Elegance Question

by plaid (Chaplain)
on Apr 13, 2000 at 22:30 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found