"A. Sinan Unur" <> wrote in message news:<Xns95B1E9DD6A3D7asu1cornelledu@132.236.56.8> ...
> (Mostafa) wrote in
> news: om:
>
> I don't see
>
> use strict;
> use warnings;
>
> > open(PH,"customers.txt") or die "Cannot open customers.txt: $!\n";
> > while(<PH>) {
> > chomp;
> > ($number, $email) = ( split(/\s+/, $_) )[1,2];
>
> my ($number, $email) = ( split(/\s+/, $_) )[1,2];
>
> >
> > $Phone{$number} = $_;
> > $Email{$email} = $_;
> > }
> > close(PH);
>
> ...
>
> > i couldn't find what does this expression means in split function
> > [1,2]
>
> ..
>
> [1,2] is not an argument to the split function. The syntax is for selecting
> array slices. For example:
>
> my @ary = qw(a b c d);
> print join "\n", @ary[1,2];
>
> Now, in the code above, you are creating hash tables that allow you to look
> up the full record by phone number and email. I am assuming that is what
> you want but do look at the resulting data structures using Data:
umper to
> make sure that is indeed what you want.
>
> use strict;
> use warnings;
>
> my %Phone;
> my %Email;
>
> while(<DATA>) {
> chomp;
> my ($number, $email) = ( split /\s+/, $_ )[1,2];
> $Phone{$number} = $_;
> $Email{$email} = $_;
> }
>
> use Data:
umper;
> print Dumper \%Phone, \%Email;
>
> __DATA__
> Hunter,Apryl (810)-555-3029
> Stewart,Pat (405)-555-8710
> Ching,Iris (305)-555-0919
> __END__
>
> C:\Home> ph
> $VAR1 = {
> '(405)-555-8710' => 'Stewart,Pat (405)-555-8710 ',
> '(305)-555-0919' => 'Ching,Iris (305)-555-0919 ',
> '(810)-555-3029' => 'Hunter,Apryl (810)-555-3029 '
> };
>
> $VAR2 = {
> '' => 'Ching,Iris (305)-555-0919 ',
> '' => 'Hunter,Apryl (810)-555-3029 ',
> '' => 'Stewart,Pat (405)-555-8710
> '
> };
>
>
> > i guess [1,2 ]somehow saves phone and email column to $number and
> > $email , nnow if i want to retrive name from the .txt file , then
> > should i do like below---
>
> I still don't see:
>
> use strict;
> use warnings;
>
> > open(PH,"customers.txt") or die "Cannot open customers.txt: $!\n";
> > while(<PH>) {
> > chomp;
> > ($name, $number, $email) = ( split(/\s+/, $_) )[0,1,2];
>
> my ($name, $number, $email) = ( split(/\s+/, $_) )[0,1,2];
>
> Well, this time you don't really need to explicitly select the elements of
> the returned array.
>
> > $Name{name} = $_;
> > $Phone{$number} = $_;
> > $Email{$email} = $_;
> > }
> > close(PH);
>
> ...
>
> > i did but it's not working
>
> That is not a helpful description of the problem you are experiencing. have
> you read the posting guidelines posted here regularly?
>
> use strict;
> use warnings;
>
> my %Phone;
> my %Email;
> my %Name;
>
> while(<DATA>) {
> chomp;
> my ($name, $number, $email) = split /\s+/, $_;
> $Phone{$number} = $_;
> $Email{$email} = $_;
> $Name{$name} = $_;
> }
>
> use Data:
umper;
> print Dumper \%Phone, \%Email, \%Name;
>
> __DATA__
> Hunter,Apryl (810)-555-3029
> Stewart,Pat (405)-555-8710
> Ching,Iris (305)-555-0919
> __END__
>
>
> C:\Home\asu1> ph
> $VAR1 = {
> '(405)-555-8710' => 'Stewart,Pat (405)-555-8710 ',
> '(305)-555-0919' => 'Ching,Iris (305)-555-0919 ',
> '(810)-555-3029' => 'Hunter,Apryl (810)-555-3029 '
> };
> $VAR2 = {
> '' => 'Ching,Iris (305)-555-0919 ',
> '' => 'Hunter,Apryl (810)-555-3029 ',
> '' => 'Stewart,Pat (405)-555-8710
> '
> };
> $VAR3 = {
> 'Hunter,Apryl' => 'Hunter,Apryl (810)-555-3029 ',
> 'Ching,Iris' => 'Ching,Iris (305)-555-0919 ',
> 'Stewart,Pat' => 'Stewart,Pat (405)-555-8710 '
> };
>
> > any clue?????????
>
> Depending on exactly what you are trying to accomplish, you might benefit
> from using DBI with DBD::CSV.
************************************************** ***********************
thanks a lot it's working;
but i am getting some warnings , how can i get rid of this warnings .
i also add following codes with my program ---
use strict;
my %Name;
my %Phone;
my %Email;
my $name;
my $number;
my $email;
my $address;
i am giving u the list of warnings for the line 17,18,19. i add those
lines right below the warnings.------
C:\mp>perl customer.pl
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 2.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 2.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 2.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 4.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 4.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 4.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 6.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 6.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 6.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 8.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 8.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 8.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 10.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 10.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 10.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 12.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 12.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 12.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 14.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 14.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 14.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 16.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 16.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 16.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 18.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 18.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 18.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 20.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 20.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 20.
Use of uninitialized value in hash element at customer.pl line 17,
<PH> line 22.
Use of uninitialized value in hash element at customer.pl line 18,
<PH> line 22.
Use of uninitialized value in hash element at customer.pl line 19,
<PH> line 22.
************************************************** ****************************
17 $Name{$name} = $_;
18 $Phone{$number} = $_;
19 $Email{$email} = $_;
************************************************** **********************
so how can i initialize this value ---
************************************************** *************************