From: KEVIN ZEMBOWER <[EMAIL PROTECTED]>
> I'm trying to clean up some data and load it into a database.
> 
> One transformation I have to do is strip quotation marks from a lot of
> fields, so I did this:
>    foreach my $varref (\$budgetdesc, \$thru_date, \$from_date,
>    \$active, \$on_off_campus, \$old_budget, \$bregion, \$funding,
>    \$finanalyst, \$progoffice, \$daterecord, \$datelastmo,
>    \$timelastm9, \$lastmodified, \$timerectm9, \$createdby,
>    \$typefunding, \$country, \$notes) {
>       $$varref =~ s/"//g;                       # Strip the quotes
>       from strings
>    }

You don't need those references there. foreach() aliases the loop 
variable to the elements so any change to the loop variables affects 
the elements of the list/variables:

  foreach my $var ($budgetdesc, $thru_date, $from_date, $active,
    $on_off_campus, $old_budget, $bregion, $funding, $finanalyst,
    $progoffice, $daterecord, $datelastmo, $timelastm9, 
$lastmodified,
    $timerectm9, $createdby, $typefunding, $country, $notes) {
      $var =~ s/"//g;    # Strip the quotes from strings
  }

And in this case it would be better (more Perlish) to make use of the 
default variable $_ and postfix foreach. Also tr/// is more efficient 
than s///:

  tr/"//d foreach ($budgetdesc, $thru_date, $from_date, $active,
    $on_off_campus, $old_budget, $bregion, $funding, $finanalyst,
    $progoffice, $daterecord, $datelastmo, $timelastm9, 
$lastmodified,
    $timerectm9, $createdby, $typefunding, $country, $notes);

> This seems to work well. I also need to rearrange the DATE data, so I
> tried to do this:
>    foreach my $dateref (\$thru_date, \$from_date, \$daterecord,
>    \$datelastmo) {
>       my ($MM, $DD, $YY, $hh, $mm, $ss); 
>       (($MM, $DD, $YY, $hh, $mm, $ss) = $$dateref) =~ m[(..)/(..)/(..)
>       (..):(..):(..)]; $$dateref = "$YY-$MM-$DD";
>    } #for each of the date-type fields

You have the braces wrong. It should be:

($MM, $DD, $YY, $hh, $mm, $ss) 
  = ($$dateref =~ m[(..)/(..)/(..)(..):(..):(..)]);

You want to apply the regexp to the $$dateref variable and then 
assign the resulting list to those variables.

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


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

Reply via email to