in reply to Re: Constructing a hash - why isn't my regex matching anything
in thread Constructing a hash - why isn't my regex matching anything

I keep getting the below warning

Use of uninitialized value in hash element at hash_construct.pl line 15, <$fh> line 909. Use of uninitialized value in concatenation (.) or string at hash_construct.pl line 11, <$fh> line 910.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; open my $fh, '<', $ARGV[0] or die "could not open $ARGV[0]'' $!"; while (my $line = <$fh>) { $line =~/;(.*)\s-\s/; my $key = $1; print "KEY:$key\n"; $line =~/\.\\(.*)-/; my $value = $1; print "VALUE:$value\n"; $hash{$key}=$value; } print Dumper(\%hash);

Replies are listed 'Best First'.
Re^3: Constructing a hash - why isn't my regex matching anything
by Anonymous Monk on Dec 19, 2010 at 08:58 UTC
    Yes, I know, do you have a question?

      why is $key and $match not matching anything?what change should I do in regex to match them?

        why is $key and $match not matching anything?

        Because there is nothing to match. An empty line, all whitespace line, is empty :) It has no dots. It has no dashes, semicolons, slashes. Your regex won't match. :D

        what change should I do in regex to match them?

        Allow for the possibility of failure,ie test for success, just like this guy shows