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.

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
  • Comment on Re^2: Getting "un initialized value" error though variable is initialized. Please help.
  • Download Code

Replies are listed 'Best First'.
Re^3: Getting "un initialized value" error though variable is initialized. Please help.
by AnomalousMonk (Archbishop) on Dec 18, 2011 at 00:06 UTC

    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);