In article <00bb01c1b645$0b8eef80$[EMAIL PROTECTED]> wrote "Brian Johnson"
<[EMAIL PROTECTED]>:
> I have the following code that I need a little advice on.
It'e easier for us all,
if you short describe your problem.
I assume that the following contains some errors,
you can't find.
>
> The $record->{month} returns the month in integer format (ie 1, 2, 3), I need to
>change it to to a
> three letter string (ie Jan, Feb, Mar)
There are sure some Date:: modules absolving this job.
Unless them a simple array will convert:
my @month_long = (undef, qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
now $month_long[4] contains 'Apr'.
>
> foreach $item (@items) {
> my $record;
Declare your variables, where you need them.
> my $test;
Where do you need $test;
> foreach $record (@{$PDB->{records}}) {
^^
my $record
> # look for date, from, or subject
> # XXX add date/time check
> # Skip everything except the Inbox folder
> next if ($record->{category} ne $cat);
> my $emaildate = "$record->{day} $record->{month} $record->{year}
> $record->{hour}:$record->{minute}";
> if ( $record->{subject} eq $item->{Subject} &&
> $record->{from} eq $item->{From} &&
> $item->{Date} =~ $emaildate) {
^^^^^^^^^^
looks dangerous, didn't you mean $item->{Date} eq /$emaildate/;
> # do something
> if( $record->{is_read} ne $item->{is_read}) {
> $record->{is_read} = $item->{is_read};
> $record->{attributes}{dirty}=1;
> }
> }
> }
> }
I find the code hard to read, because there are so many $record assignments.
I would shorten the code to:
my @month_long = (undef, qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
foreach my $item (@items) {
foreach (grep {$_->{category} eq $cat} @{$PDB->{records}}) {
my $emaildate =
"$_->{day} $month_long[$_->{month}] $_->{year} $_->{hour}:$_->{minute}";
if ($_->{subject} eq $item->{Subject} &&
$_->{from} eq $item->{From} &&
$_->{Date} eq $emaildate) {
# do something
}
}
}
Best Wishes,
Andrea
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]