Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Adding and Deleting Upload File name and File

by larryk (Friar)
on Dec 03, 2001 at 14:34 UTC ( [id://129061]=note: print w/replies, xml ) Need Help??


in reply to Adding and Deleting Upload File name and File

instead of:
my %test = qw( @song_titles, @song_files );
Update: this is a typo (credit to blakem) - the qw will not concatenate the lists but treat the two array names as strings. instead try:
my @test{@song_titles} = @song_files;
have a look in perldoc perldata and look at the section on slices
   larryk                                          
perl -le "s,,reverse killer,e,y,rifle,lycra,,print"

Replies are listed 'Best First'.
Re: Re: Adding and Deleting Upload File name and File
by blakem (Monsignor) on Dec 03, 2001 at 16:28 UTC
    Your solution is correct, but the analysis of the original code isn't quite right...
    my %test = qw( @song_titles, @song_files );
    Will actually do something more like:
    my %test = ('@song_titles', '@song_files');
    So, you'll get a hash with a single key.

    It will also toss an error if warnings are on....

    -Blake

      <cheek tongue="1">Your reply is correct, but your example isn't quite right</cheek>

      I missed the qw which would indeed mean that the other '@lists' would be treated as strings but your example will yield a valid hash (no warning) since you have an even number of elements in the list:

      my %test = ( '@song_titles' => '@song_files' );
         larryk                                          
      perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
      Will code for food - looking for work - London - CV
      
        Just to clarify (and yes, I know we're way off in left field here....) the warning I was speaking of is thrown by the qw() code whenever it gets passed a comma (or #). From perlop:
        qw/STRING/
        ...
        A common mistake is to try to separate the words with comma or to put comments into a multi-line "qw"-string. For this reason, the "use warnings" pragma and the -w switch (that is, the "$^W" variable) produces warnings if the STRING contains the "," or the "#" character.
        % perl -we 'qw(@song_titles, @song_files)' Possible attempt to separate words with commas at -e line 1. [snip void context errors]
        On a side note, I should have realized that you just misread the qw. A quick /msg would have probably been a better response than the node I posted.... ;-)

        -Blake

        thanks for the info. This is what I've got to work so far.
        # brings in arrays song_title and song_files &song_list; &file_list; #works by single elements my %test = ($song_titles[0], $song_files[0], $song_titles[1], $song_files[1]); foreach my $key (keys %test) { print qq[<br> Delete this File: $key <INPUT TYPE="checkbox" NAME=" +files" VALUE="$test{$key}">\n]; }
        Whatever is selected is then passed on to another subroutine that takes the value of "file" and deletes the file
        # check for tainted data my $files = $q->param( "files") || error( $q, "couldn't read File valu +e"); $files =~ /^([\/.\w.]+)$/; # The "untainted" file is now in $1 $files = $1; die "Bad filename" unless $files; foreach ($files){ unlink($_); }
        However I still can't figure out how I would delete the song title that goes with the song file. How could I also pass the value of the key (song_title) along with the song file? also I tried doing
        my %test = (@song_titles, @song_files);
        however, it printed out the first key right (song_title) but the next key contained the song file as the key and so on ... thanks in advance...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://129061]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-23 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found