[25255] in Perl-Users-Digest
Perl-Users Digest, Issue: 7500 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 9 11:05:39 2004
Date: Thu, 9 Dec 2004 08:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 9 Dec 2004 Volume: 10 Number: 7500
Today's topics:
Re: $300 reward for identity of poster with email addre <joe@inwap.com>
[XML::XSLT] empty result while parsing xml file <PietLaroy@hotmail.com>
Re: [XML::XSLT] empty result while parsing xml file <jwillmore@fastmail.us>
Convert text to Hex <zglickman@il.bphx.com>
Re: Convert text to Hex <this.address@is.invalid>
Re: Convert text to Hex <craig@codenation.net>
Re: examples using PDF::Template <botfood@yahoo.com>
Facile user-agent statistics tool <rob@nova.hbx.us>
Re: How to detect an undefined SV* value in XS? <kalinaubears@iinet.net.au>
Re: How to detect an undefined SV* value in XS? <jl_post@hotmail.com>
Re: HTML2JPEG <jurgenex@hotmail.com>
Re: kindergarten array vs. for question (Anno Siegel)
Re: kindergarten array vs. for question <tadmc@augustmail.com>
Re: Matching words and letters (Anno Siegel)
Re: Matching words and letters <josef.moellers@fujitsu-siemens.com>
Re: Maximum length of hash key <tadmc@augustmail.com>
Re: MS Perl question -- how to use hacked script to wor <djcameron60616@yahoo.com>
Re: MS Perl question -- how to use hacked script to wor <djcameron60616@yahoo.com>
Re: MS Perl question -- how to use hacked script to wor <1usa@llenroc.ude.invalid>
Re: Question on loops and return values <tadmc@augustmail.com>
Re: regular expressions problem <tadmc@augustmail.com>
Re: regular expressions problem <sbryce@scottbryce.com>
Re: Seeking Internet Protection Service (Anno Siegel)
Using MIME::Lite for multipart message - trouble with alamukutty@gmail.com
Re: why the following HereDoc print don't work? (Anno Siegel)
Re: why the following HereDoc print don't work? <1usa@llenroc.ude.invalid>
Re: why the following HereDoc print don't work? <tadmc@augustmail.com>
Re: why the following HereDoc print don't work? <do-not-use@invalid.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 09 Dec 2004 15:49:04 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: $300 reward for identity of poster with email address: my_stu_pitt@yahoo.com
Message-Id: <Qt_td.735921$8_6.448942@attbi_s04>
Gerald Newton3 wrote:
> This perosn has posted slander and obscenitieis under my name
>
> From: "Gerald Newton" <my_stu_pitt@yahoo.com>
> Newsgroups: alt.engineering.electrical, alt.culture.alaska
> Subject: Re: Merry Christmas from electrician.com - North Pole, Alaska
Didn't Kira claim to be a slandered electrician in Alaska?
------------------------------
Date: Thu, 9 Dec 2004 12:50:13 +0100
From: "PL" <PietLaroy@hotmail.com>
Subject: [XML::XSLT] empty result while parsing xml file
Message-Id: <cp9e2c$qmu$1@snic.vub.ac.be>
Hey
I'm using in my perl-script following line:
my $xslparser = XML::XSLT->new(Source => $xslfile);
my $result = $xslparser->serve(Source => $xmlfile);
print $result;
Now I'm trying to perform a <xsl:template>, but It gives an empty
result (just <html><body/></html>)
If I try the xls-transformation with altova xmlspy it works
correctly.
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Faculty/select">
<html><body>
<xsl:apply-templates select="group"/>
</body></html>
</xsl:template>
<xsl:template match="Vakgroep[normalize-space(team_type)='V']">
<xsl:value-of select="name_dutch"/>
<xsl:value-of select="team_code"/>)<br/>
</xsl:template>
<xsl:template match="group"/>
</xsl:stylesheet>
The xmlfile looks as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Faculty><select><group>
<team_code>DWIS</team_code>
<name_dutch>Wiskunde</name_dutch>
<team_type>V</team_type>
</group></select></Faculty>
I've taken a look at cpan, and I'm thinking that the problem is that
certain thinks are not supported in de module.
Can someone help?
Thanks
------------------------------
Date: Thu, 09 Dec 2004 08:34:18 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: [XML::XSLT] empty result while parsing xml file
Message-Id: <pan.2004.12.09.13.34.16.420602@fastmail.us>
On Thu, 09 Dec 2004 12:50:13 +0100, PL wrote:
> I'm using in my perl-script following line:
> my $xslparser = XML::XSLT->new(Source => $xslfile);
> my $result = $xslparser->serve(Source => $xmlfile);
> print $result;
I would write (as complete code that works):
#!/usr/bin/perl
use strict;
use warnings;
use XML::XSLT;
my $xmlfile = 'test.xml';
my $xslfile = 'test.xsl';
my $xslparser = XML::XSLT->new(Source => $xslfile);
my $result = $xslparser->serve(Source => $xmlfile);
print $result;
> Now I'm trying to perform a <xsl:template>, but It gives an empty
> result (just <html><body/></html>)
> If I try the xls-transformation with altova xmlspy it works
> correctly.
I don't see how it did. OTOH, I had not used XMLSpy, so maybe it does
some sort of "magic" when there's an error in the XSLT. Read on ...
> Here is the code:
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="Faculty/select">
> <html><body>
> <xsl:apply-templates select="group"/>
> </body></html>
> </xsl:template>
> <xsl:template match="Vakgroep[normalize-space(team_type)='V']">
> <xsl:value-of select="name_dutch"/>
> <xsl:value-of select="team_code"/>)<br/>
> </xsl:template>
> <xsl:template match="group"/>
> </xsl:stylesheet>
Again, here's an XSL that works:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Faculty/select">
<html>
<body>
<xsl:apply-templates select="group"/>
</body>
</html>
</xsl:template>
<xsl:template match="Vakgroep[normalize-space(team_type)='V']">
<xsl:value-of select="name_dutch"/>
<xsl:value-of select="team_code"/>
<br/>
</xsl:template>
<xsl:template match="group">
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
When using <xsl:template> and performing a match or select, you have to do
something with the values. Just using an empty element tag is not enough.
OTOH, using <xsl:apply-templates> will produce values - because the
default is to provide the text() value of whatever was matched or
selected.
Of course, this is provided to demonstrate that there is nothing wrong
with the module.
< ... >
> Can someone help?
The results I got with the above changes were:
Content-Type: text/xml
Content-Length: 108
<?xml version="1.0" encoding="UTF-8"?>
<html><body>
DWIS
Wiskunde
V
</body></html>
Which is XML, but would (I think) cause most browsers to choke or render
XML instead of HTML. Visit comp.text.xml to see better ways to write XSLT
to deliver HTML content.
HTH
Jim
------------------------------
Date: 9 Dec 2004 05:06:28 -0800
From: "zvika" <zglickman@il.bphx.com>
Subject: Convert text to Hex
Message-Id: <1102597588.317138.182930@c13g2000cwb.googlegroups.com>
How can I want to convert this text:
01 SYSOT VALUE '^@^X^@^A^@^AA' PIC X(07).
To:
01 SYSOT VALUE X'001800010001C1' PIC X(07).
(This is the eqvivalent hex values.)
------------------------------
Date: Thu, 9 Dec 2004 13:49:40 +0000
From: Stephane CHAZELAS <this.address@is.invalid>
Subject: Re: Convert text to Hex
Message-Id: <slrncrglvk.7c6.stephane.chazelas@spam.is.invalid>
2004-12-9, 05:06(-08), zvika:
> How can I want to convert this text:
>
> 01 SYSOT VALUE '^@^X^@^A^@^AA' PIC X(07).
>
> To:
>
> 01 SYSOT VALUE X'001800010001C1' PIC X(07).
> (This is the eqvivalent hex values.)
[...]
s/VALUE '(.*?)'/"VALUE '" . unpack("H*", $1) . "'"/e;
--
Stephane
------------------------------
Date: Thu, 9 Dec 2004 13:59:51 +0000
From: Craig Dunn <craig@codenation.net>
Subject: Re: Convert text to Hex
Message-Id: <Pine.LNX.4.61.0412091351580.9116@gw.codenation.net>
> How can I want to convert this text:
>
> 01 SYSOT VALUE '^@^X^@^A^@^AA' PIC X(07).
>
> To:
>
> 01 SYSOT VALUE X'001800010001C1' PIC X(07).
> (This is the eqvivalent hex values.)
>
>
The binary part of your string can be decoded easily with:
$hex = unpack "H*, $bin;
------------------------------
Date: 9 Dec 2004 07:41:21 -0800
From: "botfood" <botfood@yahoo.com>
Subject: Re: examples using PDF::Template
Message-Id: <1102606881.374661.223440@f14g2000cwb.googlegroups.com>
wow,
hey, this may be exactly what I need! The formatting looks simple, and
I think the printer will accept either PostScript or eps files. Looks
like a much cleaner solution than .pdf !
I just KNEW that somebody had been down this road before...
mucho gracias,
d
------------------------------
Date: Thu, 9 Dec 2004 16:35:36 +0100
From: Robert Manea <rob@nova.hbx.us>
Subject: Facile user-agent statistics tool
Message-Id: <8cr9pc.cmk.ln@rob.unisolblade.de>
Hello,
ever wondered how many different user agents are beeing used in a
newsgroup or even a whole usenet hierarchy? But didn't want to use
'the other' tools cause they draw their statistics based on wrong
criteria.
No?
Well, I did and came out with the following.
Suggestions, improvements, corrections and the like are highly welcome.
---8<---------------------------------------------------------------8<---
Example output for comp.lang.perl.misc:
1. Microsoft Outlook Express : 81
2. Mozilla : 35
3. Mozilla Thunderbird : 33
4. G2 : 32
5. slrn : 25
6. KNode : 21
7. Gnus : 19
8. Pan : 17
9. Forte Agent : 15
10. tin : 12
[...]
Summary:
- 2141 postings in total
- 30 different neawsreaders in 333 distinct postings
- Average of 5.574 articles per poster (with agent header)
- 285 without User Agent header
---8<---------------------------------------------------------------8<---
The code:
#!/bin/perl -w
#
# (c) 2004 by Robert Manea
#
# Retreive 'User-Agent' headers from usenet postings and display the
# commonnes of each newsreader. Only distinct postings count, e.g.
# every posting with the same email address counts as a single occurence
# of the according newsreader.
#
# Caveats: Postings with the same email address but different user
# agents can't be distinguished correctly
use strict;
use warnings;
use File::Find;
die "Usage: $0 <path/to/newsspool>" unless $ARGV[0];
our ( %agents, %emails );
our $cnt_file = 0;
our $no_agent = 0;
find( \&wanted, $ARGV[0] );
# Tiger Woods himself ;)
my $max_len = '';
$max_len |= $_ foreach keys %agents;
$max_len = 1 + length $max_len;
my ( $cnt_reader, $cnt_articles ) = ( 0, 0 );
for ( sort { $agents{$b} <=> $agents{$a} } keys %agents ) {
my $len = $max_len - length $_;
printf "%3d. %s %*s: %d\n", ++$cnt_reader, $_, $len, ' ', $agents{$_};
$cnt_articles += $agents{$_};
}
my $w_agent_avg = sprintf "%.3f", ($cnt_file - $no_agent) / $cnt_articles;
print << "EOF";
Summary:
- $cnt_file postings in total
- $cnt_reader different neawsreaders in $cnt_articles distinct postings
- Average of $w_agent_avg articles per poster (with agent header)
- $no_agent without User Agent header
EOF
sub wanted {
my $agent_header = qr/^User-Agent:|^X-User-Agent:|^X-Newsreader:|^X-Mailer:/;
my $from_header = qr/From:.*?([A-Za-z0-9\.]+@[A-Za-z0-9\.]+)\s*.*/;
my $file_name = $File::Find::name;
if ( -f $file_name && $file_name !~ /\/\./ ) {
open FH, "<$file_name" or ( warn "Cannot open $file_name: $!" and return 0);
++$cnt_file;
my ( $email, $reader );
while (<FH>) {
chomp;
if (/$from_header/) {
$email = $1;
}
elsif (/$agent_header/) {
# TODO: Faster general approach to determine the
# newsreader
my $raw_agent_str = ( split /: / )[1];
( $reader = ( split /\//, $raw_agent_str )[0] ) =~
s/( [A-Za-z]*\.*\d+\.\d+.*$)|(\(*?\[+?.*$)|(\[*?\(+?.*$)//o;
}
elsif ( $email && $reader ) {
if ( !$emails{$email} ) {
$agents{$reader}++;
$emails{$email}++;
}
last;
}
elsif (/^$/) { # Parse only header lines
++$no_agent;
last;
}
}
}
close FH;
1;
}
__END__
Thanks & Greets, Rob
--
The Enterprise meets God, and it's a child, a computer, or a C program.
------------------------------
Date: Thu, 09 Dec 2004 10:06:53 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: How to detect an undefined SV* value in XS?
Message-Id: <41b83330$0$25779$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Tassilo v. Parseval wrote:
> I said elsewhere to use SvOK as it will do what you want
My perlapi docs tell me that SvOK "returns a boolean indicating whether
the value is an SV". I had wondered previously just what that meant ...
now I know.
(Sorry - I missed that piece of advice in your earlier post. I think the
OP might have done the same.)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: 9 Dec 2004 06:00:12 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How to detect an undefined SV* value in XS?
Message-Id: <1102600812.956232.105870@z14g2000cwz.googlegroups.com>
> "jl_post@hotmail.com" <jl_post@hotmail.com> wrote:
> >
> > Thanks to the replies of other posters, I now know of three
> > different ways to check for an undefined value:
> >
> > if (SvTYPE(sv) == SVt_NULL) printf("Undefined");
> > # Contributed by Rob (Sisyphus):
> > if (SvANY(sv) == NULL) printf("Undefined");
> > # Contributed by Tassilo v. Parseval:
> > if (SvOK(sv) == false) printf("Undefined");
xhoster@gmail.com replied:
>
> SvANY doesn't seem to work properly for me.
>
> It claims a variable that was once defined but is now undef as if it
> were defined. It also treats array slots which are off the end of
the
> array differently than those "inside" the array (but never assigned
to).
Good find. Because of what you said, I tested the three ways I
listed above, and I found out that SvTYPE suffered from the same
problem. SvOK, however, still worked without any problems.
So that leaves only one way that I know of for checking for an
undefined value, and that's the solution provided by Tassilo v.
Parseval:
if (SvOK(sv) == false) printf("Undefined");
Since this is the only solution that seems to "work correctly" in
all cases, maybe that's the reason that it's the only one mentioned in
"perldoc perlapi".
It would make more sense to me if it were named SvDEFINED instead of
SvOK. Of course, there could very well be a reason it's named that
(that I'm just not aware of).
Regardless, thanks to everyone who has given input. It's very much
appreciated!
-- Jean-Luc
------------------------------
Date: Thu, 09 Dec 2004 15:04:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: HTML2JPEG
Message-Id: <0QZtd.3182$Qp.372@trnddc01>
Roman M. Parparov wrote:
> "J?rgen Exner" <jurgenex@hotmail.com> wrote:
>> Katja Zinchenko wrote:
>>> Thanks for the hint, and sorry, yes, my question was too vague. What
>>> I wanted to ask is: Is there a perlish way to save the contents of a
>>> web page to an image file exactly the way a browser (any recent
>>> browser) would render it?
>
>> Of course. And it is so trivial that you don't even need Perl.
>> Just use Lynx. It has an option to write the rendered text to a file:
>
>> -dump
>> dumps the formatted output of the default document or one specified
>> on the command line to standard out.
>
> I suspect Katja wants to take screenshots of specific pages
> _including_ graphics, so lynx isn't sufficient.
<quote>
the way [...] any recent browser would render it
</quote>
Anything beyond that is pure speculation
jue
------------------------------
Date: 9 Dec 2004 12:52:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: kindergarten array vs. for question
Message-Id: <cp9hr0$pqv$5@mamenchi.zrz.TU-Berlin.DE>
Dan Jacobson <jidanni@jidanni.org> wrote in comp.lang.perl.misc:
> I read perldata and perllol. How do I fill in the for() so "new
> array" gets printed twice instead of six times, without changing other
> lines of the program?
> my @a=(1,2,3); my @b=(4,5,6);
> for( .....@a......@b.........what do I write?.........)
> print "new array\n"; #this line get printed only twice, not six times?
> for($_){
> print "element $_\n"}}
for ( \ @a, \ @b ) {
print "new array\n";
print "element $_\n" for @$_;
}
Anno
------------------------------
Date: Thu, 9 Dec 2004 08:57:28 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: kindergarten array vs. for question
Message-Id: <slrncrgpuo.91s.tadmc@magna.augustmail.com>
Dan Jacobson <jidanni@jidanni.org> wrote:
> I read perldata and perllol.
You missed the tutorial for references:
perldoc perlreftut
> How do I fill in the for() so "new
> array" gets printed twice instead of six times,
Loop over _references_ to the arrays.
> without changing other
> lines of the program?
> my @a=(1,2,3); my @b=(4,5,6);
> for( .....@a......@b.........what do I write?.........)
> print "new array\n"; #this line get printed only twice, not six times?
> for($_){
This for() loop will execute exactly ONE time, because there
is only one element in the list given to it.
> print "element $_\n"}}
>
-------------------
#!/usr/bin/perl
use warnings;
use strict;
my @a=(1,2,3); my @b=(4,5,6);
foreach my $aref ( \@a, \@b ) {
print "new array\n";
print "element $_\n" for @$aref;
}
-------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Dec 2004 11:16:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching words and letters
Message-Id: <cp9c6a$pqv$1@mamenchi.zrz.TU-Berlin.DE>
Sandman <mr@sandman.net> wrote in comp.lang.perl.misc:
> I just can't seem to wrap my mind around how to attack this problem in the best
> way, so I thought I'd just post here and see if anyone here has done something
> similar and/or has a logical solution to it.
>
> I have a series of letters, say "kljetilamnop", then I have a big textfile with
> legit words, but let's use a short one here:
>
> mall
> bill
> kill
> lot
> pile
> antilope
> hello
>
> Now, I want to cycle through this word list and match it to the letters, and
> return true if the word can be formed by the letters. So, the above would
> return:
>
> mall
> kill
> lot
> antilope
[snip other requirements]
One way of looking at this is to consider a string (word, or list of
available letters) as a multiset of its letters. A multiset is like
a set, but each element can appear with a multiplicity. The bag of
available letters, for instance, would contain each letter of
"kjetiamnop" once and the letter "l" twice.
A word can be built from the given letters when its bag is contained
(in the obvious sense of multisets) in the bag of given letters.
Fortunately, there is a CPAN module that implements bags. Unfortunately,
the implementation doesn't have a "contained" method, so we'll have to
extend the class. Fortunately, the class is well-written, so inheritance
makes this easy:
#!/usr/local/bin/perl
use strict; use warnings; $| = 1;
my $letters = CBag->new->insert( map { $_ => 1 } split //, 'kljetilamnop');
while ( <DATA> ) {
chomp;
my $word = CBag->new->insert( map { $_ => 1 } split //);
print "$_\n" if $word <= $letters;
}
# Extend Set::Bag to support comparison
{{
package CBag;
use base 'Set::Bag';
sub contained {
my ( $bag, $other) = @_;
for ( $bag->elements ) {
return 0 if $bag->grab( $_) > ( $other->grab( $_) || 0);
}
return 1;
}
use overload(
'<=' => 'contained',
);
}}
__DATA__
mall
bill
kill
lot
pile
antilope
hello
------------------------------
Date: Thu, 09 Dec 2004 12:59:28 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Matching words and letters
Message-Id: <cp9ega$6bb$1@nntp.fujitsu-siemens.com>
Sandman wrote:
[ elaborate problem description deleted ]
A very simple/simplistic solution:
my @words =3D qw(mall bill kill lot pile antilope hello);
my $fixed =3D 'k';
my $set =3D 'ljetilamnop' . $fixed;
foreach (@words) {
print "$_\n" if m/[$fixed]/ && m/^[$set]*$/;
}
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Thu, 9 Dec 2004 08:02:05 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Maximum length of hash key
Message-Id: <slrncrgmmt.91s.tadmc@magna.augustmail.com>
Peter Corlett <abuse@dopiaza.cabal.org.uk> wrote:
> If we're playing golf, I'm going to offer:
>
> my $l;
> $l|=$_ foreach keys %category; $l=1+length $l;
If you're playing golf you never use "foreach",
it costs 4 strokes for no gain.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Dec 2004 05:27:57 -0800
From: "James" <djcameron60616@yahoo.com>
Subject: Re: MS Perl question -- how to use hacked script to work correctly(was Question on loops and return values or sumpin)
Message-Id: <1102598877.107193.278620@c13g2000cwb.googlegroups.com>
A. Sinan Unur wrote:
> "James" <djcameron60616@yahoo.com> wrote in
> news:1102535945.679552.290720@z14g2000cwz.googlegroups.com:
Hi Sinan and thanks for your time,
>
> > So the question is how to get this function (GetDriveSpace) to be
> > passed an array, essentially - is this impossible potentially
because
> > of the module design? Resources.pm is the module used with this
> > script. ShowKeys is what returns total, used and free space -- so
this
> > is a third factor in manipulating this array.
> > I'm really trying to get the values for used, total and free space
-
> > and I'm not quite sure how to get at it, and this is already taking
too
> > long for me to figure out.
>
> It would be useful if you learned a little bit of Perl first.
True, this would be the ideal situation and I do have a goal to do so.
>
> > use lib "$ENV(HOME)/site/lib";
>
> What do you think this does?
I thought it explicitly stated where the library was.
>
> > no lib ".";
>
> Why do you think this is necessary?
To not search in the curretn directory for library files?
>
> > use Win32::Resources;
>
> From:
>
>
http://search.cpan.org/~fabpot/Win32-Resources-0.02/lib/Win32/Resources.pm
>
> Win32::Resources allows you to deal with windows
> executable (.exe or .dll) resources (load, update
> and delete resources).
>
> What does this have to do with getting drive space info?
>
> > use Win32API::Resources;
>
> OK. This module is not available through ppm but I found it on CPAN.
> Downloaded and installed it and read the docs. Have you tried that?
>
> > # use strict;
> > # use warnings;
>
> Why are these commented out?
These were commented out because it was complaining about global
symbols (for every stated variable) needing an explicit package
reference, and was not quite sure how to get around it. Other than
commenting it out.
>
> > my @Drives = Win32API::Resources::GetDrives();
> > my %DRVSpace = Win32API::Resources::GetDriveSpace("C:\\");
> > my $pathtofiles = "\\C:\\scripts\\";
> > my $pathtoserverslist = "\\\\xxxxxnnnnnn\\";
> > my $Threshold = "80";
> > my $last_updated = localtime (time);
>
> I give up. This crap is much too hard to read. So, you want to:
>
> 1. Find out what are the valid drive assignments on your system
> 2. Find out how much space is on each one
>
> Why not do that?
>
> use strict;
> use warnings;
>
> use Win32API::Resources;
>
> use Data::Dumper;
>
> sub get_drive_space_info {
> my @drives = Win32API::Resources::GetDrives();
> my %drives;
> for (@drives) {
> $drives{$_} = { Win32API::Resources::GetDriveSpace($_) };
> }
> return \%drives;
> }
>
> sub print_drive_space_info {
> my %ds_info = %{ $_[0] };
>
> for my $d (sort keys %ds_info) {
> my %drive = %{ $ds_info{$d} };
> print "Drive $d\n";
> next if exists $drive{0};
> for my $k (keys %drive) {
> print "\t$k => $drive{$k}\n";
> }
> }
> }
>
> print_drive_space_info(get_drive_space_info());
>
>
> __END__
>
> Adapt this script to your needs.
>
>
> Sinan.
Excellent. Thank you very much for your time. And I will try to learn
(more ?) Perl quickly.
James
------------------------------
Date: 9 Dec 2004 05:37:13 -0800
From: "James" <djcameron60616@yahoo.com>
Subject: Re: MS Perl question -- how to use hacked script to work correctly(was Question on loops and return values or sumpin)
Message-Id: <1102599433.494820.322580@z14g2000cwz.googlegroups.com>
Hi Rob and thanks for your time,
I will try to install AdminMisc using the method you suggested after
trying the code above.
Thanks and cheers,
James
------------------------------
Date: 9 Dec 2004 14:03:37 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: MS Perl question -- how to use hacked script to work correctly(was Question on loops and return values or sumpin)
Message-Id: <Xns95BA5C2A8BCC3asu1cornelledu@132.236.56.8>
"James" <djcameron60616@yahoo.com> wrote in
news:1102598877.107193.278620@c13g2000cwb.googlegroups.com:
> A. Sinan Unur wrote:
>> "James" <djcameron60616@yahoo.com> wrote in
>> news:1102535945.679552.290720@z14g2000cwz.googlegroups.com:
>>
>> > use lib "$ENV(HOME)/site/lib";
>>
>> What do you think this does?
>
> I thought it explicitly stated where the library was.
C:\Home> cat t.pl
use strict;
use warnings;
use lib "$ENV(HOME)/site/lib";
print @INC;
__END__
C:\Home> perl t.pl
Use of uninitialized value in concatenation (.) or string at t.pl line 4.
(HOME)/site/libc:/opt/Perl/libc:/opt/Perl/site/lib.
>> > no lib ".";
>>
>> Why do you think this is necessary?
>
> To not search in the curretn directory for library files?
Why do you think it is necessary to specify that?
Sinan
------------------------------
Date: Thu, 9 Dec 2004 08:52:13 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Question on loops and return values
Message-Id: <slrncrgpkt.91s.tadmc@magna.augustmail.com>
James <djcameron60616@yahoo.com> wrote:
>> Please show *real code*!
>> use lib "$ENV(HOME)/site/lib"; # occasionally perl whines about not
>> ^ ^
>> ^ ^ {HOME}
>
> Tad thanks .. I did not catch that at all.
You should always enable warnings when developing Perl code!
warnings would have caught that mistake *for you*.
Take all the help you can get. Start your programs with:
use warnings;
use strict;
>> Why are you using package variables instead of lexical variables?
>
> This I will have to re-read on, I can't recall what the difference is
> between them,
See:
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
> but if I think I know what they are, I believe I was
> using package variables because they were what I thought was necessary.
I don't see anything that makes them necessary...
>>> our $let = ['A-Z']; # character value for
> drive letters
>> You never make use of this variable, and it almost certainly
>> is not what you think it is.
>
> I thought it was used in a foreach for a loop control variable
> associated with an array, but I could be wrong on that too.
$let contains a _reference_ to an anonymous array.
> I was
> trying to define
The array referenced by $let has ONE element in it,
a 3-character string "A", "-", "Z".
> a range of characters in a variable (which I guess
> would have to be an array anyway).
If you want the anon array to contain 26 elements then:
my $let = ['A' .. 'Z'];
but you have no need for an anon array at all, you can just
use the 26-element list right in the foreach
foreach my $letter ( 'A' .. 'Z' ) {
...
}
>> our @line = ""; # was going to be used for
> file looping
>> How may elements are you expecting to be in @line right here?
>> Were you expecting zero elements, an empty array?
>> That isn't what you are getting there...
>
> I was expecting an empty array actually, or at least null values in
> it.
It has ONE element in it. The value of the one element is the empty string.
If you wanted zero elements, then either of these will do it:
my @line; # contains empty list by default
my @line = (); # be unnecessarily explicit about the empty list
>>> open (file2,"+<"); # open machines input file for read
>> You are opening for read AND write, the comment is a trick!
>> Did you mean to put a filename in there somewhere?
>> You should use UPPER CASE for filehandles.
>> You should always, yes *always*, check the return value from open().
>
> I thought the + was to keep it from being clobbered..
It cannot be clobbered since your program never writes to that filehandle.
> Why does the return value matter?
Because it tells you whether you actually got what you asked for or not.
> Wouldn't it
> just open or fail (die)?
No. (so you should put the "or die" stuff in there yourself)
If you read from an unopen()ed filehandle, you get an immediate EOF,
it looks like the file is empty.
If you write to an unopen()ed filehandle, your output goes in
the bit bucket, ie. is lost.
warnings will complain for either of those cases, but you should
test the return value yourself so that you can exit more gracefully.
>>> while <file2> # loop while not eof in machines.cvs
>> Syntax error.
>> Show *real code*!
> Man this script was a piece.
Errr, right.
Have you seen the Posting Guidelines that are posted here frequently?
> does foreach only
> provide list context?
Yes.
Why do you ask?
Do you think you need something other than list context?
>>> $curr = %DRVSpace;
>> This most certainly does not do what you think it does.
>> The value of a hash in scalar context is not of interest to
>> a Perl programmer, it is only of interest to a perl programmer.
>
> So would it be $curr = /%DRVSpace to get the value of the key,
What happened when you tried it?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 9 Dec 2004 07:25:09 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regular expressions problem
Message-Id: <slrncrgkhl.91s.tadmc@magna.augustmail.com>
Shailesh Humbad <humbads1@hotmail.com> wrote:
> I want to parse the values from the second-to-last row in an html
> table.
use HTML::TableExtract;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 09 Dec 2004 08:52:28 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: regular expressions problem
Message-Id: <Gridnc6FXvsm6SXcRVn-hA@comcast.com>
Sherm Pendley wrote:
> The VBScript group is down the hall on your left. Don't let the door hit
> you on the way out.
Which, when translated, means...
Regular expressions in VBScript are different than regular expressions
in Perl. Any help we give you may not carry over into VBScript. Asking
in a Perl newsgroup about programming in VBScript is a waste of our time
and yours.
------------------------------
Date: 9 Dec 2004 11:32:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Seeking Internet Protection Service
Message-Id: <cp9d4i$pqv$2@mamenchi.zrz.TU-Berlin.DE>
[newsgroups trimmed]
Gerald Newton3 <electrician@nospam.com> wrote in comp.lang.perl.misc:
> I am willing to pay $3,000 per year for an Internet Protection Service.
[...]
Ah, the canadian electrician...
Anno
------------------------------
Date: 9 Dec 2004 07:31:38 -0800
From: alamukutty@gmail.com
Subject: Using MIME::Lite for multipart message - trouble with string manipulation
Message-Id: <1102606298.518074.181700@f14g2000cwb.googlegroups.com>
Hi,
I am pretty new to cgi-perl and I'm trying to process a form and
send the email using sendmail. I figured how to send attachments using
MIME::Lite and also figured how to process a form and send a plain
text mail like
for each param()
ParamName = Param vAlue
When I try to put the two together, I am stuck. I don't know how to
process strings with perl and any help will be appreciated.
For now, this is what I am trying and I get a server error.
----------------------
#! / usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use lib '/usr/lib/perl5/site_perl/5.8.0/MIME';
use MIME::Lite;
print start_html("Thank You");
# Set the PATH environment variable to the same path
# where sendmail is located:
$ENV{PATH} = "/usr/sbin";
# Now print the body of your mail message.
my $body_string;
foreach my $p (param()) {
$body_string = print "$p = ", param($p), "\n";
}
my $msg = MIME::Lite->new(
>From =>'webmas...@myhost.org',
To =>m...@myhost.org',
Subject =>'Form Data!',
Type =>'multipart/mixed',
);
$msg->attach(
Type => 'TEXT',
Data => $body_string );
$msg->attach(
Type =>'application/msword',
Path => '/usr/local/apache2/htdocs/checking.doc'
);
$msg->send();
# Be sure to close the MAIL input stream so that the
# message actually gets mailed.
# Now print a thank-you page
print <<EndHTML;
<h2>Thank You</h2>
<p>Your information has been submitted.</p>
<p>Return to our <a href="index.htm">home page</a>.</p>
EndHTML
print end_html;
----------
Thanks in advance.
AK
------------------------------
Date: 9 Dec 2004 11:54:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: why the following HereDoc print don't work?
Message-Id: <cp9eco$pqv$4@mamenchi.zrz.TU-Berlin.DE>
Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> A. Sinan Unur wrote:
>
> > "bingfeng" <zhao_bingfeng@topsec.com.cn> wrote in
> > news:cp8arq$2649$1@mail.cn99.com:
> >
> >
> >>The following codes does not work still:
> >>
> >><CODE>
> >>use strict;
> >>use warnings;
> >>
> >>print <<EOF;
> >>Help text:
> >>Command line is:
> >>Datecheck [options] <files> [<files>...]
> >>where:
> >> [Option] are to be defined
> >>EOF
> >></CODE>
> >
> >
> > Funny ... odd ... curious ...
>
> ... and correct. I copy everything up to and including the EOF - but
> *NOT* the newline after EOF - into a text file and run it. What do I see?
>
> Sherm-Pendleys-Computer:~ sherm$ perl test.pl
> Can't find string terminator "EOF" anywhere before EOF at test.pl line 6.
>
> Now I add a newline to the end, after EOF, and what do I see?
>
> Sherm-Pendleys-Computer:~ sherm$ perl test.pl
> Help text:
> Command line is:
> Datecheck [options] <files> [<files>...]
> where:
> [Option] are to be defined
>
I cannot reproduce this with v5.8.1, but if it is the reason then
it *is* arguably a bug in (some version of) Perl. The final line
feed shouldn't matter.
Anno
------------------------------
Date: 9 Dec 2004 13:58:56 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <Xns95BA5B5FDCA44asu1cornelledu@132.236.56.8>
Sherm Pendley <spamtrap@dot-app.org> wrote in news:t4qdndRySqsYjCXcRVn-
hw@adelphia.com:
> A. Sinan Unur wrote:
>
>> "bingfeng" <zhao_bingfeng@topsec.com.cn> wrote in
>> news:cp8arq$2649$1@mail.cn99.com:
>>
>>
>>>The following codes does not work still:
>>>
>>><CODE>
>>>use strict;
>>>use warnings;
>>>
>>>print <<EOF;
>>>Help text:
>>>Command line is:
>>>Datecheck [options] <files> [<files>...]
>>>where:
>>> [Option] are to be defined
>>>EOF
>>></CODE>
>>
>>
>> Funny ... odd ... curious ...
>
> ... and correct. I copy everything up to and including the EOF - but
> *NOT* the newline after EOF - into a text file and run it. What do I
> see?
A-ha! I was using Gvim and I think my settings ensure that there is
always a newline there. So, I went and did what you describe above using
Notepad this time:
C:\Home> perl -v
This is perl, v5.8.4 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)
C:\Home> cat t.pl
use strict;
use warnings;
print <<EOF;
Help text:
Command line is:
Datecheck [options] <files> [<files>...]
where:
[Option] are to be defined
EOF
C:\Home> perl t.pl
Can't find string terminator "EOF" anywhere before EOF at t.pl line 4.
You are right.
Sinan
------------------------------
Date: Thu, 9 Dec 2004 07:40:42 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <slrncrgleq.91s.tadmc@magna.augustmail.com>
Sherm Pendley <spamtrap@dot-app.org> wrote:
> Tad McClellan wrote:
>
>> You can most often answer questions about messages from perl if
>> you read up on the message in perldiag.pod.
>
> Excellent advice for the general case, but in this case specifically it
> looks to me like perldiag is missing a critical bit of info that might
> have been helpful:
We should be able to assume that the documentation for here-docs
has been consulted when debugging a problem related to here-docs.
So the critical bit of info is in perlop.pod, though it could be
more explicit in either place...
>> If you're getting this error from a here-document, you may have included
>> unseen whitespace before or after your closing tag.
>
> ... or, the closing tag might be at the end of the file, on a line that
> doesn't end with a newline character.
If it doesn't end with a newline, we shouldn't be calling it "a line"
(maybe "chunk" or "input"?).
=head2 Quote and Quote-like Operators
...
The terminating string must appear by itself (unquoted and
with no surrounding whitespace) on the terminating line.
ie. it won't work if the closing tag is not on a (real) "line".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 09 Dec 2004 16:32:53 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <yzd653bmqqi.fsf@invalid.net>
Tad McClellan <tadmc@augustmail.com> writes:
> Sherm Pendley <spamtrap@dot-app.org> wrote:
> > Tad McClellan wrote:
> >
> >> You can most often answer questions about messages from perl if
> >> you read up on the message in perldiag.pod.
> >
> > Excellent advice for the general case, but in this case specifically it
> > looks to me like perldiag is missing a critical bit of info that might
> > have been helpful:
>
>
> We should be able to assume that the documentation for here-docs
> has been consulted when debugging a problem related to here-docs.
>
> So the critical bit of info is in perlop.pod, though it could be
> more explicit in either place...
>
>
> >> If you're getting this error from a here-document, you may have included
> >> unseen whitespace before or after your closing tag.
> >
> > ... or, the closing tag might be at the end of the file, on a line that
> > doesn't end with a newline character.
>
>
> If it doesn't end with a newline, we shouldn't be calling it "a line"
> (maybe "chunk" or "input"?).
>
>
> =head2 Quote and Quote-like Operators
> ...
> The terminating string must appear by itself (unquoted and
> with no surrounding whitespace) on the terminating line.
>
>
> ie. it won't work if the closing tag is not on a (real) "line".
There are programs that work if the final line is not ended by a
newline. The above text alone does not indicate that the terminating
line must be ended by a newline - it depends on the notion of "line"
used.
The name itself does not prove much, but is an indication: both
"newline" and "linefeed" seem to say something about the _next_ line,
not that the current line is ended.
There is more than one Unix program that does not work if the final
line is not newline-terminated ('sed' for example), so it's probably a
good habit to conform to the "a line is always newline-terminated"
school when you produce text files.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7500
***************************************