Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

(bbfu) (soft-refs) Re(2): Spliting letters in a string

by bbfu (Curate)
on May 08, 2001 at 02:15 UTC ( [id://78684]=note: print w/replies, xml ) Need Help??


in reply to Re: Spliting letters in a string
in thread Spliting letters in a string

I really do believe that you already realize that this is dangerous and were just offering it as a "well, if that's really what you want to do then this is how you do it..." kind of thing.

Continuing in that spirit, some suggestions...

You should make sure that you don't conflict with use strict by doing a (block-scoped) no strict 'refs';. You might also want to local $_. I would also suggest avoiding using map in void context because it spends a lot of energy building a return list and actually tends to be slower than an equivalent for loop in many cases; and, IMHO, it doesn't really improve the legibility any.

{ no strict 'refs'; local $_ = "abcdefghijklmnopqrstuvwxyz"; # or $string $$_ = $_ for split //; } print $c; #prints letter 'c' to the screen

Of course, these are all just suggestions. You're code was perfectly useable to begin with. :-)

Update: Improved the wording a little. Removed unnecessary braces in deref in code. Changed no meaning. :-)

bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.

Replies are listed 'Best First'.
Re: (bbfu) (soft-refs) Re(2): Spliting letters in a string
by srawls (Friar) on May 08, 2001 at 05:05 UTC
    >>I really do believe that you already realize that this is dangerous and were just offering it as a "well, if that's really what you want to do then this is how you do it..." kind of thing. >>

    Yep. I just want to stress, I don't recomend that the questioner actually use this, I just meant it as exactly what you said. The reason I didn't provide the additional info was the fear that the questioner would actually use it : )

    The 15 year old, freshman programmer,
    Stephen Rawls

      Well, if you're going to shoot yourself in the foot, you might as well do it elegantly. ;-)

      I also think it is a very bad idea for people to go around using soft references like that. That's why I posted my array suggestion below (and why I felt compelled to mention that it was a bad idea; out loud, as it were). Besides the danger of overwriting someone else's (or your own!) variables, there's the simple fact that, once you're done creating all those variables, you won't know which they were! :-)

      bbfu
      Seasons don't fear The Reaper.
      Nor do the wind, the sun, and the rain.
      We can be like they are.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found