in reply to Win32 Opening files

@_ contains the list of arguments to your function, and when you interpolate it in a string, you get all your parameters separated by a space (unless you fiddled with some funny variables, but I assume you didn't).

I suppose you pass your two full pathnames as arguments, so you have to loop on @_:

sub parse_mail { my @mail; foreach my $mail ( @_ ) { open (MAIL,$mail) || die "Cannot open $mail, $!"; push @mailf, <MAIL>; chomp (@mailf); close (MAIL) || die "Cannot close $mail, $!"; } return @mailf; }

I also assume you want to concatenate both files. But may be it's better that your sub handles one file at a time and you call it from within a loop...

--bwana147

Replies are listed 'Best First'.
Re: Re: Win32 Opening files
by Dalin (Sexton) on Jun 29, 2001 at 19:15 UTC
    Ok, all you guys rock for all of the help. I changed;
    my $mail = "@_";
    to
    my $mail = @_[0];
    This seems to work because I actually have a foreach loop in the main. It is getting past the open but not the close on the filehandle. I basically get the same message: Cannot close C:/windows/desktop/ tmp/test.f2mail,Bad file descriptor. Where ever there is confusion to be had... I'll be there.
      which should be my $mail = $_[0];

      I suggest you put -w after your path to perl at the top of the file (#!/usr/bin/perl or whatever) which will pick up on stuff like that.

      "Argument is futile - you will be ignorralated!"

Re: Re: Win32 Opening files
by MadraghRua (Vicar) on Jun 30, 2001 at 03:02 UTC
    Perhaps it might work better in windows if you break it down into simpler elements, for instance
    sub parse_mail ( my @mail; @mail = @_; foreach my $mail ( @mail ) { open (MAIL,$mail) || die "Cannot open $mail, $!"; push @mailf, <MAIL>; chomp (@mailf); close (MAIL) || die "Cannot close $mail, $!"; } return @mailf; }

    I realize that you have set up a shortcut in the code, but I have found perl works better in Windows if I avoid shortcuts in the code, I don't know why.

    MadraghRua
    yet another biologist hacking perl....

      Whats the deal with this line:
      foreach my $mail ( @mail ) {
      or this :
      my @mail; @mail = @_;
      Why not just say:
      foreach my $mail (@_) {
      and using $mail as the looping element of @mail is kind of silly... I dont know that perl would even let you do that (at least not with strict and warnings).

      --
      Laziness, Impatience, Hubris, and Generosity.