[23712] in Perl-Users-Digest
Perl-Users Digest, Issue: 5918 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 10 00:05:49 2003
Date: Tue, 9 Dec 2003 21:05:10 -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 Tue, 9 Dec 2003 Volume: 10 Number: 5918
Today's topics:
Re: #!/usr/bin/perl <lv@aol.com>
Re: appending to file appends twice!? <waltman@pobox.com>
Beginners Program <ned@challis2000.fsnet.co.uk>
Re: Beginners Program <invalid-email@rochester.rr.com>
Re: Beginners Program <ned@challis2000.fsnet.co.uk>
Re: Beginners Program <matthew.garrish@sympatico.ca>
Re: Beginners Program (Sam Holden)
Re: Beginners Program <noreply@gunnar.cc>
Re: Beginners Program <go@away.spam>
Re: Beginners Program <ned@challis2000.fsnet.co.uk>
Re: Beginners Program <matthew.garrish@sympatico.ca>
Re: Beginners Program <noreply@gunnar.cc>
Re: Beginners Program (Tad McClellan)
Character class [\W_] clarification (Fiaz Idris)
Re: Character class [\W_] clarification (William Herrera)
connection fail with ppm (jhhan)
Re: How to run _init for all ancestor classes in diamon <uri@stemsystems.com>
Re: net::scp::expect error (Daniel Berger)
Re: Perl Installation Copied to Another Machine <nospam@bigpond.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 09 Dec 2003 21:21:01 -0600
From: l v <lv@aol.com>
Subject: Re: #!/usr/bin/perl
Message-Id: <AiwBb.2871$5M.75302@dfw-read.news.verio.net>
Gunnar Hjalmarsson wrote:
> Roman Khutkyy wrote:
>
>> is there any ability in Perl to write the first string in script as
>> alternative string for different platforms.
>> I write CGI scripts on the Win32 computer, then I transport it to
>> the Unix server, and each time i need to rewrite this string. Is
>> there universal string for both platforms?
>
>
> On my Win32 computer, I have a C:/usr/bin directory where I have an
> extra copy of perl.exe. That makes '#!/usr/bin/perl' work there as well.
>
Microsoft has a program called linkd.exe located on their resourse kit
which allows you to make a unix type symlink on NTFS. It allows to link
c:/usr/bin to your perl install location.
I could not find the Windows 2000 version on MS's web site but they do
have the Win 2003 version
http://download.microsoft.com/download/8/e/c/8ec3a7d8-05b4-440a-a71e-ca3ee25fe057/rktools.exe
Directory of C:\usr
12/09/2003 09:18 PM <DIR> .
12/09/2003 09:18 PM <DIR> ..
12/09/2003 09:18 PM <JUNCTION> bin
C:\usr>dir bin
Volume in drive C has no label.
Volume Serial Number is 5C27-E982
Directory of C:\usr\bin
08/24/2003 08:41 PM <DIR> .
08/24/2003 08:41 PM <DIR> ..
01/02/2002 04:17 PM 90,112 a2p.exe
05/28/2003 07:17 PM 38,124 c2ph.bat
12/28/2001 09:34 AM 5,154 config.pl
08/20/2001 10:09 AM 3,555 configPPM.pl
10/26/2001 01:06 PM 3,888 configPPM3.pl
01/02/2002 04:19 PM 21,820 dprofpp.bat
01/02/2002 04:19 PM 3,265 exetype.bat
05/28/2003 07:17 PM 24,172 find2perl.bat
05/28/2003 07:17 PM 20,708 h2ph.bat
05/28/2003 07:17 PM 49,506 h2xs.bat
08/20/2001 10:09 AM 1,820 IISScriptMap.pl
12/09/2002 01:40 AM 1,876 Keywords.txt
01/02/2002 04:23 PM 13,323 libnetcfg.bat
08/20/2001 10:31 AM 12,905 libnetcfg.pl
12/09/2002 01:42 AM 69,632 MSIdump.exe
12/09/2002 01:43 AM 106,496 pdkdebug.exe
01/02/2002 04:17 PM 20,480 perl.exe
01/02/2002 04:17 PM 20,480 perl5.6.1.exe
01/02/2002 04:17 PM 663,552 perl56.dll
Very handy tool.
Len
------------------------------
Date: Tue, 9 Dec 2003 22:33:33 -0500
From: Walt Mankowski <waltman@pobox.com>
Subject: Re: appending to file appends twice!?
Message-Id: <slrnbtd50d.d5l.waltman@waltman.dnsalias.org>
On 2003-12-07, Guy <someone@somewhere.nb.ca> wrote:
> Well I think I found the cause, but I still don't understand what's wrong...
> (BTW, I will read up on perldoc -q quot, thanks for that :-)
>
> I recently added a locking scheme to prevent 2 instances of my Perl script
> from updating the text data files at the same time.
>
> Basically it locks a dummy file for exclusive - once the file is locked it
> does its stuff - then it closes that dummy file.
>
> In any case, it turns out that if I don't call those locksys and unlocksys
> routines of mine, this problem doesn't occur.
> Am I doing anything wrong.
> The only thing I can see different is that I have 2 files open at the same
> time: LCKFILE and FILE
> Do I need to so anything before opening a 2nd file or using a 2nd file
> handle?
This code looks fine as well. I think the locking here is a symptom, not the
cause of your problem. My theory remains that somehow your Perl script is being
called twice. If you have locking, then they're effectively single-threaded
and update your file one after another. Without locking they both run
simultaneously and whichever process happens to finish last overwrites the work
of the one that finished first.
Have you checked your weblogs yet to see if the perl script is being hit twice?
Walt
------------------------------
Date: Wed, 10 Dec 2003 00:51:29 -0000
From: "Lenny Challis" <ned@challis2000.fsnet.co.uk>
Subject: Beginners Program
Message-Id: <br5qmj$fp8$1@newsg3.svr.pol.co.uk>
Good evening everyone.
I am currently in college doing a National Diploma in computing. Most of the
guys there haven't studied HTML or CSS or the likes and next year I think
they may be asking us to do ASP. I'm not very fond of the idea at all, so I
thought I would code my first assignment in Perl.
I had to work with 2 friends however and they have never seen perl, or even
heard of it. In fact, the looks on peoples faces when I did a presentation
on Larry Wall and Perl were kind of strange to say the least.
Anyway, to the point. I am quite new to perl myself, but I absolutely adore
it already. I am very keen to learn and make good habits from the very
beginning. I hope you don't mind, but here is a program I have made in Perl
to convert HTML files into CGI. I will use this while working with my
friends.
I would love to accept any criticism's. It is one of my first programs, but
don't miss anything. One thing I hate is getting into bad habits, so I would
like to pick them up now.
Anyway, here goes.
Thanks alot,
Lenny Challis.
___________________________
#!/usr/bin/perl -w
#this program takes in the input (html) file as command lines first argument
and output cgi file as second
use strict;
my $ofile = shift @ARGV;
my $cfile = shift @ARGV; #get the two filenames
open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
both files
print OUTPUT "\#!/usr/bin/perl\n\n";
print OUTPUT "print \"Content-type:text/html\\n\\n\";\n"; #print
the shebang and content tags
while (<INPUT>)
{
chomp($_); #getting rid of the \n's makes the code
alot more understandable
$_ =~ s/"/\\"/g; #first, escape
all quotes
$_ = "print \"" . $_ . "\\n\";\n"; #add print function
and newlines to $_
print OUTPUT $_; #add line to the output
file
}
print "Completed."; #let them know its
done
_____________________________
I am looking into getting in CGI and want to also get into mod_perl in the
future.
Thanks alot for your time.
------------------------------
Date: Wed, 10 Dec 2003 01:51:03 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Beginners Program
Message-Id: <3FD677C9.6000101@rochester.rr.com>
Lenny Challis wrote:
> Good evening everyone.
>
> I am currently in college doing a National Diploma in computing. Most of the
> guys there haven't studied HTML or CSS or the likes and next year I think
> they may be asking us to do ASP. I'm not very fond of the idea at all, so I
> thought I would code my first assignment in Perl.
Excellent choice IMHO.
>
> I had to work with 2 friends however and they have never seen perl, or even
----------------------------------------------------------------^
The official correct name of the language is Perl.
> heard of it. In fact, the looks on peoples faces when I did a presentation
> on Larry Wall and Perl were kind of strange to say the least.
>
> Anyway, to the point. I am quite new to perl myself, but I absolutely adore
> it already. I am very keen to learn and make good habits from the very
> beginning. I hope you don't mind, but here is a program I have made in Perl
> to convert HTML files into CGI. I will use this while working with my
> friends.
>
> I would love to accept any criticism's. It is one of my first programs, but
> don't miss anything. One thing I hate is getting into bad habits, so I would
> like to pick them up now.
>
> Anyway, here goes.
> Thanks alot,
> Lenny Challis.
>
> ___________________________
>
> #!/usr/bin/perl -w
------------------^^
Excellent!
>
> #this program takes in the input (html) file as command lines first argument
> and output cgi file as second
--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Commentary wrapped somewhere between your posting and my reading. Try
to avoid posting commentary (or code) which wraps.
>
> use strict;
--^^^^^^^^^^
Outstanding!
>
> my $ofile = shift @ARGV;
> my $cfile = shift @ARGV; #get the two filenames
>
> open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
> open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
> both files
>
> print OUTPUT "\#!/usr/bin/perl\n\n";
----------------^
It is not necessary to escape a # character in a qq() string.
> print OUTPUT "print \"Content-type:text/html\\n\\n\";\n"; #print
> the shebang and content tags
>
> while (<INPUT>)
> {
> chomp($_); #getting rid of the \n's makes the code
--^-----^^
It is usually good style to indent the bodies of loops by four
characters. Makes it much more readable.
Also, $_ is the default argument to chomp, so you can say just:
chomp;
Likewise $_ can be omitted in many other places, like the next
statement, which could be just s/"/\\"/g; . That is usually the Perlish
thing to do.
> alot more understandable
> $_ =~ s/"/\\"/g; #first, escape
> all quotes
> $_ = "print \"" . $_ . "\\n\";\n"; #add print function
-----------------^^^^^^^^
Here you could "interpolate" $_ into the string, as in:
$_ = "print \"$_\\n\";\n";
Any scalar variable appearing in a "-string is substituted into the
string, so:
$v='y';
print "x $v z\n";
prints
x y z
That is why there are "-strings in addition to '-strings, and why they
aren't the same.
> and newlines to $_
> print OUTPUT $_; #add line to the output
> file
> }
>
> print "Completed."; #let them know its
-------------------^
Depending on your OS, you might want a \n at the end of this string to
avoid having a command prompt following the output on the same line.
> done
>
> _____________________________
>
> I am looking into getting in CGI and want to also get into mod_perl in the
> future.
>
> Thanks alot for your time.
You're welcome. Looks to me like you did a fine job on your Perl
program. Hope you find Perl as fascinating and useful as I do.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Wed, 10 Dec 2003 01:58:48 -0000
From: "Lenny Challis" <ned@challis2000.fsnet.co.uk>
Subject: Re: Beginners Program
Message-Id: <br5ukp$p9q$1@newsg2.svr.pol.co.uk>
<snip>
>Bob Walton Wrote:
>
>
> You're welcome. Looks to me like you did a fine job on your Perl
> program. Hope you find Perl as fascinating and useful as I do.
>
> --
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl
>
I have been practicing making the shorter scripts (ie: not having to write
$_). Also, I know all about interpolating, I jut didn't think of doing it
this way :-) (TMTOWTDI!).
Theres plenty to remember but it's such a versatile language and its so much
fun to learn. I have programmed C++, Visual Basic and a couple others, Perl
is my favourite by far. I am slowly getting my head into perl mode and yes I
_am_ finding it really useful.
Thanks for the great feedback.
Lenny
------------------------------
Date: Tue, 9 Dec 2003 20:52:46 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Beginners Program
Message-Id: <j0vBb.2393$tk1.530348@news20.bellglobal.com>
"Lenny Challis" <ned@challis2000.fsnet.co.uk> wrote in message
news:br5qmj$fp8$1@newsg3.svr.pol.co.uk...
>
> #!/usr/bin/perl -w
>
> #this program takes in the input (html) file as command lines first
argument
> and output cgi file as second
>
> use strict;
Very nice beginning.
>
> my $ofile = shift @ARGV;
> my $cfile = shift @ARGV; #get the two filenames
>
unless (scalar(@ARGV) == 2) {
die "Correct usage: perl myscript.pl input_file output_file\n";
}
my ($ofile, $cfile) = @ARGV;
You're better off checking your arguments before you try processing them.
Saves the user having to guess why the script might not be running. Also,
strange names for an input file and output file. It might make more sense to
call them $infile and $outfile so you don't confuse yourself later on. It
also helps when you have to come back to your code somewhere down the line
(or when someone else does).
> open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
> open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
> both files
>
> print OUTPUT "\#!/usr/bin/perl\n\n";
print OUTPUT "#!/usr/bin/perl\n\n"; # no need to escape a # within quotes
> print OUTPUT "print \"Content-type:text/html\\n\\n\";\n";
#print
> the shebang and content tags
>
print OUTPUT 'print "Content-type: text/html\n\n";' . "\n";
Don't use double-quotes unless you need them.
> while (<INPUT>)
while (my $line = <INPUT>) {
...
Better to name your variables. It's okay to use $_ for a very small block,
but it's easy to forget what you're operating on and what $_ might be set
to.
Not an exhaustive review, but hope that gives you a few things to think
about.
Matt
------------------------------
Date: 10 Dec 2003 02:10:23 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Beginners Program
Message-Id: <slrnbtd04e.bfa.sholden@flexal.cs.usyd.edu.au>
On Wed, 10 Dec 2003 00:51:29 -0000,
Lenny Challis <ned@challis2000.fsnet.co.uk> wrote:
>
> I would love to accept any criticism's. It is one of my first programs, but
> don't miss anything. One thing I hate is getting into bad habits, so I would
> like to pick them up now.
>
> Anyway, here goes.
> Thanks alot,
> Lenny Challis.
>
> ___________________________
>
> #!/usr/bin/perl -w
>
> #this program takes in the input (html) file as command lines first argument
> and output cgi file as second
>
> use strict;
Warnings and strictures are good :)
>
> my $ofile = shift @ARGV;
> my $cfile = shift @ARGV; #get the two filenames
>
> open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
> open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
> both files
Watch your line wrapping, I realise it's probably a posting to usenet
artifact, but even so some of the following lines are far too long, in
my opinion anyway.
I'd put single quotes aroung the < and >, since they don't need
double quote features. I'd leave off the \n on the die output so
that perl will add the line number information (which may of course
not be wanted in your case).
>
> print OUTPUT "\#!/usr/bin/perl\n\n";
> print OUTPUT "print \"Content-type:text/html\\n\\n\";\n"; #print
> the shebang and content tags
# isn't special and doesn't need to be escaped in a double quoted string.
Why no warnings and strictures in the generated code?
If you are putting "s in a string then it is usually best to use a different
quote character than ". Saves on the escaping, something like:
print OUTPUT 'print "Content-type:text/html\n\n";', "\n";
or if you really must have it as one string (but I'd rather avoid the
\\s):
print OUTPUT qq{print "Content-type:text/html\\n\\n";\n};
>
> while (<INPUT>)
> {
> chomp($_); #getting rid of the \n's makes the code
> alot more understandable
> $_ =~ s/"/\\"/g; #first, escape
> all quotes
If you are using $_ there is not need to mention it, just use
s/"/\\"/g, if you want to be explicit about the variable than don't
use $_, read into $line or something...
> $_ = "print \"" . $_ . "\\n\";\n"; #add print function
> and newlines to $_
> print OUTPUT $_; #add line to the output
> file
You seem to be producing an output file that is a CGI script that will
output the input file when run. However, if there are \ characters in the
input file things could go wrong.
Try running it on a file containing
\"
in it somewhere to see the problem.
And what about files containing things like:
Bananas only $1.99 a kilo, save $$. email: foo@example.com
You need to escape a lot more characters than just ".
Something like (completely untested):
s/\\/\\\\/g; #this must be done first, before we add \s
s/"/\\"/g;
s/\$/\\\$/g;
s/@/\\\@/g; # I prefer \@ in the pattern, but it isn't needed
s/\t/\\t/g;
s/\r/\\r/g;
print qq{print "$_\\n";\n};
> }
>
> print "Completed."; #let them know its
> done
You should close the OUTPUT file, and check for failure. After all
writes can actually fail (the disk might fill up, for example) and
it's good to check that the output file closed successfully (you could
check on all the print calls, but that would be ugly and unwarranted
in this case).
The loop could be replaced with:
print OUTPUT "print <<'HTML';\n";
print OUTPUT while (<INPUT>);
print OUTPUT "HTML\n";
Assuming the string 'HTML' isn't found on a line by itself in the input
and that the final line of input does end with a newline character.
But that probably misses the point of introducing some perl features.
As an aside, for those who might know:
Why is
print "@";
OK, but
print "$";
isn't?
To me the first should be illegal (but I'm clearly wrong).
--
Sam Holden
------------------------------
Date: Wed, 10 Dec 2003 03:20:06 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Beginners Program
Message-Id: <br5vsi$299d12$1@ID-184292.news.uni-berlin.de>
Lenny Challis wrote:
> I would love to accept any criticism's.
Okay, these are my comments:
> #!/usr/bin/perl -w
You may want to consider the lexically scoped warnings pragma before
the dynamically scoped -w switch.
#!/usr/bin/perl
use warnings;
See http://www.perldoc.com/perl5.8.0/pod/perllexwarn.html
> print OUTPUT "print \"Content-type:text/html\\n\\n\";\n";
You should learn the difference between ' and ", and consider using '
sometimes to reduce the need to escape things. For instance, that line
could be written:
print OUTPUT 'print "Content-type: text/html\n\n";', "\n";
Personally I think it makes it easier to read. See
http://www.perldoc.com/perl5.8.0/pod/perlop.html#q%2DSTRING%2D
> while (<INPUT>)
> {
> chomp($_);
> $_ =~ s/"/\\"/g;
> $_ = "print \"" . $_ . "\\n\";\n";
> print OUTPUT $_;
> }
The here-document syntax is very useful when printing HTML. Those
lines could be replaced with:
print OUTPUT "print <<HTML;\n";
print OUTPUT $_ while <INPUT>;
print OUTPUT "\nHTML\n";
See http://www.perldoc.com/perl5.8.0/pod/perlop.html#%3c%3cEOF
Also, you should make it a habit to close filehandles when you no
longer need them:
close INPUT or die $!;
close OUTPUT or die $!;
> I am looking into getting in CGI
When dealing with CGI, you may want to benefit from some of the tools
in the CGI.pm module. (But don't forget to learn the basics about
what's going on behind the scenes.)
http://www.perldoc.com/perl5.8.0/lib/CGI.html
Good luck!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 10 Dec 2003 02:24:21 GMT
From: LaDainian Tomlinson <go@away.spam>
Subject: Re: Beginners Program
Message-Id: <Xns944CD9ED390F7bclennoxeosncsuedu@24.25.9.43>
On 09 Dec 2003, "Lenny Challis" <ned@challis2000.fsnet.co.uk> wrote in
comp.lang.perl.misc:
<snip>
> I would love to accept any criticism's. It is one of my first
> programs, but don't miss anything. One thing I hate is getting into
> bad habits, so I would like to pick them up now.
You'd like to pick up bad habits? Hmmm...
> #!/usr/bin/perl -w
>
> #this program takes in the input (html) file as command lines first
> argument and output cgi file as second
# Consider cutting your comments at a reasonable length (around 80
# characters) and continuing on the next line instead of letting your
# newsreader or text editor do the wrapping for you.
Also, rather than using the -w switch, use the warnings pragma instead
(see below).
>
> use strict;
use warnings;
>
> my $ofile = shift @ARGV;
> my $cfile = shift @ARGV; #get the two filenames
If no arguments are passed to shift(), it assumes @ARGV (or @_ in
subroutines), so either:
my $ofile = shift;
my $cfile = shift;
or
# preferred when there are many arguments
my ($ofile, $cfile) = @ARGV;
> open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
> open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n";
> #open both files
Note that the newline at the end of your die-string supresses the
filename and line number in the error message. For such a small script,
it's not a big deal, but there's no reason to ignore it.
> print OUTPUT "\#!/usr/bin/perl\n\n";
> print OUTPUT "print \"Content-type:text/html\\n\\n\";\n";
> #print the shebang and content tags
No need to escape '#' characters. You can also avoid interpolation
altogether by using single quotes:
print OUTPUT 'print "Content-type:text/html\n\n";', "\n";
> while (<INPUT>)
> {
> chomp($_); #getting rid of the \n's makes the
> code alot more understandable
> $_ =~ s/"/\\"/g; #first,
> escape all quotes
> $_ = "print \"" . $_ . "\\n\";\n"; #add print
> function and newlines to $_
> print OUTPUT $_; #add line to the
> output file
> }
>
> print "Completed."; #let them
> know its done
chomp() and s/// both operate on $_ by default:
while (<INPUT>){
chomp;
s/"/\\"/g;
# ...
}
Overall it looks fine to me. I'm somewhat new as well (but not as new
as you ;-). Style-wise, though, I would suggest removing a lot of the
superfluous commenting, and make sure you indent your blocks properly.
Keep reading clpm and you can't help but learn.
Brandan L.
--
bclennox AT eos DOT ncsu DOT edu
------------------------------
Date: Wed, 10 Dec 2003 02:35:33 -0000
From: "Lenny Challis" <ned@challis2000.fsnet.co.uk>
Subject: Re: Beginners Program
Message-Id: <br60pm$i94$1@newsg3.svr.pol.co.uk>
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnbtd04e.bfa.sholden@flexal.cs.usyd.edu.au...
> On Wed, 10 Dec 2003 00:51:29 -0000,
> Lenny Challis <ned@challis2000.fsnet.co.uk> wrote:
> >
> > I would love to accept any criticism's. It is one of my first programs,
but
> > don't miss anything. One thing I hate is getting into bad habits, so I
would
> > like to pick them up now.
> >
> > Anyway, here goes.
> > Thanks alot,
> > Lenny Challis.
> >
> > ___________________________
> >
> > #!/usr/bin/perl -w
> >
> > #this program takes in the input (html) file as command lines first
argument
> > and output cgi file as second
> >
> > use strict;
>
> Warnings and strictures are good :)
>
> >
> > my $ofile = shift @ARGV;
> > my $cfile = shift @ARGV; #get the two filenames
> >
> > open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
> > open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
> > both files
>
> Watch your line wrapping, I realise it's probably a posting to usenet
> artifact, but even so some of the following lines are far too long, in
> my opinion anyway.
>
> I'd put single quotes aroung the < and >, since they don't need
> double quote features. I'd leave off the \n on the die output so
> that perl will add the line number information (which may of course
> not be wanted in your case).
>
> >
> > print OUTPUT "\#!/usr/bin/perl\n\n";
> > print OUTPUT "print \"Content-type:text/html\\n\\n\";\n";
#print
> > the shebang and content tags
>
> # isn't special and doesn't need to be escaped in a double quoted string.
>
> Why no warnings and strictures in the generated code?
>
> If you are putting "s in a string then it is usually best to use a
different
> quote character than ". Saves on the escaping, something like:
>
> print OUTPUT 'print "Content-type:text/html\n\n";', "\n";
>
> or if you really must have it as one string (but I'd rather avoid the
> \\s):
>
> print OUTPUT qq{print "Content-type:text/html\\n\\n";\n};
>
> >
> > while (<INPUT>)
> > {
> > chomp($_); #getting rid of the \n's makes the
code
> > alot more understandable
> > $_ =~ s/"/\\"/g; #first,
escape
> > all quotes
>
> If you are using $_ there is not need to mention it, just use
> s/"/\\"/g, if you want to be explicit about the variable than don't
> use $_, read into $line or something...
>
> > $_ = "print \"" . $_ . "\\n\";\n"; #add print
function
> > and newlines to $_
> > print OUTPUT $_; #add line to the
output
> > file
>
> You seem to be producing an output file that is a CGI script that will
> output the input file when run. However, if there are \ characters in the
> input file things could go wrong.
>
> Try running it on a file containing
>
> \"
>
> in it somewhere to see the problem.
>
> And what about files containing things like:
>
> Bananas only $1.99 a kilo, save $$. email: foo@example.com
>
> You need to escape a lot more characters than just ".
>
> Something like (completely untested):
>
> s/\\/\\\\/g; #this must be done first, before we add \s
> s/"/\\"/g;
> s/\$/\\\$/g;
> s/@/\\\@/g; # I prefer \@ in the pattern, but it isn't needed
> s/\t/\\t/g;
> s/\r/\\r/g;
> print qq{print "$_\\n";\n};
>
>
> > }
> >
> > print "Completed."; #let them know
its
> > done
>
> You should close the OUTPUT file, and check for failure. After all
> writes can actually fail (the disk might fill up, for example) and
> it's good to check that the output file closed successfully (you could
> check on all the print calls, but that would be ugly and unwarranted
> in this case).
>
> The loop could be replaced with:
>
> print OUTPUT "print <<'HTML';\n";
> print OUTPUT while (<INPUT>);
> print OUTPUT "HTML\n";
>
> Assuming the string 'HTML' isn't found on a line by itself in the input
> and that the final line of input does end with a newline character.
>
> But that probably misses the point of introducing some perl features.
>
> As an aside, for those who might know:
>
> Why is
> print "@";
> OK, but
> print "$";
> isn't?
>
> To me the first should be illegal (but I'm clearly wrong).
>
> --
> Sam Holden
>
That was really great feedback.
I have learnt alot from it, Thanks alot
Lenny
------------------------------
Date: Tue, 9 Dec 2003 21:24:54 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Beginners Program
Message-Id: <LtvBb.2447$tk1.543161@news20.bellglobal.com>
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnbtd04e.bfa.sholden@flexal.cs.usyd.edu.au...
>
> As an aside, for those who might know:
>
> Why is
> print "@";
> OK, but
> print "$";
> isn't?
>
$" is a predefined variable. How would you then use it in a double-quoted
string if the above were not an error?
Matt
------------------------------
Date: Wed, 10 Dec 2003 04:20:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Beginners Program
Message-Id: <br63eu$23dcrh$1@ID-184292.news.uni-berlin.de>
Sam Holden wrote:
> You need to escape a lot more characters than just ".
>
> Something like (completely untested):
>
> s/\\/\\\\/g; #this must be done first, before we add \s
> s/"/\\"/g;
> s/\$/\\\$/g;
> s/@/\\\@/g; # I prefer \@ in the pattern, but it isn't needed
> s/\t/\\t/g;
> s/\r/\\r/g;
> print qq{print "$_\\n";\n};
<snip>
> The loop could be replaced with:
>
> print OUTPUT "print <<'HTML';\n";
------------------------^----^
Which is a much smarter way to deal with the need for escaping things.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 9 Dec 2003 21:54:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Beginners Program
Message-Id: <slrnbtd67v.tdf.tadmc@magna.augustmail.com>
Lenny Challis <ned@challis2000.fsnet.co.uk> wrote:
[ snip 150 lines of quoting ]
> That was really great feedback.
Please learn to compose followups properly.
Have you seen the Posting Guidelines that are posted here frequently?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Dec 2003 19:29:36 -0800
From: ifiaz@hotmail.com (Fiaz Idris)
Subject: Character class [\W_] clarification
Message-Id: <93c1947c.0312091929.6018038c@posting.google.com>
Keywords: Character Class Regex Regular Expression Regular Expressions \W_ \W
I know that [\W] matches [^a-zA-Z_0-9]
From Mastering Algorithms with Perl (Page.110), I see a character class
[\W_] that does the following
s/[\W_]+//g
i.e. to replace (all non-word character and underscore) with (nothing).
First, I couldn't understand the above that is because I interpreted
above regex as *** replace "\W" with "^a-zA-Z_0-9" ***
s/[^a-zA-Z_0-9_]+//g -------------->(regex XXX)
That is to replace (non-word characters including underscore) with (nothing)
and thought that the last underscore is infact unnecessary.
My question is where in the documentation (anywhere) that says
the [\W] will infact work with the interpretation as below:
[~`!@#$%^&*()-[]:;<,./"? ........and so on] but not the interpretation
give in (regex XXX) above.
If this seems to be a dumb question, I apologise. But, still I require
an explanation.
------------------------------
Date: Wed, 10 Dec 2003 04:18:50 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: Character class [\W_] clarification
Message-Id: <3fd69d68.47947591@news2.news.adelphia.net>
On 9 Dec 2003 19:29:36 -0800, ifiaz@hotmail.com (Fiaz Idris) wrote:
>Keywords: Character Class Regex Regular Expression Regular Expressions \W_ \W
>
>I know that [\W] matches [^a-zA-Z_0-9]
>
>From Mastering Algorithms with Perl (Page.110), I see a character class
>[\W_] that does the following
>
>s/[\W_]+//g
>
>i.e. to replace (all non-word character and underscore) with (nothing).
>
>First, I couldn't understand the above that is because I interpreted
>above regex as *** replace "\W" with "^a-zA-Z_0-9" ***
>
>s/[^a-zA-Z_0-9_]+//g -------------->(regex XXX)
>
>That is to replace (non-word characters including underscore) with (nothing)
>and thought that the last underscore is infact unnecessary.
I think the underscore is considred a legal character for perl words.
Try this:
#!/usr/bin/perl
my $txt = '$$% 3b__c4 101 _ z42';
my $i = $txt;
my $j = $txt;
my $k = $txt;
$i =~ s/[\W_]+//g;
$j =~ s/([\W]|_)+//g;
$k =~ s/[\W]+//g;
print "txt $txt, i $i, j $j, k $k;";
>
>My question is where in the documentation (anywhere) that says
>the [\W] will infact work with the interpretation as below:
perlre, thinks I
---
Use the domain skylightview (dot) com for the reply address instead.
------------------------------
Date: 9 Dec 2003 20:39:50 -0800
From: jeunghun@terrasem.com (jhhan)
Subject: connection fail with ppm
Message-Id: <c2c31e10.0312092039.7e66b489@posting.google.com>
Hello,
>ppm
PPM>search pty claimed always
Error connecting to'http://ppm.ActiveState.com/dgibin/PPM/ppmserver.pl?urn:/PPMServer'.
and I tried
>ppm3
ppm>search pty
Searching in Active Repositories
No matched for ;pty'; see 'help search'.
ppm>rep add active http://www.ActiveState.com/cgibin/PPM/ppmserver.plex?urn:/PPMServer
Error: 500 Can't read entity body: Unknown error at
C:/Perl/site/lib/PPM/Repository.pm line 84
line 84 of Repository.pm is my $soap_result = $client->ppm_protocol;
Is anyone who can help me?
Thanks
JH
------------------------------
Date: Wed, 10 Dec 2003 04:55:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <x7u149gtlk.fsf@mail.sysarch.com>
>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@rwth-aachen.de> writes:
TvP> sub _class_init {
TvP> my ($self, %args) = @_;
TvP> for (@SolarCar::ISA) {
TvP> my $init = $_->can("_init")
TvP> and $self->$init;
i would double check if that works. there is a well known problem with
refering to a my var in the statement that declares it. the second $init
refers to a previously existing $init and is not strict safe. i would
write that as:
if (my $init = $_->can("_init") ) {
$self->$init;
}
and that is my safe and even clearer IMO.
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: 9 Dec 2003 18:18:13 -0800
From: djberg96@hotmail.com (Daniel Berger)
Subject: Re: net::scp::expect error
Message-Id: <6e613a32.0312091818.4c17a39d@posting.google.com>
ctippur@msn.com (Chandrashekar Tippur) wrote in message news:<629c1390.0312040940.281d8a89@posting.google.com>...
> Daniel,
>
> SSH version is Secure Shell 3.2.5 and the OS is SunOS 2.8.
>
> - Shekar
>
Ah, I've received a couple of other reports about this. I only tested
against OpenSSH, not Sun's. I'm not sure what the problem is, except
that there's some text appearing at a moment when I don't expect it
(no pun intended).
Does using the "-verbose" option provide any more detail?
It may be a while before I resolve this. In the meantime, you may
want to take a look at Net::SFTP.
Regards,
Dan
------------------------------
Date: Wed, 10 Dec 2003 12:40:44 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Perl Installation Copied to Another Machine
Message-Id: <1498612.PhJGQU8SOk@gregs-web-hosting-and-pickle-farming>
It was a dark and stormy night, and bear managed to scribble:
> Can I make and install Perl and install all the Perl modules on one
> machine and then copy the Perl directory to a second machine and have it
> work correctly? I 've got all the Perl modules installed correctly on the
> first machine including
> Apache, mysql DBI, DBD, etc. After copying the perl directory to the
> second
> machine I can not start Apache httpd. I get the message
> "Can't locate loadable object for module DBI in @INC"
>
> Should I make Perl or DBI on the second machine?
>
> thanks
I doubt it. Some modules have underlying C routines and install software in non-obvious places.
Just install the underlying modules from scratch - it takes only a few minutes
But your question eraises other points. Most linux distros come with DBI and dozens(hundreds?) of other modules already installed.
And Perl has nothing to do with stareting the Apache httpd daemon.
gtoomey
------------------------------
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 5918
***************************************