Bass-Fighter has asked for the wisdom of the Perl Monks concerning the following question:

ok perlmonks, I've got a question. I've made a piece of code:
#!usr/bin/perl use 5.6.1; use strict; use warnings; use Mail::Internet; use MIME::Parser; my $mail = Mail::Internet->new($ARGV[0]); my $headers = $mail->head()->header_hashref(); my $maximum = 100000; my $mailnummer = int(rand($maximum)); my $from = $headers->{From}->[0]; my $to = $headers->{To}->[0]; my $cc = $headers->{CC}->[0]; if ($cc eq ""){ $cc = 0; } my $date_time = $headers->{Date}->[0]; my $subject = $headers->{Subject}->[0]; if ($subject eq ""){ $subject = 0; } my $parser = MIME::Parser->new(); $parser->output_under('/tmp'); my $entity = $parser->parse($ARGV[0]); my $file; if ( $entity->is_multipart ) { for my $part ( $entity->parts ) { my $head = $part->head; if ( my $filename = $head->recommended_filename ) +{ $file = $filename; } } }
in this code stands 2 times: $ARGV[0]. I give the command in linux: perl program.txt perltst.

my information is inside perltst for this code. but with this form of the code this will only look at the "word" perltst itself.

in what way can I change $ARGV[0] to get there everything what is inside perltst?

Replies are listed 'Best First'.
Re: using arguments
by Anonymous Monk on Dec 19, 2008 at 11:03 UTC
Re: using arguments
by dHarry (Abbot) on Dec 19, 2008 at 11:03 UTC

    Your question confuses me, I'm not sure what you mean. What is perltst? Is it a file? if so you have to open the file, read it's content etc. You might want to investigate one of the GetOpt modules and supply all the data inside perltst on the command line.

      yes that perltst is a file

        From the documentation:

        Mail::Internet->new([ARG], [OPTIONS]) ARG is optional and may be either a file descriptor (reference to +a GLOB) or a reference to an array. If given the new object will be i +nitialized with headers and body either from the array of read from t +he file descriptor.

        Under the assumption that your file is in the right format you could construct a file descriptor to the file and pass that into the constructor.