freelanceprogrammers.org Forum Index » Perl

Arrays


Goto page 1, 2  Next
View user's profile Post To page top
redstarfcs Posted: Tue Jun 21, 2005 5:39 pm


Joined: 21 Jun 2005

Posts: 3
Arrays
I have this Array:

$perl = [
{
fname => `Fred`,
lname => `Flintstone`,
residence => `Bedrock`
},
{
fname => `Barney`,
lname => `Rubble`,
residence => `Bedrock`
}
];

How to reach Fred?

How to add new rows to this array?!
Reply with quote
Send private message
View user's profile Post To page top
psk_suresh Posted: Wed Jun 22, 2005 3:04 pm


Joined: 21 Feb 2005

Posts: 7
Arrays
Okay ....

you want to print the value "Fred".... go through the code

@yes = @$perl;
foreach $ha1 (@yes) {
%val = %$ha1;
print $val{`fname`};
last;
}


redstarfcs <no_reply@yahoogroups.com> wrote:
I have this Array:

$perl = [
{
fname => `Fred`,
lname => `Flintstone`,
residence => `Bedrock`
},
{
fname => `Barney`,
lname => `Rubble`,
residence => `Bedrock`
}
];

How to reach Fred?

How to add new rows to this array?!






---------------------------------
Yahoo! Groups Links

To visit your group on the web, go to:
http://groups.yahoo.com/group/perl_official/

To unsubscribe from this group, send an email to:
perl_official-unsubscribe@yahoogroups.com

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



---------------------------------
How much free photo storage do you get? Store your holiday snaps for FREE with
Yahoo! Photos. Get Yahoo! Photos

[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
merlynstoneh... Posted: Wed Jun 22, 2005 3:14 pm


Joined: 21 May 2004

Posts: 44
Arrays
>>>>> "redstarfcs" == redstarfcs <no_reply@yahoogroups.com> writes:

redstarfcs> I have this Array:
redstarfcs> $perl = [
redstarfcs> {
redstarfcs> fname => `Fred`,
redstarfcs> lname => `Flintstone`,
redstarfcs> residence => `Bedrock`
redstarfcs> },
redstarfcs> {
redstarfcs> fname => `Barney`,
redstarfcs> lname => `Rubble`,
redstarfcs> residence => `Bedrock`
redstarfcs> }
redstarfcs> ];

redstarfcs> How to reach Fred?

redstarfcs> How to add new rows to this array?!

perldoc perlref
perldoc perlreftut
perldoc perllol
"Learning Perl Objects, References, and Modules" from O`Reilly

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Reply with quote
Send private message
View user's profile Post To page top
hharish_harish Posted: Wed Jun 22, 2005 4:01 pm


Joined: 22 Jun 2005

Posts: 1
Arrays
Hi,

i beleive this is the way to reach `fred`.

print $perl->[0]->{`fname`};




redstarfcs <no_reply@yahoogroups.com> wrote:
I have this Array:

$perl = [
{
fname => `Fred`,
lname => `Flintstone`,
residence => `Bedrock`
},
{
fname => `Barney`,
lname => `Rubble`,
residence => `Bedrock`
}
];

How to reach Fred?

How to add new rows to this array?!






---------------------------------
Yahoo! Groups Links

To visit your group on the web, go to:
http://groups.yahoo.com/group/perl_official/

To unsubscribe from this group, send an email to:
perl_official-unsubscribe@yahoogroups.com

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
georges_toullat Posted: Wed Jun 22, 2005 4:25 pm


Joined: 22 May 2005

Posts: 3
Arrays
Hello,

Try this:

print $$perl[0]{fname};

Regards,

Georges

-------------------------------------------------------------
NetCourrier, votre bureau virtuel sur Internet : Mail, Agenda, Clubs, Toolbar...
Web/Wap : www.netcourrier.com
Téléphone/Fax : 08 92 69 00 21 (0,34 € TTC/min)
Minitel: 3615 NETCOURRIER (0,16 € TTC/min)
Reply with quote
Send private message
View user's profile Post To page top
kprasanna_79 Posted: Wed Jun 22, 2005 5:20 pm


Joined: 21 Apr 2005

Posts: 3
Arrays
Hai,
For getting Fred try this
$perl = [
{
fname => `Fred`,
lname => `Flintstone`,
residence => `Bedrock`
},
{
fname => `Barney`,
lname => `Rubble`,
residence => `Bedrock`
}
];
print $perl->[0]->{fname};

For adding try this..

$perl = [
{
fname => `Fred`,
lname => `Flintstone`,
residence => `Bedrock`
},
{
fname => `Barney`,
lname => `Rubble`,
residence => `Bedrock`
}
];
$perl->[2] = {
fname =>`prasanna`,
lname => `k`,
residence => `panruti`
};
print $perl->[2]->{fname};

Regards
Prasanna.K



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
paulalapatt Posted: Wed Jun 22, 2005 5:32 pm


Joined: 06 Apr 2005

Posts: 12
Arrays
> I have this Array:
>
> $perl = [
> {
> fname => `Fred`,
> lname => `Flintstone`,
> residence => `Bedrock`
> },
> {
> fname => `Barney`,
> lname => `Rubble`,
> residence => `Bedrock`
> }
> ];
>
> How to reach Fred?

You can do that in this way: $perl->[0]->{`fname`};
This is referring the first anonymous hash, and in turn the key `fname`.


> How to add new rows to this array?!

This can be achieved by :

push(@$perl, {fname=>`Paul`,lname=>`Alapatt`,residence=>`Bombay`});

Take care,
Paul Alapatt

http://www.bernardlabs.org/
Reply with quote
Send private message
View user's profile Post To page top
kandepet_pavan Posted: Wed Jun 22, 2005 9:36 pm


Joined: 22 Jun 2005

Posts: 4
Arrays
--- redstarfcs <no_reply@yahoogroups.com> wrote:

> I have this Array:
>
> $perl = [
> {
> fname => `Fred`,
> lname => `Flintstone`,
> residence => `Bedrock`
> },
> {
> fname => `Barney`,
> lname => `Rubble`,
> residence => `Bedrock`
> }
> ];
>
> How to reach Fred?
>
> How to add new rows to this array?!
>
>
>
>
>

Hi,
Here`s how,

$perl = [
{
fname=> `Fred`,
lname=> `Flintstone`,
residence=> `Bedrock`
},
{
fname=> `Barney`,
lname=> `Rubble`,
residence=> `Bedrock`
}
];

print $perl->[0]->{fname},"
";

$perl->[2]->{New} = "Hello World";
$perl->[2]->{Old} = "GoodBye World";

print $perl->[2]->{pavan},"
";

-Pavan



____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
egcalso Posted: Thu Jun 23, 2005 12:13 am


Joined: 01 May 2004

Posts: 7
Arrays
This is how:
$perl->[0]->{fname}

Also, please read about references.
Try:
`perldoc perlref`
or
`perldoc perlreftut`

BTW, that`s an array of hashes.

HTH


redstarfcs wrote:
> I have this Array:
>
> $perl = [
> {
> fname => `Fred`,
> lname => `Flintstone`,
> residence => `Bedrock`
> },
> {
> fname => `Barney`,
> lname => `Rubble`,
> residence => `Bedrock`
> }
> ];
>
> How to reach Fred?
>
> How to add new rows to this array?!
>
>

--
eman
http://www.bloodpet.tk/
gpg --keyserver pgp.mit.edu --recv-keys 4C683E4C
Registered Linux User #287022
+63(2)455-3222
Books just wanna be FREE! See what I mean at:
http://bookcrossing.com/friend/bloodpet


[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
egcalso Posted: Thu Jun 23, 2005 6:36 am


Joined: 01 May 2004

Posts: 7
Arrays
merlyn@... wrote:
>
> perldoc perlref
> perldoc perlreftut
> perldoc perllol
> "Learning Perl Objects, References, and Modules" from O`Reilly
>

I didn`t know there`s a perllol... hehe
Checked it out, and there is. What does lol in perllol stand for?

--
eman
http://www.bloodpet.tk/ || http://www.bloodpet.dsl.ph/
gpg --keyserver pgp.mit.edu --recv-keys 4C683E4C
Registered Linux User #287022
+63(2)455-3222
Books just wanna be FREE! See what I mean at:
http://bookcrossing.com/friend/bloodpet


[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
merlynstoneh... Posted: Thu Jun 23, 2005 3:14 pm


Joined: 21 May 2004

Posts: 44
Arrays
>>>>> "skumar" == skumar <psk_suresh@...> writes:

skumar> %val = %$ha1;

This *copies* the data. That`s inefficient, unnecessary,
and prevents updating the data.

Please read other answers already given, and ignore this answer.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Reply with quote
Send private message
View user's profile Post To page top
merlynstoneh... Posted: Thu Jun 23, 2005 3:15 pm


Joined: 21 May 2004

Posts: 44
Arrays
>>>>> "g" == g toullat <g.toullat@...> writes:

g> Hello,
g> Try this:

g> print $$perl[0]{fname};

The preferred syntax for this is $perl->[0]{fname}.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Reply with quote
Send private message
View user's profile Post To page top
merlynstoneh... Posted: Thu Jun 23, 2005 3:29 pm


Joined: 21 May 2004

Posts: 44
Arrays
>>>>> "Emanuel" == Emanuel Gardaya Calso <bloodpet@...> writes:

Emanuel> I didn`t know there`s a perllol... hehe
Emanuel> Checked it out, and there is. What does lol in perllol stand for?

"lists of lists".

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Reply with quote
Send private message
View user's profile Post To page top
psk_suresh Posted: Mon Jun 27, 2005 10:33 am


Joined: 21 Feb 2005

Posts: 7
Arrays
Randal L. Schwartz,

Don`t think all are perl gurus in this world , but you may be. If a person
approaches for some solution, everyone can give some link for reference (That
you did), but try to provide some solution for that.

I can see many developers (Harish,georges_toullat,k prasanna etc) provided
solutions without giving reference blah blah ...

And please try to understand that this is not a proper place to display your
identity (may be you are a TOP consultant etc...)

Skumar

"Randal L. Schwartz" <merlyn@...> wrote:
>>>>> "skumar" == skumar
writes:

skumar> %val = %$ha1;

This *copies* the data. That`s inefficient, unnecessary,
and prevents updating the data.

Please read other answers already given, and ignore this answer.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


---------------------------------
Yahoo! Messenger NEW - crystal clear PC to PCcalling worldwide with voicemail

[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
merlynstoneh... Posted: Mon Jun 27, 2005 7:00 pm


Joined: 21 May 2004

Posts: 44
Arrays
>>>>> "skumar" == skumar <psk_suresh@...> writes:

skumar> Don`t think all are perl gurus in this world , but you may
skumar> be. If a person approaches for some solution, everyone can
skumar> give some link for reference (That you did), but try to
skumar> provide some solution for that.

But the people that give wrong answers need to be told that, so that
the original seeker knows to ignore it as well. And maybe that means
the person who gave the wrong answer also needs to stop answering
questions for a while because apparently they know less than they
think they know.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Reply with quote
Send private message
Goto page 1, 2  Next
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 2
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help