[22820] in Perl-Users-Digest
Perl-Users Digest, Issue: 5041 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 26 11:06:44 2003
Date: Mon, 26 May 2003 08:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 26 May 2003 Volume: 10 Number: 5041
Today's topics:
a Bayesian intelligent e-mail autoresponder? (totojepast)
Code exits after printing data to the browser. <david@[no_spam]simplymaya.com>
drop down selection from flatfile <pfeldmann@web.de>
Re: Error message with perl -MCPAN -e shell <bart.lateur@pandora.be>
Re: How do I make a graph with this module? <bart.lateur@pandora.be>
Re: How to get picture file in web which involve redire <mbudash@sonic.net>
Re: need explanation <krahnj@acm.org>
Re: need explanation <bart.lateur@pandora.be>
Re: Perl Nightmare on OS X <bart.lateur@pandora.be>
Re: Perl Script to Caluclate Averages? <abigail@abigail.nl>
Re: Perl Script to Caluclate Averages? <thens@nospam.com>
Re: Recursive Matching Using foreach <No_4@dsl.pipex.com>
sprintf question <Rene.Scheibe@gmx.net>
Re: sprintf question (Helgi Briem)
Re: sprintf question <rev_1318@hotmail.com>
Re: sprintf question (Jay Tilton)
Re: sprintf question <barryk2@SPAM-KILLER.mts.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 May 2003 07:03:56 -0700
From: totojepast@atlas.cz (totojepast)
Subject: a Bayesian intelligent e-mail autoresponder?
Message-Id: <1445a2d7.0305260603.3adc879@posting.google.com>
Please can you tell me if anybody has tried to use ifile or a similar
Bayesian for an automatic e-mail autoresponder?
http://www.google.com/search?q=bayesian+autoresponder+-spam
didn't work well :-(
------------------------------
Date: Mon, 26 May 2003 15:45:36 +0100
From: David <david@[no_spam]simplymaya.com>
Subject: Code exits after printing data to the browser.
Message-Id: <5o94dvs8jrfuqfplnuv19bone7qlst98p9@4ax.com>
Hi,
sub download {
my $fh = new FileHandle;
$fh->open("</home/downloads/$tutorial_info[0]");
my $piece_size = ($rh_fi->{'file_size_bits'} / 60) + 40;
my $data;
my $file_offset = ($rh_fi->{'part_size_bits'} -
$rh_fi->{'part_size_bits'} * $input{'part'});
print "Content-type: application/ipp\n";
print "Content-length: $rh_fi->{'part_size_bits'}\n";
print "Content-Disposition: filename=test.zip\n\n";
if ($input{'size'} ne 'Full' && $rh_fi->{'no_parts'} != 1) {
$fh->seek( ($file_offset - $rh_fi->{'part_size_bits'}),1 );
for (my $loop=0; $loop <= $rh_fi->{'file_size_bits'}; $loop +=
$piece_size) {
$fh->read($data, $piece_size,);
print $data;
}
} else {
$fh->seek(0,1);
for (my $loop=0; $loop <= $rh_fi->{'file_size_bits'}; $loop +=
$piece_size) {
$fh->read($data, $piece_size);
print $data;
}
}
&clean_up;
}
The clean_up sub is never called, the script seems to exit after the
print $data statement could someone enlighten me as to why the
clean_up sub is not executed?
Thanks for your time :)
David
------------------------------
Date: Mon, 26 May 2003 09:17:49 +0200
From: "Peter Feldmann" <pfeldmann@web.de>
Subject: drop down selection from flatfile
Message-Id: <3ed1bf9e$0$10140$4d4ebb8e@read.news.de.uu.net>
hello there,
i've written a couple of programms to adminstrate
network-printers via snmp over a html-interface.
to select a printer i have to enter the hostname or the ip
in a submit-field and then it work (see program below)
well, as i only know the hostnames and the ips, i want to
replace the submit-field ($value) by a drop-down which reads a file
including all ips, hostnames and describtions (just as the /etc/hosts).
can anybody give me the syntax how to read that flatfile and how to select
one field from it ???
thanks for your help.
regards
peter
the programm (so far) written for an aix-enviroment
----------------------------------------------------
#!/usr/bin/perl
read(STDIN, $Daten, $ENV{'CONTENT_LENGTH'});
print "Content-type: text/html\n\n";
print "<html>\n";
@Formularfelder = split(/&/, $Daten);
foreach $Feld (@Formularfelder)
{
($name, $value) = split(/=/, $Feld);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$Formular{$value} = $value;
my $counter = qx(/usr/sbin/snmpinfo -m get -c public -h $value
mib-2.43.10.2.1.4.1.1| /usr/bin/cut -d ' ' -f3);
wait();
my $dis1 = qx(/usr/sbin/snmpinfo -m get -c public -h $value
1.3.6.1.4.1.2.6.112.1.1.9.2.11.0| /usr/bin/cut -d ' ' -f3);
wait();
my $dis2 = qx(/usr/sbin/snmpinfo -m get -c public -h $value
1.3.6.1.4.1.2.6.112.1.1.9.2.6.0| /usr/bin/cut -d ' ' -f3);
wait();
my $dis3 = qx(/usr/viega/snmp_display1 $value);
wait();
my $dis4 = qx(/usr/viega/snmp_display2 $value);
wait();
print "<body><table><TR><TD>Druckername:</td>";
print "<td>$value</td>";
print "</tr>";
print "<TR><TD>Zählerstand:</td>";
print "<td>$counter</td>";
print "</tr>";
print "<TR><TD>IP Adresse:</td>";
print "<td>$dis1</td>";
print "</tr>";
print "<TR><TD>Gateway:</td>";
print "<td>$dis2</td>";
print "</tr>";
print "<TR><TD>Display:</td>";
print "<td>$dis3</td>";
print "</tr>";
print "<TR><TD>Display:</td>";
print "<td>$dis4</td>";
print "</tr>";
}
print "</table></body></html>\n";
------------------------------
Date: Mon, 26 May 2003 11:47:35 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Error message with perl -MCPAN -e shell
Message-Id: <ilv3dv4368bt612rkrcp6b2ep7gftivrsa@4ax.com>
Alan wrote:
>Hi Randy,
>
>This seemed to work pretty good. Now when I run the command ...
A: Top Posting.
Q: What is the most annoying thing on Usenet?
--
Bart.
------------------------------
Date: Mon, 26 May 2003 12:05:37 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How do I make a graph with this module?
Message-Id: <jl04dvogd71q33588fj2hhvhjobte8rnlp@4ax.com>
James E Keenan wrote:
>If I were in your shoes at this point, I'd go back to search.cpan.org
>and plug "Graph" into the search engine. The _next_ module that comes
>up, Martin Viebruggen's GDGraph, looks more promising. There's even
>an FAQ as part of the docs! (Note: I haven't tried any of these
>myself.)
WTF?
Graph builds a "graph", which is some abstract form of network, which
you think of as connecting nodes with arrows.
GDGraph build a graphic image.
There's no connection between the two.
--
Bart.
------------------------------
Date: Mon, 26 May 2003 07:21:22 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: How to get picture file in web which involve redirection using LWP
Message-Id: <mbudash-D226F8.00212126052003@typhoon.sonic.net>
In article <e6e46c65.0305251023.34644f14@posting.google.com>,
alam@netscape.com (Antonio Lam) wrote:
> I tried to get some images from the web using LWP, and find out some
> sites won't allow me to do it directly with absolute URL address (eg.
> http://www.hostname.com/dir/pic.jpg). Even from the browser, if I type
> the absolute URL address, it will redirect me to other page insted
> retrieve the image. So I need to go to their main page (eg.
> http://www.hostname.com) and click its link within the page to
> retrieve the image. I think there are some sort of file protection in
> the site which force the user to navigate through their pages to get
> those files.
>
> So if I do the following code in Perl:
>
> ---------------------
> use LWP::Simple;
>
> if (is_success($rtrcode =
> getstore("http://www.hostname.com/dir/pic.jpg", "pic.jpg"))) {
> print "Got file.\n";
> } else {
> print "Can not find file\n";
> }
> print "rtrcode is: $rtrcode\n";
> ----------------------
>
> the return code still '200' but i am not getting the right file.
> (instead, it is a redirected index file).
>
> Any idea on how to solve this problem?
>
> Thanks,
> Antonio.
sounds like they don't want you to get the images... why not honor their
intentions?
--
Michael Budash
------------------------------
Date: Mon, 26 May 2003 08:29:08 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: need explanation
Message-Id: <3ED1D038.E5EECD09@acm.org>
> Anthony wrote:
>
> trying to work out this script, and what it means!!!!!!! Can someone
> explain what is highlighted in purple for me. Am finding it hard to
> know what it means.
> Sstill trying to work perl out....
> Any help would be appreciated
>
>
> my $num = 1;
> my $filename = "ABCDEFF.TXT";
> my $time = time();
> my ($min, $hour, $day, $mon, $year) = (localtime($time))[1..5];
> $mon++; $year+=1900;
> $num =
> $num<10?"0$num":$num;
> $min = $min<10?"0$min":$min;
> my $h2 = $hour%10;
> my $h1 = ($hour - $hour%10)/10;
> $day = $day<10?"0$day":$day;
> $mon = $mon<10?"0$mon":$mon;
> $year = $year%1000;
>
> my $stamp = "${num}${day}${mon}${year}${h1}.${h2}${min}";
>
> rename($filename, $stamp) or die("RENAME: $!");
If you write it like this it may be easier to understand:
my $num = 1;
my $filename = 'ABCDEFF.TXT';
my ( $min, $hour, $day, $mon, $year ) = (localtime)[1..5];
my $stamp = sprintf '%02d%02d%02d%d%d.%d%02d',
$num, $day, $mon + 1, $year % 100, $hour / 10, $hour % 10,
$min;
rename $filename, $stamp or die "RENAME: $!";
Or like this:
use POSIX 'strftime';
my $num = '01';
my $filename = 'ABCDEFF.TXT';
my $stamp = strftime "$num%d%m%g%H%M", localtime;
substr $_, -3, 0, '.';
rename $filename, $stamp or die "RENAME: $!";
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 26 May 2003 11:56:15 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: need explanation
Message-Id: <i104dvk56c5qi9g0gs23bvmes54877b3c3@4ax.com>
Erick Jones wrote:
>It takes the 24 hour server time and converts it to standard 12 hour (am/pm) time
Does not.
It appears to want to format some components of the data as 2 digits,
except for the year where it doesn't give a shit, plus it puts a dot
between the two digits of the hour.
Don't try to understand this code. Except maybe for backward
compatibility, I'd throw it in the bin.
--
Bart.
------------------------------
Date: Mon, 26 May 2003 11:45:42 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Perl Nightmare on OS X
Message-Id: <gfv3dvg5c6rjf2e1lef4tmcr3g07v8cq25@4ax.com>
Nick wrote:
>I'm a new to Perl and OS X, but I recently tried to install Perl 5.8.0
>on my iMac for the primary reason that I wasn't able to download
>anything from CPAN without it trying to install Perl 5.8.0 as well.
Ouch. You must have an old version of CPAN. Install the new version for
CPAN, for example by following its instructions as it prompts you
("install Bundle::CPAN", IIRC), and it should no longer do that. BTW you
can decline following recommended upgrades if you wish. Perhaps it's a
setting.
HTH,
Bart.
------------------------------
Date: 26 May 2003 11:30:43 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl Script to Caluclate Averages?
Message-Id: <slrnbd3un3.kuj.abigail@alexandra.abigail.nl>
Spread Eagle (redsky@virtualhosts.net) wrote on MMMDLV September MCMXCIII
in <URL:news:7059619f.0305252058.1f2faad4@posting.google.com>:
%% I'm trying to teach myself perl, and am just getting the basics down.
%% I want to write a script that would allow the user to enter a sequence
%% of numbers from the standard input, it would then calculate the
%% average of those numbers, then print that average on the standard
%% output. Can someone show mw a sample script for that? I keep getting
%% compile arrors and syntax errors.
perl -nle'$;+=$_}{$_=$;/$.}{'
Abigail
--
# Count the number of lines; code doesn't match \w. Linux specific.
()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`;
------------------------------
Date: Mon, 26 May 2003 20:08:25 +0530
From: Thens <thens@nospam.com>
Subject: Re: Perl Script to Caluclate Averages?
Message-Id: <20030526200825.26bd289a.thens@nospam.com>
On 26 May 2003 11:30:43 GMT
Abigail <abigail@abigail.nl> wrote:
>
>perl -nle'$;+=$_}{$_=$;/$.}{'
>
When I do a perldoc perlvar it says $; is "The subscript separator
for multidimensional array emulation". Any special reasons for using
this ??
-Thens
>
>
>Abigail
>--
># Count the number of lines; code doesn't match \w. Linux specific.
>()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
>$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`;
------------------------------
Date: Mon, 26 May 2003 13:09:11 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Recursive Matching Using foreach
Message-Id: <3ed203e7$0$10626$cc9e4d1f@news.dial.pipex.com>
rusneht wrote:
> foreach (@tmpary)
> {
> if ( "$_" ne "$userip" )
> {
> next ;
> }
> elsif ("$_" eq "$userip")
> {
> &sub_call();
> }
> else
> { ;; }
since either the if or the elsif must be true, the else will never
execute.
The sort of thing you need here is:
my $found = 0;
foreach (@tmpary) {
if ($_ eq $userip) {
sub_call();
$found = 1;
last;
}
}
print "Error message here" if (not $found);
--
-*- Just because I've written it here doesn't -*-
-*- mean that you should, or I do, believe it. -*-
------------------------------
Date: Mon, 26 May 2003 12:52:29 +0200
From: "Rene Scheibe" <Rene.Scheibe@gmx.net>
Subject: sprintf question
Message-Id: <basrlp$34vv2$1@ID-65612.news.dfncis.de>
i have numbers and want to pad them with a given number
of leading zeros instead of whitespaces. but i don't want to
hardcode them so the number is given by a variable:
my $number_padded = sprintf "%0$DIGIGSd", $number_unpadded;
but perl complains about undefined $DIGITSd so i tried
some things and got it working with "%0DIGITS\d". but
this isnt really correct i think (httpd gives some warnings
about unrecognized escapes '\d')
so can you plz help me out...
...rene
------------------------------
Date: Mon, 26 May 2003 11:04:27 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: sprintf question
Message-Id: <3ed1f434.3960779509@news.cis.dfn.de>
On Mon, 26 May 2003 12:52:29 +0200, "Rene Scheibe"
<Rene.Scheibe@gmx.net> wrote:
>i have numbers and want to pad them with a given number
>of leading zeros instead of whitespaces. but i don't want to
>hardcode them so the number is given by a variable:
>
>my $number_padded = sprintf "%0$DIGIGSd", $number_unpadded;
Are you sure that it's $DIGIGS ?
>but perl complains about undefined $DIGITSd so i tried
>some things and got it working with "%0DIGITS\d". but
>this isnt really correct i think
my $number_padded = sprintf "%0${DIGITS}d",
>(httpd gives some warnings about unrecognized escapes '\d')
httpd gives warnings?
What does httpd have to do with Perl?
--
Regards, Helgi Briem
helgi DOT briem AT decode DOT is
------------------------------
Date: Mon, 26 May 2003 13:05:04 +0200
From: "Paul van Eldijk" <rev_1318@hotmail.com>
Subject: Re: sprintf question
Message-Id: <pan.2003.05.26.11.05.04.615150@hotmail.com>
On Mon, 26 May 2003 12:52:29 +0200 Rene Scheibe wrote:
> i have numbers and want to pad them with a given number
> of leading zeros instead of whitespaces. but i don't want to
> hardcode them so the number is given by a variable:
>
> my $number_padded = sprintf "%0$DIGIDSd", $number_unpadded;
tell Perl what your variable name is using ${}:
my $number_padded = sprintf "%0${DIGIGS}d", $number_unpadded;
HTH
Paul
--
$_=q{ ^4;c;14;1b:a^5;16:c^17:e^a;11;19:h^9;15:j^0:k^18:l^13
:n^6:o^7:p^10:r^b;12;1a:s^2:t^3;8:u^1};s{(?<=[;^])(\d)?([\d
abc])}{$a=$1;$2=~/([abc])/?$a*13+ord($1)%87:$1*13+$2}egx;
for(split/:/){($a,@_)=split/[;^]/;@@[@_]=($a)x@_}print@@
------------------------------
Date: Mon, 26 May 2003 12:50:58 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: sprintf question
Message-Id: <3ed20da1.34785715@news.erols.com>
"Rene Scheibe" <Rene.Scheibe@gmx.net> wrote:
: i have numbers and want to pad them with a given number
: of leading zeros instead of whitespaces. but i don't want to
: hardcode them so the number is given by a variable:
:
: my $number_padded = sprintf "%0$DIGIGSd", $number_unpadded;
my $number_padded = sprintf "%0*d", $DIGIGS, $number_unpadded;
------------------------------
Date: Mon, 26 May 2003 08:06:49 -0500
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: sprintf question
Message-Id: <MPG.193bcd5f329623769897e2@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <basrlp$34vv2$1@ID-65612.news.dfncis.de>, Rene Scheibe
(Rene.Scheibe@gmx.net) says...
> i have numbers and want to pad them with a given number
> of leading zeros instead of whitespaces. but i don't want to
> hardcode them so the number is given by a variable:
>
> my $number_padded = sprintf "%0$DIGIGSd", $number_unpadded;
>
> but perl complains about undefined $DIGITSd so i tried
> some things and got it working with "%0DIGITS\d". but
> this isnt really correct i think (httpd gives some warnings
> about unrecognized escapes '\d')
>
> so can you plz help me out...
>
> ...rene
Try the following :
my $number_padded = sprintf "%0${DIGIGS}d", $number_unpadded;
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.
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 V10 Issue 5041
***************************************