[21701] in Perl-Users-Digest
Perl-Users Digest, Issue: 3905 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 2 21:05:40 2002
Date: Wed, 2 Oct 2002 18:05:12 -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 Wed, 2 Oct 2002 Volume: 10 Number: 3905
Today's topics:
cat * | perl, then interactive STDIN <3b533a81314e4@heavyk.org>
Re: cat * | perl, then interactive STDIN (Walter Roberson)
Re: cat * | perl, then interactive STDIN <s_grazzini@hotmail.com>
Re: cat * | perl, then interactive STDIN <ak@freeshell.org.REMOVE>
Re: code for loading and copying Web Pages <steven.smolinski@sympatico.ca>
Re: code for loading and copying Web Pages <tony_curtis32@yahoo.com>
Re: code for loading and copying Web Pages <jurgenex@hotmail.com>
Re: How to geta list of perl modules (Damien Carbery)
Re: html::treebuilder <s_grazzini@hotmail.com>
Re: Messages getting truncated. <s_grazzini@hotmail.com>
Re: New Perl Module for QA Engineers <pkent77tea@yahoo.com.tea>
Re: newbie fine-tune first program mod_perl <bigj@kamelfreund.de>
Re: newbie fine-tune first program mod_perl <mike_constant@yahoo.com>
Re: newbie fine-tune first program mod_perl <nuba@dcc.ufmg.br>
Re: newbie fine-tune first program mod_perl <mike_constant@yahoo.com>
Re: newbie fine-tune first program mod_perl <nuba@dcc.ufmg.br>
Re: numbers & strings again (and again and again) <s_grazzini@hotmail.com>
Re: Odd behavior for variables "a" and "b" <steven.smolinski@sympatico.ca>
Re: Odd behavior for variables "a" and "b" <bigj@kamelfreund.de>
Open File problem (kazchan)
Re: Open File problem <mike_constant@yahoo.com>
Re: Open File problem <krahnj@acm.org>
Re: Perl script "rename" does not work... <mike_constant@yahoo.com>
Perl Tutor Wanted - Mtn View, CA <penny1482@attbi.com>
Re: Perl Tutor Wanted - Mtn View, CA <mike_constant@yahoo.com>
Re: Perl Tutor Wanted - Mtn View, CA <mike_constant@yahoo.com>
Re: Perl Tutor Wanted - Mtn View, CA <penny1482@attbi.com>
Re: Rescheduling a perl script with AT (Tad McClellan)
Re: script.pl?parameter - can anyone help me figure thi (Damien Carbery)
Re: script.pl?parameter - can anyone help me figure thi <nuba@dcc.ufmg.br>
Re: simple grep Q <s_grazzini@hotmail.com>
Re: simple grep Q <krahnj@acm.org>
Re: simple grep Q (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 02 Oct 2002 23:03:11 GMT
From: Keith Resar <3b533a81314e4@heavyk.org>
Subject: cat * | perl, then interactive STDIN
Message-Id: <PWKm9.430667$5r1.19005107@bin5.nnrp.aus1.giganews.com>
Another program provides input piped to my PERL script, after which
I'd like to regain control of STDIN. For example:
# Read initial input
while (<>) {
....
}
# Read second group of input
my $t = <>;
Any ideas on how the piped input can be read during the while loop and
keyboard input can be read after this?
Thanks,
Keith Resar.
--
------------------------------
Date: 2 Oct 2002 23:26:19 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: cat * | perl, then interactive STDIN
Message-Id: <anfvar$n2e$1@canopus.cc.umanitoba.ca>
In article <PWKm9.430667$5r1.19005107@bin5.nnrp.aus1.giganews.com>,
Keith Resar <3b533a81314e4@heavyk.org> wrote:
:Another program provides input piped to my PERL script, after which
:I'd like to regain control of STDIN. For example:
: # Read initial input
: while (<>) {
: ....
: }
: # Read second group of input
: my $t = <>;
:Any ideas on how the piped input can be read during the while loop and
:keyboard input can be read after this?
My first suggestion would be "Don't do that!" ;-)
perl SCRIPTNAME *
which will automatically progress through all the named input files
as sources. When you hit eof, null out ARGV and <> again to read from
stdin.
If the 'cat' was just an example, then if you are on a unix system
to read from the terminal, open /dev/tty . If you aren't on a unix system,
you might have to read from CON: or similar.
--
Warhol's Law of Usenet: "In the future, everyone will troll for 15 minutes."
------------------------------
Date: Wed, 02 Oct 2002 23:27:34 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: cat * | perl, then interactive STDIN
Message-Id: <GhLm9.32749$YI.6533655@twister.nyc.rr.com>
Keith Resar <3b533a81314e4@heavyk.org> wrote:
> Another program provides input piped to my PERL script, after
> which I'd like to regain control of STDIN. For example:
>
> # Read initial input
> while (<>) {
> ....
> }
>
> # Read second group of input
> my $t = <>;
>
> Any ideas on how the piped input can be read during the while loop
> and keyboard input can be read after this?
>
I don't know the portable solution, but on Unix:
open STDIN, '/dev/tty' or die "open /dev/tty : $!";
You could also dup STDOUT (if -t STDOUT)...
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Thu, 03 Oct 2002 00:57:20 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: cat * | perl, then interactive STDIN
Message-Id: <slrnapn5f2.qdq.ak@otaku.freeshell.org>
Submitted by "Keith Resar" to comp.lang.perl.misc:
> Another program provides input piped to my PERL script, after which
> I'd like to regain control of STDIN. For example:
>
> # Read initial input
> while (<>) {
> ....
> }
>
> # Read second group of input
> my $t = <>;
>
> Any ideas on how the piped input can be read during the while loop and
> keyboard input can be read after this?
>
> Thanks,
> Keith Resar.
>
One solution (given last week I think) was to close and re-open
the STDIN file handle from either "/dev/tty" or from "com"
(depending on operating system) after the while loop. Don't
forget to check for success from 'open()'.
--
Andreas Kähäri +------ Have a Unix: netbsd.org
-----------------------------+------ This post ends with :wq
------------------------------
Date: Wed, 02 Oct 2002 22:04:17 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: code for loading and copying Web Pages
Message-Id: <B3Km9.10250$Qh1.1192468@news20.bellglobal.com>
GET NJ <aolsz@bellatlantic.net> wrote:
> Can anybody suggest a reference to code for loading a Web Page (from a
> remote server) and copying/saving the Page?
>
> Clearly any few Pages can be saved manually within a broswer. I'm
> looking for a way to save thousands of Pages that are numbered
> sequentially. I'm figgering on nesting the code.
See LWP::Simple (specifically getprint).
If you're looking at parsing for images and links and what-not and
downloading them, I'd suggest you look at system('/usr/bin/wget -r ...')
instead. That wheel has already been invented.
Steve
------------------------------
Date: Wed, 02 Oct 2002 17:41:05 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: code for loading and copying Web Pages
Message-Id: <87k7l0h3b2.fsf@limey.hpcc.uh.edu>
>> On Wed, 02 Oct 2002 21:59:36 GMT,
>> GET NJ <aolsz@bellatlantic.net> said:
> Can anybody suggest a reference to code for loading a
> Web Page (from a remote server) and copying/saving the
> Page?
> Clearly any few Pages can be saved manually within a
> broswer. I'm looking for a way to save thousands of
> Pages that are numbered sequentially. I'm figgering on
> nesting the code.
perldoc lwpcook
------------------------------
Date: Wed, 2 Oct 2002 16:40:46 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: code for loading and copying Web Pages
Message-Id: <3d9b83fe$1@news.microsoft.com>
GET NJ wrote:
> Can anybody suggest a reference to code for loading a Web Page (from a
> remote server) and copying/saving the Page?
Well, you know, this question has been asked before. Actually a few times.
Really so often that it became an FAQ:
"How do I fetch an HTML file?"
For further details please see "perldoc -q fetch".
jue
------------------------------
Date: 2 Oct 2002 15:46:02 -0700
From: daymobrw@wenet.net (Damien Carbery)
Subject: Re: How to geta list of perl modules
Message-Id: <8237eee7.0210021446.60bc5d65@posting.google.com>
Barry Kimelman <barryk2@delete_me.mts.net> wrote in message news:<MPG.1804fb78d306445598972d@east.usenetserver.com>...
> How do you get a list of modules that are installed on your system
> (UNIX or windows) ? I know you can use perldoc to get info on a
> specific module, but I need to get a list of ALL the installed modules.
>
> TIA for all your help.
>
>
> ---------
>
> Barry Kimelman
> Winnipeg, Manitoba, Canada
> email : bkimelman@hotmail.com
Look up the perl diver CGI script:
http://www.scriptsolutions.com/programs/free/perldiver/
which will list info about your perl executable and then list all the
modules in a neat table.
------------------------------
Date: Wed, 02 Oct 2002 23:04:13 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: html::treebuilder
Message-Id: <NXKm9.32745$YI.6513948@twister.nyc.rr.com>
David A. Finney <dfinney@cts.com> wrote:
> Checking www.perldoc.com, I find that HTML::TreeBuilder is
> documented for version 5.6.1, but a search in the 5.8 documents
> yields no hits at all. Is this module available for 5.8? Should
> a documentation search list previously documented modules with
> an explanation of their fate (documentation restructured,
> obsoleted, deprecated)?
This isn't a core module, so you'll have to find the latest
version on CPAN and check its documentation yourself.
perldoc.com is just a (very nice) collection of pods; there
are probably thousands of supported modules that will never
get published there.
Anyway if the HTML::Treebuilder docs don't mention 5.8, I'd
assume the best. Install it, run the test suite, and see how
things go.
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Wed, 02 Oct 2002 22:31:24 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Messages getting truncated.
Message-Id: <0tKm9.32737$YI.6492988@twister.nyc.rr.com>
Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> Also sprach No Spam Please:
>> I'm wondering if my problem might be setting $/ = 0777 to make
>> the <STDIN> give me the whole message. Could Perl be assuming
>> I meant "0777" as a string instead of 0777 the octal number
>> (which would be 0x01FF and not possible in any 8 bit stream --
>> that's the point)
Not quite -- 0777 is an octal literal, but $/ is going to be
interpreted as a string, not a char.
> I thought so, too, for a second. perlvar does not mention this
> setting $/ to an octal value. I only knew it from the -0 switch
> but obviously it works with $/ as well (tested it).
You probably didn't have "511" in the test data.
[f'up to clpm]
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Thu, 03 Oct 2002 01:02:13 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: New Perl Module for QA Engineers
Message-Id: <pkent77tea-258D8A.02021203102002@news-text.blueyonder.co.uk>
In article <021020021125083485%comdog@panix.com>,
brian d foy <comdog@panix.com> wrote:
> In article <65fb4119.0210020522.13118b48@posting.google.com>, Rob Marchetti
> <robert.marchetti@fmr.com> wrote:
>
> > http://sourceforge.net/projects/samie/
> >
> > S.A.M. is a simple automation module written in Perl that allows a
> > user to automate Internet Explorer.
>
> don't forget to mention that it's only for Windows platforms...
with but a small look at the code, is there any reason why it cannot
work on MacOS (classic and X) or the Unix release of IE?
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Thu, 03 Oct 2002 01:39:11 +0200
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: newbie fine-tune first program mod_perl
Message-Id: <3d9b7501$0$11483$afc38c87@auth.de.news.easynet.net>
Nuba wrote at Wed, 02 Oct 2002 20:35:07 +0200:
> Big thanks Janek for the feedback. I stripped the code hardly to reduce it
> to the essential but wasn't able to get it under the 100-lines-limit that
> were recommended. ( Of course I could reduce it to a long one-line, but
> that wouldn't be fair. Currently it takes 450 lines with a LOT of
> whitespaces to helo organize it visually).
I looked to your program and from my opinion it's quite good written and
readable (allthough I've got problems with the spanish/portugese words).
One very important part is that I would miss is the Taint-mode.
E.g., in your code an attacker could do nearly everything with your database,
see lowerside for details.
One thing that could still improved is to get the advantage
of precompilation of the SQL statements.
The standard way is just to define the wanted SQL statements with placeholders
and to prepare them once in a program,
and execute them with the real arguments when they are needed.
Especially I'm talking about the construction of one where clause:
sub trata_input_busca_audio_e_video {
my($item);
$parametros = {};
$parametros->{'instituicao'} = param('instituicao');
$parametros->{'tipo_evento'} = param('tipo_evento');
$parametros->{'titulo_evento'} = param('titulo_evento');
$parametros->{'titulo_projeto'} = param('titulo_projeto');
$parametros->{'cidade'} = param('cidade');
foreach $item ( keys %{$parametros} )
{
unless ( !(defined ($parametros->{$item})) )
{
push(@where, ( '( ' . $item . ' LIKE "' . $parametros->{$item} . '" ) ' ) ) ;
push(@bagagem, { "key" => $item, "value" => $parametros->{$item} });
$st{$item} = 'DISABLED' ;
} # unless
} # end foreach
}; # end sub trata input
Obviously one of the jobs of this subroutine is to create a where clause,
but it could be also written as
my $sth = $dbh->prepare('... WHERE instituicao LIKE ?
AND tipo_evento LIKE ?
AND titulo_evento LIKE ?
AND titulo_projeto LIKE ?
AND cidade LIKE ?
...');
and then later in the input handling subroutine it could be used as
$sth->execute(param('instituicao'),param('tipo_evento'),...);
Note, it also would remove the security bug,
as an atacker could have included something like
arbitrary SQL stuff into its parameters,
he only had to include some simple quotes into the passed parameters,
e.g.
instituicao="xyz' AND COUNT(DELETE * FROM table)>0 AND instituicao LIKE 'xyz"
Greetings,
Janek
------------------------------
Date: Wed, 2 Oct 2002 16:43:18 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: newbie fine-tune first program mod_perl
Message-Id: <ang0bh$e4st2$1@ID-161864.news.dfncis.de>
"Nuba" <nuba@dcc.ufmg.br> wrote in message
>
> So, instead of posting all this stuff here, I've upped the code to my
> webserver. There is a syntax-highlighted page generated by VIM and a plain
> one too. Both of them are plenty of comments.
[snipped]
Your subject line indicates that this is a mod_perl handler, but it's
actually an CGI script.
If you port it to mod_perl, you might want to drop the bloated CGI module
all together. You will have better memory usage and much much greater
performance boost with mod_perl. One of the misconceptions mod_perl is
people would think that writing modperl handlers is more complicated than
CGI scripts. It is not.
------------------------------
Date: Wed, 2 Oct 2002 20:55:30 -0300
From: Nuba <nuba@dcc.ufmg.br>
Subject: Re: newbie fine-tune first program mod_perl
Message-Id: <Pine.GSO.4.21.0210022046001.2559-100000@turmalina.dcc.ufmg.br>
Ooops!....
What, in fact, I have done is a 'perl script to generate html pages using
mod_perl resources and some perl modules' . I suppose it is what we should
call a perl script or cgi script, then.
I thought - as it seems, erroneously - that a perl script running in a
mod_perl environment would be called a 'mod_perl script'. But now I see
people think 'mod_perl script' as meaning 'mod_perl handlers'.
Should I post again with a more proper subject ?
Nuba
On Wed, 2 Oct 2002, Newbie wrote:
> Date: Wed, 2 Oct 2002 16:43:18 -0700
> From: Newbie <mike_constant@yahoo.com>
> Newsgroups: comp.lang.perl.misc
> Subject: Re: newbie fine-tune first program mod_perl
>
>
> "Nuba" <nuba@dcc.ufmg.br> wrote in message
> >
> > So, instead of posting all this stuff here, I've upped the code to my
> > webserver. There is a syntax-highlighted page generated by VIM and a plain
> > one too. Both of them are plenty of comments.
>
> [snipped]
>
> Your subject line indicates that this is a mod_perl handler, but it's
> actually an CGI script.
>
> If you port it to mod_perl, you might want to drop the bloated CGI module
> all together. You will have better memory usage and much much greater
> performance boost with mod_perl. One of the misconceptions mod_perl is
> people would think that writing modperl handlers is more complicated than
> CGI scripts. It is not.
>
>
>
------------------------------
Date: Wed, 2 Oct 2002 17:17:58 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: newbie fine-tune first program mod_perl
Message-Id: <ang2cg$e6o1a$1@ID-161864.news.dfncis.de>
"Nuba" <nuba@dcc.ufmg.br> wrote in message
news:Pine.GSO.4.21.0210022046001.2559-100000@turmalina.dcc.ufmg.br...
>
> Ooops!....
>
> What, in fact, I have done is a 'perl script to generate html pages using
> mod_perl resources and some perl modules' . I suppose it is what we should
> call a perl script or cgi script, then.
How about a CGI Perl script? ;-) You can always write CGI code in C.
> I thought - as it seems, erroneously - that a perl script running in a
> mod_perl environment would be called a 'mod_perl script'. But now I see
> people think 'mod_perl script' as meaning 'mod_perl handlers'.
I haven't heard the term "mod_perl script". People tend to think that
scripts and programs are run as independent processes, hence, they don't use
ther phrase "mod_perl scripts" as mod_perl handlers are part of the
webserver themselves (ie. they are functions/methods/procedures invoked by
the webserver process).
> Should I post again with a more proper subject ?
You don't have to re-post it. People would know the difference anyways.
> Nuba
Newbie
>
> On Wed, 2 Oct 2002, Newbie wrote:
>
> > Date: Wed, 2 Oct 2002 16:43:18 -0700
> > From: Newbie <mike_constant@yahoo.com>
> > Newsgroups: comp.lang.perl.misc
> > Subject: Re: newbie fine-tune first program mod_perl
> >
> >
> > "Nuba" <nuba@dcc.ufmg.br> wrote in message
> > >
> > > So, instead of posting all this stuff here, I've upped the code to my
> > > webserver. There is a syntax-highlighted page generated by VIM and a
plain
> > > one too. Both of them are plenty of comments.
> >
> > [snipped]
> >
> > Your subject line indicates that this is a mod_perl handler, but it's
> > actually an CGI script.
> >
> > If you port it to mod_perl, you might want to drop the bloated CGI
module
> > all together. You will have better memory usage and much much greater
> > performance boost with mod_perl. One of the misconceptions mod_perl is
> > people would think that writing modperl handlers is more complicated
than
> > CGI scripts. It is not.
> >
> >
> >
>
------------------------------
Date: Wed, 2 Oct 2002 21:35:24 -0300
From: Nuba <nuba@dcc.ufmg.br>
Subject: Re: newbie fine-tune first program mod_perl
Message-Id: <Pine.GSO.4.21.0210022106380.2780-100000@turmalina.dcc.ufmg.br>
Hello Janek.
On Thu, 3 Oct 2002, Janek Schleicher wrote:
> I looked to your program and from my opinion it's quite good written and
> readable (allthough I've got problems with the spanish/portugese words).
WOW ! BIG THANKS !
At least someone looked at it.
I were almost hopeless I would receive some feedback.
I can translate the var names to english if needed.
Just drop a line.
>
> One very important part is that I would miss is the Taint-mode.
>
I still don't know how to TAINT, and simply adding the -T swith gives
back the 'too late for taint mode' warning from perl. It seems the
next learning step I should take is in how to taint.
> my $sth = $dbh->prepare('... WHERE instituicao LIKE ?
> AND tipo_evento LIKE ?
> AND titulo_evento LIKE ?
> AND titulo_projeto LIKE ?
> AND cidade LIKE ?
> ...');
>
> and then later in the input handling subroutine it could be used as
> $sth->execute(param('instituicao'),param('tipo_evento'),...);
The problem here is that these parameters aren't obligatory.
I only push it at my WHERE array in case it is defined. So, your
construction would left me with 'holes' in the SQL statement.
> Note, it also would remove the security bug,
> as an atacker could have included something like
> arbitrary SQL stuff into its parameters,
> he only had to include some simple quotes into the passed parameters,
> e.g.
> instituicao="xyz' AND COUNT(DELETE * FROM table)>0 AND instituicao LIKE 'xyz"
I choosed to restric this user only to SELECT statements in the mysql server. I'll learn some tainting and then work on these param() calls.
One thing I'm trying out is the =~ operator.
$variable =~ s/['"].*//
This way I can kick out of it any single/doube quote which would let the user insert a SQL code of his own.
> Greetings,
> Janek
Hey, please don't go yet !!! :-)
And what about keeping it all in one single file ? Am I supposed to work this way or should I spread it in smaller files ? If so, how, please !?
print("THANKS" x inf );
Nuba
nuba@dcc.ufmg.br
------------------------------
Date: Wed, 02 Oct 2002 22:50:13 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: numbers & strings again (and again and again)
Message-Id: <FKKm9.32742$YI.6504605@twister.nyc.rr.com>
Dick Penny <penny1482@attbi.com> wrote:
> 3) ALL docs say adding a zero (ie, forcing a numeric evaluate) converts a
> string to a number.
>
> My simplified tests below do not support #3. I am using Data::Dumper
> printout as the arbitrar of what is number and what is a string. Maybe this
> is wrong.
...
> use strict;
> use warnings;
> use Data::Dumper;
> my @list1 = ('30','37' );
> my @list2 = ('3',4 );
> print Dumper @list1;
> print Dumper @list2;
> foreach (@list1) { $_ += 1; }
> print Dumper @list1;
> _____________output
> VAR1 = '30';
> $VAR2 = '37';
> $VAR1 = '3';
> $VAR2 = 4; #clearly D::D sees this as an integer
> $VAR1 = '31'; #but not this even after a clear numeric operation
> $VAR2 = '38';
>
Devel::Peek is a better way to see how things look
to perl:
~ > perl -MDevel::Peek -e '$x="22"; $x+=1; Dump $x'
SV = PVIV(0x81256c0) at 0x81305c4
FLAGS = (IOK,pIOK)
IV = 23
PV = 0x8134478 "22"\0
CUR = 2
LEN = 3
You can see the integer and the invalidated string.
Data::Dumper would print '$VAR1 = 23' here, as you
expected it to, but 5.6.1 converts the same $x to
a PVNV:
~ > perl5.6.1 -MDevel::Peek -e '$x="22"; $x+=1; Dump $x'
SV = PVNV(0x80fbf18) at 0x8106a38
REFCNT = 1
FLAGS = (NOK,pNOK)
IV = 0
NV = 23
PV = 0x8108070 "22"\0
CUR = 2
LEN = 3
And Data::Dumper prints NVs as strings.
~ > perl -MData::Dumper -e 'print Dumper 22.5'
$VAR1 = '22.5';
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Wed, 02 Oct 2002 21:59:46 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Odd behavior for variables "a" and "b"
Message-Id: <m%Jm9.9985$Qh1.1190774@news20.bellglobal.com>
Tom Ewall <tewall@lycos.com> wrote:
> The question is, why the unique behavior with the variables "a" and
> "b"?
They're already defined as package globals for sort. See perldoc -f
sort.
Steve
------------------------------
Date: Thu, 03 Oct 2002 01:22:50 +0200
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: Odd behavior for variables "a" and "b"
Message-Id: <3d9b712c$0$11473$afc38c87@auth.de.news.easynet.net>
Tom Ewall wrote at Wed, 02 Oct 2002 23:25:53 +0200:
> Wierd behavior question. There are two files here. The second one
> calls the first and prints out the value of the variable b. This
> program works. However, if the "b" is replaced everywhere by "c", it
> no longer works. (The following error message appears. Global symbol
> "$c" requires explicit package name at C:\ScopeTest.pl line 9.) If
> the line "#our $b;" is uncommented (replacing "b" with "c" of course),
> then it will work. The variables "a" and "b" work with the "our $b;"
> commented, but other variables (at least none we could find) do not
> work.
>
> The question is, why the unique behavior with the variables "a" and
> "b"? We're using Perl 5.6.1 build 630 on Windows 2000. Several of us
> have tried it and the behavior is consistent on different machines.
Well, $a and $b are in fact global variables.
From perldoc perlvar:
$a
$b Special package variables when using sort(), see
"sort" in perlfunc. Because of this specialness
$a and $b don't need to be declared (using
local(), use vars, or our()) even when using the
strict vars pragma. Don't lexicalize them with
"my $a" or "my $b" if you want to be able to use
them in the sort() comparison block or function.
So in reality,
you changed these global variables,
where $c was only changed and defined in the ScopeTest2.pl file.
To understand the rest,
we have to read perldoc -f our:
An "our" declaration declares a global variable
that will be visible across its entire lexical
scope, even across package boundaries.
The lexical scope ends with the end of the script file,
especially it ends at ScopeTest2.pl,
so $c is really unknown in ScopeTest.pl.
Also in perldoc -f our,
there's a way to solve the problem mentioned:
(But only
within the lexical scope of the "our" declaration.
In this it differs from "use vars", which is
package scoped.)
So, perhaps you better should trie to say
use vars qw/$c/;
in ScopeTest2.pl
Greetings,
Janek
------------------------------
Date: 2 Oct 2002 15:44:24 -0700
From: kazchan@curio-city.com (kazchan)
Subject: Open File problem
Message-Id: <3baaab4f.0210021444.5daeb7ae@posting.google.com>
I am trying make people put number to send an E-mail. It works when
the data file has only one line, but it does not work when it has two
or more lines.
Here is part of problem:
open(FILEHANDLE,"<address.dat") or &error("Could not open
address.dat");
while($line = <FILEHANDLE>)
{
$line =~ s/\n//g;
($member,$mailto) = split(/::/, $line);
if ($id ne $member)
{
close FILEHANDLE;
&error('No valid member found.');
exit;
}
}
The data file is something like this:
This works fine
1033444038::user@mail.com
But this does not work
1033444038::user@mail.com
1027847623::user@hotmail.com
I guess the command does work correctly.
$line =~ s/\n//g;
Please help.
------------------------------
Date: Wed, 2 Oct 2002 15:51:40 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Open File problem
Message-Id: <anftam$dqgqk$1@ID-161864.news.dfncis.de>
"kazchan" <kazchan@curio-city.com> wrote in message
news:3baaab4f.0210021444.5daeb7ae@posting.google.com...
> I am trying make people put number to send an E-mail. It works when
> the data file has only one line, but it does not work when it has two
> or more lines.
>
>
> Here is part of problem:
>
> open(FILEHANDLE,"<address.dat") or &error("Could not open
> address.dat");
> while($line = <FILEHANDLE>)
> {
> $line =~ s/\n//g;
> ($member,$mailto) = split(/::/, $line);
> if ($id ne $member)
> {
> close FILEHANDLE;
> &error('No valid member found.');
> exit;
> }
> }
>
> The data file is something like this:
>
> This works fine
> 1033444038::user@mail.com
>
> But this does not work
> 1033444038::user@mail.com
> 1027847623::user@hotmail.com
>
>
> I guess the command does work correctly.
> $line =~ s/\n//g;
>
> Please help.
How is $id generated? Also, should it be a "next" instead of "exit"?
------------------------------
Date: Wed, 02 Oct 2002 23:49:46 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Open File problem
Message-Id: <3D9B85FB.E06B1355@acm.org>
kazchan wrote:
>
> I am trying make people put number to send an E-mail. It works when
> the data file has only one line, but it does not work when it has two
> or more lines.
>
> Here is part of problem:
>
> open(FILEHANDLE,"<address.dat") or &error("Could not open
> address.dat");
> while($line = <FILEHANDLE>)
> {
> $line =~ s/\n//g;
> ($member,$mailto) = split(/::/, $line);
> if ($id ne $member)
> {
> close FILEHANDLE;
> &error('No valid member found.');
> exit;
> }
> }
>
> The data file is something like this:
>
> This works fine
> 1033444038::user@mail.com
>
> But this does not work
> 1033444038::user@mail.com
> 1027847623::user@hotmail.com
>
> I guess the command does work correctly.
> $line =~ s/\n//g;
No, that's not it, but you should be using chomp() instead. The problem
is the program exits if $id is NOT found which means that it will only
work if the member you are looking for is the first one in the list.
You need to look through the entire list and find out if the member IS
there.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 2 Oct 2002 17:25:48 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Perl script "rename" does not work...
Message-Id: <ang2r6$e27qf$1@ID-161864.news.dfncis.de>
"Tad McClellan" <tadmc@augustmail.com> wrote
> Joel <joel_bearden@hotmail.com> wrote:
>
> > Okay, I am about to pull my hair out...
>
>
> That is why so many programmers have pony tails.
>
> It is easier to get a good grip.
I thought that's why many programmers have volley-ball look-alike head. In
fact, they have nothing left to pull except for their ears. No wonder why
programmers have bigger ears, especially those with a ball head.
------------------------------
Date: Wed, 02 Oct 2002 22:18:06 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Perl Tutor Wanted - Mtn View, CA
Message-Id: <ygKm9.13753$Pz.14235@rwcrnsc51.ops.asp.att.net>
Is there a real guru in Mtn View, CA area whose got 1-2 hrs once a week for
some Perl tutoring and Q's? Initial subjects would be lists, arrays, greps,
maps, their implicit iterators, and building functional chains to transform
data. How much would you charge?
--
Dick Penny
------------------------------
Date: Wed, 2 Oct 2002 15:37:13 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Perl Tutor Wanted - Mtn View, CA
Message-Id: <anfsfk$e155o$1@ID-161864.news.dfncis.de>
"Dick Penny" <penny1482@attbi.com> wrote in message
news:ygKm9.13753$Pz.14235@rwcrnsc51.ops.asp.att.net...
> Is there a real guru in Mtn View, CA area whose got 1-2 hrs once a week
for
> some Perl tutoring and Q's? Initial subjects would be lists, arrays,
greps,
> maps, their implicit iterators, and building functional chains to
transform
> data. How much would you charge?
How much would you like to pay? I'm interested and in San Jose/Palo Alto
area.
------------------------------
Date: Wed, 2 Oct 2002 15:46:40 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Perl Tutor Wanted - Mtn View, CA
Message-Id: <anft1b$dsrjb$1@ID-161864.news.dfncis.de>
"Newbie" <mike_constant@yahoo.com> wrote in
> How much would you like to pay? I'm interested and in San Jose/Palo Alto
> area.
Of course, the best tutorial sessions are perldoc and clpm. If you can
endure the egoistic and arrogant attitude, you'll learn a bunch on clpm.
------------------------------
Date: Thu, 03 Oct 2002 00:00:58 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: Perl Tutor Wanted - Mtn View, CA
Message-Id: <_MLm9.13422$PP.15039@rwcrnsc53>
IMHO perldoc sucks unless you know what Q to ask it - there are not enough
SIMPLE examples. For me clpm is either 100% success or 100% failure for
reasons you mention.
Do you have space & a white/black board we could use? As you know, there is
a big difference between SJ and PA depending on time of day, ie, convienence
in getting together. What are your suggestions on these (before discussing
$) ?
Dick Penny
"Newbie" <mike_constant@yahoo.com> wrote in message
news:anft1b$dsrjb$1@ID-161864.news.dfncis.de...
>
> "Newbie" <mike_constant@yahoo.com> wrote in
> > How much would you like to pay? I'm interested and in San Jose/Palo Alto
> > area.
>
> Of course, the best tutorial sessions are perldoc and clpm. If you can
> endure the egoistic and arrogant attitude, you'll learn a bunch on clpm.
>
>
>
------------------------------
Date: Wed, 02 Oct 2002 23:08:44 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Rescheduling a perl script with AT
Message-Id: <slrnapmuan.425.tadmc@magna.augustmail.com>
Ralph Slate <usenet@hockeydb.com> wrote:
> I want to reschedule the
> exact same script to run in 10 minutes. I should be able to do this
> with the AT command/program.
> But my script.pl needs to take an input
> parameter, so I need to do this:
>
> if (data_not_ready) {
> system("at now + 10 minutes script.pl INPUT_PARAMETER");
> exit();
> }
>
> This fails with an "unknown word" error, which is an AT error. If I
> want to run this using AT interactively, I'd have to do it like this:
>
> at now + 10 minutes
> script.pl INPUT_PARAMETER
><Ctrl-D>
So, "at" can read the script name and parameters on STDIN then.
> The man page for AT tells me that I can send it a script file with
> this command in it, but I'm trying to dynamically generate the
> INPUT_PARAMETER, so it wouldn't be available in a static script file
> So the question is, how can I call the AT command from a perl script,
> to execute a perl script with an input parameter?
Write the script name and parameters on "at"s STDIN :-)
system qq( echo "script.pl INPUT_PARAMETER" | at now + 10 minutes)
or, use a pipe open to write to at:
open AT, '|at now + 10 minutes' or die "problem with open $!";
print AT "script.pl INPUT_PARAMETER";
close AT or die "problem with close $!;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Oct 2002 15:43:34 -0700
From: daymobrw@wenet.net (Damien Carbery)
Subject: Re: script.pl?parameter - can anyone help me figure this out?
Message-Id: <8237eee7.0210021443.b9dfd12@posting.google.com>
gwarble@moonman.com (gwarble) wrote in message news:<47b16626.0210021054.49bfdd70@posting.google.com>...
> hey all
>
> i'm new to perl programming, mostly doing it for fun and practice on
> my website... and i want to ask something... i've searched high and
> low on the internet and in books on how to pass a parameter to a perl
> script like this: script.pl?parameter in the url... i've seen it done
> but i cant find how to read the parameter in the code
>
> if you see my page (www.arcadefanatic.com) it might make more sense...
> i have seperate html files for each game in my collection, and want to
> make a game.pl script which will set up the basic layout that is the
> same for each game, and then pass ?tetris for example so it
> dynamically loads the equivalent of tetris.html
>
> if i'm an idiot, let me know, if you can help, also please let me know
>
> thanks
> joel
> gwarble@hotmail.com
> www.arcadefanatic.com
How about give the info you are passing a name e.g.
game.pl?game=tetris
and the in your script look at
$gamename = param( 'game' );
(assuming you are using CGI.pm).
------------------------------
Date: Wed, 2 Oct 2002 20:40:06 -0300
From: Nuba <nuba@dcc.ufmg.br>
Subject: Re: script.pl?parameter - can anyone help me figure this out?
Message-Id: <Pine.GSO.4.21.0210022032270.2258-100000@turmalina.dcc.ufmg.br>
Hi Damien and Perl Gurus Out There
EUREKA ! Your post inspired on trying the script below - and
surprisingly, it worked :-)
The 'what-we-want' part receives the name 'keywords'.
So, would now someone be nice as Janek and please send me some
feedback and help on my first mod_perl perl program ? Please adopt a
perlbaby :)
All good things,
Nuba
nuba@dcc.ufmg.br
====== start of perl code ==============
use CGI qw"param debug";
print("Content-type: text/html\n\r\n\r");
&exibe_input();
sub exibe_input {
if (param()) {
%params = CGI::Vars();
print("\n <BR> <table border=1 align=center> \n");
foreach $parametro (sort keys %params) {
print "<TR><TD> $parametro </TD><TD> $params{$parametro}
</TD></TR>\n";
} # foreach
print("\n </table> <BR>\n");
}; # fim if
}; # fim sub
======== end of perl code =============
On 2 Oct 2002, Damien Carbery wrote:
> Date: 2 Oct 2002 15:43:34 -0700
> From: Damien Carbery <daymobrw@wenet.net>
> Newsgroups: comp.lang.perl.misc
> Subject: Re: script.pl?parameter - can anyone help me figure this out?
>
> gwarble@moonman.com (gwarble) wrote in message news:<47b16626.0210021054.49bfdd70@posting.google.com>...
> > hey all
> >
> > i'm new to perl programming, mostly doing it for fun and practice on
> > my website... and i want to ask something... i've searched high and
> > low on the internet and in books on how to pass a parameter to a perl
> > script like this: script.pl?parameter in the url... i've seen it done
> > but i cant find how to read the parameter in the code
> >
> > if you see my page (www.arcadefanatic.com) it might make more sense...
> > i have seperate html files for each game in my collection, and want to
> > make a game.pl script which will set up the basic layout that is the
> > same for each game, and then pass ?tetris for example so it
> > dynamically loads the equivalent of tetris.html
> >
> > if i'm an idiot, let me know, if you can help, also please let me know
> >
> > thanks
> > joel
> > gwarble@hotmail.com
> > www.arcadefanatic.com
>
> How about give the info you are passing a name e.g.
> game.pl?game=tetris
> and the in your script look at
> $gamename = param( 'game' );
> (assuming you are using CGI.pm).
>
------------------------------
Date: Wed, 02 Oct 2002 23:11:44 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: simple grep Q
Message-Id: <Q2Lm9.32746$YI.6520480@twister.nyc.rr.com>
Dick Penny <penny1482@attbi.com> wrote:
> In the following code & output why do the two 3 digit numbers pass
> the grep filter but if I remove the [ ] then only the 6 digit
> numbers pass out of grep? I understand the 2nd output, but NOT
> the first.
> _______code#1
> use strict;
> use warnings;
> use Data::Dumper;
> my @lines = (
> 'SPH 083000 111200 111300 111100 111280 503 959',
> 'SPH 084000 111250 111380 111200 111370 354 115',
> 'SPH 084500 111350 111390 111050 111100 353 747' );
> my $text = $lines[0];
> my @numbers= grep { [ s/(\d{4})(\d{2})/$1\.$2/g ] } $text =~ /\d+/g;
This grep doesn't do a test; it runs the substitution --
which is bad style in a grep(), by the way -- but returns
the result of s///g wrapped in an array reference.
And even an empty array reference is "true".
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Wed, 02 Oct 2002 23:40:12 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: simple grep Q
Message-Id: <3D9B83B9.1CFC97@acm.org>
Dick Penny wrote:
>
> In the following code & output why do the two 3 digit numbers pass the grep
> filter but if I remove the [ ] then only the 6 digit numbers pass out of
> grep? I understand the 2nd output, but NOT the first.
> _______code#1
> use strict;
> use warnings;
> use Data::Dumper;
> my @lines = (
> 'SPH 083000 111200 111300 111100 111280 503 959',
> 'SPH 084000 111250 111380 111200 111370 354 115',
> 'SPH 084500 111350 111390 111050 111100 353 747' );
> my $text = $lines[0];
> my @numbers= grep { [ s/(\d{4})(\d{2})/$1\.$2/g ] } $text =~ /\d+/g;
> print Dumper @numbers;
> ________output #1
> $VAR1 = '0830.00';
> $VAR2 = '1112.00';
> $VAR3 = '1113.00';
> $VAR4 = '1111.00';
> $VAR5 = '1112.80';
> $VAR6 = '503';
> $VAR7 = '959';
> __________code#2 remove only [ ]
> my @numbers= grep { s/(\d{4})(\d{2})/$1\.$2/g ]} $text =~ /\d+/g;
> __________output #2
> $VAR1 = '0830.00';
> $VAR2 = '1112.00';
> $VAR3 = '1113.00';
> $VAR4 = '1111.00';
> $VAR5 = '1112.80';
Putting [] around an expression creates an anonymous array which returns
a reference [eg. ARRAY(0x80f47a0)] and since a reference in a boolean
context is always true then all numbers are passed through the grep.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 03 Oct 2002 01:03:10 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: simple grep Q
Message-Id: <slrnapn5kb.485.tadmc@magna.augustmail.com>
Dick Penny <penny1482@attbi.com> wrote:
> In the following code & output why do the two 3 digit numbers pass the grep
Every string will pass the grep() because the anonymous array
constructor returns a reference, and a reference is never false.
> filter but if I remove the [ ]
^ ^
^ ^
That is the "anonymous array constructor".
If you remove it, then the grep() is looking at the value of
the s///g instead of looking at a reference.
> then only the 6 digit numbers pass out of
> grep? I understand the 2nd output, but NOT the first.
> _______code#1
> use strict;
> use warnings;
> use Data::Dumper;
> my @lines = (
> 'SPH 083000 111200 111300 111100 111280 503 959',
> 'SPH 084000 111250 111380 111200 111370 354 115',
> 'SPH 084500 111350 111390 111050 111100 353 747' );
> my $text = $lines[0];
> my @numbers= grep { [ s/(\d{4})(\d{2})/$1\.$2/g ] } $text =~ /\d+/g;
^
^
The replacement string part of s/// is "double quotish", it acts
like a double quoted string.
You do not need to escape dots in double quoted strings.
> print Dumper @numbers;
> ________output #1
> $VAR1 = '0830.00';
> $VAR2 = '1112.00';
> $VAR3 = '1113.00';
> $VAR4 = '1111.00';
> $VAR5 = '1112.80';
> $VAR6 = '503';
> $VAR7 = '959';
[snip 2nd case]
What did you _want_ to get by adding the square brackets?
--
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 3905
***************************************