How to add to Associative Array
How to add to Associative Array
am 10.07.2007 09:37:37 von Reddy.Beri-Veera-ext
This is a multi-part message in MIME format.
--===============0877690443==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C7C2C5.308F9379"
This is a multi-part message in MIME format.
------_=_NextPart_001_01C7C2C5.308F9379
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello,
I want to add to Associative Array dynamically (means=3D> I don't =
exact size of Associative Array).
=20
Ex: In test.txt I have the fallowing data.
red,danger
blue,going smooth
yellow, pending
Green, accept.
....etc
=20
I have to add these values to Associative Array
like
%info=3D (red =3D>danger=20
blue =3D>going smooth
yellow =3D> pending
Green=3D>accept.
...etc)
=20
For these I have read the test.txt line by line and add to %info. Please =
guide me how to do this....
=20
Thanks && Regards=20
Karunakar Reddy B.V.=20
BSH Bosch Siemens Hausgeräte GmbH
------_=_NextPart_001_01C7C2C5.308F9379
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
charset=3Diso-8859-1">
class=3D136012807-10072007>Hello,
class=3D136012807-10072007> I want=20
to add to Associative Array dynamically (means=3D> I don't exact size =
of=20
Associative Array).
class=3D136012807-10072007>
Ex: In =
test.txt I=20
have the fallowing data.
class=3D136012807-10072007> =20
red,danger
class=3D136012807-10072007> =
blue,going=20
smooth
class=3D136012807-10072007> =
yellow,=20
pending
class=3D136012807-10072007> =
Green,=20
accept.
class=3D136012807-10072007> &nbs=
p;=20
.....etc
class=3D136012807-10072007>
I have =
to add these=20
values to Associative Array
class=3D136012807-10072007>like
=20
%info=3D (red =3D>danger
class=3D136012807-10072007> =
blue=20
=3D>going smooth
class=3D136012807-10072007> =
yellow=20
=3D> pending
class=3D136012807-10072007> =20
Green=3D>accept.
class=3D136012807-10072007> =20
....etc)
class=3D136012807-10072007>
=
For =
these I have=20
read the test.txt line by line and add to %info. Please guide me how to =
do=20
this....
class=3D136012807-10072007>
lang=3Den-us>
face=3D"Monotype Corsiva" color=3D#0000ff>
style=3D"BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: =
medium none; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm =
0pt; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: =
windowtext; mso-element: para-border-div; mso-border-bottom-alt: solid =
windowtext .75pt; mso-padding-alt: 0cm 0cm 1.0pt 0cm"=20
align=3Dleft>
style=3D"COLOR: blue">Thanks && =
Regards=20
Karunakar Reddy B.V.
"urn:schemas-microsoft-com:office:office" =
/>
style=3D"MARGIN: 0cm 0cm 0pt; mso-pagination: none; =
mso-layout-grid-align: none">
lang=3DDE style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Arial; =
mso-ansi-language: DE">
color=3D#000000>BSH Bosch Siemens Hausgeräte=20
GmbH
------_=_NextPart_001_01C7C2C5.308F9379--
--===============0877690443==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0877690443==--
Re: How to add to Associative Array
am 10.07.2007 09:47:40 von Bill Luebkert
Beri-Veera-ext, Reddy (n.a.) wrote:
> Hello,
> I want to add to Associative Array dynamically (means=> I don't exact
> size of Associative Array).
>
> Ex: In test.txt I have the fallowing data.
> red,danger
> blue,going smooth
> yellow, pending
> Green, accept.
> ....etc
>
> I have to add these values to Associative Array
> like
> %info= (red =>danger
> blue =>going smooth
> yellow => pending
> Green=>accept.
> ...etc)
>
> For these I have read the test.txt line by line and add to %info. Please
> guide me how to do this....
use strict;
use warnings;
my @lines = ( # phoney test data simulating file data
"red,danger\n",
"blue,going smooth\n",
"yellow, pending\n",
"Green, accept\n",
);
my %info = ();
foreach (@lines) { # would normally be: while () { # reading from file
chomp;
my @a = split /\s*,\s*/;
$info{$a[0]} = $a[1];
}
print "$_ => $info{$_}\n" foreach keys %info;
__END__
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: [RMX:#] Re: How to add to Associative Array
am 10.07.2007 09:52:37 von Reddy.Beri-Veera-ext
Hi,
Thanks for your quick info. How I will get
my @lines = ( # phoney test data simulating file data
"red,danger\n",
"blue,going smooth\n",
"yellow, pending\n",
"Green, accept\n",
);
How I will convert test.txt to @line.
Please explain this.
Thanks && Regards
Karunakar Reddy B.V.
-----Original Message-----
From: Bill Luebkert [mailto:dbecoll@roadrunner.com]
Sent: 10 July 2007 09:48
To: Beri-Veera-ext, Reddy (n.a.)
Cc: ActivePerl
Subject: [RMX:#] Re: How to add to Associative Array
Beri-Veera-ext, Reddy (n.a.) wrote:
> Hello,
> I want to add to Associative Array dynamically (means=> I don't
exact
> size of Associative Array).
>
> Ex: In test.txt I have the fallowing data.
> red,danger
> blue,going smooth
> yellow, pending
> Green, accept.
> ....etc
>
> I have to add these values to Associative Array
> like
> %info= (red =>danger
> blue =>going smooth
> yellow => pending
> Green=>accept.
> ...etc)
>
> For these I have read the test.txt line by line and add to %info.
Please
> guide me how to do this....
use strict;
use warnings;
my @lines = ( # phoney test data simulating file data
"red,danger\n",
"blue,going smooth\n",
"yellow, pending\n",
"Green, accept\n",
);
my %info = ();
foreach (@lines) { # would normally be: while () { # reading
from file
chomp;
my @a = split /\s*,\s*/;
$info{$a[0]} = $a[1];
}
print "$_ => $info{$_}\n" foreach keys %info;
__END__
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: How to add to Associative Array
am 10.07.2007 10:06:26 von Ingo Schwarze
Beri-Veera-ext, Reddy (n.a.) wrote on Tue, Jul 10, 2007 at 09:37:37AM +0200:
> I want to add to Associative Array dynamically
> (means=> I don't exact size of Associative Array).
That's what these beasts are meant for in the first place. RTFM.
> Ex: In test.txt I have the fallowing data.
> red,danger
> blue,going smooth
> yellow, pending
> Green, accept.
> ....etc
>
> I have to add these values to Associative Array
> like
> %info= (red =>danger
> blue =>going smooth
> yellow => pending
> Green=>accept.
> ...etc)
>
> For these I have read the test.txt line by line and add to %info.
> Please guide me how to do this....
ischwarze@ischwarze:~$ perl -e 'while (<>) {/(.+),(.*)/ and $info{$1}=$2}; use Data::Dumper; print %info."\n".Dumper(\%info);'
red,danger
blue,going smooth
yellow, pending
green,accept
4/8
$VAR1 = {
'green' => 'accept',
'blue' => 'going smooth',
'red' => 'danger',
'yellow' => ' pending'
};
> Karunakar Reddy B.V.
> BSH Bosch Siemens Hausgeraete GmbH
Are you trolling?
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: [RMX:#] Re: How to add to Associative Array
am 10.07.2007 10:10:21 von n.haigh
If you want to read the lines in from a file, you need to open a filehandle:
open(IN, $path_to_my_file) or die "Couldn't open file: $!\n";
then use the IN filehandle in the while loop, such as::
foreach () {
# stuff to do with each line
# ...
}
The close the filehandle with:
close IN;
Hope this helps
Nath
Quoting "Beri-Veera-ext, Reddy (n.a.)" :
> Hi,
> Thanks for your quick info. How I will get
> my @lines = ( # phoney test data simulating file data
> "red,danger\n",
> "blue,going smooth\n",
> "yellow, pending\n",
> "Green, accept\n",
> );
> How I will convert test.txt to @line.
> Please explain this.
>
>
> Thanks && Regards
> Karunakar Reddy B.V.
>
>
> -----Original Message-----
> From: Bill Luebkert [mailto:dbecoll@roadrunner.com]
> Sent: 10 July 2007 09:48
> To: Beri-Veera-ext, Reddy (n.a.)
> Cc: ActivePerl
> Subject: [RMX:#] Re: How to add to Associative Array
>
> Beri-Veera-ext, Reddy (n.a.) wrote:
> > Hello,
> > I want to add to Associative Array dynamically (means=> I don't
> exact
> > size of Associative Array).
> >
> > Ex: In test.txt I have the fallowing data.
> > red,danger
> > blue,going smooth
> > yellow, pending
> > Green, accept.
> > ....etc
> >
> > I have to add these values to Associative Array
> > like
> > %info= (red =>danger
> > blue =>going smooth
> > yellow => pending
> > Green=>accept.
> > ...etc)
> >
> > For these I have read the test.txt line by line and add to %info.
> Please
> > guide me how to do this....
>
> use strict;
> use warnings;
>
> my @lines = ( # phoney test data simulating file data
> "red,danger\n",
> "blue,going smooth\n",
> "yellow, pending\n",
> "Green, accept\n",
> );
>
> my %info = ();
> foreach (@lines) { # would normally be: while () { # reading
> from file
> chomp;
> my @a = split /\s*,\s*/;
> $info{$a[0]} = $a[1];
> }
> print "$_ => $info{$_}\n" foreach keys %info;
>
> __END__
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: [RMX:#] Re: How to add to Associative Array
am 10.07.2007 10:54:16 von Reddy.Beri-Veera-ext
This is a multi-part message in MIME format.
------_=_NextPart_001_01C7C2CF.E5B36123
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi all,
I wrote a sample program with your guide lines but the associative
array has double entries. Please the attachment for my program and
test.txt file. Please tell me what I did the wrong.=20
Thanks && Regards=20
Karunakar Reddy B.V.=20
-----Original Message-----
From: Nathan S. Haigh [mailto:N.Haigh@sheffield.ac.uk]=20
Sent: 10 July 2007 10:10
To: Beri-Veera-ext, Reddy (n.a.)
Cc: Bill Luebkert; ActivePerl
Subject: RE: [RMX:#] Re: How to add to Associative Array
If you want to read the lines in from a file, you need to open a
filehandle:
open(IN, $path_to_my_file) or die "Couldn't open file: $!\n";
then use the IN filehandle in the while loop, such as::
foreach () {
# stuff to do with each line
# ...
}
The close the filehandle with:
close IN;
Hope this helps
Nath
Quoting "Beri-Veera-ext, Reddy (n.a.)" :
> Hi,
> Thanks for your quick info. How I will get =20
> my @lines =3D ( # phoney test data simulating file data
> "red,danger\n",
> "blue,going smooth\n",
> "yellow, pending\n",
> "Green, accept\n",
> );
> How I will convert test.txt to @line.=20
> Please explain this.
>=20
>=20
> Thanks && Regards=20
> Karunakar Reddy B.V.=20
>=20
>=20
> -----Original Message-----
> From: Bill Luebkert [mailto:dbecoll@roadrunner.com]=20
> Sent: 10 July 2007 09:48
> To: Beri-Veera-ext, Reddy (n.a.)
> Cc: ActivePerl
> Subject: [RMX:#] Re: How to add to Associative Array
>=20
> Beri-Veera-ext, Reddy (n.a.) wrote:
> > Hello,
> > I want to add to Associative Array dynamically (means=3D> I don't
> exact=20
> > size of Associative Array).
> > =20
> > Ex: In test.txt I have the fallowing data.
> > red,danger
> > blue,going smooth
> > yellow, pending
> > Green, accept.
> > ....etc
> > =20
> > I have to add these values to Associative Array
> > like
> > %info=3D (red =3D>danger
> > blue =3D>going smooth
> > yellow =3D> pending
> > Green=3D>accept.
> > ...etc)
> > =20
> > For these I have read the test.txt line by line and add to %info.
> Please=20
> > guide me how to do this....
>=20
> use strict;
> use warnings;
>=20
> my @lines =3D ( # phoney test data simulating file data
> "red,danger\n",
> "blue,going smooth\n",
> "yellow, pending\n",
> "Green, accept\n",
> );
>=20
> my %info =3D ();
> foreach (@lines) { # would normally be: while () { # reading
> from file
> chomp;
> my @a =3D split /\s*,\s*/;
> $info{$a[0]} =3D $a[1];
> }
> print "$_ =3D> $info{$_}\n" foreach keys %info;
>=20
> __END__
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>=20
------_=_NextPart_001_01C7C2CF.E5B36123
Content-Type: text/plain;
name="test.txt"
Content-Transfer-Encoding: base64
Content-Description: test.txt
Content-Disposition: attachment;
filename="test.txt"
Iw0KIyBCU0ggRXhwb3J0IFNlcnZlciBKb2IgRmlsZQ0KIyBjcmVhdGVkIHdp dGggc3R5bGVzaGVl
dCB2ZXJzaW9uIDEuMC4yDQojDQpCU0ggRXhwb3J0I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B36123
Content-Type: application/octet-stream;
name="cr_ass_array.pl"
Content-Transfer-Encoding: base64
Content-Description: cr_ass_array.pl
Content-Disposition: attachment;
filename="cr_ass_array.pl"
IyEvdXNyL2Jpbi9wZXJsDQokUEFUSF9ERUxJTQkJCT0gIlxcIjsNCiRmaWxl ID0gImM6XFx0ZW1w
Ii4kUEFUSF9ERUxJTS4iZXhwb3J0Ii4kUEFUSF9ERUxJTS4iQ09OVkVSU0lP TiIuJFBBVEhfREVM
SU0uInRlc3QudHh0IjsNCiVpbmZvID0oKTsNCmlmKG9wZW4gKFRFU1QgLCI8 JGZpbGUiKSkNCnsN
CiAgd2hpbGUoPFRFU1Q+KQ0KICB7DQogIGNob21wOw0KICBpZiAoICRfICF+ IC9QTE1FSm9iIE1h
c3Rlci8gKQ0KICAgICAgICB7DQogICAgICAgICAgICAgICAgbmV4dCA7DQog ICAgICAgIH0gDQog
ICAgICAgICRfID0gPFRFU1Q+IDsNCiAgICAgICAgY2hvbXA7DQogICAgICAg ICB3aGlsZSAoICRf
ICF+IC9eJC8pDQogICAgICAgIHsNCiAgICAgICAgICAgcHJpbnQgIiRfXG4i Ow0KICAgICAgICAg
ICBteSBAYSA9IHNwbGl0IC89LzsNCgkgICAgICAgICAkaW5mb3skYVswXX0g PSAkYVsxXTsgIA0K
CSAgICAgICAgICRfID0gPFRFU1Q+Ow0KCSAgICAgICAgIGNob21wOw0KICAg ICAgICB9IA0KICAg
ICAgICBjbG9zZShURVNUKTsgICANCiAgfQ0KfQ0KI2Nsb3NlKFRFU1QpOw0K Zm9yZWFjaCglaW5m
bykNCnsNCiAgcHJpbnQgIiRfID0+ICRpbmZveyRffVxuIg0KfQ0KI3ByaW50 ICIkXyA9PiAkaW5m
b3skX31cbiIgZm9yZWFjaCBrZXlzICVpbmZvOw0K
------_=_NextPart_001_01C7C2CF.E5B36123
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
------_=_NextPart_001_01C7C2CF.E5B36123--
Re: [RMX:#] Re: How to add to Associative Array
am 10.07.2007 11:20:10 von Bill Luebkert
Beri-Veera-ext, Reddy (n.a.) wrote:
> Hi all,
> I wrote a sample program with your guide lines but the associative
> array has double entries. Please the attachment for my program and
> test.txt file. Please tell me what I did the wrong.
If you post a script without the use strict and use warnings, I'll
pass on replying:
#!/usr/bin/perl
use strict;
use warnings;
my $file = 'C:/temp/export/CONVERSION/test.txt';
$file = 'data/test.txt'; # modified for me
my %info = ();
open TEST, $file or die "open $file: $! ($^E)";
my $found = 0;
while () {
chomp;
if (/PLMEJob Master/) {
$found = 1;
next;
}
if ($found) {
last if /^\s*$/;
my @a = split /=/;
$info{$a[0]} = $a[1] || ''; # or use something like 'No value'
}
}
close TEST;
print "$_ => $info{$_}\n" foreach keys %info;
__END__
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs