r.joseph has asked for the wisdom of the Perl Monks concerning the following question:
(The ... are not intended to be perl operators, they just mean 'something else goes here').while (<FILE>) { if (/.../) { ... } }
(Obviously, this is all psuedo-code because my actual code is very messy and would not suffice for this discussion, but you get the idea.) Now here is where I get stuck. In the if() clause above (where $1 and $2 are assigned) I want to assign a hash value on the fly. Here is what I want to do (assume that anytime we are in the if(), $stuff has a value that was already assigned in the elsif() - in my code, it has to happen this way):my $stuff; while (<FILE>) { if (/(...)(...)/) { # we have $1 and $2 in here, both some string } elsif (/(...)/) { $stuff = $1; } }
but as you can imagine, this does not in fact work. Now, I have never really been good at the whole reference thing and dynamic varible creation and such, so could someone please explain to me how I would do what I have illustrated above? I have a feeling that it is in fact a rather simple solution, but I continualy find myself up against a wall in this area!eval "\$$stuff{$1} = $2";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Creating on-the-fly hashes?
by tilly (Archbishop) on Jan 08, 2001 at 08:50 UTC | |
by Dominus (Parson) on Jan 08, 2001 at 23:50 UTC | |
|
Re: Creating on-the-fly hashes?
by chipmunk (Parson) on Jan 08, 2001 at 09:08 UTC | |
|
Re: Creating on-the-fly hashes?
by t'mo (Pilgrim) on Jan 08, 2001 at 08:40 UTC |