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

Discussion in 'Perl Misc' started by Alextophi, Sep 7, 2005.

  1. Alextophi

    Alextophi Guest

    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.
     
    Alextophi, Sep 7, 2005
    #1
    1. Advertising

  2. 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
     
    Josef Moellers, Sep 7, 2005
    #2
    1. Advertising

  3. 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
     
    Josef Moellers, Sep 7, 2005
    #3
  4. Alextophi

    George Guest

    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")
     
    George, Sep 7, 2005
    #4
  5. Alextophi

    Alextophi Guest

    Re: faire un tableau / to make a table

    tank's....:)
     
    Alextophi, Sep 7, 2005
    #5
  6. Alextophi

    George Guest

    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
     
    George, Sep 7, 2005
    #6
  7. Alextophi

    Paul Lalli Guest

    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
     
    Paul Lalli, Sep 7, 2005
    #7
  8. "George" <> wrote in news:xn0e6ysfg39enkw002
    @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::Dumper;
    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 <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Sep 7, 2005
    #8
  9. 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
     
    Josef Moellers, Sep 8, 2005
    #9
  10. Alextophi

    George Guest

    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?
     
    George, Sep 8, 2005
    #10
  11. Alextophi

    George Guest

    A. Sinan Unur wrote:

    > "George" <> wrote in news:xn0e6ysfg39enkw002
    > @news.europe.nokia.com:
    >
    > > Josef Moellers wrote:
    > >
    > >> George wrote:
    > >> > Alextophi wrote:
    > >> >
    > >> >
    > >> > > FR ----------------------------------------------
    > >> > > Bonjour
    > >> > >
    > >> > > Comment faire un tableau avec 1 'cli' avec 2 valeurs.
    > >> > >
    > >> > > ex: {cli} = (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::Dumper;
    > 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


    what are you trying to say by these lines
    > Oh, by the way PLONK
     
    George, Sep 8, 2005
    #11
  12. Alextophi

    John Bokma Guest

    "George" <> wrote:

    > what are you trying to say by these lines


    >> Oh, by the way PLONK


    That he has configured his news reader to hide all messages written by you
    in this group ( and maybe others as well) from now on. (Hence I answer,
    because he isn't going to ;-) )

    I am sure there was a good reason, which might mean others have done the
    same. It also might mean that next time you post a question here you get
    not as much replies as expected.

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
     
    John Bokma, Sep 8, 2005
    #12
  13. George wrote:
    > 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


    You don't have to post "complete code", at least, I didn't.
    However, you posted a bad example as it manipulates the symbol table.
    The reference to @{...} is considered bad code and "use strict" is there
    to catch these. Uncounted replies have pointed out that using a hash is
    The Right Thing to do.

    > , 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?


    Sorry, but I can't quite parse this.

    If a question is answered by one of the articles in the FAQ or
    documentation, then pointing people at the FAQ list is OK. IMHO, if
    answering the question requires less keystrokes than pointing at the
    FAQ, then I do prefer that.
    When I post a code snipped, I try to adhere to posting rules in that the
    code posted should pass
    use warnings;
    use strict;
    and, if possible, it should have been tested (putting them within
    <untested>, </untested> might be OK in some circumstances).
    If I correct someone's code snippets, then, yes, the OP should be able
    to cut-and-paste the correction. In this case, as the question was about
    a technique, rather than a non-working code (Alextophi didn't post any
    code that is proper Perl), no cut-and-paste solution could be given.

    But I stand by my statement that the code line you provided does not
    pass "use strict" and, as such, does not adhere to posting rules here.

    Your attitude ("dumb head", "why should I") strikes me as being
    impolite, but that is my very personal feeling and others might regard
    you as being nice and considerate (as it appears, some do not).

    This now has little to do with Perl any more, so I think we should close
    this debate here.

    Josef
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Sep 8, 2005
    #13
  14. Alextophi

    George Guest

    Josef Moellers wrote:

    > George wrote:
    > > 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

    >
    > You don't have to post "complete code", at least, I didn't.
    > However, you posted a bad example as it manipulates the symbol table.
    > The reference to @{...} is considered bad code and "use strict" is
    > there to catch these. Uncounted replies have pointed out that using a
    > hash is The Right Thing to do.
    >
    > > , 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?

    >
    > Sorry, but I can't quite parse this.
    >
    > If a question is answered by one of the articles in the FAQ or
    > documentation, then pointing people at the FAQ list is OK. IMHO, if
    > answering the question requires less keystrokes than pointing at the
    > FAQ, then I do prefer that.
    > When I post a code snipped, I try to adhere to posting rules in that
    > the code posted should pass
    > use warnings;
    > use strict;
    > and, if possible, it should have been tested (putting them within
    > <untested>, </untested> might be OK in some circumstances).
    > If I correct someone's code snippets, then, yes, the OP should be
    > able to cut-and-paste the correction. In this case, as the question
    > was about a technique, rather than a non-working code (Alextophi
    > didn't post any code that is proper Perl), no cut-and-paste solution
    > could be given.
    >
    > But I stand by my statement that the code line you provided does not
    > pass "use strict" and, as such, does not adhere to posting rules here.
    >
    > Your attitude ("dumb head", "why should I") strikes me as being
    > impolite, but that is my very personal feeling and others might
    > regard you as being nice and considerate (as it appears, some do not).
    >
    > This now has little to do with Perl any more, so I think we should
    > close this debate here.
    >
    > Josef


    I got the point, and so no hard feeling
     
    George, Sep 8, 2005
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnaud
    Replies:
    2
    Views:
    3,521
    Amontec Team, Laurent Gauch
    Feb 11, 2004
  2. Vianney =?iso-8859-1?Q?Lan=E7on?=

    Calcule l element maximum d'un tableau

    Vianney =?iso-8859-1?Q?Lan=E7on?=, Aug 28, 2003, in forum: C++
    Replies:
    1
    Views:
    404
    Artie Gold
    Aug 29, 2003
  3. spidey12345
    Replies:
    6
    Views:
    936
    Thomas Fritsch
    Feb 8, 2007
  4. eXistenZ|
    Replies:
    1
    Views:
    167
    eXistenZ|
    Jan 24, 2005
  5. kungfu-free

    faire équivalent en python

    kungfu-free, Dec 13, 2008, in forum: Ruby
    Replies:
    0
    Views:
    106
    kungfu-free
    Dec 13, 2008
Loading...

Share This Page