> -----Original Message----- > From: Paul Tremblay [mailto:[EMAIL PROTECTED]] > Sent: Thursday, August 01, 2002 12:17 PM > To: [EMAIL PROTECTED] > Subject: changing multiple flags and changing them back > > > I have a series of flags that I need to change all at once, and then > change back, and was wondering if I could use an array or hash to do > this. > > I am parsing an RTF file, and when I find a footnote, I need > to preserve > the flags of the non-footnote text. So if I was in a table, I need to > save the $in_table flag. Then when I am done with the footnote text, I > need to re-set the $in_table flag to its previous state. > > So far I have this: > > sub start_footnote{ > $previous_in_table = $in_table; > ... > } > > sub end_footnone{ > $in_table = $previous_in_table; > ... > } > > This works find except I might have 15 or 20 flags I need to set or > re-set. I would like to use an array like this: > > @flags = ($in_table, $after_cell, $in_paragraph); > > When I finish with my footnote, I will have an array of the previous > values. Now how do I assign these values to the variables?
Just reverse the assignment: ($in_table, $after_cell, $in_paragraph) = @flags; You might also consider using a simple stack: my @stack; sub start_footnote { push @stack, [ $in_table, $after_cell, $in_paragraph ]; ... } sub end_footnote { ($in_table, $after_cell, $in_paragraph) = @{ pop @stack }; ... } This will support multiple levels, if that is required (i.e. footnote within a footnote). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]