Re: misunderstanding with the function split



sfantar wrote:
John W. Krahn a écrit :

#!/usr/local/bin/perl
use strict;
use warnings;

my @authors;
my @titles;


for my $file ( @ARGV ) {
$file =~ tr/ /_/;

my ( $author, $title ) = split /-/, $file;

push @authors, $author;
push @titles, $title;
}

__END__

Thank for your explanation.
Can I use a hash array to do what I wanted initially that is to say if I
choose an author then I get his songs ?

For instance : Freda Payne -> first_song.mp3

-> second_song.mp3

The name of the author must be the value and not the key because we
can't have two equal keys. Is that right?

Yes, hash keys are unique so you probably want to use a Hash of Arrays.

perldoc perldsc
perldoc perllol



John
--
use Perl;
program
fulfillment
.



Relevant Pages

  • set like table
    ... What I need to do is mix many phrases into one continuous stream of midi ... (defstruct short-midi ... What I do is use a hash table with each hash table key being the note ... because we use push to populate the value list in the hash table ...
    (comp.lang.lisp)
  • Re: Question on File::Find
    ... Paul Lalli wrote: ... You didn't include the wanted option in your %findoption hash. ... what you think your push statement is doing ... sorry for the mistake, I presume I modified during posting, my mistake, ...
    (comp.lang.perl.misc)
  • Problem printing specific hash array element
    ... and prints the reference to a hash array. ... The next section commented "#Print first element of current hash key" ...
    (perl.beginners)
  • Re: Question on File::Find
    ... Paul Lalli wrote: ... You didn't include the wanted option in your %findoption hash. ... what you think your push statement is doing ... If this is your real code, ...
    (comp.lang.perl.misc)
  • RE: Perl Analyzing Maillog
    ... Is the @surrounding the hash used to make push work with a hash? ... "$msgids->" is an array reference. ...
    (perl.beginners)