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

Respected Monks,

Thank you for your direction and guidance.

Anonymous Monk, my intention of using $wwn and @wwn is not to confuse.I do understand that @wwn and $wwn are two seperate entities and that having the same name doesn't mean that they are related in any ways, unless ofcourse I say $wwn[0] or something like that which indicates that its a scalar context of @wwn. I used $wwn and @wwn because the name WWN stands for World Wide Name and this ways, I can make a mental note that both these refer to it, though inherently they are not related.

ww, I will surely follow indentation.

Perl Version - (v5.14.2) MSWin32-x64-multi-thread on Windows 7 64 Bit.
  • Comment on Re: Getting "un initialized value" error though variable is initialized. Please help.
  • Download Code

Replies are listed 'Best First'.
Re^2: Getting "un initialized value" error though variable is initialized. Please help.
by GrandFather (Saint) on Dec 17, 2011 at 21:57 UTC

    Overloading names in that way is a great way to introduce subtle bugs and make code hard to understand. If it's an array it likely contains more than one item so using a plural form of the name (@wwns) may make sense. Alternatively I'd use the slightly more generic variable name $name for the input variable.

    Oh, and don't use our as a substitute for my, especially as a temporary variable - it doesn't do what you think it does and is not at all appropriate. I'd tend to rewrite the thing as:

    #!/usr/bin/perl use warnings; use strict; while (1) { print "Enter the wwn: "; chomp (my $name = lc <STDIN>); last if $name eq "q"; print join (':', unpack ("(a2)*", $name)), "\n"; }

    Update: s/own/our/

    True laziness is hard work

      I quite agree with GrandFather.

      In fact, I think I would go a bit further and advise the use of more 'documentary' scalar variable names:
          chomp (my $raw_wwn = lc <STDIN>);
          ...
          my $fixed_wwn = join ':', unpack '(a2)*', $raw_wwn;
          do_something_with($fixed_wwn);