Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > [FR/EN] faire un tableau / to make a table

Reply
Thread Tools

[FR/EN] faire un tableau / to make a table

 
 
Alextophi
Guest
Posts: n/a
 
      09-07-2005
FR ----------------------------------------------
Bonjour

Comment faire un tableau avec 1 'clé' avec 2 valeurs.

ex: {clé} = (valueA, valueB)


EN ----------------------------------------------
Hello

How to make a table with 1 'key' with 2 values.

ex : {key} = (valueA, valueB)


regard

ch.

 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      09-07-2005
Alextophi wrote:
> FR ----------------------------------------------
> Bonjour
>
> Comment faire un tableau avec 1 'clé' avec 2 valeurs.
>
> ex: {clé} = (valueA, valueB)
>
>
> EN ----------------------------------------------
> Hello
>
> How to make a table with 1 'key' with 2 values.
>
> ex : {key} = (valueA, valueB)


use warnings;
use strict;
my %table = ();
$table{key} = [ 'valueA', 'valueB' ];
print $table{key}->[0], "\n";
print $table{key}->[1], "\n";

valueA
valueB

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      09-07-2005
George wrote:
> Alextophi wrote:
>
>
>>FR ----------------------------------------------
>>Bonjour
>>
>>Comment faire un tableau avec 1 'clé' avec 2 valeurs.
>>
>>ex: {clé} = (valueA, valueB)
>>
>>
>>EN ----------------------------------------------
>>Hello
>>
>>How to make a table with 1 'key' with 2 values.
>>
>>ex : {key} = (valueA, valueB)
>>
>>
>>regard
>>
>>ch.

>
>
> @{$key}=("value1","value2")


use warnings; use strict;
@{$key}=("value1","value2")

Global symbol "$key" requires explicit package name at - line 2.
Execution of - aborted due to compilation errors.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
George
Guest
Posts: n/a
 
      09-07-2005
Alextophi wrote:

> FR ----------------------------------------------
> Bonjour
>
> Comment faire un tableau avec 1 'clé' avec 2 valeurs.
>
> ex: {clé} = (valueA, valueB)
>
>
> EN ----------------------------------------------
> Hello
>
> How to make a table with 1 'key' with 2 values.
>
> ex : {key} = (valueA, valueB)
>
>
> regard
>
> ch.


@{$key}=("value1","value2")
 
Reply With Quote
 
Alextophi
Guest
Posts: n/a
 
      09-07-2005
tank's....

 
Reply With Quote
 
George
Guest
Posts: n/a
 
      09-07-2005
Josef Moellers wrote:

> George wrote:
> > Alextophi wrote:
> >
> >
> > > FR ----------------------------------------------
> > > Bonjour
> > >
> > > Comment faire un tableau avec 1 'clé' avec 2 valeurs.
> > >
> > > ex: {clé} = (valueA, valueB)
> > >
> > >
> > > EN ----------------------------------------------
> > > Hello
> > >
> > > How to make a table with 1 'key' with 2 values.
> > >
> > > ex : {key} = (valueA, valueB)
> > >
> > >
> > > regard
> > >
> > > ch.

> >
> >
> > @{$key}=("value1","value2")

>
> use warnings; use strict;
> @{$key}=("value1","value2")
>
> Global symbol "$key" requires explicit package name at - line 2.
> Execution of - aborted due to compilation errors.


should I also tell him to install perl,dumb head
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-07-2005
George wrote:
> Alextophi wrote:
>
> > Hello
> >
> > How to make a table with 1 'key' with 2 values.
> >
> > ex : {key} = (valueA, valueB)

>
> @{$key}=("value1","value2")


This creates an array reference named $key with two values. The fact
that the OP is using the terms 'key' and 'values' suggests he's looking
for a hash, not an array, where the keys of the hash can have more than
one value in the hash. Your example simply creates one array
reference, with no association to any other 'keys'.

my %hash;
$hash{'key'} = [qw/value1 value2/];
$hash{'key2'} = [qw/value3 value4/];
#etc ...

Paul Lalli

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      09-07-2005
"George" <(E-Mail Removed)> wrote in newsn0e6ysfg39enkw002
@news.europe.nokia.com:

> Josef Moellers wrote:
>
>> George wrote:
>> > Alextophi wrote:
>> >
>> >
>> > > FR ----------------------------------------------
>> > > Bonjour
>> > >
>> > > Comment faire un tableau avec 1 'clé' avec 2 valeurs.
>> > >
>> > > ex: {clé} = (valueA, valueB)
>> > >
>> > >
>> > > EN ----------------------------------------------
>> > > Hello
>> > >
>> > > How to make a table with 1 'key' with 2 values.
>> > >
>> > > ex : {key} = (valueA, valueB)
>> > >
>> > >
>> > > regard
>> > >
>> > > ch.
>> >
>> >
>> > @{$key}=("value1","value2")

>>
>> use warnings; use strict;
>> @{$key}=("value1","value2")
>>
>> Global symbol "$key" requires explicit package name at - line 2.
>> Execution of - aborted due to compilation errors.

>
> should I also tell him to install perl,dumb head


No, but you should realize you are in no position to hurl insults at
people, let alone give advice.

I presume you meant to use a hash slice above. But even with a hash
slice, you get the following:

#!/usr/bin/perl

use strict;
use warnings;

my %hash;
@hash{key} = ('value1', 'value2');

use Data:umper;
print Dumper \%hash;

__END__

D:\Home\asu1\UseNet\clpmisc> z
Scalar value @hash{key} better written as $hash{key} at D:\Home\asu1
\UseNet\clpmisc\z.pl line 7.
$VAR1 = {
'key' => 'value1'
};

To have a hash element refer to more than one element, you need to set
$hash{key} to an array reference:

$hash{key} = ['value1', 'value2'];

Oh, by the way *PLONK*

Sinan
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
Josef Moellers
Guest
Posts: n/a
 
      09-08-2005
George wrote:
> Josef Moellers wrote:
>
>
>>George wrote:
>>
>>>Alextophi wrote:
>>>
>>>
>>>
>>>>FR ----------------------------------------------
>>>>Bonjour
>>>>
>>>>Comment faire un tableau avec 1 'clé' avec 2 valeurs.
>>>>
>>>>ex: {clé} = (valueA, valueB)
>>>>
>>>>
>>>>EN ----------------------------------------------
>>>>Hello
>>>>
>>>>How to make a table with 1 'key' with 2 values.
>>>>
>>>>ex : {key} = (valueA, valueB)
>>>>
>>>>
>>>>regard
>>>>
>>>>ch.
>>>
>>>
>>>@{$key}=("value1","value2")

>>
>>use warnings; use strict;
>>@{$key}=("value1","value2")
>>
>>Global symbol "$key" requires explicit package name at - line 2.
>>Execution of - aborted due to compilation errors.

>
>
> should I also tell him to install perl,dumb head


I always put my name on a separate line, but then ...

Your solution does not pass the "use strict", which is sort of a
prerequisite for proper solutions.

Stay cool,

Josef

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
George
Guest
Posts: n/a
 
      09-08-2005
Josef Moellers wrote:

> George wrote:
> > Josef Moellers wrote:
> >
> >
> > > George wrote:
> > >
> > > > Alextophi wrote:
> > > >
> > > >
> > > >
> > > > > FR ----------------------------------------------
> > > > > Bonjour
> > > > >
> > > > > Comment faire un tableau avec 1 'clé' avec 2 valeurs.
> > > > >
> > > > > ex: {clé} = (valueA, valueB)
> > > > >
> > > > >
> > > > > EN ----------------------------------------------
> > > > > Hello
> > > > >
> > > > > How to make a table with 1 'key' with 2 values.
> > > > >
> > > > > ex : {key} = (valueA, valueB)
> > > > >
> > > > >
> > > > > regard
> > > > >
> > > > > ch.
> > > >
> > > >
> > > > @{$key}=("value1","value2")
> > >
> > > use warnings; use strict;
> > > @{$key}=("value1","value2")
> > >
> > > Global symbol "$key" requires explicit package name at - line 2.
> > > Execution of - aborted due to compilation errors.

> >
> >
> > should I also tell him to install perl,dumb head

>
> I always put my name on a separate line, but then ...
>
> Your solution does not pass the "use strict", which is sort of a
> prerequisite for proper solutions.
>
> Stay cool,
>
> Josef


I never wanted to give the complete code, and why should I , I answered
what I though OP asked, Paul Lalli pointed that out that mistake,
people many sometime just point towards documentation should OP cut and
paste those lines in perl code and compile them as it is?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vigenere tableau, HOW to generate this algorithm in two dimensional array spidey12345 Java 6 02-08-2007 12:23 PM
insertion du contenu d'un tableau dans une table eXistenZ| ASP General 1 01-24-2005 07:08 AM
Tableau associatif Guy Roydor Javascript 1 02-13-2004 01:02 PM
comment faire une détection de niveau haut ou "1" en vhdl ? Arnaud VHDL 2 02-11-2004 06:34 PM
Calcule l element maximum d'un tableau Vianney =?iso-8859-1?Q?Lan=E7on?= C++ 1 08-29-2003 12:36 AM



Advertisments