Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: strict or not strict?

by Tanalis (Curate)
on Aug 19, 2005 at 14:15 UTC ( #485146=note: print w/replies, xml ) Need Help??

in reply to strict or not strict?

I'm trying to plug a hash into an old piece of code (for a once off) and I was hoping not to have to change every instance of i.e $blah to $hash{'blah'}. Just being lazy...

Replace All is your friend, surely? That or write a one-liner to replace it for you ...

Replies are listed 'Best First'.
Re^2: strict or not strict?
by rsiedl (Friar) on Aug 19, 2005 at 14:20 UTC
    Of course 'replace all' was my first thought, but then I did think of the above method and just wanted to investigate further down this road.
    Hence my question...
    Thanks for your help.

      If the variables are declared already above your loop, then you can do it via string eval. E.g.

      #!/usr/bin/perl use strict; use warnings; my ($blah, $boo, $hoo); # DECLARED HERE my %data = ( "blah"=>1, "boo"=>2, "hoo"=>3 ); # assign each key to a variable of the same name foreach (keys %data) { eval " \$$_ = \$data{$_} "; } # end-foreach print $blah; exit;

      Replace is still probably a better long run strategy.


      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://485146]
[Corion]: Meh. I think I have now the parts down that I want from a simple Javascript frontend for single-page- applications with a aPerl backend. But it seems that all Javascript templating modules either don't support two-way binding (which would be nice) or ...
[Corion]: ... don't support server-side precompilation (which means the client has to compile all templates to Javascript themselves), or are giant frameworks that expect to do everything (which is not what I want)
[Corion]: I feel that there is a talk somewhere in there, either about the structure and parts, or how I used several parts to get a complete whole.
[Corion]: Maybe I can still find something that is compatible with handlebars.js (which has JS precompilation) but allows for two-way data binding (which is great for the UI)
[Corion]: Two-way data binding means that if you change something in a text box, the corresponding variable in your Javascript gets updated immediately as well, and if you then change the variable, the corresponding text box also gets updated

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-03-30 07:52 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (355 votes). Check out past polls.