[23588] in Perl-Users-Digest
Perl-Users Digest, Issue: 5795 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 13 18:05:51 2003
Date: Thu, 13 Nov 2003 15:05:15 -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, 13 Nov 2003 Volume: 10 Number: 5795
Today's topics:
Re: "DBI->connect() failed: ERROR OCIEnvInit" <r_reidy@comcast.net>
Re: "tree" view of directory <mikeflan@earthlink.net>
Re: "tree" view of directory <usenet@morrow.me.uk>
Re: "tree" view of directory <mikeflan@earthlink.net>
Re: "tree" view of directory <wwonko@rdwarf.com>
Re: "tree" view of directory <usenet@morrow.me.uk>
Re: "tree" view of directory <usenet@morrow.me.uk>
Re: "tree" view of directory (Jay Tilton)
Re: "tree" view of directory (Tad McClellan)
Re: bit sequence match <edady2002@yahoo.com>
Re: CGI - unreloadable page? <no@email.com>
Re: CGI - unreloadable page? <no@email.com>
Re: Echo '*' chars instead of what's typed <usenet@morrow.me.uk>
Re: Echo '*' chars instead of what's typed (Greg Bacon)
Re: Echo '*' chars instead of what's typed <syscjm@gwu.edu>
Evaluating nester variables <gtb104gtb@netscape.net>
Re: Evaluating nester variables <noreply@gunnar.cc>
Re: Evaluating nester variables <perl@my-header.org>
Re: Evaluating nester variables <perl@my-header.org>
Re: Evaluating nester variables <usenet@morrow.me.uk>
Re: Giving back (Tad McClellan)
Re: Giving back Default@User011011101101.net
Re: Giving back <uri@stemsystems.com>
Re: Giving back (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 13 Nov 2003 14:47:58 -0700
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: "DBI->connect() failed: ERROR OCIEnvInit"
Message-Id: <3FB3FC0E.7070301@comcast.net>
Yes, display the Oracle error number, user the 'oerr' utility to get a
description of the error and it's cause, and then address that.
Ed_Zep wrote:
> Hi.
>
> We've recently upgraded from Oracle 8 to Oracle 9.2.0.4.
>
> The Perl script that we have now fails with:
>
> DBI->connect() failed: ERROR OCIEnvInit at
> /u02/app/sct/banner/general/exe/ucas_ftp.pl line 124
> Couldn't connect to database.
>
> We're using the following:
>
> DBI-1.12
> Data-Dumper-2.101
> perl5.005_03
> DBD-Oracle-1.02
> DBI-1.32
> libnet-1.0606
>
> Any ideas as to what I need to do?
>
> Thanks.
>
> Ed.
--
Ron Reidy
Oracle DBA
------------------------------
Date: Thu, 13 Nov 2003 19:28:07 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: "tree" view of directory
Message-Id: <3FB3DC00.958F6D1D@earthlink.net>
Jay Tilton wrote:
snip
> Your code comes within inches of its goal. Just uncomment the line
> declaring those arrays and shift it up by one line.
>
> : sub readADir{
> : my $dir=shift;
> : print '<ul>';
> :
> : opendir DIR, $dir or die "Cannot open dir $!";
> : my @files = readdir DIR;
> : closedir DIR;
>
> my( @regular_files, @directories );
>
> : foreach my $file(@files){
> : # my @regular_files=();my @directories=();
> : if(-d "$dir/$file"){unless($file=~/^\./){push @directories, "$dir/$file"}}
> : if(-f "$dir/$file"){push @regular_files, $file;}
> : }
> :
> : @directories=sort @directories;
> : foreach my $directory(@directories){
> : if($dir ne $directory){readADir($directory)};
> : }
> :
> : @regular_files=sort @regular_files;
> : foreach my $regular_file(@regular_files){
> : print qq{<li> $regular_file </li>};
> : }
> : print '</ul>';
> : }
This code shown below does not work on my Win2000 box.
I pass it a directory via perl file.pl c:/copy
but it simply runs, produces no output, and gives the
command prompt. Anybody know why it doesn't work?
I can't see the problem.
Mike
use strict;
use warnings;
sub readADir{
my $dir=shift;
print '<ul>';
opendir DIR, $dir or die "Cannot open dir $!";
my @files = readdir DIR;
closedir DIR;
my @regular_files=();my @directories=();
foreach my $file(@files){
if(-d "$dir/$file"){unless($file=~/^\./){push @directories, "$dir/$file"}}
if(-f "$dir/$file"){push @regular_files, $file;}
}
@directories=sort @directories;
foreach my $directory(@directories){
if($dir ne $directory){readADir($directory)};
}
@regular_files=sort @regular_files;
foreach my $regular_file(@regular_files){
print qq{<li> $regular_file </li>};
}
print '</ul>';
}
__END__
------------------------------
Date: Thu, 13 Nov 2003 19:46:50 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: "tree" view of directory
Message-Id: <bp0n3a$bf2$1@wisteria.csv.warwick.ac.uk>
Mike Flannigan <mikeflan@earthlink.net> wrote:
> This code shown below does not work on my Win2000 box.
> I pass it a directory via perl file.pl c:/copy
> but it simply runs, produces no output, and gives the
> command prompt. Anybody know why it doesn't work?
> I can't see the problem.
The problem is that everything you print is on one unterminated line,
which the cmd window therefore does not display. Add '$\ = "\n";' to
the top, to put a newline after each print statement.
Ben
--
It will be seen... that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher arises among them who... convinc[es] them that their
...institutions are not based on... morality. [Samuel Butler] ben@morrow.me.uk
------------------------------
Date: Thu, 13 Nov 2003 20:18:09 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: "tree" view of directory
Message-Id: <3FB3E7BA.CF949BBB@earthlink.net>
Ben Morrow wrote:
> The problem is that everything you print is on one unterminated line,
> which the cmd window therefore does not display. Add '$\ = "\n";' to
> the top, to put a newline after each print statement.
>
> Ben
I don't know what I am doing wrong, but there was no
change when I did the script below, or about a half dozen
other variations (replacing ' with " in print statements,
putting new line print on a separate line, etc.)
No big deal since another version is working, but I
wanted to figer it out :-)
Mike
use strict;
use warnings;
$\ = "\n";
sub readADir{
my $dir=shift;
print '<ul>\n';
opendir DIR, $dir or die "Cannot open dir $!";
my @files = readdir DIR;
closedir DIR;
my @regular_files=();my @directories=();
foreach my $file(@files){
if(-d "$dir/$file"){unless($file=~/^\./){push @directories, "$dir/$file"}}
if(-f "$dir/$file"){push @regular_files, $file;}
}
@directories=sort @directories;
foreach my $directory(@directories){
if($dir ne $directory){readADir($directory)};
}
@regular_files=sort @regular_files;
foreach my $regular_file(@regular_files){
print qq{<li> $regular_file </li>\n};
}
print '</ul>\n';
}
__END__
------------------------------
Date: Thu, 13 Nov 2003 20:19:23 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: "tree" view of directory
Message-Id: <bp0p0b$830$1@holly.rdwarf.com>
Ben Morrow <usenet@morrow.me.uk> wrote:
: Mike Flannigan <mikeflan@earthlink.net> wrote:
:> This code shown below does not work on my Win2000 box.
:> I pass it a directory via perl file.pl c:/copy
:> but it simply runs, produces no output, and gives the
:> command prompt. Anybody know why it doesn't work?
:> I can't see the problem.
: The problem is that everything you print is on one unterminated line,
: which the cmd window therefore does not display. Add '$\ = "\n";' to
: the top, to put a newline after each print statement.
I've never seen Windows 2000's command prompt behave that way. Am I
misunderstanding what you mean?
If that were the case, this perl would produce nothing:
#!/usr/bin/perl
use strict;
use warnings;
for(0...100) {
print "$_ ";
}
__END__
And, when run, it produces the integers between zero and one hundred,
with spaces between them. The command prompt even gives you a trailing
carriage return before it prints the prompt.
(Bash on Linux and in Cygwin shows everything, but the prompt immediately
follows the space after '100'. This is probably more correct. Microsoft's
is more readable.)
Am I misunderstanding what you mean by "one unterminated line"? Or is there
something else going on?
--
Louis Erickson - wwonko@rdwarf.com - http://www.rdwarf.com/~wwonko/
The doctrine of human equality reposes on this: that there is no man
really clever who has not found that he is stupid. -- Gilbert K. Chesterson
------------------------------
Date: Thu, 13 Nov 2003 22:30:06 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: "tree" view of directory
Message-Id: <bp10le$fmg$1@wisteria.csv.warwick.ac.uk>
Mike Flannigan <mikeflan@earthlink.net> wrote:
> This code shown below does not work on my Win2000 box.
> I pass it a directory via perl file.pl c:/copy
> but it simply runs, produces no output, and gives the
> command prompt. Anybody know why it doesn't work?
> I can't see the problem.
OK, sorry, my previous response was wrong... :(
If you sort out the indentation, thus...
use strict;
use warnings;
sub readADir{
my $dir=shift;
print '<ul>';
opendir DIR, $dir or die "Cannot open dir $!";
my @files = readdir DIR;
closedir DIR;
my @regular_files=();
my @directories=();
foreach my $file(@files) {
if(-d "$dir/$file") {
unless($file=~/^\./) {
push @directories, "$dir/$file"
}
}
if(-f "$dir/$file") {
push @regular_files, $file;
}
}
@directories=sort @directories;
foreach my $directory(@directories) {
if($dir ne $directory) {
readADir($directory)
};
}
@regular_files=sort @regular_files;
foreach my $regular_file(@regular_files) {
print qq{<li> $regular_file </li>};
}
print '</ul>';
}
__END__
...it will become more apparent that you have simply defined a sub
called 'readADir', but not actually called it anywhere... You perhaps
meant to add
readADir @ARGV;
at the end?
Ben
--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: Thu, 13 Nov 2003 22:33:09 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: "tree" view of directory
Message-Id: <bp10r5$fmg$2@wisteria.csv.warwick.ac.uk>
Louis Erickson <wwonko@rdwarf.com> wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote:
> : The problem is that everything you print is on one unterminated line,
> : which the cmd window therefore does not display. Add '$\ = "\n";' to
> : the top, to put a newline after each print statement.
>
> I've never seen Windows 2000's command prompt behave that way. Am I
> misunderstanding what you mean?
No you're not, and I'm wrong :).
> (Bash on Linux and in Cygwin shows everything, but the prompt immediately
> follows the space after '100'. This is probably more correct. Microsoft's
> is more readable.)
...and zsh, which I use, goes back to the beginning of the line and
clears it before printing the prompt, so you never see the output at
all. I've been caught by this so many times I thought it must be the
problem here... sorry.
Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
------------------------------
Date: Thu, 13 Nov 2003 22:46:04 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: "tree" view of directory
Message-Id: <3fb40068.87936474@news.erols.com>
Mike Flannigan <mikeflan@earthlink.net> wrote:
: This code shown below does not work on my Win2000 box.
: I pass it a directory via perl file.pl c:/copy
: but it simply runs, produces no output, and gives the
: command prompt. Anybody know why it doesn't work?
: I can't see the problem.
: use strict;
: use warnings;
:
: sub readADir{
[snip subroutine guts]
: }
:
: __END__
The readADir() subroutine is never called. :)
It should work just fine after that is fixed.
@ARGV = '.' unless @ARGV; # whatever should happen if @ARGV is empty
readADir( @ARGV );
------------------------------
Date: Thu, 13 Nov 2003 16:57:47 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: "tree" view of directory
Message-Id: <slrnbr833b.m88.tadmc@magna.augustmail.com>
Ben Morrow <usenet@morrow.me.uk> wrote:
> If you sort out the indentation, thus...
I skipped to the next article due to that lack of indentation...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 14 Nov 2003 06:45:59 +1100
From: Edo <edady2002@yahoo.com>
Subject: Re: bit sequence match
Message-Id: <3FB3DF77.8020605@yahoo.com>
Jay Tilton wrote:
> Edo <edady2002@yahoo.com> wrote:
>
> : e.g, if the code gets 20 matches from %h2. then those matches are
> : identical to %h1 in as a sorted-whole so
> : if %h1 = (1 => '000001', 2 => '000010', 3 => '000100');
> : and there are in the "key-sorted-%h2"
> : (20 => '000001', 21 => '000010', 22 => '000100')
> : (41 => '000001', 42 => '000010', 43 => '000100')
> : (111 => '000001', 112 => '000010', 113 => '000100')
> :
> : then I need those above 3 lines in array of hrefs.
>
> I see now. The sequence of values in %h1 can occur more than once in
> %h2. That was the missing piece of the puzzle. See how this grabs you.
>
> my %h1 = (
> 1 => '000001', 2 => '000010', 3 => '000100'
> );
> my %h2 = (
> 20 => '000001', 21 => '000010', 22 => '000100',
> 41 => '000001', 42 => '000010', 43 => '000100',
> 111 => '000001', 112 => '000010', 113 => '000100'
> );
> my @k1 = sort {$a <=> $b} keys %h1;
> my @k2 = sort {$a <=> $b} keys %h2;
> my $look_for = pack('(B6)*' => @h1{ @k1 });
> my $look_in = pack('(B6)*' => @h2{ @k2 });
> my @results;
> while( $look_in =~ /(?=\Q$look_for\E)/g ) {
> push @results,
> {
> map { $_ => $h2{$_} }
> @k2[ $-[0] .. $-[0]+@k1-1 ]
> };
> }
>
> Now instead of using index() to find where the sequence of values in %h1
> occurs in %h2, it uses a match operator and $-[0] to determine where the
> sequence begins. The /g switch will catch all occurrences of the
> sequence. The "\Q...\E" will escape any regex metacharacters. The
> "(?=...)" zero-width lookahead is there in case the sequence of values
> in %h1 can have overlapping occurrences in %h2.
>
this is working but I need to understand how it worked. as still
learning perl. and after reading all what I can find in the programming
perl book about pack. could you explain in details what this line do
my $look_for = pack('(B6)*' => @h1{ @k1 });
thanks
------------------------------
Date: Thu, 13 Nov 2003 22:42:22 +0000
From: Brian Wakem <no@email.com>
Subject: Re: CGI - unreloadable page?
Message-Id: <pan.2003.11.13.22.42.21.701043@email.com>
On Thu, 13 Nov 2003 16:10:29 +0200, Roman Khutkyy wrote:
> Hi all.
> There is a problem (i hope so). When i submit the form first time, the
> script put fields data into database. But when on next page i make "Reload"
> this process repeats again, and the same record are being placed. How to
> disallow this. I mean, how to make the new page withot any parameter in
> address string?
POST the data to a scripts that does whatever processing you require and
then redirect the user to another page. If they then reload that page
there wont be any parameters to re-send and it will be a different page
anyway.
use CGI;
print $query->redirect($url);
--
Brian Wakem
------------------------------
Date: Thu, 13 Nov 2003 22:43:50 +0000
From: Brian Wakem <no@email.com>
Subject: Re: CGI - unreloadable page?
Message-Id: <pan.2003.11.13.22.43.50.398668@email.com>
> use CGI;
> print $query->redirect($url);
Sorry, should have been;
use CGI;
$query = new CGI;
print $query->redirect($url);
--
Brian Wakem
------------------------------
Date: Thu, 13 Nov 2003 19:09:21 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Echo '*' chars instead of what's typed
Message-Id: <bp0kt1$ah3$1@wisteria.csv.warwick.ac.uk>
Ben Morrow <usenet@morrow.me.uk> wrote:
>
> bl8n8r@yahoo.com (bad_knee) wrote:
> > I'm getting password input from the user in a perl script,
> > and was wondering if anyone knows how to echo splats at them
> > instead of not showing any chars at all? (eg: stty -echo)
>
> perldoc -q password
Sorry, the 'stty -echo' put me off, and I assumed you were asking how
to not echo...
I guess what you want to do is read one char at a time, either using
read or by setting $/ = \1, and print the *s yourself. Note that you
will probably have to put the terminal into cbreak mode and handle
delete/backspace/etc yourself, which is probably why most Unix
commands simply don't echo passwords... :) (There is also a slight
security advantage: with *s, someone peering over your shoulder sees
how long the password is.)
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'
------------------------------
Date: Thu, 13 Nov 2003 19:31:53 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Echo '*' chars instead of what's typed
Message-Id: <vr7n198ae5d0de@corp.supernews.com>
In article <e817ca4d.0311131043.1d2c0f43@posting.google.com>,
bad_knee <bl8n8r@yahoo.com> wrote:
: I'm getting password input from the user in a perl script,
: and was wondering if anyone knows how to echo splats at them
: instead of not showing any chars at all? (eg: stty -echo)
Borrowing from tchrist's <6l8isu$cs7$2@csnews.cs.colorado.edu>:
% cat try
#! /usr/local/bin/perl
use warnings;
use strict;
use IO::Handle;
use POSIX qw(:termios_h);
sub termattr {
my $fh = shift;
my $fd = fileno $fh;
my $term = POSIX::Termios->new();
$term->getattr($fd);
my $oterm = $term->getlflag();
{
fd => $fd,
term => $term,
oterm => $oterm,
noecho => $oterm & ~(ECHO | ECHOK | ICANON),
};
}
sub cbreak {
my $attr = shift;
my $term = $attr->{term};
$term->setlflag($attr->{noecho}); # ok, so i don't want echo either
$term->setcc(VTIME, 1);
$term->setattr($attr->{fd}, TCSANOW);
}
sub cooked {
my $attr = shift;
my $term = $attr->{term};
$term->setlflag($attr->{oterm});
$term->setcc(VTIME, 0);
$term->setattr($attr->{fd}, TCSANOW);
}
sub done {
my $attr = shift;
cooked $attr;
}
package main;
sub ask_for_pw {
print "Enter password: ";
STDOUT->flush;
my $attr = termattr \*STDIN;
cbreak $attr;
my $passwd;
my $ch;
while (defined sysread STDIN, $ch, 1) {
last if $ch eq "\n";
print "*";
STDOUT->flush;
$passwd .= $ch;
}
done $attr;
print "\n";
$passwd;
}
my $pw = ask_for_pw;
print "The password is '$pw'\n";
% ./try
Enter password: ******************
The password is 'theycallhimflipper'
Hope this helps,
Greg
--
But the majesty of capitalism is not that it that it
makes people rich, but that it makes them humble.
-- Bill Bonner
------------------------------
Date: Thu, 13 Nov 2003 14:35:09 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Echo '*' chars instead of what's typed
Message-Id: <3FB3DCED.200@gwu.edu>
bad_knee wrote:
> Hello,
> I'm getting password input from the user in a perl script,
> and was wondering if anyone knows how to echo splats at them
> instead of not showing any chars at all? (eg: stty -echo)
>
Why tell potetial shoulder surfers how long the password is?
That's valuable information.
Chris Mattern
------------------------------
Date: Thu, 13 Nov 2003 12:52:16 -0800
From: Geoff <gtb104gtb@netscape.net>
Subject: Evaluating nester variables
Message-Id: <bp0qtv02j22@enews3.newsguy.com>
I have an array:
@array = [\$a, \$b, \$c];
How do I evaluate what $a is? I've tried:
print $array[0];
But this gives me "$a".
I also tried using eval, but I must be using it wrong cause it doesn't
seem to do anything.
Thanks in advance.
------------------------------
Date: Thu, 13 Nov 2003 22:54:58 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Evaluating nester variables
Message-Id: <bp0ut3$1ii95u$1@ID-184292.news.uni-berlin.de>
Geoff wrote:
> I have an array:
> @array = [\$a, \$b, \$c];
It's an array with one element that consists of a reference to an
anonymous array with three scalar references.
> How do I evaluate what $a is?
print ${$array[0][0]};
> I've tried:
> print $array[0];
> But this gives me "$a".
Sounds very strange. It should give you something like
'ARRAY(0x15551bc)'. You'd better post some complete code that
illustrates the behaviour you describe.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 13 Nov 2003 23:04:36 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Evaluating nester variables
Message-Id: <elv7rvgm11upng04pmj8dlp81a01v7pg28@4ax.com>
X-Ftn-To: Geoff
Geoff <gtb104gtb@netscape.net> wrote:
>I have an array:
>@array = [\$a, \$b, \$c];
>
>How do I evaluate what $a is? I've tried:
>print $array[0];
>But this gives me "$a".
Can you describe what do you want as a final result?
I heavily /guess/ that you really want to,
$aref = [$a, $b, $c];
print $aref->[0];
>I also tried using eval, but I must be using it wrong cause it doesn't
>seem to do anything.
Leave eval alone for now and go carefully trough perldoc perlref.
--
Matija
------------------------------
Date: Thu, 13 Nov 2003 23:07:13 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Evaluating nester variables
Message-Id: <4208rv896cnkjkmnqt30a2to9kqd9tc5s7@4ax.com>
Matija Papec <perl@my-header.org> wrote:
>Leave eval alone for now and go carefully trough perldoc perlref.
There should be "through".
--
Matija
------------------------------
Date: Thu, 13 Nov 2003 22:40:36 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Evaluating nester variables
Message-Id: <bp1194$fmg$4@wisteria.csv.warwick.ac.uk>
Matija Papec <perl@my-header.org> wrote:
> Geoff <gtb104gtb@netscape.net> wrote:
> >I have an array:
> >@array = [\$a, \$b, \$c];
> >
> >How do I evaluate what $a is? I've tried:
> >print $array[0];
> >But this gives me "$a".
>
> Can you describe what do you want as a final result?
> I heavily /guess/ that you really want to,
> $aref = [$a, $b, $c];
> print $aref->[0];
Or perhaps simply
my @array = ($a, $b, $c);
print $array[0];
or then again maybe
my @array = (\$a, \$b, \$c);
print ${$array[0]};
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Thu, 13 Nov 2003 14:06:38 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Giving back
Message-Id: <slrnbr7p2e.lqd.tadmc@magna.augustmail.com>
[Please limit your line lengths to the conventional 70-72 characters]
Default@User011011101101.net <Default@User011011101101.net> wrote:
> I just finished this little program that fixes letter case, im not
> sure if its bulletproof yet.
Using tr/// for letter case will never be bulletproof, it is not
the Right Tool for the job. It does not respect locales (perllocale.pod).
You should use uc()/lc() etc... instead, because they _do_
respect locales.
> Anyhow it was kind of a pain as I've never delt with RegEx before,
> so if this is usefull to anyone
> please by all means have it.
If you had used the Right Tool, you wouldn't even have had to mess
with regexes you know. :-)
> print "\n" . " " . "="x78 . "\n";
> print " Reads a text file and capitalizes the first letter of each sentence.\n\n";
> print "\tUSAGE:\t perl 15_1.plx <inputfile> <outputfile> [options]\n";
> print "\tNOTE:\t wildcards are not allowed.\n";
> print "\tOPTIONS: -l Lowercases everything before doing the capitalization.\n";
> print "\t\t -d Display work being done on screen.\n";
> print "\n\tEXAMPLE: perl 15_1.plx fixcase.txt casefixed.txt\n";
> print " " . "="x78 . "\n\n";
I like code that makes output to look like the output
that it is making, so I would replace all of those prints
with:
-------------------------
print "\n ", '='x78, "\n";
print <<ENDTEXT; # a "here document"
Reads a text file and capitalizes the first letter of each sentence.
USAGE:\t perl 15_1.plx <inputfile> <outputfile> [options]
NOTE:\t wildcards are not allowed.
OPTIONS: -l Lowercases everything before doing the capitalization.
-d Display work being done on screen.
EXAMPLE: perl 15_1.plx fixcase.txt casefixed.txt
ENDTEXT
print ' ', '='x78, "\n";
-------------------------
See the "Quote and Quote-like Operators" section in perlop.pod.
> our $lines = "";
> our $options1 = "";
> our $options2 = "";
You should always prefer lexical (my) variables over dynamic (our)
variables, except when you can't.
And you can, so these should all be my() instead of our().
> $options1 = shift || $options1 eq "";
I'm pretty sure that that does not do what you think it does.
What are you trying to accomplish there?
I think you might have been trying for:
$options1 = shift || "";
> $options1 =~ tr/A-Z/a-z/;
my $options1 = lc(shift) || ''; # fetch arg and lower case it
> open_files($inputfile, $outputfile);
Here you act like you are passing arguments to the function...
> sub open_files
> {
> open(INPUT, $inputfile) || die "\nError:\nCould not open $inputfile $!\n";
> if (-e $outputfile)
... but the function uses global variables rather than its arguments.
sub open_files
{
my($inputfile, $outputfile) = @_; # copy the arguments
# same code here as you had before
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 13 Nov 2003 21:28:58 GMT
From: Default@User011011101101.net
Subject: Re: Giving back
Message-Id: <uISsb.35726$y95.16297@nwrdny01.gnilink.net>
ahh right on... thanks alot for all the tips, I will try my best to implement them.
btw - im only using the tr for the options bit.. those are like switches.
im not using tr to change case of the input file. you see im not trying to uppercase the first letter
of each line, only the letters following punctuation marks. ;>
i especially appreciate the tips on using the 'use' thingie.
to tell you the truth im not liking "use strict" at all atm. :p
so any info you can give me on this is valuable to me.
particularly when it comes to things like my our local in relation to formats.
anyhow thanks again for the awesome tips.. ill get right on it.
------------------------------
Date: Thu, 13 Nov 2003 22:42:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Giving back
Message-Id: <x77k23ubzm.fsf@mail.sysarch.com>
>>>>> "D" == Default <Default@User011011101101.net> writes:
D> i especially appreciate the tips on using the 'use' thingie. to
D> tell you the truth im not liking "use strict" at all atm. :p so any
D> info you can give me on this is valuable to me. particularly when
D> it comes to things like my our local in relation to formats.
if you always use strict you will save yourself many hours of trouble
later on. it is not a difficult habit to learn and using my all over is
also easy to pick up. this is for your own good so byte the bullet and
use strict and don't whine about it. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 13 Nov 2003 17:02:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Giving back
Message-Id: <slrnbr83bv.m88.tadmc@magna.augustmail.com>
[ Please please limit your line lengths ]
Default@User011011101101.net <Default@User011011101101.net> wrote:
> to tell you the truth im not liking "use strict" at all atm. :p
It is the "eat your vegatables" of Perl programming.
It will be good for you whether you like the taste or not.
It is really easy to get along with, most often all you need
to do is to put "my " in front of the first use of every variable.
It will pay you back by finding common mistakes for you.
> so any info you can give me on this is valuable to me.
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 5795
***************************************