Toon posts:

[PERL] Variable naam samenstellen uit 2 scalars.

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik wil dit doen, maar 't werkt niet:

code:
1
$form_values{$copy_field} = ${"c_adm_$field"};


Ik gebruik, zoals elke perl-coder betaamt, use strict; & perl -wT, maar bij bovenstaande stukje code krijg ik de melding:

code:
1
[Sat Nov  2 21:38:30 2002] addCustomer.pl: Can't use string ("c_adm_firstname") as a SCALAR ref while "strict refs" in use at /extra/vhosts/[censored]/html/addCustomer.pl line 44.


Hoe ga ik dit oplossen? En "no strict;" / "use strict niet gebruiken" is geen optie, als het even kan wil ik strict blijven gebruiken...

  • m-m
  • Registratie: Augustus 2001
  • Niet online

m-m

kan je niet ff va;s spelen?
$tmpvar = $var1.$var2;
$blaat{$var3} = $tmpvar;

Verwijderd

Topicstarter
Nah, het gaat er juist om dat $c_adm_firstname een waarde bevat die in $form_values{$copy_field} moet komen. Alleen de naam $c_adm_firstname moet worden 'samengesteld'. Ik weet dat het eerste gedeelte c_adm_ is, maar daarachter kan firstname, lastname, street, nouja, ga zo door...

  • Red Sonja
  • Registratie: Juli 2001
  • Laatst online: 01-07 13:16

Red Sonja

Linux: power to de wortel

Je hebt 2 oplossingen:
use strict;
no strict refs;

of
$form_values{$copy_field} = ${"c_adm_$field"};
vervangen voor:

my $temp = "c_adm_$field";
$form_values{$copy_field} = $$temp;


sim-pel toch?

And the beast shall be made legion. Its numbers shall be increased a thousand thousand fold. The din of a million keyboards like unto a great storm shall cover the earth, and the followers of Mammon shall tremble. from The Book of Mozilla, 3:31


  • pim
  • Registratie: Juli 2001
  • Laatst online: 27-08 23:26

pim

Ik heb het probleem ook gehad, maar bij mij werkte jouw oplossing wel?

[rml][ BC3] [ Perl] Variablen van gekoppelde variablen.[/rml]

  • Red Sonja
  • Registratie: Juli 2001
  • Laatst online: 01-07 13:16

Red Sonja

Linux: power to de wortel

En Pim heeft ook 'use strict;' bovenaan z'n script? Volgens mij niet... want daar zat t m in ;)

And the beast shall be made legion. Its numbers shall be increased a thousand thousand fold. The din of a million keyboards like unto a great storm shall cover the earth, and the followers of Mammon shall tremble. from The Book of Mozilla, 3:31

Pagina: 1