[16862] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4274 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 9 21:05:22 2000

Date: Sat, 9 Sep 2000 18:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968547908-v9-i4274@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 9 Sep 2000     Volume: 9 Number: 4274

Today's topics:
    Re: 2 versions of Perl (Martien Verbruggen)
    Re: 2 versions of Perl <pgapro@eclipse.net>
    Re: 2 versions of Perl (Martien Verbruggen)
    Re: close(STDIN) bad, but why? (Martien Verbruggen)
    Re: Environment variables - how to list them all? <mbk59@hotmail.com>
        Finding installed modules (David Wall)
        Howto debug a perl cgi script yossariancomputing@my-deja.com
    Re: Howto debug a perl cgi script <tony_curtis32@yahoo.com>
    Re: Howto debug a perl cgi script yossariancomputing@my-deja.com
    Re: Howto debug a perl cgi script <tony_curtis32@yahoo.com>
    Re: need advice on locale problem (Martien Verbruggen)
    Re: Need Help! OK Who wants to laugh at my first perl a (Mark-Jason Dominus)
        Perl/CGI to retrieve stock quotes from another server? <davesisk@ipass.net>
    Re: Perl/CGI to retrieve stock quotes from another serv (Tony L. Svanstrom)
    Re: Perl/CGI to retrieve stock quotes from another serv <jeff@vpservices.com>
    Re: Perl/CGI to retrieve stock quotes from another serv <billhess2000@home.com>
        Read MP3 tag <nnort@start.no>
    Re: Read MP3 tag <jeff@vpservices.com>
    Re: Read MP3 tag <jeff@vpservices.com>
    Re: Restricting simultaneous file downloads in CGI prog <clive@NOTheSourceSPAM.org.uk>
    Re: use strict: why? (David H. Adler)
    Re: what is the best way to get the lastest line from a <rick.delaney@home.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 10 Sep 2000 09:28:32 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: 2 versions of Perl
Message-Id: <slrn8rlecg.dgd.mgjv@martien.heliotrope.home>

On Sat, 09 Sep 2000 15:14:12 -0400,
	john <pgapro@eclipse.net> wrote:
> I have found that I have two versions of Perl installed on my Redhat
> Linux box.    The first is version 5.0 and is installed in the folder
> /usr/lib/perl5/  The second in installed to /local/ActivePel-5.6
> 
> I would like to remove the 5.0 version.  It seems like my programs are
> using these libraries instead of the more recent ActivePerl libraries.

I'd remove both, get the sources of perl 5.6.0 and compile and install
one myself. You probably used rpm to install both of the ones you have
now, so you should also use rpm to uninstall them. How that works is
totally offtopic here, and I suggest that you read the rpm manual page.

Martien
-- 
Martien Verbruggen              | Since light travels faster than
Interactive Media Division      | sound, isn't that why some people
Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
NSW, Australia                  | speak?


------------------------------

Date: Sat, 09 Sep 2000 19:57:31 -0400
From: john <pgapro@eclipse.net>
Subject: Re: 2 versions of Perl
Message-Id: <39BACE6B.F1674873@eclipse.net>

> I'd remove both, get the sources of perl 5.6.0 and compile and install
> one myself. You probably used rpm to install both of the ones you have
> now, so you should also use rpm to uninstall them. How that works is
> totally offtopic here, and I suggest that you read the rpm manual page.
>

Removing both is just a matter of deleting the directories or is there
something else I should do?   If this is off topic could you give a me a
hint on where to look for information on how to uninstall.  I have been
looking all over (perl sites, faqs....etc and nothing on removing perl from
your system.



------------------------------

Date: Sun, 10 Sep 2000 11:15:08 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: 2 versions of Perl
Message-Id: <slrn8rlkkc.m53.mgjv@martien.heliotrope.home>

On Sat, 09 Sep 2000 19:57:31 -0400,
	john <pgapro@eclipse.net> wrote:
[And I said:]
> > I'd remove both, get the sources of perl 5.6.0 and compile and install
> > one myself. You probably used rpm to install both of the ones you have
> > now, so you should also use rpm to uninstall them. How that works is
> > totally offtopic here, and I suggest that you read the rpm manual page.
> >
> 
> Removing both is just a matter of deleting the directories or is there
> something else I should do?   If this is off topic could you give a me a
> hint on where to look for information on how to uninstall.  I have been
> looking all over (perl sites, faqs....etc and nothing on removing perl from
> your system.

That depends on your system, and how they were installed. As I already
mentioned, some Linux distributions use rpm to manage the installation
of software packages. When you installed ActiveState's, how did you do
it?

If you use rpm to install, use rpm to remove. If you used another
package manager, use its reverse. If you just unpacked an archive with
binaries, remove all the files and directories it created. If you
compiled from source, and use make install, then reverse whatever it
did.

But that is not a Perl issue at all. It's the same for each an any
software package you install.

I doubt that you compiled the source and installed it yourself, because
the paths you gave suggest installations of some rpm package, and some
ActiveState distribution.

*sigh*

Try

$ rpm -qa | grep -i perl

and please, do read the manual page.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | That's not a lie, it's a
Commercial Dynamics Pty. Ltd.   | terminological inexactitude.
NSW, Australia                  | 


------------------------------

Date: Sun, 10 Sep 2000 10:03:33 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: close(STDIN) bad, but why?
Message-Id: <slrn8rlge5.dgd.mgjv@martien.heliotrope.home>

On 09 Sep 2000 19:03:17 +0100,
	Chris Martin <chris@localhost.localdomain.invalid> wrote:
> A colleague has sent me the following question -- he accepts that
> closing STDIN is a bad thing to do but wants to know why.
> 
> Can anybody help?
> 
>    Here is the problem in a very simple form...
>    
>    #! /usr/bin/perl
>    print glob('*.pl'), "\n";
>    close(STDIN);
>    print glob('users*'), "\n";
>    
>    The two filename globs are for different patterns which both match
>    a number of files in the directory where the program is run but the
>    second line of output is blank.  If the close(STDIN); is removed
>    then the program works as expected.

Interesting...

$ /opt/perl5.00405/bin/perl -wl
print glob '*.pl';
close STDIN;
print glob '*.c';
__END__
foo.pl
foo.c
$ perl5.00503  -wl
print glob '*.pl';
close STDIN;
print glob '*.c';
__END__
foo.pl
foo.c
$ perl5.6.0 -wl 
print glob '*.pl';
close STDIN;
print glob '*.c';
__END__
foo.pl
foo.c

I was going to say something like: Older perls do their globbing by
spawning a shell, and they would need STDIN to get info from a spawned
process. Newer perls shouldn't display this behaviour. However, I can't
even duplicate your problem with any of the three perls that I have
installed on my linux box.

I don't know whether the behaviour of the OS is determined by the
standard when a parent closes stdin before using fork, pipe, or stuff
like that, or whether it's up to the implementation. I don't have access
to my Unix books right now.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


------------------------------

Date: Sat, 9 Sep 2000 20:52:20 -0400
From: "Mike Krell" <mbk59@hotmail.com>
Subject: Re: Environment variables - how to list them all?
Message-Id: <39badaf2_3@news3.prserv.net>


"Abigail" <abigail@foad.org> wrote in message
news:slrn8ri4qb.vlt.abigail@alexandra.foad.org...

> $ perl -wle '$, = "="; $\ = $/; print @ENV while @ENV = each %ENV'

Wow.  I learned a heck of a lot playing around with this snippet.  But I'm
still puzzled by one thing:  "-l" and "$\ = $/" apparently do the same
thing.  Are both necessary?

   Mike





------------------------------

Date: 9 Sep 2000 19:44:59 -0400
From: darkon@one.net (David Wall)
Subject: Finding installed modules
Message-Id: <8FAAC1B91darkononenet@206.112.192.118>

I've seen some posts asking how to find out what modules are present for a 
particular installation of Perl.  It's not something I've worried about 
much, but I happened upon a program called Perldiver and decided to look at 
it. I didn't like the way it did things, so I decided to write my own.

Perhaps I've reinvented a wheel, but I haven't seen anything quite like 
this in the standard Perl modules.  Comments or criticism are welcome.

I excluded modules beginning with an underscore, since the convention seems 
to be that they're for private use by other modules, and not meant for 
"public" use.  I'm not sure if this is a good idea or not.

It only looks at the file names, but doesn't check to see if they're 
installed correctly.



#!/usr/bin/perl -w
require 5.0;
use strict;
use File::Find;

sub get_module_names {
    my @modules;
    my $filter_file_names = sub {
        push(@modules, $File::Find::name) if /\.pm$/ && /^[^_]/;
    };
    find( $filter_file_names, @INC );
    foreach my $mod (@modules) {
        foreach my $dir (@INC) {
            last if $mod =~ s|^$dir/||;
        }
        $mod =~ s/\.pm$//;
        $mod =~ s|/|::|g;
    }
    return @modules;
}

sub is_present {
    my @check = @_;
    my @found = get_module_names();
    my %modules;
    @modules{ @found } = (1) x @found;
    my %checked;
    @checked{ @check } =  @modules{ @check };
    return \%checked;
}

my $t = is_present('Exporter', 'PSI::ESP', 
                   'Text::Wrap', 'DWIM::Correctly');
print map { "$_ is " . ($t->{$_} ? "present\n" : "missing\n") } keys %$t;
print "\n", '='x60, "\n\n";
print map { "$_\n" } sort { lc $a cmp lc $b } get_module_names();

-- 
David Wall
darkon@one.net


------------------------------

Date: Sat, 09 Sep 2000 22:45:19 GMT
From: yossariancomputing@my-deja.com
Subject: Howto debug a perl cgi script
Message-Id: <8peehr$mfg$1@nnrp1.deja.com>

Hi,

Not a full time perl programmer, so forgive me if this is rather
obvious....

However, I have a strange problem.  I have a perl cgi script that works
perfectly via my apache 1.3.12 server running perl 5.005_3 at home, but
when run via my apache 1.3.9 5.005_2 live webserver, generates a "500
Internal error", logging the rather *un*helpful "Premature end of
script headers".

I accept this could be for a variety of reasons (versions,server
misconfiguration,script error), but I don't even know where to begin
debugging the problem.  To debug it, I need some information, but other
than perl -w, I don't know how to generate what the scripts doing and
hence why it breaks one place, but not the other....

Can I run it usefully via the command line..i.e. supply the required
input for it to generate the web page to stdout?  I've tried;
script "name=value&othername=othervalue", but that doesn't give me
anything useful....can I get the script to throw out a little more info
somehow?

Any light provided on the subject would be most appreciated....I learnt
a long time ago not to let stuff like this frustrate me, but even
so...I'm frustrated ;)

Rgds,

Steve Huckle


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 09 Sep 2000 18:06:24 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Howto debug a perl cgi script
Message-Id: <87hf7p2mj3.fsf@limey.hpcc.uh.edu>

>> On Sat, 09 Sep 2000 22:45:19 GMT,
>> yossariancomputing@my-deja.com said:

> Hi, Not a full time perl programmer, so forgive me if
> this is rather obvious....

> However, I have a strange problem.  I have a perl cgi
> script that works perfectly via my apache 1.3.12 server
> running perl 5.005_3 at home, but when run via my apache
> 1.3.9 5.005_2 live webserver, generates a "500 Internal
> error", logging the rather *un*helpful "Premature end of
> script headers".

that's the webserver.

I'd suggest: on your live server, the program is probably
outputting something to stdout before the HTTP response
(or maybe mixed up with it).

Perhaps there's an error/warning/info message coming out
on stdout due to a difference in the setup, or lack of
permissions.

hth
t

-- 
WWNKD?


------------------------------

Date: Sat, 09 Sep 2000 23:48:58 GMT
From: yossariancomputing@my-deja.com
Subject: Re: Howto debug a perl cgi script
Message-Id: <8pei95$qfu$1@nnrp1.deja.com>

Hi Tony,

> I'd suggest: on your live server, the program is probably
> outputting something to stdout before the HTTP response
> (or maybe mixed up with it).
>
> Perhaps there's an error/warning/info message coming out
> on stdout due to a difference in the setup, or lack of
> permissions.

Yup helped...I've been at it far too long....couldn't see some basic
errors....indeed, permissions were incorrect on diorectories I need to
write to/read from, but I've corrected them now...alas to no avail %(

Problem is I don't run my live server, someone does that for me...so I
can't check/amend httpd.conf if ExecCGI's not on (could that cause
this?)..and I can get no response from support (full marks
virtualis)....

Is there a way I could perhaps get to see those errors you mention
though?

I'll pick this up tomorrow...the script that's not working is at least
flagged as such (see www.yossarian-music.com/content/content.html)...so
it'll have to wait as I'm off to my pit to get some rest ;)

Thnx for your help,

Steve H


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 09 Sep 2000 19:09:58 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Howto debug a perl cgi script
Message-Id: <87em2t2jl5.fsf@limey.hpcc.uh.edu>

>> On Sat, 09 Sep 2000 23:48:58 GMT,
>> yossariancomputing@my-deja.com said:

> Yup helped...I've been at it far too long....couldn't
> see some basic errors....indeed, permissions were
> incorrect on diorectories I need to write to/read from,
> but I've corrected them now...alas to no avail %(

Print out the program.  Get as far away from the computer
as you can.  Walk through it by hand.  Spot where the
extraneous output occurs.

Have you tried running it from the command line?  As
another user, in a different directory.  That would be a
start locally.

-- 
WWNKD?


------------------------------

Date: Sun, 10 Sep 2000 10:46:59 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: need advice on locale problem
Message-Id: <slrn8rlivj.m53.mgjv@martien.heliotrope.home>

On Sat, 09 Sep 2000 13:52:15 GMT,
	104073.3433@compuserve.com <104073.3433@compuserve.com> wrote:
> I have Mandarke Linux 7.0 w/ perl 5.004. Perl worked fine until I ungraded 
> glibc to version 2.1.3-5, at which time perl started saying that locale 
> could'nt be set. The three LANG environment variables are set to "en", and 
> locale -a
> has "en" as one of the locales. Also, xstart says locales are not supported.
> 
> Things seem to point to a locale problem in glibc. Does anybody know what is 
> wrong and how to go about fixing it? A newer glic perhaps?

I would get a new version of Perl, compile it, and install it. Yours is
slightly on the old side. If you must use 5.004, get the source
distribution for 5.004_05, and compile and install that.

For information about changes to glibc you should contact mandrake, or
check their web site.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.   | Gates?
NSW, Australia                  | 


------------------------------

Date: 9 Sep 2000 19:26:56 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Need Help! OK Who wants to laugh at my first perl attempt?
Message-Id: <8pe2u0$t06$1@tikehau.netreach.net>

In article <8pbmpm$oge$1@nnrp1.deja.com>,
Greg Donovan  <sysnovice@my-deja.com> wrote:
>    opendir(BIN, "/var/spool/mailbox/$MAILBOX/inbox") || die "Can not
>find mailbox for " .
>"$MAILBOX.: $! \n";
>    while(defined ($letters = readdir BIN)) {
>    next if $letters =~ /^\.\.?$/;
>    next if $letters =~ /[__]/;
>    $messages = $messages + 1;
>    }
>    if ($messages == 0) {print "No messages found in mailbox.\n"; }
>    else { print "$messages messages found in $MAILBOX\'s mailbox.\n"}
>
>    closedir(BIN);
>#ask for mail address to forward mail to.
>
>print "\nWhat address would you like to forward $MAILBOX\'s messages to?
>\n" ;
>
>    my $DESTADD = <STDIN>;
>    chomp($DESTADD);
>    opendir(BIN, "/var/spool/mailbox/$MAILBOX/inbox") || die "Can not
>find mailbox for " .
>"$MAILBOX.: $! \n";
>my $MessagesSent;
>    while(defined ($letters = readdir BIN)) {
>    next if $letters =~ /^\.\.?$/;
>    next if $letters =~ /[__]/;
>    open(SENDMAIL, "|/usr/lib/sendmail -odg $DESTADD") || die "Can't
>fork for sendmail: $!\n";
>    print SENDMAIL ($letters);
>    close(SENDMAIL);
>}


OK, here you have a problem:  You have written the same code twice.
That's against the Cardinal Rule of Programming; you must *never*
write the same code twice.

Here you've looked through the inbox for messages, and then if there
are any, you ask what the destination address is, and then you look
through the inbox all over again to send the messages.  

If you really want that structure for the code, the
looking-through-the-inbox should be in a subroutine, like this:

        sub list_messages {
          my $MAILBOX = shift;
          local *BIN;
          opendir(BIN, "/var/spool/mailbox/$MAILBOX/inbox") 
            || die "Can not find mailbox for $MAILBOX: $!\n";
          my (@messages, $messagefile);
          while(defined ($messagefile = readdir BIN)) {          
            next if $letters =~ /^\.\.?$/;
            next if $letters =~ /[__]/;    # This is a bug
            push @messages, "/var/spool/mailbox/$MAILBOX/inbox/$messagefile";
          }
          return @messages;
        }

If you do this, then the main program is about one-third shorter:

  while (1) {                     # Loop forever
    my $num_messages = 0;
    my $MAILBOX;
    my $letters;
    print "\nPlease enter the userID of the mailbox you want to forward, " .
       " or quit (q):\n ";
  
    $MAILBOX= <STDIN>;
  
    chomp($MAILBOX);
    $MAILBOX =~ tr/A-Z/a-z/;
    # Check if they want to quit
    if ($MAILBOX eq 'q') {
      last;
    }
    $num_messages = list_messages($MAILBOX);
    if ($messages == 0) {
      print "No messages found in mailbox.\n";
      # Shouldn't you exit here?
    } else {
      print "$messages messages found in $MAILBOX\'s mailbox.\n";
    }
  
    print "\nWhat address would you like to forward $MAILBOX\'s messages to?
\n" ;
    my $DESTADD = <STDIN>;
    chomp($DESTADD);
    for $letters (list_messages($MAILBOX)) {
      open(SENDMAIL, "|/usr/lib/sendmail -odg $DESTADD") 
        || die "Can't fork for sendmail: $!\n";
      print SENDMAIL ($letters);
    }
    close(SENDMAIL);
  }

I would tighten this up a little further:

  while (1) {                     # Loop forever
    print "\nPlease enter the userID of the mailbox you want to forward, or quit (q):\n ";
  
    my $MAILBOX= <STDIN>;
    chomp($MAILBOX);
    $MAILBOX =~ tr/A-Z/a-z/;
    last if $MAILBOX eq 'q';     # Check if they want to quit

    { my $num_messages = list_messages($MAILBOX);
      if ($num_messages == 0) {
        print "No messages found in mailbox.\n";
        # Shouldn't you exit here?
      } else {
        print "$num_messages messages found in $MAILBOX\'s mailbox.\n";
      }
    }
  
    print "\nWhat address would you like to forward $MAILBOX\'s messages to?\n" ;
    my $DESTADD = <STDIN>;
    chomp($DESTADD);
    for my $letters (list_messages($MAILBOX)) {
      open(SENDMAIL, "|/usr/lib/sendmail -odg $DESTADD") 
        || die "Can't fork for sendmail: $!\n";
      print SENDMAIL ($letters);
      close(SENDMAIL);
    }
  }

This is about half as long as the original.

The other big problem I see with your code is that you haven't always
chosen good names for your variables. I think this is confusing you.
For example, when you open the mailbox directory, you use a filehandle
named BIN, instead of MAILBOX_DIRECTORY or INBOX or something like
that.  $DESTADD is OK, and SENDMAIL is fine, but I wonder about the
wisdom of $letters.  First, it should be $letter, not $letters,
because it's a scalar.  But also if you had named it something like
$mail_filename you would be more likely to remember that it is the
*name* of a file, not the contents.  The final loop, the one that
talks to Sendmail, needs to open that file and hand the contents to
sendmail.  The easy way to do that:

    for my $message_file (list_messages($MAILBOX)) {
      unless (system("/usr/lib/sendmail -odg $DESTADD < $message_file") == 0) {
        warn "Couldn't run sendmail for $message_file; aborting";
        last;  
      }
    }

I think this will fix your problem, although I haven't tested it,
because I don't have sendmail here and because my mailbox structure is
different from yours.  (So beware.)

Now, if I were designing this program, I would do it a little
differently.  I would give it a non-interactive mode, because my
experience is that to be really useful as a tool, it should be easy to
incorporate a program into another program.  Maybe someday I will
write a script that will need to forward someone's mail.  If the
mail-forwarding program is designed properly, that other program
should just be able to invoke it.  But if the other program has to
worry about sending it input on stdin and entering 'q' and soforth, it
will be harder to make the programs work together.

This is how I would have done it:

    #!/usr/bin/perl
    $MAILER = '/usr/lib/sendmail -odg'; # prefer '/var/qmail/bin/qmail-inject'
    $SPOOL = '/var/spool/mailbox';

    if ($ARGV[0] =~ /^-q/) { $QUIET = 1; shift }
    my ($MAILBOX, $DESTADD) = @_;
    $MAILBOX = prompt('Please enter the userID of the mailbox you want to forward: ')
      unless defined $MAILBOX;
        
    $DEST_ADDR = prompt("What address would you like to forward $MAILBOX's messages to?")
      unless defined $DESTADD;

    my @message_files = list_messages($MAILBOX);
    unless ($QUIET) { 
      if (@message_files == 0) {
        print "No messages found in mailbox.\n";
      } else {
        print scalar(@message_files), " messages found in $MAILBOX's mailbox.\n";
      }
    }

    for (@message_files) {
      unless (system("$MAILER $DESTADD < $_") == 0) {
        die "Couldn't run sendmail for $_ (error code $?); aborting";  
      }
    }
    print "Program completed.\n" unless $QUIET;
    exit 0;

    sub prompt {
      my $RESP;
      do {
        print "\n", $_[0], " " unless $QUIET;
        chomp($RESP = <STDIN>);
      } unless $RESP ne '';
      return $RESP;
    }    

    sub usage {
      print "Usage: $0 [-q] [source userid] [dest address]\n";
      exit 1;
    }

    sub list_messages {
      my $MAILBOX = shift;
      local *BIN;
      opendir(BIN, "$SPOOL/$MAILBOX/inbox") 
        || die "Can not find mailbox for $MAILBOX: $!\n";
      my @messages = grep !/^\.\.?$/ && !/[__]/, readdir BIN;
      @messages = map "$SPOOL/$MAILBOX/$_", @messages;
      return @messages;
    }

This is about the same length as the original, but it does more.
It gets its arguments from the command line so that you can say

        forward fredf flooney@biz.com

inside another program or script.  You can get it to shut up by using
the -q option:

        forward -q fredf flooney@biz.com

('q' for 'quiet'.)  If you omit the arguments:

        forward fredf
        forward

it prompts you for the missing information.  (In quiet mode it just
waits silently for the required data to arrive from the standard
input.)  The reason it isn't longer is because I cut out the repeated
code and replaced it with subroutines.

One other thing I cut out was the infinite loop.  I figure that if you
are using this program from the shell it is probably just as easy to
do something like

        for username in *; do
          forward $username
        done

and similarly if 'forward' is being called from another Perl program
it will be a simple matter to wrap it in a loop if that is what is
wanted.

If I were writing the program from scratch, I would have omitted all
the prompts and all the messages.  This would have cut down the length
by about 50%:

    #!/usr/bin/perl
    $MAILER = '/var/qmail/bin/qmail-inject';
    $SPOOL = '/var/spool/mailbox';

    my ($MAILBOX, $DESTADD) = @_;
    usage() unless defined $DESTADD;

    for (list_messages($MAILBOX)) {
      unless (system("$MAILER $DESTADD < $_") == 0) {
        die "$0: Couldn't run sendmail for $_ (error code $?); aborting";  
      }
    }
    exit 0;

    sub usage {
      print "Usage: $0 [-q] [source userid] [dest address]\n";
      exit 1;
    }

    sub list_messages {
      my $MAILBOX = shift;
      local *BIN;
      opendir(BIN, "$SPOOL/$MAILBOX/inbox") 
        || die "$0: can't open directory $SPOOL/$MAILBOX/inbox: $!\n";
      my @messages = grep !/^\.\.?$/ && !/[__]/, readdir BIN;
      return @messages;
    }


Hope this helps.


------------------------------

Date: Sat, 09 Sep 2000 22:43:58 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Perl/CGI to retrieve stock quotes from another server?
Message-Id: <O2zu5.23823$gg.6695653@typhoon.southeast.rr.com>

I want to use a Perl CGI script to retrieve a stock quote from Yahoo,
perform some calculations, then return a list of values to the user (on my
home page, my ISP supports running Perl CGI scripts).  I guess the question
is really can Perl, running as a CGI script, retrieve an HTML document from
a different HTTP site?  Anyone know where I might find an example of how to
do this?  Please post or email!

Best regards,
Dave





------------------------------

Date: Sun, 10 Sep 2000 01:05:37 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Perl/CGI to retrieve stock quotes from another server?
Message-Id: <1egpxou.1h7i6t9nta5ogN%tony@svanstrom.com>

David Sisk <davesisk@ipass.net> wrote:

> I want to use a Perl CGI script to retrieve a stock quote from Yahoo,
> perform some calculations, then return a list of values to the user (on my
> home page, my ISP supports running Perl CGI scripts).  I guess the question
> is really can Perl, running as a CGI script, retrieve an HTML document from
> a different HTTP site?  Anyone know where I might find an example of how to
> do this?  Please post or email!

Yes, it can, take a look at LWP.


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


------------------------------

Date: Sat, 09 Sep 2000 16:23:45 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Perl/CGI to retrieve stock quotes from another server?
Message-Id: <39BAC681.4043E184@vpservices.com>

David Sisk wrote:
> 
> I want to use a Perl CGI script to retrieve a stock quote from Yahoo,
> perform some calculations, then return a list of values to the user (on my
> home page, my ISP supports running Perl CGI scripts).  I guess the question
> is really can Perl, running as a CGI script, retrieve an HTML document from
> a different HTTP site?  Anyone know where I might find an example of how to
> do this?  Please post or email!

LWP.

That, is the LWP.pm bundle also called libwww, the perl library for
manipulating remote files via http and ftp.  Get it on CPAN, or if you
are on windoze, at activestate.  It comes with something called lwpcook, 

-- 
Jeff


------------------------------

Date: Sat, 09 Sep 2000 23:57:27 GMT
From: "Bill Hess" <billhess2000@home.com>
Subject: Re: Perl/CGI to retrieve stock quotes from another server?
Message-Id: <H7Au5.36274$QW4.447317@news1.rdc1.mi.home.com>

Check out CPAN - Finance::YahooQuote and Finance::YahooChart

Bill Hess


"David Sisk" <davesisk@ipass.net> wrote in message
news:O2zu5.23823$gg.6695653@typhoon.southeast.rr.com...
> I want to use a Perl CGI script to retrieve a stock quote from Yahoo,
> perform some calculations, then return a list of values to the user (on my
> home page, my ISP supports running Perl CGI scripts).  I guess the
question
> is really can Perl, running as a CGI script, retrieve an HTML document
from
> a different HTTP site?  Anyone know where I might find an example of how
to
> do this?  Please post or email!
>
> Best regards,
> Dave
>
>
>




------------------------------

Date: Sun, 10 Sep 2000 02:33:20 +0200
From: Tronn =?iso-8859-1?Q?W=E6rdahl?= <nnort@start.no>
Subject: Read MP3 tag
Message-Id: <39BAD6D0.15F23260@start.no>

Hello

I need to read the "mp3 tag" from a mp3 file, I'am using ver 5.005_03 on
Redhat 6.2
Could someone help,  prefeer working ex

Tronn




------------------------------

Date: Sat, 09 Sep 2000 17:34:43 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Read MP3 tag
Message-Id: <39BAD723.D04F6073@vpservices.com>

Tronn Wærdahl wrote:
> 
> Hello
> 
> I need to read the "mp3 tag" from a mp3 file, I'am using ver 5.005_03 on
> Redhat 6.2
> Could someone help,  prefeer working ex
> 
> Tronn

There are a ton of MP3 modules on CPAN.  Check out Chris Nandor's
MP3-Info.  If you want to do database queries on a one or more
directories of MP3 files, DBD::RAM will extract the tags from the files
and econvert them into a database of artists, song title etc. on the
fly.

-- 
Jeff


------------------------------

Date: Sat, 09 Sep 2000 17:52:31 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Read MP3 tag
Message-Id: <39BADB4F.32DFCA68@vpservices.com>

Jeff Zucker wrote:
> 
> Tronn Wærdahl wrote:
> >
> > Hello
> >
> > I need to read the "mp3 tag" from a mp3 file, I'am using ver 5.005_03 on
> > Redhat 6.2
> > Could someone help,  prefeer working ex

I missed the part where you said "working ex".  Why do you want her
working, to get out of paying alimony? Be a mencsh and pay up! (sorry,
couldna hep myself)

So here's a working example that creates a list of all mp3 files in two
directories that match a certain criterion and are sorted by genre and
title:

#!/usr/local/bin/perl -w
use strict;
use DBI;
my $dbh=DBI->connect('dbi:RAM:',,,{RaiseError=>1)
   or die $DBI::errstr;
my $dirlist = ['d:/My Music/', 'c:/mp3/'];
$dbh->func( {data_type=>'MP3',dirs=>$dirlist},'import' );
my $sth = $dbh->prepare(q{
    SELECT song_name, genre FROM table1 
     WHERE genre = 'Trip Hop'
        OR genre = 'Acid Jazz'
       AND year  = '1999'
  ORDER BY genre, song_name
});
$sth->execute;
while( my($name,$genre) = $sth->fetchrow_array ) {
    printf "%25s : %s\n", $genre, $name if $name;
}
__END__

NOTE BENE: for more general purpose stuff you are probably better off
with the MP3-Info module as this example has a lot of database stuff you
may not need and it currently only works on IDv3.1x tags.

-- 
Jeff


------------------------------

Date: Sat, 9 Sep 2000 15:26:31 -0700
From: "brandx" <clive@NOTheSourceSPAM.org.uk>
Subject: Re: Restricting simultaneous file downloads in CGI program
Message-Id: <8ped77$snc$1@madmax.keyway.net>

very elegant :)

I guess in a similar way you could restrict the number of users *uploading*
files too.

Oh hang on, can't FTP servers do that already?

That's another solution, maybe.

cLive ;-)


"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:m1snr9306w.fsf@halfdome.holdit.com...
> >>>>> "news-east" == news-east newscene com <brad@smithart.net> writes:
>
> news-east> 3) Of course, I could use file locking to restrict the
> news-east> download to a single user.  Unfortunately, that's a little
> news-east> *too* restrictive.
>
> Have a series of flock sentinel files, equal to the number of streams
> you want to provide.  When a new request comes in, try flocking each
> one in sequence using a non-blocking flock.  If you get a flock, start
> the download.  If you get all the way through the list without winning,
> say "overloaded" and exit.
>
> Even if the download is interrupted for unexpected reasons, the flock
> gets released, and the "slot" becomes available again.





------------------------------

Date: 9 Sep 2000 22:35:04 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: use strict: why?
Message-Id: <slrn8rleoo.ke9.dha@panix6.panix.com>

On Fri, 08 Sep 2000 15:40:04 -0700, Godzilla!
<godzilla@stomp.stomp.tokyo> wrote:

>Bart Lateur wrote:

>> If $x is a global variable outside the block, 
>> then it is a global variable *inside* the block 
>> as well, because it is the SAME VARIABLE!
>
>If Mr. X is not a jailbird outside the gray bar hotel,
>Mr. X is a jailbird inside the gray bar hotel,
>and Mr. X is no longer a jailbird back outside again.
>
>Same name, different Birdman.

No.  Same Birdman, different condition.  What you seem to be
contending is analogous to this scenario:

Mr. X is not in jail.  Mr. X goes to jail.  At the gates of the jail,
another Mr. X magically appears and goes into jail, leaving the
original one to go about his merry business in the outside world.

That's not actually the worst description of how variables created by
my() work.

With local(), Mr. X is just in jail until released (i.e. the scope in
which the local() functions is departed).

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I'm occasionally callous and strange.	- Willow


------------------------------

Date: Sat, 09 Sep 2000 23:42:58 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <39BACD84.1CE55B28@home.com>


"Andrew N. McGuire" wrote:
> 
> Here is another method, a spoof of your 'count the lines' one
> -liner.  It is slower than tail as well, but cute (I think).
> 
> perl -wne '$l=$_}{print$l' file

Another variation:

    perl -pe '$l=$_}{$_=$l' file

-- 
Rick Delaney
rick.delaney@home.com


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4274
**************************************


home help back first fref pref prev next nref lref last post