[31032] in Perl-Users-Digest
Perl-Users Digest, Issue: 2277 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 16 03:09:41 2009
Date: Mon, 16 Mar 2009 00:09:06 -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, 16 Mar 2009 Volume: 11 Number: 2277
Today's topics:
Re: How to set the message displayed when a Perl Script <noreply@gunnar.cc>
Re: How to set the message displayed when a Perl Script <noreply@gunnar.cc>
Re: How to set the message displayed when a Perl Script <schaitan@gmail.com>
Re: Most efficient way to do set-comparison sln@netherlands.com
new CPAN modules on Mon Mar 16 2009 (Randal Schwartz)
Why can I not name my own formats? <elhmbre@ozemail.com.au>
Re: Why can I not name my own formats? cmic@live.fr
Re: Why can I not name my own formats? <elhmbre@ozemail.com.au>
Re: Why can I not name my own formats? <tadmc@seesig.invalid>
Re: Why can I not name my own formats? <ben@morrow.me.uk>
Re: Why can I not name my own formats? <eric.amick@verizon.net>
Re: Why can I not name my own formats? <elhmbre@ozemail.com.au>
Re: Why can I not name my own formats? <elhmbre@ozemail.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 15 Mar 2009 08:37:02 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to set the message displayed when a Perl Script fails compilation?
Message-Id: <723ph7Fn19tdU1@mid.individual.net>
Nigel wrote:
> My problem is with the message that is displayed in a web browser when
> a script fails compilation. At the moment I'm getting this:
>
> For help, please send mail to the webmaster ([no address given]),
> giving this error message and the time and date of the error.
>
> At least, I'd like to know how to set the email address for the
> webmaster instead of no address given.
>
> Ideally I'd like to handle the failed compilation in some way that
> would allow me to display a friendly page to my visitor and send me an
> email to alert me to the problem.
>
> Has anyone got any ideas? Apart that is from not uploading scripts
> that don't compile! ;-)
Assuming Apache, this might be helpful:
http://httpd.apache.org/docs/2.0/mod/core.html#errordocument
Redirect to another script (that compiles...) and have it both send an
email alert to you and print a friendly message.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 15 Mar 2009 20:36:56 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to set the message displayed when a Perl Script fails compilation?
Message-Id: <7253n3Fo3qkrU1@mid.individual.net>
Krishna Chaitanya wrote:
> Hi, I don't know if this is going to help you....but read up on
> fatalsToBrowser ...
That feature
1) might reveal sensitive information,
2) does typically not display "a friendly page" to a visitor, and
3) does not alert the script author if the error happens when a visitor
uses the script.
In short, it's not what the OP asked for.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 15 Mar 2009 11:59:11 -0700 (PDT)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: How to set the message displayed when a Perl Script fails compilation?
Message-Id: <269a8d98-8f2d-4912-8ccf-ed0d180beda7@p2g2000prf.googlegroups.com>
Hi, I don't know if this is going to help you....but read up on
fatalsToBrowser ...
------------------------------
Date: Mon, 16 Mar 2009 06:57:16 GMT
From: sln@netherlands.com
Subject: Re: Most efficient way to do set-comparison
Message-Id: <2msrr49ebkhs6fiia8ololseoovee1nf8o@4ax.com>
On Sat, 14 Mar 2009 21:10:26 GMT, sln@netherlands.com wrote:
>On Fri, 13 Mar 2009 06:05:56 -0700 (PDT), Krishna Chaitanya <schaitan@gmail.com> wrote:
>
>>Hi all,
>>
>>If set A defined elements a,b,c (a set of permissible program options,
>>let's say), and we receive from user options in set B.
>>
>>I want to make sure that user options in B are exactly same as those
>>defined in A .... nothing more, nothing less and completely
>>identical....this represents some kinda set operation if I'm not
>>wrong...
>>
>>A U B = A
>>A int B = A
>>
>>How to do this most efficiently in Perl...?
>
>You seem (in another post under this thread) to want more than just intersection
>and equality. There is no real efficient way to do this under any language, but
>if you want to report over/under relationships, this may help.
>
>This is one approach. There may be more generalization that could be done,
>perhaps combining all the mappings into one array. Certainly though, there
>is no one-liner hiding for this problem.
>
So this is possible. There is getOptions() and getOptionsNoCase().
I found it interresting for my own use and, I thought I would drop
it back into here for anybody elses use. All mappings are now in one array,
and only one function call is needed per comparison of parameter pairs.
Since all the parts are broken out, there is many possibilities available
for error reporting. If the rigid standards are removed (its just interpretation),
the array of common parameter keys can be silently processed quite easily.
That is of interrest to me.
-sln
======================================
## options3.pl
##
use strict;
use warnings;
# indexes, if fully referenced option is needed
use constant OPT_LEGAL_ONLY => 0;
use constant OPT_USER_ONLY => 1;
use constant OPT_ALL => 2;
use constant OPT_COMMON => 3;
sub getOptions {
my ($legal, $user) = @_;
my @options = ([],[],[],[]);
# -- 'user only' and common
my %legalonly = %{ $legal };
for ( sort keys %{ $user } ) {
push @{ !exists $legal->{ $_ } ? $options[1] : $options[3] }, $_;
delete $legalonly{ $_ };
}
# -- legal only
@{ $options[0] } = sort keys %legalonly;
# -- all
@{ $options[2] } = sort keys %{ { map { $_ => 1 } (keys %{ $legal }, keys %{ $user }) } };
@options;
}
sub getOptionsNoCase {
my ($l, $u) = @_;
my $legal = { map { lc $_, 1 } keys %{ $l } };
my $user = { map { lc $_, 1 } keys %{ $u } };
getOptions( $legal, $user );
}
##
my $Debug = 1;
my %legalopts = (a => 1, b => 1, c => 1, d => 1);
my %useropts = (a => 1, c => 1, e => 1, f => 1, g => 1);
#my %useropts = (a => 1, b => 1, c => 1, d => 1); # try a sucessfull match
my ($legalonly, $useronly, $all, $common) = getOptions ( \%legalopts, \%useropts );
if ( $Debug ) {
print "\nDebug:\n";
print "All - ",@$all, ", elements = ", scalar(@$all), "\n";
print "Legal missing/non-matching - ",@$legalonly,", elements = ", scalar(@$legalonly), "\n";
print "User too many/non-matching - ",@$useronly, ", elements = ", scalar(@$useronly), "\n";
print "Common matching - ",@$common, ", elements = ", scalar(@$common), "\n";
}
if ( @$legalonly || @$useronly ) {
print "\nError:\n";
print "Legal options are '",( sort keys %legalopts ),"'\n";
print "Missing legal user options '",@$legalonly,"'\n" if (@$legalonly);
print "Non-legal user options '",@$useronly,"'\n" if (@$useronly);
} else {
print "\nSucessfully enterred legal options '",( sort keys %useropts ),"' !\n"
}
__END__
output:
-------
Debug:
All - abcdefg, elements = 7
Legal missing/non-matching - bd, elements = 2
User too many/non-matching - efg, elements = 3
Common matching - ac, elements = 2
Error:
Legal options are 'abcd'
Missing legal user options 'bd'
Non-legal user options 'efg'
------------------------------
Date: Mon, 16 Mar 2009 04:42:25 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Mar 16 2009
Message-Id: <KGL12p.124r@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Acme-Blarghy-McBlarghBlargh-0.002
http://search.cpan.org/~dhoss/Acme-Blarghy-McBlarghBlargh-0.002/
----
Acme-Blarghy-McBlarghBlargh-0.0021
http://search.cpan.org/~dhoss/Acme-Blarghy-McBlarghBlargh-0.0021/
----
Acme-Blarghy-McBlarghBlargh-0.0022
http://search.cpan.org/~dhoss/Acme-Blarghy-McBlarghBlargh-0.0022/
----
Authen-DecHpwd-2.004
http://search.cpan.org/~zefram/Authen-DecHpwd-2.004/
DEC VMS password hashing
----
Barcode-Zebra-0.1
http://search.cpan.org/~spadix/Barcode-Zebra-0.1/
Perl interface to the Zebra Barcode Reader Library
----
Bio-Graphics-1.89
http://search.cpan.org/~lds/Bio-Graphics-1.89/
Generate GD images of Bio::Seq objects
----
Bio-Graphics-1.90
http://search.cpan.org/~lds/Bio-Graphics-1.90/
Generate GD images of Bio::Seq objects
----
ChainMake-0.9.0
http://search.cpan.org/~schroeer/ChainMake-0.9.0/
Make targets with dependencies
----
Champlain-0.01
http://search.cpan.org/~potyl/Champlain-0.01/
Map rendering canvas
----
Collection-0.43
http://search.cpan.org/~zag/Collection-0.43/
Collections framework for CRUD of the data or objects.
----
Convert-Binary-C-0.72
http://search.cpan.org/~mhx/Convert-Binary-C-0.72/
Binary Data Conversion using C Types
----
DBD-Google-0.51
http://search.cpan.org/~darren/DBD-Google-0.51/
Treat Google as a datasource for DBI
----
DBE-0.99_1
http://search.cpan.org/~chrmue/DBE-0.99_1/
Database (Express) Engine for Perl
----
DBI-Easy-0.02
http://search.cpan.org/~apla/DBI-Easy-0.02/
yet another perl ORM for SQL databases
----
Devel-PPPort-3.17
http://search.cpan.org/~mhx/Devel-PPPort-3.17/
Perl/Pollution/Portability
----
Filter-Arguments-0.04
http://search.cpan.org/~dylan/Filter-Arguments-0.04/
Configure and read your command line arguments from @ARGV.
----
GRID-Machine-0.102
http://search.cpan.org/~casiano/GRID-Machine-0.102/
Remote Procedure Calls over a SSH link
----
IO-Easy-0.02
http://search.cpan.org/~apla/IO-Easy-0.02/
is easy to use class for operations with filesystem objects.
----
JavaScript-Packer-0.01_01
http://search.cpan.org/~nevesenin/JavaScript-Packer-0.01_01/
Perl version of Dean Edwards' Packer.js
----
Jcode-CP932-0.07
http://search.cpan.org/~asakura/Jcode-CP932-0.07/
----
Jcode-CP932-0.08
http://search.cpan.org/~asakura/Jcode-CP932-0.08/
----
Jifty-Plugin-Gravatar-0.02
http://search.cpan.org/~cornelius/Jifty-Plugin-Gravatar-0.02/
Jifty Plugin for Gravatar Icon Service
----
Mail-Chimp-0.11
http://search.cpan.org/~dpirotte/Mail-Chimp-0.11/
Perl wrapper around the Mailchimp v1.1 API
----
Marpa-0.001_003
http://search.cpan.org/~jkegl/Marpa-0.001_003/
General BNF Parsing (Experimental version)
----
Math-GSL-0.17_02
http://search.cpan.org/~leto/Math-GSL-0.17_02/
Perl interface to the GNU Scientific Library (GSL)
----
MouseX-ConfigFromFile-0.03
http://search.cpan.org/~masaki/MouseX-ConfigFromFile-0.03/
An abstract Mouse role for setting attributes from a configfile
----
MouseX-Types-Path-Class-0.05
http://search.cpan.org/~masaki/MouseX-Types-Path-Class-0.05/
A Path::Class type library for Mouse
----
Net-OAuth-Simple-0.5
http://search.cpan.org/~simonw/Net-OAuth-Simple-0.5/
a simple wrapper round the OAuth protocol
----
Net-OAuth-Simple-0.6
http://search.cpan.org/~simonw/Net-OAuth-Simple-0.6/
a simple wrapper round the OAuth protocol
----
Net-Oping-1.10
http://search.cpan.org/~octo/Net-Oping-1.10/
ICMP latency measurement module using the oping library.
----
POE-XS-Queue-Array-0.005_02
http://search.cpan.org/~tonyc/POE-XS-Queue-Array-0.005_02/
an XS implementation of POE::Queue::Array.
----
Search-Xapian-1.0.11.0
http://search.cpan.org/~olly/Search-Xapian-1.0.11.0/
Perl XS frontend to the Xapian C++ search library.
----
Shipwright-2.1.5
http://search.cpan.org/~sunnavy/Shipwright-2.1.5/
Best Practical Builder
----
Simo-Wrapper-0.0220
http://search.cpan.org/~kimoto/Simo-Wrapper-0.0220/
Wrapper class to manipulate object.
----
Socket-Class-2.0
http://search.cpan.org/~chrmue/Socket-Class-2.0/
A class to communicate with sockets
----
Socket-Class-2.01
http://search.cpan.org/~chrmue/Socket-Class-2.01/
A class to communicate with sockets
----
Socket-Class-2.02
http://search.cpan.org/~chrmue/Socket-Class-2.02/
A class to communicate with sockets
----
Socket-Class-SSL-1.0
http://search.cpan.org/~chrmue/Socket-Class-SSL-1.0/
SSL support for Socket::Class
----
Sys-Statistics-Linux-0.49
http://search.cpan.org/~bloonix/Sys-Statistics-Linux-0.49/
Front-end module to collect system statistics
----
Test-DistManifest-1.1.2
http://search.cpan.org/~frequency/Test-DistManifest-1.1.2/
Tests that your MANIFEST matches the distribution as it exists, excluding those in your MANIFEST.SKIP
----
Text-Mining-0.08
http://search.cpan.org/~rogerhall/Text-Mining-0.08/
Perl Tools for Text Mining Research
----
Thread-Cleanup-0.01
http://search.cpan.org/~vpit/Thread-Cleanup-0.01/
Hook thread destruction.
----
Video-FrameGrab-0.03
http://search.cpan.org/~mschilli/Video-FrameGrab-0.03/
Grab a frame or metadata from a video
----
WWW-Shorten-PunyURL-0.01
http://search.cpan.org/~pfig/WWW-Shorten-PunyURL-0.01/
An interface to SAPO's URL shortening service
----
lib-0.62
http://search.cpan.org/~smueller/lib-0.62/
manipulate @INC at compile time
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Sun, 15 Mar 2009 17:59:11 +1000
From: "elhombre" <elhmbre@ozemail.com.au>
Subject: Why can I not name my own formats?
Message-Id: <49bcb57e$0$5623$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
The following code attempts to create a report of any line created by diff
in the format nnnannn, 10c10, 10a11 etc. However perl complains about
"write() on unopened filehandle OUTPUT ", however I'm not writing to the
filehandle, I'm trying to write to the defined format which I understand has
its own namespace?
I'm not using STDOUT for this section as that is used for the first part of
the report that lists the file sizes, number of words etc.
Any hints?
Thanks in advance.
use English;
#Check that the correct number of arguments are passed to the interpreter
if($#ARGV != 1) {
print "usage : levelA.pl file1 file2";
exit;
}
system("diff -l -w $ARGV[0] $ARGV[1] > output.txt"); #For *nix
#now report the lines that are different
open(OUTPUT_FILE, "output.txt") or die "File $_ does not exist";
my $FORMAT_NAME = "OUTPUT";
my $FORMAT_TOP_NAME = "OUTPUT_TOP";
while (our $ln = <OUTPUT_FILE>) {
if($ln =~ m/^[0-9]*[a c][0-9]*/) {
write OUTPUT;
}
}
format OUTPUT_TOP =
line
------------------------------------------------
.
format OUTPUT =
@<<<<<<<<<<<<<<<<<<<<<<<<
our $ln
.
------------------------------
Date: Sun, 15 Mar 2009 06:07:17 -0700 (PDT)
From: cmic@live.fr
Subject: Re: Why can I not name my own formats?
Message-Id: <ecd9e5be-acc1-4249-aec8-362911f10475@a12g2000yqm.googlegroups.com>
Hello
On 15 mar, 08:59, "elhombre" <elhm...@ozemail.com.au> wrote:
> The following code attempts to create a report of any line created by dif=
f
> in the format nnnannn, 10c10, 10a11 etc. However perl complains about
> "write() on unopened filehandle OUTPUT ", however I'm not writing to the
> filehandle, I'm trying to write to the defined format which I understand =
has
> its own namespace?
>
> I'm not using STDOUT for this section as that is used for the first part =
of
> the report that lists the file sizes, number of words etc.
>
> Any hints?
Yes. You should assign the format to $~, (the name of the current
report format) then write
Provided your formats are complete with the variables you want to
output, you could write somethink like :
local $~=3D"OUTPUT_TOP";
write;
local $~=3D"OUTPUT";
write;
rgds
--
michel marcon aka cmic
>
> Thanks in advance.
>
> use English;
> #Check that the correct number of arguments are passed to the interpreter
> if($#ARGV !=3D 1) {
> =A0 =A0 print "usage : levelA.pl file1 file2";
> =A0 =A0 exit;}
>
> system("diff -l -w $ARGV[0] $ARGV[1] > output.txt"); =A0#For *nix
> #now report the lines that are different
> open(OUTPUT_FILE, "output.txt") or die "File $_ does not exist";
> my $FORMAT_NAME =3D "OUTPUT";
> my $FORMAT_TOP_NAME =3D "OUTPUT_TOP";
> while (our $ln =3D <OUTPUT_FILE>) {
> =A0 =A0 if($ln =3D~ m/^[0-9]*[a c][0-9]*/) {
> =A0 =A0 =A0 =A0 write OUTPUT;
> =A0 =A0 }}
>
> format OUTPUT_TOP =3D
> line
> ------------------------------------------------
> .
> format OUTPUT =3D
> @<<<<<<<<<<<<<<<<<<<<<<<<
> our $ln
> .
------------------------------
Date: Sun, 15 Mar 2009 23:48:59 +1000
From: "elhombre" <elhmbre@ozemail.com.au>
Subject: Re: Why can I not name my own formats?
Message-Id: <49bd0777$0$5589$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
<>> Any hints?
> Yes. You should assign the format to $~, (the name of the current
> report format) then write
> Provided your formats are complete with the variables you want to
> output, you could write somethink like :
>
> local $~="OUTPUT_TOP";
> write;
> local $~="OUTPUT";
> write;
>
> rgds
> --
> michel marcon aka cmic
>
Thanks Michel. I would never have figured this out on my own. I have a lot
to learn about this cryptic language.
------------------------------
Date: Sun, 15 Mar 2009 08:57:11 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Why can I not name my own formats?
Message-Id: <slrngrq29n.sc8.tadmc@tadmc30.sbcglobal.net>
elhombre <elhmbre@ozemail.com.au> wrote:
> The following code attempts to create a report of any line created by diff
> in the format nnnannn, 10c10, 10a11 etc. However perl complains about
> "write() on unopened filehandle OUTPUT ", however I'm not writing to the
> filehandle,
Yes you are.
> I'm trying to write to the defined format which I understand has
> its own namespace?
You cannot write() to a format, you can only write() to a filehandle.
> Any hints?
open() an OUTPUT filehandle.
open OUTPUT, '>', 'report_out.txt' or
die "could not open 'report_out.txt' $!";
> use English;
Why have you included this module?
You do not make use of it anywhere...
> #Check that the correct number of arguments are passed to the interpreter
> if($#ARGV != 1) {
> print "usage : levelA.pl file1 file2";
> exit;
> }
Error messages should go to STDERR, not STDOUT.
Programs that encounter an error should have a NON-zero exit value.
Using an array in scalar context is easier to understand that
the funky $#array syntax.
You can replace that entire if block with:
warn "usage : levelA.pl file1 file2" unless @ARGV == 2;
> system("diff -l -w $ARGV[0] $ARGV[1] > output.txt"); #For *nix
> #now report the lines that are different
> open(OUTPUT_FILE, "output.txt") or die "File $_ does not exist";
^^
^^
What value do you expect $_ to have at this point in your program?
You should include the $! special variable in your error message.
There is no need for the output.txt intermediate file, unless
you happen to need it for something else.
You should choose accurate descriptive names for your filehandles.
open DIFF_OUT, "diff -l -w @ARGV|" or die "problem running diff $!";
> my $FORMAT_NAME = "OUTPUT";
> my $FORMAT_TOP_NAME = "OUTPUT_TOP";
What purpose do those assignments have?
You do not make use of those variables anywhere...
> while (our $ln = <OUTPUT_FILE>) {
> if($ln =~ m/^[0-9]*[a c][0-9]*/) {
That will match lines that have no digit characters at all.
It will match lines that start with a space character.
It will not match the diff output for lines that were deleted.
if ( $ln =~ m/^[0-9]+[acd][0-9]+$/ ) {
> write OUTPUT;
perldoc -f write
shows that write() may be called in one of three ways:
write FILEHANDLE
write EXPR
write
You are using the 1st way, where you need to provide a filehandle.
> }
> }
> format OUTPUT_TOP =
> line
> ------------------------------------------------
> .
> format OUTPUT =
> @<<<<<<<<<<<<<<<<<<<<<<<<
> our $ln
> .
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 15 Mar 2009 15:13:13 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Why can I not name my own formats?
Message-Id: <9hiv86-jo1.ln1@osiris.mauzo.dyndns.org>
Quoth Tad J McClellan <tadmc@seesig.invalid>:
> elhombre <elhmbre@ozemail.com.au> wrote:
>
> > use English;
>
>
> Why have you included this module?
>
> You do not make use of it anywhere...
>
<snip>
>
> > my $FORMAT_NAME = "OUTPUT";
> > my $FORMAT_TOP_NAME = "OUTPUT_TOP";
>
>
> What purpose do those assignments have?
>
> You do not make use of those variables anywhere...
The OP has presumably not realised that the variables in perlvar must
not be declared with 'my'. $::FORMAT_NAME is aliased by English to $~,
which is what he actually should be setting; ditto $FORMAT_TOP_NAME and
$^.
To the OP: I would recommend you avoid formats and 'write'. They aren't
much used now, which means you still need to use perl4-style cryptic
global variables to control them. If your case, it looks like 'sprintf'
will do what you want; in general, a good, flexible replacement for
'write' is the Perl6::Form module. Don't be put off by the 'Perl6' in
the name, it's simply emulating a useful Perl 6 builtin in Perl 5.
Ben
------------------------------
Date: Sun, 15 Mar 2009 13:01:00 -0400
From: Eric Amick <eric.amick@verizon.net>
Subject: Re: Why can I not name my own formats?
Message-Id: <pmcqr411mv4jkga1jr0e6pupft61mh7bv0@4ax.com>
On Sun, 15 Mar 2009 17:59:11 +1000, "elhombre" <elhmbre@ozemail.com.au>
wrote:
>The following code attempts to create a report of any line created by diff
>in the format nnnannn, 10c10, 10a11 etc. However perl complains about
>"write() on unopened filehandle OUTPUT ", however I'm not writing to the
>filehandle, I'm trying to write to the defined format which I understand has
>its own namespace?
>
>I'm not using STDOUT for this section as that is used for the first part of
>the report that lists the file sizes, number of words etc.
>
>Any hints?
>
>Thanks in advance.
The argument to write() is the filehandle name, not the format name. The
simplest fix would be changing the filehandle's name in the rest of the
code to OUTPUT.
--
Eric Amick
Columbia, MD
------------------------------
Date: Mon, 16 Mar 2009 10:22:18 +1000
From: "elhombre" <elhmbre@ozemail.com.au>
Subject: Re: Why can I not name my own formats?
Message-Id: <49bd9bd8$0$5587$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Thank you Tad !
"Tad J McClellan" <tadmc@seesig.invalid> wrote in message
news:slrngrq29n.sc8.tadmc@tadmc30.sbcglobal.net...
> elhombre <elhmbre@ozemail.com.au> wrote:
>> The following code attempts to create a report of any line created by
>> diff
>> in the format nnnannn, 10c10, 10a11 etc. However perl complains about
>> "write() on unopened filehandle OUTPUT ", however I'm not writing to the
>> filehandle,
>
>
> Yes you are.
>
>
>> I'm trying to write to the defined format which I understand has
>> its own namespace?
>
>
> You cannot write() to a format, you can only write() to a filehandle.
>
>
>> Any hints?
>
>
> open() an OUTPUT filehandle.
>
> open OUTPUT, '>', 'report_out.txt' or
> die "could not open 'report_out.txt' $!";
>
>
>> use English;
>
>
> Why have you included this module?
>
> You do not make use of it anywhere...
>
>
>> #Check that the correct number of arguments are passed to the interpreter
>> if($#ARGV != 1) {
>> print "usage : levelA.pl file1 file2";
>> exit;
>> }
>
>
> Error messages should go to STDERR, not STDOUT.
>
> Programs that encounter an error should have a NON-zero exit value.
>
> Using an array in scalar context is easier to understand that
> the funky $#array syntax.
>
> You can replace that entire if block with:
>
> warn "usage : levelA.pl file1 file2" unless @ARGV == 2;
>
>
>> system("diff -l -w $ARGV[0] $ARGV[1] > output.txt"); #For *nix
>> #now report the lines that are different
>> open(OUTPUT_FILE, "output.txt") or die "File $_ does not exist";
> ^^
> ^^
>
> What value do you expect $_ to have at this point in your program?
>
> You should include the $! special variable in your error message.
>
> There is no need for the output.txt intermediate file, unless
> you happen to need it for something else.
>
> You should choose accurate descriptive names for your filehandles.
>
>
> open DIFF_OUT, "diff -l -w @ARGV|" or die "problem running diff $!";
>
>
>> my $FORMAT_NAME = "OUTPUT";
>> my $FORMAT_TOP_NAME = "OUTPUT_TOP";
>
>
> What purpose do those assignments have?
>
> You do not make use of those variables anywhere...
>
>
>> while (our $ln = <OUTPUT_FILE>) {
>> if($ln =~ m/^[0-9]*[a c][0-9]*/) {
>
>
> That will match lines that have no digit characters at all.
>
> It will match lines that start with a space character.
>
> It will not match the diff output for lines that were deleted.
>
> if ( $ln =~ m/^[0-9]+[acd][0-9]+$/ ) {
>
>
>> write OUTPUT;
>
>
> perldoc -f write
>
> shows that write() may be called in one of three ways:
> write FILEHANDLE
> write EXPR
> write
>
> You are using the 1st way, where you need to provide a filehandle.
>
>
>> }
>> }
>> format OUTPUT_TOP =
>> line
>> ------------------------------------------------
>> .
>> format OUTPUT =
>> @<<<<<<<<<<<<<<<<<<<<<<<<
>> our $ln
>> .
>
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 16 Mar 2009 10:24:00 +1000
From: "elhombre" <elhmbre@ozemail.com.au>
Subject: Re: Why can I not name my own formats?
Message-Id: <49bd9c3e$0$5618$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Thank you Ben. I'm looking at ::Form now. Much appreciated.
"Ben Morrow" <ben@morrow.me.uk> wrote in message
news:9hiv86-jo1.ln1@osiris.mauzo.dyndns.org...
>
> Quoth Tad J McClellan <tadmc@seesig.invalid>:
>> elhombre <elhmbre@ozemail.com.au> wrote:
>>
>> > use English;
>>
>>
>> Why have you included this module?
>>
>> You do not make use of it anywhere...
>>
> <snip>
>>
>> > my $FORMAT_NAME = "OUTPUT";
>> > my $FORMAT_TOP_NAME = "OUTPUT_TOP";
>>
>>
>> What purpose do those assignments have?
>>
>> You do not make use of those variables anywhere...
>
> The OP has presumably not realised that the variables in perlvar must
> not be declared with 'my'. $::FORMAT_NAME is aliased by English to $~,
> which is what he actually should be setting; ditto $FORMAT_TOP_NAME and
> $^.
>
> To the OP: I would recommend you avoid formats and 'write'. They aren't
> much used now, which means you still need to use perl4-style cryptic
> global variables to control them. If your case, it looks like 'sprintf'
> will do what you want; in general, a good, flexible replacement for
> 'write' is the Perl6::Form module. Don't be put off by the 'Perl6' in
> the name, it's simply emulating a useful Perl 6 builtin in Perl 5.
>
> Ben
>
------------------------------
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 V11 Issue 2277
***************************************