Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

have also tried to undefine @clsses in the loop. However, like above, no success.

for my $name (keys %characters) { my $id = $name; $id =~ s! !_!g; $id =~ s![^-\w:.]!!g; my $experience = $characters{$name}{experience}; my @classes = @{$characters{$name}{classes}};

You are declaring @classes inside the loop. Therefore, every time through the loop, the @classes variable is destroyed. A new @classes variable is created each time through the loop and it is assigned a new value.

It's not clear to me why you want to 'undefine' @classes. Is it possible you are doing something like this:

use strict; use warnings; use 5.010; my @classes = ('A', 'B'); for (1 .. 3) { my @classes = ('C', 'D'); say "@classes"; } say "\n@classes"; --output:-- C D C D C D A B

Anything you do to @classes inside the loop braces only affects the @classes variable that you declared inside the loop braces. Changes to the @classes variable inside the loop braces aren't going to affect the @classes variable declared outside the loop braces.


In reply to Re: Problem undefining a variable in a loop using a module causing a list to not empty after use of a subroutine by 7stud
in thread Problem undefining a variable in a loop using a module causing a list to not empty after use of a subroutine by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-26 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found