Loading ...
Sorry, an error occurred while loading the content.

Pass array to subroutine, scope, Net::POP3

Expand Messages
  • Alan
    Hi, Why, when the near the bottom below sub routine is added in, brings a global (scope, evidently) error as it reports that the @messg is used only once?
    Message 1 of 4 , Jul 4, 2004
    • 0 Attachment
      Hi,

      Why, when the near the bottom below sub routine is added in, brings a
      global (scope, evidently) error as it reports that the @messg is used
      only once? Also, the sub routine does not print any data, why not?

      I want to end up with a numerically sorted (get that hashref of msgnum
      => size into a sorted order, sorted by msgnum).

      But, so far, I went into array because it maybe easier to sort an array
      (at least for me, the Noob). And, I WILL use apop instead of login when
      I learn some more.

      Want to delete all mail that is a week old or older is the end purpose.

      The next works:

      #!/usr/bin/perl -w
      use strict;
      use Net::POP3;

      my $pop = Net::POP3->new('mail.cwnet.com');
      $pop = Net::POP3->new('mail.cwnet.com', Timeout => 60);

      my $username = "username";
      my $password = "password";
      if ($pop->login($username, $password) > 0) {
      my $msgnums = $pop->list; # hashref of msgnum => size
      foreach my $msgnum (keys %$msgnums) {
      # my $msg = $pop->get($msgnum);
      my $msg = $pop->top($msgnum, 1);

      my $id_num = "Msgnum: $msgnum\n";
      my @messg = @$msg;
      unshift( @messg, $id_num );

      print "~~\t~~";
      print @messg;
      }
      }
      $pop->quit;
      --------------------------------------------

      But that prints the entire header. Instead, from a header, I want to
      print which message number it is, followed by the Date: line

      Here's an example of the desired print, for message number 2:

      2, Wed, 30 Jun 2004 00:56:20 -0000
      --------------------
      So, as next, I added in a sub routine and called the sub:
      ----------

      PrintList(@messg);
      }

      $pop->quit;
      # --- above script ends at this point here -------

      sub PrintList
      {
      # Assign parameter to a local variable
      my (@lines) = @_;

      # Declare local variables
      my ($date, $line, $id_digit);

      # Check each line in the header
      foreach $line (@lines)
      {
      if($line =~ m/^Msgnum: (.*)/)
      {
      # get what we need
      $id_digit = $1;
      # $id_digit = substr($from, 0, 39);
      }
      elsif( $line =~ m/^Date: (.*)/)
      {
      # get what we need
      $date = $1;
      $date = substr($date, 0, 29);
      }

      last if( defined($date) && defined($id_digit) );
      }
      printf "IdNum: %-40s Date: %s\n", $id_digit, $date;
      }
      ----------------------------------------------------------

      --
      Alan.
    Your message has been successfully submitted and would be delivered to recipients shortly.