Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: difficult error checking

by Sol-Invictus (Scribe)
on Jan 28, 2004 at 21:48 UTC ( #324796=note: print w/replies, xml ) Need Help??

in reply to difficult error checking

use a hash to filter doubles
#! perl -w use strict; my($file); my(%upload,%seen); %upload=(a=> 'dog', b=> 'cat', c=> 'llama', d => 'dog' ); for (keys %upload){ $file=$upload{$_}; if(defined $seen{$file}) { print "<center><font color=red>Duplicate filename found: $ +file</font></center>\n"; exit; } $seen{$file}=$file; print "<font color=blue><center>Uploaded $file</font></center>"; + }
Instead of the exit call you could just make the filename more unique by tagging on a number (much like your OS does when you make try to make a file with a non unique name)

#! perl -w use strict; my(%upload,%seen); my($counter,$file,$old); %upload=(a=> 'dog.gif', b=> 'cat.gif', c=> 'llama.gif', d => 'dog.gif' ); for (keys %upload){ $file=$upload{$_}; if(defined $seen{$file}) { $old=$file; while (defined $seen{$file}){ $file=$old; $counter++; $file=join('.',$file,$counter); } } $seen{$file}=$file; print "<font color=blue><center>Uploaded ",$file,"</font></cente +r>\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://324796]
[choroba]: Corion A colleague has helped me. It seems the "Modification of read-only value" was caused by old Test::More version which doesn't have done_testing, plus the old bug with $@ sometimes showing a different exception
[choroba]: will upload a fixed version and see
[Corion]: choroba: Ah, OK - sounds like a really weird combination :)

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2018-06-25 14:14 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.