[23054] in Perl-Users-Digest
Perl-Users Digest, Issue: 5275 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 26 14:07:20 2003
Date: Sat, 26 Jul 2003 11: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 Sat, 26 Jul 2003 Volume: 10 Number: 5275
Today's topics:
Re: "theory vs practice" ceases power <ed@membled.com>
can't kill child process - program hangs up <jwall@t-online.de>
Re: can't kill child process - program hangs up <shawn@magma.ca>
Re: DBI: oralce DBD drivers <pm@katz.cc.univie.ac.at>
Re: document ID tracking (slash)
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Re: How to find out installed packages on Unix <noreply@gunnar.cc>
iHL =?Big5?B?ue+n3KSjtLqu8A==?= iHL <sohoman@yahoo.com>
Re: Is there a clean way to export all constants from a <REMOVEsdnCAPS@comcast.net>
Re: module and $ARGV help <eric-amick@comcast.net>
Re: module and $ARGV help <grazz@pobox.com>
Re: module and $ARGV help <grazz@pobox.com>
Perl lib version (v5.6.0) doesn't match executable vers (Francesco Moi)
Re: Pesky added line <krahnj@acm.org>
Re: Pesky added line <wasell@bahnhof.se>
script redirect 2 hotmail <sheukels=cuthere=@yahoo.co.uk>
script redirect 2 hotmail <sheukels=cuthere=@yahoo.co.uk>
Re: UTF-8 module <julian@mehnle.net>
Re: UTF-8 module <flavell@mail.cern.ch>
Re: Where to hitch the <<EOF to plaster input file? <eric-amick@comcast.net>
Re: Where to hitch the <<EOF to plaster input file? (Tad McClellan)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Jul 2003 09:58:44 +0100
From: Ed Avis <ed@membled.com>
Subject: Re: "theory vs practice" ceases power
Message-Id: <l18yql64vv.fsf@budvar.future-i.net>
"Dave Benjamin" <dave@3dex.com> writes:
>Perl supports anonymous subrotines, closures, map/filter, currying,
Currying - hardly. You _can_ do it:
sub curry( $ ) {
my $f = $_[0];
sub( $ ) { my $x = $_[0]; sub( $ ) { $f->($x, $_[0]) } };
}
sub uncurry( $ ) {
my $f = $_[0];
sub( $$ ) { $f->($_[0])->($_[1]) };
}
sub plus( $$ ) { $_[0] + $_[1] }
my $plus_curried = curry(\&plus);
my $plus_five = $plus_curried->(5);
print $plus_five->(1), "\n";
but no libraries are written in a curried style. You cannot, for
example, partially apply the 'map' function to get the function that
adds 1 to every element of a list. Not unless you write the necessary
machinery yourself.
>but there's no reason Perl has to be an "imperative language", at
>least no more than OCaml is, since it provides imperative features as
>well.
But most 'functional languages', even if they are not pure, usually
provide help for the functional style. With type checking, or a
reasonably clean syntax, or things like function composition in the
standard library. With Perl the syntax is not that clean (though
manageable once you get used to it) but the lack of any strong type
checking does make life difficult for complex programs.
A rudimentary Scheme-to-Perl translator is at
<http://www.venge.net/graydon/scm2p.html>. It doesn't have
continuations, but I think it does manage closures (since Perl
supports them). I think the vapourware Perl 6 will have
continuations, I don't know if it's possible to get them in Perl 5.
--
Ed Avis <ed@membled.com>
------------------------------
Date: Sat, 26 Jul 2003 11:48:32 +0200
From: "Jochen Wall" <jwall@t-online.de>
Subject: can't kill child process - program hangs up
Message-Id: <bftipg$658$05$1@news.t-online.com>
Hi!
I tried to kill a "forked" child-process with the kill-signal(9). But the
last message on the screen is "father: I killed my child". The program
doesn't return to the command line "c:>_" and I have to kill it with CTRL+C.
What's wrong? Why does the program not terminate?
if ($pid=fork()) {
for ($i=0;$i<10;$i++) {print "father: I will repeat this 10 times and then
kill you\n";};
kill(9,$pid);
print "father: I killed my child\n";
}
else {
while(1){print "child: I will repeat this forever\n";}
}
------------------------------
Date: Sat, 26 Jul 2003 10:03:24 -0400
From: Shawn Corey <shawn@magma.ca>
Subject: Re: can't kill child process - program hangs up
Message-Id: <j7mcnWfw2s8MFL-iU-KYvA@magma.ca>
Hi,
I didn't know fork worked in M$ DOS. Try:
if( undefined( $pid = fork())){
print "Can't fork\n";
exit;
}elsif( $pid ){
...
Jochen Wall wrote:
> Hi!
>
> I tried to kill a "forked" child-process with the kill-signal(9). But the
> last message on the screen is "father: I killed my child". The program
> doesn't return to the command line "c:>_" and I have to kill it with CTRL+C.
> What's wrong? Why does the program not terminate?
>
> if ($pid=fork()) {
> for ($i=0;$i<10;$i++) {print "father: I will repeat this 10 times and then
> kill you\n";};
> kill(9,$pid);
> print "father: I killed my child\n";
> }
> else {
> while(1){print "child: I will repeat this forever\n";}
> }
>
>
------------------------------
Date: 26 Jul 2003 11:51:53 GMT
From: Peter Marksteiner <pm@katz.cc.univie.ac.at>
Subject: Re: DBI: oralce DBD drivers
Message-Id: <3f226b59$0$10836$3b214f66@usenet.univie.ac.at>
Vespasian <julie.spicer@verizon.net> wrote:
: When using DBI, will the latest oracle DBD drivers from cpan work with
: oracle 9i? Looks like the drivers only support oracle 7 and 8
Works fine here without any problems.
Peter
--
Peter Marksteiner
Vienna University Computer Center
------------------------------
Date: 26 Jul 2003 10:43:39 -0700
From: satishi@gwu.edu (slash)
Subject: Re: document ID tracking
Message-Id: <30fe9f1e.0307260943.1f4352b1@posting.google.com>
Thanks so much for all the helpful responses. (Sinan, this is not a HW
problem! :) I didn't get any helpful responses in another related
postiing so I am adding this as a followup here hoping that it will
get reviewed.
I am trying to improve an existing process that does ngrams and
document tracking in a rather complicated way. I tried integrating
your code with what I have so far but just couldn't find ways. I will
try to lay out what I am trying to do and what I have so far.
I am trying to add another column of data that carries the filename
from which the ngrams are being done. The reason for this is so that
my other script can pick it up later and do some other processing.
The program below parses a text file and performs an ngram on the word
level and I select certain columns for display. For hours I have been
trying to figure out how to add the documentID also at the end of each
line. Following is the code I am trying to improve:
use Text::Table;
undef $/;
my @words = split /\W+/, <> ;
my $line_number = 2;
my $n;
my $line_num = 2;
my $n_cols = 5;
my $col = { align => 'left'}; # no title, left alignment
my $tb = Text::Table->new( ( $col) x $n_cols);
my @stack = ( '*' ) x $n_cols;
foreach $word ( @words ) {
shift @stack;
push @stack, $word;
$tb->add(@stack);
}
my @lines = $tb->add("$stack[-4]", "$stack[-3]",
"$stack[-2]","$stack[1]", "*");
my @lines = $tb->add("$stack[-3]", "$stack[-2]", "$stack[-1]","*",
"*");
my @lines = $tb->table($line_number, $n);
#print @lines;
my $t1 = $tb->select(2, {is_sep => 2, body => " "}, 1,0,
{is_sep => 2, body => "\n"},
2, {is_sep =>2, body => " "}, 3,4);
#foreach $textID (@textID) {
#$t1 = $t1->add($ARGV); }#adds one data line at the end of ngrams not
a col
my $input = $t1->table($line_num, $n);
print $input;
What I get right now is this:
quick brown fox
brown quick
brown fox jumped
fox brown quick
fox jumped over
What I have been trying for hours is:
quick brown fox fox.txt
brown quick fox.txt
brown fox jumped fox.txt
fox brown quick fox.txt
fox jumped over fox.txt
This happens over multiple input files, so I will have fox.txt,
dog.txt, etc as my input but each branch in the output will have only
one document ID. SO,
perl -n script.pl *.TXT >branch_list
To recap, I don't know if I really need an inverted index. Perhaps an
array of arrays might help instead of the table module. Where I can
have @lines and $ARGV. Would that work? In other words, an array
consisting of the following:(first line of ngram, $ARGV)
(Second line of ngram, $ARGV)
.
.
.
(Last line of ngram, $ARGV)
And perhaps I could put this into a table and do the select statemetns
over them to display the desired output. Is this possible or I am just
dreaming?
Any suggestions on how to achieve this would be very much appreciated.
Thanks,
Slash
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns93C369C725FDAasu1cornelledu@132.236.56.8>...
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in
> news:Xns93C33D640AD40sdn.comcast@206.127.4.25:
>
> > "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in
> > news:Xns93C2A80F838A4asu1cornelledu@132.236.56.8:
> >
> >> if(exists $word_to_files{$word}) {
> >> unless(grep /$ARGV/, @{$word_to_files{$word}}) {
> >> push @{$word_to_files{$word}}, ($ARGV);
> >> }
> >> } else {
> >> $word_to_files{$word} = [$ARGV];
> >> }
> >
> > Why use an array as the second-level data structure -- why not a hash?
> >
> > $word_to_files{$word}{$ARGV} = 1;
>
> Muddled thinking I guess. And I do remember making a mental note of this
> when you pointed out the same thing in another thread, but it looks like
> I regarded that as just another deadline reminder :)
>
> Is this better?
>
> # cw: Common Word
> # Script to list words that appear in all the files
> # passed on the command line
>
> use diagnostics;
> use strict;
> use warnings;
>
> die "$0: file1 ... fileN\n" unless scalar @ARGV;
>
> my %word_to_files;
>
> while(<ARGV>) {
> chomp;
> my @words = split /\s+/;
> foreach (@words) {
> $word_to_files{$_}{$ARGV} = 1;
> }
> }
>
> foreach (sort keys %word_to_files) {
> print "$_: ", join(" ", keys %{$word_to_files{$_}}), "\n";
> }
>
> __END__
------------------------------
Date: 26 Jul 2003 10:23:53 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1059214963@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
XEmacs port is bundled in XEmacs setup.exe available from
XEmacs site.
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
<ilya@math.ohio-state.edu> Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr@ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Sat, 26 Jul 2003 19:09:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to find out installed packages on Unix
Message-Id: <bfuclg$ifo8u$1@ID-184292.news.uni-berlin.de>
dtorreblanca0205 wrote:
> "Wang, Vincent" <viwang@nortelnetworks.com> wrote in message
> news:3EA9A873.EA35E48C@nortelnetworks.com...
>> Do you know how to find out the Perl packages that already
>> installed on my UNIX or Linux, like "ppm query" does on win32?
>
> Try this (you'll need ExtUtils::Installed, obviously):
>
> #!/usr/local/bin/perl
>
> use ExtUtils::Installed;
> my $instmod = ExtUtils::Installed->new();
>
> foreach my $module ($instmod->modules())
> {
> my $version = $instmod->version($module) || "???";
> print "$module -- $version\n";
> }
I was about to say that this Q/A is a FAQ, but when I went to
http://www.perldoc.com/perl5.8.0/pod/perlfaq3.html, I found that the
question "How do I find which modules are installed on my system?" is
no longer there.
Why on earth would anybody have removed that question?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 26 Jul 2003 12:05:46 +0800
From: "Sohoman" <sohoman@yahoo.com>
Subject: iHL =?Big5?B?ue+n3KSjtLqu8A==?= iHL
Message-Id: <bftssh$f43$1@news.giga.net.tw>
對抗不景氣>>>>在家工作增加收入
www.cashcome.net
帳號:sohoman
*W3
------------------------------
Date: Sat, 26 Jul 2003 12:47:08 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Is there a clean way to export all constants from a module?
Message-Id: <Xns93C48C1AF74D3sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Steve Allan <stevea@wrq.com> wrote in news:ud6fykuzh.fsf@wrq.com:
>
> I'm creating a module for the sole purpose of defining constants to be
> shared among several Perl scripts. I'm looking for a way to simplify
> getting all the constant names into the @EXPORT_OK array...
You might want to try my experimental Config::Vars module, which is
designed for what you have in mind -- although it doesn't support
constants, it does support Readonly variables.
Perhaps I should add support for constants to the module.
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPyK+bGPeouIeTNHoEQKiXwCeMip86vOW5KiY1Y/KsxLKSzOF3e0An2We
HzYie+2TflIaQTSiNs5xajOK
=xegT
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 26 Jul 2003 11:42:25 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: module and $ARGV help
Message-Id: <3475iv00jlfvfte3dq05nn4qdjebabfcd1@4ax.com>
On 25 Jul 2003 10:30:42 -0700, satishi@gwu.edu (slash) wrote:
> #@textID=$tb->select(1);
> #foreach $textID (@textID) {
> # $t1 = $t1->add($ARGV); }
>I also have another general question about $ARGV.
>Let's say if I wanted to run the above script over multiple input
>files. Can I do the following:
>
>perl -n script.pl *.TXT
>
>I actually tried doing the above but it hung because of the while.
>What is the terminating condition for the loop? Or, is there a better
>way of doing this?
>When my script moves from one file to the next does it update the
>value of $ARGV?
$ARGV is updated automatically, but this happens only while the data is
being read. The earlier line
my @words = split /\W+/, <> ;
read all the data at once, so $ARGV probably won't be useful after that.
To be honest, I'm not entirely certain what you're trying to achieve
with that loop, so I can't say anything more.
--
Eric Amick
Columbia, MD
------------------------------
Date: Sat, 26 Jul 2003 16:46:29 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: module and $ARGV help
Message-Id: <FfyUa.3156$cM6.3005@nwrdny01.gnilink.net>
James Willmore <jwillmore@cyberia.com> wrote:
> > When my script moves from one file to the next does it update the
> > value of $ARGV?
>
> $ARGV[0] or what every position is applicable.
> @ARGV (an array) is what holds the command line parameters.
>
> (from perldoc perlvar)
>
> @ARGV The array @ARGV contains the command-line argu?
> ments intended for the script. $#ARGV is gener?
> ally the number of arguments minus one, because
> $ARGV[0] is the first argument, not the program's
> command name itself. See $0 for the command name.
Mere inches above the bit you quoted there's an entry for the
scalar $ARGV, which is what the OP was asking about.
--
Steve
------------------------------
Date: Sat, 26 Jul 2003 17:42:52 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: module and $ARGV help
Message-Id: <w4zUa.444$JS2.171@nwrdny03.gnilink.net>
Eric Amick <eric-amick@comcast.net> wrote:
> On 25 Jul 2003 10:30:42 -0700, satishi@gwu.edu (slash) wrote:
> >When my script moves from one file to the next does it update the
> >value of $ARGV?
>
> $ARGV is updated automatically, but this happens only while the
> data is being read.
I'm not sure what you mean.
$ARGV is updated when the ARGV filehandle moves from one file to
the next, so a direct answer for the OP would be "Yes".
But it isn't dynamically scoped, so the value will remain there
indefinitely afterward. (For instance, if you use <> in a loop,
$ARGV will be the last filename afterward.)
> The earlier line
>
> my @words = split /\W+/, <> ;
>
> read all the data at once, so $ARGV probably won't be useful after
> that.
That actually puts the readline() into scalar context, so only
the first file gets slurped. $ARGV will be the name of the first
file afterward.
--
Steve
------------------------------
Date: 26 Jul 2003 03:57:32 -0700
From: francescomoi@europe.com (Francesco Moi)
Subject: Perl lib version (v5.6.0) doesn't match executable version (v5.8.0)
Message-Id: <5b829932.0307260257.730ee1b2@posting.google.com>
Hello.
On a Linux PC, I'm trying to install libwww-perl, but I get this error
message when 'make':
-------------
Perl lib version (v5.6.0) doesn't match executable version (v5.8.0) at
/usr/lib/perl5/5.6.0/i386-linux/Config.pm line 21.
Compilation failed in require at
/usr/lib/perl5/5.6.0/ExtUtils/Install.pm line 10.
----------------
If get my Perl version (perl -v):
This is perl, v5.6.0 built for i386-linux
Some hours ago, I tried to installed a module by using CPAN, and
it suggested me to install the new Perl version (5.8.0), but it
failed, and I supposed it wasn't installed.
I would be extremely obliged if anybody could tell me how to solve
this
problem.
Thank you very much.
------------------------------
Date: Sat, 26 Jul 2003 07:58:40 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Pesky added line
Message-Id: <3F2234F2.4629353F@acm.org>
Eric wrote:
>
> I have a Pesky added line I just can't figure out how to get rid of in
> the following simple conversion script (substitutes a number for text
> status). It would make more sense for the new blank line to come
> *after* the substituted line, but it comes before...and is driving me
> nuts.
>
> Here's a few lines from the original file (right at the end of the
> header/field designators):
>
> FOOT","SiteCode","LocalModifyDate","LocalPhoto","RemotePhoto"
> "1","251536","01","Active","3435","ROCK","CT","1050000","5","3","0"
> "Morgan Hill","0","95037","9/24/2002","1/1/1900","0","9/24/2002","3639"
>
> Here's the way it comes out: (an unwanted blank line right-BEFORE the
> substitution line):
>
> FOOT","SiteCode","LocalModifyDate","LocalPhoto","RemotePhoto"
>
> "1","251536","01","1","3435","ROCK","CT","1050000","5","3","0"
> "Morgan Hill","0","95037","9/24/2002","1/1/1900","0","9/24/2002","3639"
>
> ...i.e, the word "Active" gets replaced with "1" ...
>
> Here's the code:
>
> #!/usr/bin/perl -w
> #
> use strict;
> use warnings;
> #
> # RAW DATA FILE ENTRY FORMAT
> # $infile will be: The raw .txt file to change all STATUS fields
> # $outfile will be: The modified .txt file with STATUS fields changed
> #
> my $infile = " ";
> my $outfile = " ";
> my $line = " ";
> #
> print "Enter File Name To Convert: "; #Input file
> chomp ($infile = <STDIN>);
> print "Enter Output File Name: "; #Output file
> chomp ($outfile = <STDIN>);
> #
> open (INFILE, $infile) ||
> die "could not open '$infile' $!"; #open file for reading or die
> open (OUTFILE ,">>$outfile") ||
> die "could not open '$outfile' $!"; #open file for appending or
> die
> # Loop for Input File to replace STATUS with Numeric Codes
> while ($line = <INFILE>) {
> $line =~ s/"Active\"/\"1\"/g unless $line !~ m/\"Active\"/;
> $line =~ s/"Pending Release\"/\"2\"/g unless $line !~ m/\"Pending
> Release\"/;
> $line =~ s/"Pending Show\"/\"3\"/g unless $line !~ m/\"Pending
> Show\"/;
> $line =~ s/"Pending\"/\"4\"/g unless $line !~ m/\"Pending\"/;
> $line =~ s/"Sold\"/\"5\"/g unless $line !~ m/\"Sold\"/;
> $line =~ s/"Expired\"/\"6\"/g unless $line !~ m/\"Expired\"/;
> $line =~ s/"Cancel\"/\"7\"/g unless $line !~ m/\"Cancel\"/;
> $line =~ s/"Withdrawn\"/\"8\"/g unless $line !~ m/\"Withdrawn\"/;
You don't need "unless $line !~ m//" because the substitution will not
happen if the regular expression does not match. And you don't need to
escape the quotes.
$line =~ s{"Active"} {"1"}g;
$line =~ s{"Pending Release"}{"2"}g;
$line =~ s{"Pending Show"} {"3"}g;
$line =~ s{"Pending"} {"4"}g;
$line =~ s{"Sold"} {"5"}g;
$line =~ s{"Expired"} {"6"}g;
$line =~ s{"Cancel"} {"7"}g;
$line =~ s{"Withdrawn"} {"8"}g;
> print OUTFILE "$line\n";
This is your problem. You don't remove the original newline and add
another one here.
print OUTFILE $line;
> }
> close (INFILE); #close raw input file
> close (OUTFILE); #close output file
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 26 Jul 2003 10:22:40 +0200
From: Thomas Wasell <wasell@bahnhof.se>
Subject: Re: Pesky added line
Message-Id: <MPG.198c580fc2aae6f0989712@news.bahnhof.se>
In article <3F2209DC.5320A25B@xx.com>, Eric <nospam@xx.com> wrote:
>I have a Pesky added line I just can't figure out how to get rid of in
>the following simple conversion script (substitutes a number for text
>status). It would make more sense for the new blank line to come
>*after* the substituted line, but it comes before...and is driving me
>nuts.
>
>Here's a few lines from the original file (right at the end of the
>header/field designators):
>
>FOOT","SiteCode","LocalModifyDate","LocalPhoto","RemotePhoto"
>"1","251536","01","Active","3435","ROCK","CT","1050000","5","3","0"
>"Morgan Hill","0","95037","9/24/2002","1/1/1900","0","9/24/2002","3639"
>
>Here's the way it comes out: (an unwanted blank line right-BEFORE the
>substitution line):
>
>FOOT","SiteCode","LocalModifyDate","LocalPhoto","RemotePhoto"
>
>"1","251536","01","1","3435","ROCK","CT","1050000","5","3","0"
>"Morgan Hill","0","95037","9/24/2002","1/1/1900","0","9/24/2002","3639"
>
>...i.e, the word "Active" gets replaced with "1" ...
Not on my machine! It adds a newline after _every_ line. (Your not
chomp()ing $line AND adding a newline when you print.)
Just a few comments:
>Here's the code:
>
>#!/usr/bin/perl -w
^^
You have 'use warnings;' below, so this is not necessary.
>#
>use strict;
>use warnings;
>#
># RAW DATA FILE ENTRY FORMAT
># $infile will be: The raw .txt file to change all STATUS fields
># $outfile will be: The modified .txt file with STATUS fields changed
>#
>my $infile = " ";
>my $outfile = " ";
>my $line = " ";
Why are you initialising these variables to blank space?
>#
>print "Enter File Name To Convert: "; #Input file
>chomp ($infile = <STDIN>);
>print "Enter Output File Name: "; #Output file
>chomp ($outfile = <STDIN>);
>#
>open (INFILE, $infile) ||
> die "could not open '$infile' $!"; #open file for reading or die
>open (OUTFILE ,">>$outfile") ||
> die "could not open '$outfile' $!"; #open file for appending or
>die
># Loop for Input File to replace STATUS with Numeric Codes
>while ($line = <INFILE>) {
> $line =~ s/"Active\"/\"1\"/g unless $line !~ m/\"Active\"/;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is _completely_ useless AND has a confusing double negation! There's no
need to escape the double-quotes.
> $line =~ s/"Pending Release\"/\"2\"/g unless $line !~ m/\"Pending
>Release\"/;
> $line =~ s/"Pending Show\"/\"3\"/g unless $line !~ m/\"Pending
>Show\"/;
> $line =~ s/"Pending\"/\"4\"/g unless $line !~ m/\"Pending\"/;
> $line =~ s/"Sold\"/\"5\"/g unless $line !~ m/\"Sold\"/;
> $line =~ s/"Expired\"/\"6\"/g unless $line !~ m/\"Expired\"/;
> $line =~ s/"Cancel\"/\"7\"/g unless $line !~ m/\"Cancel\"/;
> $line =~ s/"Withdrawn\"/\"8\"/g unless $line !~ m/\"Withdrawn\"/;
> print OUTFILE "$line\n";
>}
The while-loop is better written:
while (<INFILE>) {
s/"Active"/"1"/g;
s/"Pending Release"/"2"/g;
# etc...
print OUTFILE;
}
>close (INFILE); #close raw input file
>close (OUTFILE); #close output file
>### END
>
>Thank you for any assistance in finding out what the problem is.
>
>Eric
>
--
Thomas Wasell | Never try to outstubborn a cat.
wasell@bahnhof.se | -- Lazarus Long, "Time Enough for Love"
------------------------------
Date: Sat, 26 Jul 2003 12:23:58 +0200
From: "Seansan" <sheukels=cuthere=@yahoo.co.uk>
Subject: script redirect 2 hotmail
Message-Id: <3f2256c3$0$76457$e4fe514c@dreader8.news.xs4all.nl>
Does anyone know of a script that redirects a users login to hotmail. The
problem I am having now is that hotmail says that my browser doesnt support
cookies. So I must be missing something. Can I set a cookie from my domain
to another??
Seansan
------------------------------
Date: Sat, 26 Jul 2003 12:23:58 +0200
From: "Seansan" <sheukels=cuthere=@yahoo.co.uk>
Subject: script redirect 2 hotmail
Message-Id: <3f226a72$0$29075$e4fe514c@dreader6.news.xs4all.nl>
Does anyone know of a script that redirects a users login to hotmail. The
problem I am having now is that hotmail says that my browser doesnt support
cookies. So I must be missing something. Can I set a cookie from my domain
to another??
Seansan
------------------------------
Date: Sat, 26 Jul 2003 10:09:29 +0200
From: "Julian Mehnle" <julian@mehnle.net>
Subject: Re: UTF-8 module
Message-Id: <bftcvq$iprgs$1@ID-65075.news.uni-berlin.de>
pkent wrote:
> The problem I can forsee tripping people up is when you're encoding a
> character into a 2+ octet representation and one octet happens to be
> equal to a 'special' character, e.g. an '='.
This won't happen, since every octet that is part of a UTF-8 multibyte
character sequence is >= 0x80. That's the beauty of UTF-8. ;-)
------------------------------
Date: Sat, 26 Jul 2003 11:42:00 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: UTF-8 module
Message-Id: <Pine.LNX.4.53.0307261059370.15522@lxplus065.cern.ch>
On Sat, Jul 26, pkent inscribed on the eternal scroll:
> > I assumed this was a question about encoding per RFC2718,
> > http://www.ietf.org/rfc/rfc2718.txt
>
> ...as did I :-) ...
(the reference is to section 2.2.5, I forgot to mention that).
However, I realised since (prompted by the reference to CGI.pm) that
it might have been a question about an extension of the
application/x-www-form-urlencoded format
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
Here, the applicable recommendation would be this one:
http://www.w3.org/TR/html401/appendix/notes.html#non-ascii-chars
and I think CGI.pm is implementing that recommendation.
The two formats are evidently designed to be equivalent in some sense,
but there might be subtle issues, I'm not certain. One difference is
the representation of a space ("+" in forms submission format, "%20"
in URIencoding format).
> > Presumably what's needed is that every character whose ord() value is
> > above 127 decimal needs to be subjected to some kind of unpack() or
> > sprintf to yield the relevant number of %HH%HH... encoded ASCII
> > strings. Not forgetting, of course, to encode the so-called "unsafe"
>
> The way I understood the RFC is this:
>
> Take the original string, which can be in any form - 32-bit wide
> characters, EBCDIC, anything... and turn it into a UTF-8 string. This
> means that low-half code points will be represented in a single byte,
> but high-half (or beyond) characters will be represented as 2 or more
> bytes. Then go through the string doing the %HH escaping of every octet
> that requires escaping.
I think we're saying the same thing, except that I was assuming that
the data would be presented in native Perl 5.8 format and you're
assuming they'd first have to be converted from some other format.
> In my limited experiments (e.g. submitting an HTML form where I'd typed
> in some text with accented chars) IE6 will create a URL like:
>
> http://example.com/cgi-bin/t.pl?spanish=se%C0%A2or%20manuel
I would never use IE as my reference implementation - it deliberately
violates some mandatory requirements of the applicable
specifications.[1]
> The problem I can forsee tripping people up is when you're encoding a
> character into a 2+ octet representation and one octet happens to be
> equal to a 'special' character,
No, that's not a problem with utf-8 format. Bytes of value 0-127 are
ASCII, whereas everything larger is part of a multi-byte ("wide")
character. The utf-8 coding is defined such that the number of bytes
belonging to a character can be determined by inspecting the high bits
of the first byte.
But I think the Perl-5.8-related issue is that one needs to decide
whether one is working with "characters" (in the sense meant by
perlunicode), or with a "bunch of bytes"; and the chosen encoding
procedures then follow from that. One needs to keep a clear head when
doing this stuff.
> e.g. an '='. You can't simply escape
> _all_ the '=' in a URL because that'd trash the query string.
Yeah, this is a general principle. You can't just randomly apply and
resolve %HH-encodings: it's got to be done once and only once, in an
organised fashion, when the encoded URI is being built.
cheers
[1] Hey, I'm not so unworldly as to write a specification-conforming
document which doesn't work in MSIE (other than to demonstrate some
specific point); all that I'm saying above is that I wouldn't use IE
as any kind of arbiter of correctness per published interworking
specifications.
------------------------------
Date: Sat, 26 Jul 2003 10:44:12 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Where to hitch the <<EOF to plaster input file?
Message-Id: <q835iv0u3t52psh1tajhk7h4ap0ub80r3k@4ax.com>
On Sat, 26 Jul 2003 12:45:25 +0800, Dan Jacobson <jidanni@jidanni.org>
wrote:
>Where do I hitch the <<EOF so I can plaster my input file right into
>this source file? Yes, saw man perlop. Yes, I am prepared to give up
>-anl if that's the price to pay.
You'll have to give up the -anl; <<EOF can't put data into a filehandle.
Despite its resemblance to shell here-documents, it doesn't work the
same.
>#!/usr/bin/perl -anlw
>#Input: each line consists of seconds per rotation of electric meter disk followed by
>#a note of what appliances were on at the time.
>#Output: total watts, appliance list. The Kh factor is written on the meter.
>#Reference: http://www.earth.uni.edu/EECP/elem/mod2_math.html
>BEGIN { $Kh = 7.2 };
>unless (/^[^#]/) { next }
>$p = 3600 * $Kh / $F[0];
>shift @F;
>print int($p), "\t@F";
#!/usr/bin/perl -w
$Kh = 7.2;
while (<DATA>)
{
next if /^#/;
($p, @F) = split(' ', chomp);
$p = 3600 * $Kh / $p;
print int($p), "\t@F";
}
__DATA__
# Your data here...
See man perldata and search for __DATA__.
--
Eric Amick
Columbia, MD
------------------------------
Date: Sat, 26 Jul 2003 12:18:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Where to hitch the <<EOF to plaster input file?
Message-Id: <slrnbi5du8.drl.tadmc@magna.augustmail.com>
Eric Amick <eric-amick@comcast.net> wrote:
> ($p, @F) = split(' ', chomp);
split() will always return a 1-element list, regardless of what is in $_.
@F will always get the empty list, regardless of what is in $_.
$p will get either a 1 or a 0 ( if you haven't messed with $/ ).
Man oh man, that bug is going to present itself strangely.
The return value from chomp() is not very useful.
Seeing someone use it, therefore, is a red flag to me...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5275
***************************************