Chris Zimmerman wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Or maybe let me know if there was a bug in perl 5.6.0?
>
> Here's the situation:
>
> I have a program that scans a specially formatted config file and sends files
> to customers by e-mail.  Within that file is a field that has
> [EMAIL PROTECTED]:filename,[EMAIL PROTECTED]:filename ...
> Each file is sent to the address "attached" to it by a colon and the
> combinations are delimited by a comma.
>
>
> I have 2 subroutines that run back to back.  The first splits the combinations
> at the commas and puts them ultimately into a hash.  The second checks for
> the existance of the file, and if it does not exist then it removes if from
> the hash.  My problem is that 2 key-value pairs are getting dropped from the
> hash somehow when going from one subroutine to the other.  When I moved the
> offending combo's to the end of the field in the config file, everything
> worked.  There were no syntax problems in the field in the config file, and a
> bunch of print statements in the loops in the first subroutine showed all
> key-value pairs, but in the second there are 2 missing.  I hope I have been
> clear enough to explain the problem.  Let me know if there is something more
> you would like to see...

Hi Chris.

I don't see anything wrong with your code. We really need to see
the config file and the calling code as well, but I suspect you
probably have had a problem with embedded spacesin the config
file which you corrected when you moved the fields to the end.

You may like to consider doing the wole thing this way:

  my $tmpfile = '[EMAIL PROTECTED]:filename,[EMAIL PROTECTED]:filename ...';
  my %mail_files;

  while ( $tmpfile =~ /([^,\s]+):([^,\s]+)/g ) {
      my ($m, $f) = ($1, $2);
      printf "%s - %s\n", $m, $f;    # For demonstration only
      $mail_files{$m}=$f if -f $f;
  }

OUTPUT

  [EMAIL PROTECTED] - filename
  [EMAIL PROTECTED] - filename

which will ignore whitespace around the commas.

Oh, and by the way

  use strict; # always

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to