in reply to Re: Getting "un initialized value" error though variable is initialized. Please help.
in thread Getting "un initialized value" error though variable is initialized. Please help.

You can also use this alternative loop style that will always run at least once:

my $wwn; do { print "Enter the wwn: "; chomp ($wwn=<STDIN>); my @wwn = unpack ("(a2)*", lc($wwn)); @wwn = join (":", @wwn); print "@wwn\n"; } until ($wwn eq "q");

Also, it's confusing that you have @wwn and $wwn. You should consider renaming one.

  • Comment on Re^2: Getting "un initialized value" error though variable is initialized. Please help.
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Getting "un initialized value" error though variable is initialized. Please help.
by ww (Archbishop) on Dec 17, 2011 at 16:46 UTC
    ++ for the do { ...; } loop, annonymonk, but not so much for
    "it's confusing that you have @wwn and $wwn."

    Respectfully disagree: where an array is the child of a string (or vice versa), having both use the same base_name makes all the sense in the world to me... and from the original post, it's pretty clear that "wwn" is a meaningful name to the OP (ie, not a case of naming stuff $var1, $var2, @arr3, %h4 or the like, which, of course, would warrant advice to select meaninful names like $ip, $mac, @wwm... (sorry, no hash example in the OP).

      Well, you're just defending it because it happens to contain your initials =P

      Anyway, I'd rename the scalar to $input as that makes sense to me. That is just my opinion, though. There are other small problems such as @wwn = join (":", @wwn); (empty an array and assign a scalar value into an array's first slot) -- that is, use a previously-defined array as a scalar variable -- but I'm not to split hairs over it as the OP did not ask to review his code.