[21769] in Perl-Users-Digest
Perl-Users Digest, Issue: 3973 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 15 11:05:50 2002
Date: Tue, 15 Oct 2002 08:05:13 -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 Tue, 15 Oct 2002 Volume: 10 Number: 3973
Today's topics:
Re: !\n problem news@roaima.freeserve.co.uk
[ANNOUNCEMENT] First meeting for Oslo.pm, 16. oct 2002 (Salve J. Nilsen)
Re: array of array? <usenet@dwall.fastmail.fm>
GetUserMisc.al ? <khowlette@bigfoot.com>
How to know if packed as binary? edgue@web.de
Re: How to know if packed as binary? <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: How to know if packed as binary? <josef.moellers@fujitsu-siemens.com>
Re: How to know if packed as binary? edgue@web.de
Re: How to know if packed as binary? <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: HTTP Command help....? <flavell@mail.cern.ch>
http://lists.perl.org (slightly OT) <Tassilo.Parseval@post.rwth-aachen.de>
Installing Modules <invalid@pinnock.com>
Re: Installing Modules <nobull@mail.com>
Re: Installing Modules <invalid@pinnock.com>
Re: Learnign perl. <usenet@tinita.de>
newbie question <patrick@-/abazar\-.nl>
Re: newbie question <mniederlechner@gmx.net>
Re: newbie question <usenet@dwall.fastmail.fm>
Re: newbie question <nobody@dev.null>
Novice seeks help <bpfsa@yahoo.com>
Re: Novice seeks help <twhu@lucent.com>
Re: Novice seeks help <espenmyr@start.no.spam>
Re: Novice seeks help <Tassilo.Parseval@post.rwth-aachen.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Oct 2002 12:19:52 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: !\n problem
Message-Id: <oktgoa.emb.ln@moldev.cmagroup.co.uk>
pkent <pkent77tea@yahoo.com.tea> wrote:
> This little bit of code:
> perl -e 'for (0..1000) { print ($_%10?".":"|") }' | mail USER@HOSTNAME
> showed me that my copy of sendmail was splitting lines with a "!\n"
> sequence after 989 characters.
To be pedantic, it shows that either your mail agent ("mail") or sendmail
was splitting lines. On my box, it appears that the MUA "mail" does
split long lines, but the MTA "sendmail" doesn't.
Compare your example to this:
(
echo "From: USER"
echo "To: USER"
echo
perl -e 'for (0..1000) { print ($_%10?".":"|") }'
) | /usr/lib/sendmail USER@HOSTNAME
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: 15 Oct 2002 13:07:20 +0200
From: sjn+njus@pvv.org (Salve J. Nilsen)
Subject: [ANNOUNCEMENT] First meeting for Oslo.pm, 16. oct 2002
Message-Id: <m33cr8arkn.fsf@benzen.eiendomsnett.no>
I'd like to invite all interested parties to
Oslo.pm (Oslo Perl Mongers) first meeting
October 16th, 2002, at 19:00 CET
at "Pastiz", Tordenskiolds gate 10 (next to the city hall)
We'll start off with a social event where we try to decide what to do
with the new users group we're creating...
Additional information can be found on the Oslo.pm website,
<http://oslo.pm.org/>.
Everyone is welcome! :)
Regards,
- Salve J. Nilsen, on behalf of the Oslo-members of the
no.it.programmering.perl newsgroup :)
--
"Don't worry about what anybody else is going to do... The best way
to predict the future is to invent it." -- Alan Kay, 1971
------------------------------
Date: Tue, 15 Oct 2002 14:44:53 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: array of array?
Message-Id: <Xns92A86D55A94DAdkwwashere@216.168.3.30>
jackkon <jackkon@ms29.url.com.tw> wrote on 15 Oct 2002:
> hi, all
> How to the convert a text file below to the array of array?
> Thanks a lot.
>
>========text file
> 01 AAAA-F.
> 03 AA-ERR PIC S9(05).
> 03 AA-FNAME PIC X(10).
> 03 AA-COUNT-K PIC 9(10).
> 01 AAAA-R.
> 03 AA-REC-KEY.
> 05 AA-DEPT-NO PIC X(02).
> 05 AA-DEPT-MAX PIC X(02).
> 03 AA-DEPT-NAME PIC X(12).
> 03 AA-BED-NO PIC 9(05).
> 03 AA-TOT-BED-NO PIC 9(05).
>
>========array of array
> [
> 01 AAAA-F.
> [
> 03 AA-ERR PIC S9(05).
> 03 AA-FNAME PIC X(10).
> 03 AA-COUNT-K PIC 9(10).
> ]
> 01 AAAA-R.
> [
> 03 AA-REC-KEY.
> [
> 05 AA-DEPT-NO PIC X(02).
> 05 AA-DEPT-MAX PIC X(02).
> ]
> 03 AA-DEPT-NAME PIC X(12).
> 03 AA-BED-NO PIC 9(05).
> 03 AA-TOT-BED-NO PIC 9(05).
> ]
> ]
>
Here's a way that looks at the indentation of the data and creates array
entries based on that. It assumes that indents are exactly 8 spaces, and
"first-level" entries (lines starting with '01' in your sample data) are
indented 8 spaces. Your data looks as if it were generated by a program,
so maybe these assumptions aren't unreasonable.
Of course I had Tassilo's solution to work from, so I just altered it a
little. :-)
use Data::Dumper;
my @data;
while (<DATA>) {
chomp;
if ( ! m/((?: {8})+)(.*)/ ) {
die "Indent pattern not matched on line $.\n";
}
my $indent_level = (length($1) / 8) - 1;
push_lev(\@data, $indent_level, $2);
}
sub push_lev {
my ($array, $level, $value) = @_;
if ( $level > 1 ) {
push_lev($array->[-1], $level - 1, $value);
}
elsif ( $level == 1 ) {
if ( ref $array->[-1] ) {
push @{$array->[-1]}, $value;
}
else {
push @$array, [ $value ];
}
}
else {
push @$array, $value;
}
}
print Dumper \@data;
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Tue, 15 Oct 2002 14:24:25 +0000 (UTC)
From: "BT" <khowlette@bigfoot.com>
Subject: GetUserMisc.al ?
Message-Id: <aoh8eo$2g3$1@knossos.btinternet.com>
Hi
I've just installed the modules AdminMisc and Perms from Dave Roths Win32
extensions and get the following
error. The script is a slightly hacked example script. Any ideas - whats a
.al extension ?
Error Message below
*****************
Can't locate auto/Win32/AdminMisc/GetUserMisc.al in @INC (@INC contains:
C:/Perl
/lib C:/Perl/site/lib .) at getaccmisc.pl line 14
Script ********
# Example 3.3: Using AdminMisc's UserGetMiscAttributes() and
UserSetMiscAttributes().
# ----------------------------------------
# From "Win32 Perl Programming: The Standard Extensions Second Edition" by
Dave Roth
# Published by Macmillan Technical Publishing.
# ISBN # 1-57870-216-X
use Win32::NetAdmin;
use Win32::AdminMisc;
#my $Group = Win32::DomainName();
$Users="Test";
print "User =$User\n";
my %Attribs;
Win32::AdminMisc::GetUserMiscAttributes( "", $User, \%Attribs );
# Check to see if the account disabled bit is set
if( $Attribs{USER_FLAGS} & UF_ACCOUNTDISABLE )
{
# The account is disabled so re-enable it by ANDing the
# flags attribute
# with the two's compliment of the disable account flag. This will
# turn off only the UF_ACCOUNTDISABLE bit but leave other bits as
# they are
$Flags = $Attribs{USER_FLAGS} & ~UF_ACCOUNTDISABLE;
Win32::AdminMisc::UserSetMiscAttributes( "",
$User,
USER_FLAGS=>$Flags );
}
------------------------------
Date: Tue, 15 Oct 2002 14:48:13 +0200
From: edgue@web.de
Subject: How to know if packed as binary?
Message-Id: <3DAC0E8D.4040806@web.de>
Hi there,
I am using the following sub to create a binary
representation of an hex string:
sub x2b
{
return unpack("B*", pack("H*", shift()));
}
Works fine:
my $in = "A0F";
my $out = x2b($in);
print "in: $in -> out: $out\n";
prints:
in: A0F -> out: 1010000011110000
And that is what I want ... now I am wondering:
is there a way to find out if the value of
$out has been created like this?
Right now, when I use x2b again with $out,
the result would be
"0001000000010000000000000000000000010001000100010000000000000000"
I would prefer if x2b() could find out if the incoming
string is already such a binary string - the conversion should
only take place if necessary. Is that possible?
Or is the information "1010000011110000" is a
packed "A0F" lost after the conversion?
------------------------------
Date: Tue, 15 Oct 2002 13:05:08 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: How to know if packed as binary?
Message-Id: <slrnaqo4gb.7rm.bernard.el-hagin@gdndev25.lido-tech>
In article <3DAC0E8D.4040806@web.de>, edgue@web.de wrote:
> Hi there,
>
> I am using the following sub to create a binary
> representation of an hex string:
>
> sub x2b
> {
> return unpack("B*", pack("H*", shift()));
> }
>
> Works fine:
>
> my $in = "A0F";
> my $out = x2b($in);
> print "in: $in -> out: $out\n";
>
> prints:
>
> in: A0F -> out: 1010000011110000
>
> And that is what I want ... now I am wondering:
> is there a way to find out if the value of
> $out has been created like this?
>
> Right now, when I use x2b again with $out,
> the result would be
> "0001000000010000000000000000000000010001000100010000000000000000"
>
> I would prefer if x2b() could find out if the incoming
> string is already such a binary string - the conversion should
> only take place if necessary. Is that possible?
sub x2b {
my $in = shift;
return ($in =~ m/^[01]+$/) ? 0 : unpack("B*", pack("H*", $in));
}
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Tue, 15 Oct 2002 15:29:02 +0200
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to know if packed as binary?
Message-Id: <3DAC181E.D4A2A45@fujitsu-siemens.com>
edgue@web.de wrote:
> =
> Hi there,
> =
> I am using the following sub to create a binary
> representation of an hex string:
> =
> sub x2b
> {
> return unpack("B*", pack("H*", shift()));
> }
> =
> Works fine:
> =
> my $in =3D "A0F";
> my $out =3D x2b($in);
> print "in: $in -> out: $out\n";
> =
> prints:
> =
> in: A0F -> out: 1010000011110000
> =
> And that is what I want ... now I am wondering:
> is there a way to find out if the value of
> $out has been created like this?
> =
> Right now, when I use x2b again with $out,
> the result would be
> "0001000000010000000000000000000000010001000100010000000000000000"
> =
> I would prefer if x2b() could find out if the incoming
> string is already such a binary string - the conversion should
> only take place if necessary. Is that possible?
> =
> Or is the information "1010000011110000" is a
> packed "A0F" lost after the conversion?
Yes, the information is lost.
In general, no you can't "find out if the incoming string is already
such a binary string": every valid number written in a base b is also a
valid number in any base b' >=3D b. In your example, as you found out,
"1010000011110000" is also a valid (ternary, quaternary, ... octal,
nonal, decimal, ...) hexadecimal number!
You could augment your number-string by an indicator of the base, e.g.
"0xA0F" for hex numbers and "0b1010000011110000" for binary numbers.
Then your function could check the number base of the string given.
sub x2b
{
my $input =3D shift;
if ($input =3D~ m/^0b/) {
return $input;
} elsif ($input =3D~ m/^0x[0-9a-f]+/i) {
return "0b" . unpack("B*", pack("H*", substr($input, 2)));
} else {
return undef; # or whatever
}
}
HTH,
Josef
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Tue, 15 Oct 2002 15:46:16 +0200
From: edgue@web.de
Subject: Re: How to know if packed as binary?
Message-Id: <3DAC1C28.9060500@web.de>
Bernard El-Hagin wrote:
>
> sub x2b {
> my $in = shift;
> return ($in =~ m/^[01]+$/) ? 0 : unpack("B*", pack("H*", $in));
Bad idea.
"01" might be a binary string. But it could be a hex string, too.
I need "context knowledge" to decide what "01" means ...
My hope was that pack() would create some "magic type information"
that I could use later on.
I guess I will go for the solution that Josef pointed out ...
------------------------------
Date: Tue, 15 Oct 2002 13:50:26 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: How to know if packed as binary?
Message-Id: <slrnaqo75b.7rm.bernard.el-hagin@gdndev25.lido-tech>
In article <3DAC1C28.9060500@web.de>, edgue@web.de wrote:
> Bernard El-Hagin wrote:
>>
>> sub x2b {
>> my $in = shift;
>> return ($in =~ m/^[01]+$/) ? 0 : unpack("B*", pack("H*", $in));
>
> Bad idea.
I was hoping it would be obvious that my "solution" was a joke. I
guess I should have used a smiley. Sorry. :-)
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Tue, 15 Oct 2002 15:15:55 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HTTP Command help....?
Message-Id: <Pine.LNX.4.40.0210151508070.7201-100000@lxplus071.cern.ch>
On Oct 14, brian d foy inscribed on the eternal scroll:
> it would be nice if people who answered Perl questions actually
> knew how to help people, or at least correctly answered the
> question.
That was pretty-much my feeling too. If they disagree with the FAQ,
which they have every right to do, they should take that up with those
who wrote the FAQ, rather than undermining it by feeding newbies a lot
of inaccurate detail. Knowing where to find the authoritative specs
and citing the relevant sections in support of their reply is always
good for some bonus points too; fortunately, on Usenet the TOFU-style
still seems to be a widely-applicable bogosity alert.
> you seemed to have confused the two types of redirections, and if
> you knew who Alan was you would take your lumps and move on.
Hey, I'm nothing special: on Usenet we stand or fall by what we post,
not by who we are or what impressive job title we can parade.
all the best
------------------------------
Date: 15 Oct 2002 14:46:16 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: http://lists.perl.org (slightly OT)
Message-Id: <aoh9no$h52$1@nets3.rz.RWTH-Aachen.DE>
Hi,
anyone has an idea what happened to lists.perl.org? It doesn't appear to
be accessible (at least not since yesterday). This is a little bit
unfortunate since I intended to subscribe to the perl-xs mailing list and
now can't find the necessary data (subscription address and so on).
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Tue, 15 Oct 2002 11:27:25 +0100
From: "Graeme" <invalid@pinnock.com>
Subject: Installing Modules
Message-Id: <h4Sq9.252$v_5.42643@newsfep2-win.server.ntli.net>
I downloaded SerialPort-0_19.zip from
http://members.aol.com/Bbirthisel/alpha.html but the install
instructions are a bit light on detail.
Can anyone help with these questions:
Where should I unzip SerialPort-0_19.zip to? Is there is place for
this in the PERL directory structure for modules?
Is there a step by step guide anywhere for installing modules?
Any help much appreciated.
--
Graeme
------------------------------
Date: 15 Oct 2002 12:06:31 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Installing Modules
Message-Id: <u9r8esdkqw.fsf@wcl-l.bham.ac.uk>
"Graeme" <invalid@pinnock.com> writes:
> I downloaded SerialPort-0_19.zip from
> http://members.aol.com/Bbirthisel/alpha.html but the install
> instructions are a bit light on detail.
OK they are terse. But what, specifically, is the problem you are
finding in following them?
> Can anyone help with these questions:
>
> Where should I unzip SerialPort-0_19.zip to?
Does not matter.
> Is there is place for this in the PERL directory structure for
> modules?
Er...? The install procedure takes care of that.
> Is there a step by step guide anywhere for installing modules?
FAQ: "How do I install a module from CPAN?"
OK this module isn't from CPAN and actually it's a little non-standard
but that's covered in the README.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 15 Oct 2002 13:06:10 +0100
From: "Graeme" <invalid@pinnock.com>
Subject: Re: Installing Modules
Message-Id: <TwTq9.823$a32.67836@newsfep1-win.server.ntli.net>
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9r8esdkqw.fsf@wcl-l.bham.ac.uk...
> "Graeme" <invalid@pinnock.com> writes:
>
> > I downloaded SerialPort-0_19.zip from
> > http://members.aol.com/Bbirthisel/alpha.html but the install
> > instructions are a bit light on detail.
>
> OK they are terse. But what, specifically, is the problem you are
> finding in following them?
They are in the wrong order, they don't make sense and information is
not put in the correct section. Other than that they are fine. If the
people who write the code spent as much time on the documenation as
they did on the code, they would probably get a lot more credit for
their work.
Under "Compatibility" I found that I need to install API.pm. Hardly a
compatibility issue, more of an requirement really. Anyway, the link
doesn't exist so I'll do a search for it.
<snip>
Thanks for your help
------------------------------
Date: 15 Oct 2002 12:09:33 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Learnign perl.
Message-Id: <aoh0ht$kh2fu$1@ID-24002.news.dfncis.de>
Joe Creaney <joec@annuna.com> wrote:
> I am learning perl. I thik that I got most of the basics down. Are
> there job opertunites if I know perl?
http://jobs.perl.org
> Are there places I can go to
> learn perl.
http://learn.perl.org
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Tue, 15 Oct 2002 16:23:48 +0200
From: Patrick <patrick@-/abazar\-.nl>
Subject: newbie question
Message-Id: <Pine.LNX.4.44.0210151619080.27672-100000@abazar.nl>
Hi,
I have a ascii file with some sort of info:
<123455>786898988989829892<plokij>
<000455>788989829892<qawsedrf>
<000455>plokiju788989829892<plok909090>
Is it possible to read this file and create some vars, something like
this:
read file
var1 = firstpart of the line between the <>
var2 = secondpart of the line
var3 = thirdpart of line between the <>
replace all <> with nothing ...
print var1,var3,var4
please help ...
Patrick.
------------------------------
Date: Tue, 15 Oct 2002 16:55:16 +0200
From: Markus Niederlechner <mniederlechner@gmx.net>
Subject: Re: newbie question
Message-Id: <aoha8k$s32$04$1@news.t-online.com>
Patrick wrote:
> Is it possible to read this file and create some vars, something like
> this:
>
> read file
Open the file, then loop through it's lines.
perldoc -f open
> var1 = firstpart of the line between the <>
> var2 = secondpart of the line
> var3 = thirdpart of line between the <>
> replace all <> with nothing ...
Use a regular expression to split the lines into variables.
perldoc perlre
Basic example (with embedded data):
#!/usr/bin/perl
use strict;
use warnings;
# open a file here and replace DATA below with the filehandle
while (<DATA>) {
chomp;
/^<([^>]*)>([^<]*)<([^>]*)>$/
and print "$1 $2 $3\n";
}
__DATA__
<123455>786898988989829892<plokij>
<000455>788989829892<qawsedrf>
<000455>plokiju788989829892<plok909090>
------------------------------
Date: Tue, 15 Oct 2002 15:02:29 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: newbie question
Message-Id: <Xns92A870521B308dkwwashere@216.168.3.30>
Patrick <patrick@-/abazar\-.nl> wrote on 15 Oct 2002:
> I have a ascii file with some sort of info:
>
><123455>786898988989829892<plokij>
><000455>788989829892<qawsedrf>
><000455>plokiju788989829892<plok909090>
>
> Is it possible to read this file and create some vars, something like
> this:
>
> read file
> var1 = firstpart of the line between the <>
> var2 = secondpart of the line
> var3 = thirdpart of line between the <>
> replace all <> with nothing ...
>
>
> print var1,var3,var4
If all you want to do is read the data and print it back out with commas,
this will do it:
while (<DATA>) {
s/^<|>$//g;
tr/<>/,,/;
print;
}
But if you really need variables for subsequent processing, here's one way
to do it:
while (<DATA>) {
chomp;
s/^<|>$//g;
my ($var1, $var2, $var3) = split /[<>]/;
print "$var1, $var2, $var3\n";
}
This isn't an HTML, XML, or SGML question, is it? If so, you're better off
using another approach, i.e.; one of the modules expressly written for for
that sort of thing.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Tue, 15 Oct 2002 15:04:20 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: newbie question
Message-Id: <3DAC2EBD.70904@dev.null>
Patrick wrote:
> Hi,
>
> I have a ascii file with some sort of info:
>
> <123455>786898988989829892<plokij>
> <000455>788989829892<qawsedrf>
> <000455>plokiju788989829892<plok909090>
>
> Is it possible to read this file and create some vars, something like
> this:
>
> read file
> var1 = firstpart of the line between the <>
> var2 = secondpart of the line
> var3 = thirdpart of line between the <>
> replace all <> with nothing ...
Yes, use the split function.
perldoc -f split
will probably tell you all you need to know (and then some).
------------------------------
Date: Wed, 16 Oct 2002 00:04:25 +1000
From: "Trevor Johnson" <bpfsa@yahoo.com>
Subject: Novice seeks help
Message-Id: <aoh7a6$chu$1@lust.ihug.co.nz>
I am a total novice in any form of programming (other than simple HTML
which, let's face it, is not really programming anyway).
I have spent the last four days scouring websites, reading manuals,
experimenting with modifying free scripts, and so forth to create for myself
a very, very simple PERL CGI program..... Alas, novicehood reigns, and I am
stuck. Embarrassingly stuck.
What I am attempting to do is so basic, it seems no-one online has thought
about making such a basic script available (or at least I cannot find one).
I have no doubt that a competent PERL programmer could write what I need
from scratch, beginning to end, in under five minutes..... My wasted four
days therefore mean that I need help from someone with five minutes to
spare, please.
I am trying to write a PERL script which simply creates a CGI generated HTML
page.
I will show below my best (embarrassing) effort so far.... It does *not*
work, but will show what I am trying to do. (It is largely based on "SAMS
Teach Yourself CGI in 24 Hours".)
Could someone please put me out of my misery by pointing out the error of my
way and showing me how to actually do this properly?
<!----- Commence non-working embarrassing attemp --->
#!/usr/bin/perl
use CGI
$query = new CGI;
print $query ->header;
print "<html><head><title>Testing</title></head>\n";
print "<body>If this appears in the browser when this script is executed,
then this script works.</body></html>;
<!----- End non-working embarrassing attemp --->
For the record, the "#!/usr/bin/perl" part is not the problem. All my other
working CGI scripts (not written by me, of course) have this exact syntax.
Yes, I uploaded my feable effort in ASCII mode. I tried a number of
different CHMOD settings, though particularly 755.
I know that any competent programmer will probably be laughing that anyone -
even a novice could so badly screw up such a basic and simple little
exercise...... but please don't laugh. Just help me, please.
------------------------------
Date: Tue, 15 Oct 2002 10:22:13 -0400
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: Novice seeks help
Message-Id: <aoh8bf$pj3@netnews.proxy.lucent.com>
"Trevor Johnson" <bpfsa@yahoo.com>
> #!/usr/bin/perl
>
> use CGI
>
> $query = new CGI;
>
> print $query ->header;
>
> print "<html><head><title>Testing</title></head>\n";
> print "<body>If this appears in the browser when this script is executed,
> then this script works.</body></html>;
Did you miss an ending " or it was a typo?
You should be able to run this and see the output on your screen without any
web server.
------------------------------
Date: Tue, 15 Oct 2002 14:28:32 GMT
From: Espen Myrland <espenmyr@start.no.spam>
Subject: Re: Novice seeks help
Message-Id: <87of9v7p3w.fsf@chello.no>
"Trevor Johnson" <bpfsa@yahoo.com> writes:
> I am a total novice in any form of programming (other than simple HTML
> which, let's face it, is not really programming anyway).
>
> I have spent the last four days scouring websites, reading manuals,
> experimenting with modifying free scripts, and so forth to create for myself
> a very, very simple PERL CGI program..... Alas, novicehood reigns, and I am
> stuck. Embarrassingly stuck.
>
> What I am attempting to do is so basic, it seems no-one online has thought
> about making such a basic script available (or at least I cannot find one).
> I have no doubt that a competent PERL programmer could write what I need
> from scratch, beginning to end, in under five minutes..... My wasted four
> days therefore mean that I need help from someone with five minutes to
> spare, please.
>
> I am trying to write a PERL script which simply creates a CGI generated HTML
> page.
>
> I will show below my best (embarrassing) effort so far.... It does *not*
> work, but will show what I am trying to do. (It is largely based on "SAMS
> Teach Yourself CGI in 24 Hours".)
>
> Could someone please put me out of my misery by pointing out the error of my
> way and showing me how to actually do this properly?
>
> <!----- Commence non-working embarrassing attemp --->
>
>
> #!/usr/bin/perl
>
use strict;
> use CGI
use CGI;
>
> $query = new CGI;
my $query = new CGI;
>
> print $query ->header;
This probably works, but this is less annoying:
print $query->header;
>
> print "<html><head><title>Testing</title></head>\n";
> print "<body>If this appears in the browser when this script is executed,
> then this script works.</body></html>;
^^^
Missing end quote ".
--
espen
------------------------------
Date: 15 Oct 2002 14:33:35 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Novice seeks help
Message-Id: <aoh8vv$gdu$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Trevor Johnson:
> I am a total novice in any form of programming (other than simple HTML
> which, let's face it, is not really programming anyway).
>
> I have spent the last four days scouring websites, reading manuals,
> experimenting with modifying free scripts, and so forth to create for myself
> a very, very simple PERL CGI program..... Alas, novicehood reigns, and I am
> stuck. Embarrassingly stuck.
>
> What I am attempting to do is so basic, it seems no-one online has thought
> about making such a basic script available (or at least I cannot find one).
> I have no doubt that a competent PERL programmer could write what I need
> from scratch, beginning to end, in under five minutes..... My wasted four
> days therefore mean that I need help from someone with five minutes to
> spare, please.
>
> I am trying to write a PERL script which simply creates a CGI generated HTML
> page.
>
> I will show below my best (embarrassing) effort so far.... It does *not*
> work, but will show what I am trying to do. (It is largely based on "SAMS
> Teach Yourself CGI in 24 Hours".)
>
> Could someone please put me out of my misery by pointing out the error of my
> way and showing me how to actually do this properly?
Ok...
> #!/usr/bin/perl
>
> use CGI
>
> $query = new CGI;
It's very good that you are trying to use the CGI module and not start
with doing it the hard way. Not so good are two important omissions in
your code (perhaps your book did not mention them, but they are vital).
Also, the above contains a syntax error (missing semicolon). Change that
to:
#! /usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $query = new CGI;
First thing you notice is the -w thing in the shebang line. It turns on
warnings that will tell you if you are about to use questionable
constructs. See 'perldoc perlrun' for a description of switches that
perl recognizes.
'use strict' will require your variables to be declared prior using
them. When you just start using the variable '$foo' in your script, this
variable will necessarily be global. When strictures are turned out,
this is actually a compile time error. Therefore, variables you intend
to introduce need to be declared with 'my' and are only visible within
the current scope (scope in Perl is usually a block written as { ... }):
{ # new block
my $var = "foo";
...
}
print $var; # BANG! compile time error since $var went out of scope
Other example:
for my $element (@list) {
print $element; # this is ok
...
}
print $element; # block was left, $element no longer there, BANG!
The inclusion of CGI::Carp will make errors visible through the browser.
Usually, anything sent to stderr will show up in your webserver logs.
For testing, it is more convenient to see the error messages (and
sometimes warnings) in the browser. See 'perldoc CGI::Carp' for some
variation on this topic.
Finally, now it must be 'my $query = new CGI;' for the reasons previously
described (strictures).
> print $query ->header;
>
> print "<html><head><title>Testing</title></head>\n";
> print "<body>If this appears in the browser when this script is executed,
> then this script works.</body></html>;
^^
missing quote
Save for the missing closing quote, this is ok. Yet, you could rewrite
it a little. The following way is useful for chunks of strings that you
want to print out or assign to variables:
print $query->header;
print <<EOHTML;
<html><head><title>Testing</title></head>
<body>
If this appears in the browser when this script is executed,
then this script works.
</body>
</html>
EOHTML
This '<<LABEL' thing is called a here-document and described in
'perldata'. It prints out all stuff between '<<LABEL' and the closing
marker 'LABEL' verbatim. It even interpolates variables just as
double-quotes do, unless you use single quotes on the label:
print <<'EODOC';
This costs $5.
EODOC
Since here-docs sometimes go wrong for no apparent reason, there is even
a FAQ dealing with them:
Found in /usr/share/perl/5.6.1/pod/perlfaq4.pod
Why don't my <<HERE documents work?
><!----- End non-working embarrassing attemp --->
>
> For the record, the "#!/usr/bin/perl" part is not the problem. All my other
> working CGI scripts (not written by me, of course) have this exact syntax.
>
> Yes, I uploaded my feable effort in ASCII mode. I tried a number of
> different CHMOD settings, though particularly 755.
>
> I know that any competent programmer will probably be laughing that anyone -
> even a novice could so badly screw up such a basic and simple little
> exercise...... but please don't laugh. Just help me, please.
No need to get an inferiority-complex really. No one starts big.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
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 3973
***************************************