[17258] in Perl-Users-Digest
Perl-Users Digest, Issue: 4680 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 20 21:05:39 2000
Date: Fri, 20 Oct 2000 18: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)
Message-Id: <972090312-v9-i4680@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 20 Oct 2000 Volume: 9 Number: 4680
Today's topics:
Re: Boolean query to Perl regexp match conversion <lincmad001@telecom-digest.zzn.com>
Comments <blah.xyathn@yahoo.com>
coran??? pape_98@my-deja.com
Re: coran??? (Clay Irving)
Re: coran??? <jeff@vpservices.com>
Re: Device::SerialPort no dial even parity (David Efflandt)
Dynamic Regex building? <mrh@panix.com>
Re: Dynamic Regex building? <godzilla@stomp.stomp.tokyo>
getting the file w/ enctype=multipart/form-data <usequity@mindspring.com>
Re: getting the file w/ enctype=multipart/form-data <jeff@vpservices.com>
Re: Help DBI/ DBD mysql (Anders Hertz)
Re: Help With Split... I think... :) <lr@hpl.hp.com>
Re: Help with Split.... <lincmad001@telecom-digest.zzn.com>
Re: how can I get data from a file into variable? (Martien Verbruggen)
Re: how do i find file size? (Martien Verbruggen)
Need help again with my script <sbearden@houston.rr.com>
New at perl, help needed tmg123@hotmail.com
Re: New at perl, help needed (Clay Irving)
Re: New at perl, help needed <bart.lateur@skynet.be>
Re: New at perl, help needed <tim@ipac.caltech.edu>
Re: New at perl, help needed (Clay Irving)
Re: Perl for PalmOS? (Tony L. Svanstrom)
perldoc equivalent <james@NOSPAM.demon.co.uk>
Re: perldoc equivalent <newsposter@cthulhu.demon.nl>
Re: perldoc equivalent <james@NOSPAM.demon.co.uk>
Re: SSI and Perl (David Efflandt)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 20 Oct 2000 16:29:52 -0700
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: Boolean query to Perl regexp match conversion
Message-Id: <201020001629520944%lincmad001@telecom-digest.zzn.com>
In article <39F02F35.2D659F34@ocegr.fr>, Stephane Barizien
<sba@ocegr.fr> wrote:
> Hi all,
>
> I'm looking for a way to convert a "search engine style" boolean query
> like
>
> (foo OR bar) AND blah* AND kernel
>
> into a (set of) equivalent Perl regexp matching operation(s) (assuming
> the entire text to run the query against is in a single
> multiline-thus-with-embedded-newlines Perl $str)
>
> Any clue?
Take the problem apart piece by piece. You want to keep the parentheses
and keep track of the AND/OR/NOT and any other modifiers you may have.
Then each word will match \bword\b, unless it's followed by an
asterisk, in which case it will match \bword
You'll also want to do your matches ignoring case.
You should also think about supporting a phrase in quotes, in which
case you would change any spaces in the search text to \s+ in your
regexp, in particular to guard against the phrase's being split across
two or more lines of the original document.
One possible approach would be to use "split" to separate the search
query into atoms, something like this:
@atoms = split /\s+|([()])/, $query;
Of course, that's not the whole answer. You eventually have to build
the atoms back into a Perl construct, which you can then "eval". You
also have to deal with the presence of some extraneous "undef" values
in @atoms as I wrote it above. You also need to think about what to do
if the parentheses don't balance or if you get some other bad input.
------------------------------
Date: Fri, 20 Oct 2000 20:04:38 -0400
From: "Corey French" <blah.xyathn@yahoo.com>
Subject: Comments
Message-Id: <o05I5.16369$cO4.396072@nntp3.onemain.com>
I know that you can comment out a line or end of line with the # key, but is
there a way to comment out an entire section. For those of you that are
familiar with c/c++ what I'm looking for is something like the /* */
commands.
Thanks
Corey
------------------------------
Date: Fri, 20 Oct 2000 22:15:48 GMT
From: pape_98@my-deja.com
Subject: coran???
Message-Id: <8sqg6f$uhb$1@nnrp1.deja.com>
Has anyone heard of coran????
My boss just told me to read about it and said that it was designed to
make scripts run themselves.
Please help
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 20 Oct 2000 23:38:32 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: coran???
Message-Id: <slrn8v1lro.anj.clay@panix2.panix.com>
On Fri, 20 Oct 2000 22:15:48 GMT, pape_98@my-deja.com <pape_98@my-deja.com>
wrote:
>Has anyone heard of coran????
>My boss just told me to read about it and said that it was designed to
>make scripts run themselves.
s/o//;
s/a/o/;
--
Clay Irving <clay@panix.com>
Life is a whim of several billion cells to be you for a while.
------------------------------
Date: Fri, 20 Oct 2000 16:46:41 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: coran???
Message-Id: <39F0D961.FE35E0B4@vpservices.com>
pape_98@my-deja.com wrote:
>
> Has anyone heard of coran????
> My boss just told me to read about it and said that it was designed to
> make scripts run themselves.
Coran ... that's the French spelling of The Holy Koran. And, yes,
believers say it can make scripts run themselves, among other things.
Is there any chance you mean "cron", the Unix utility?
--
Jeff
------------------------------
Date: Fri, 20 Oct 2000 23:42:01 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Device::SerialPort no dial even parity
Message-Id: <slrn8v1m3n.13e.efflandt@efflandt.xnet.com>
On Fri, 20 Oct 2000 16:00:01 GMT, Phil xxx <phil_xxx@my-deja.com> wrote:
>I have been learning to use the Device::SerialPort module.
>I can get my program to dial if I use :
>
>$modem_obj->parity("none").
>
>When I use :
>
>$modem_obj->parity("even") || die "fail setting parity";
>$modem_obj->parity_enable('T');
>
>It wont dial.
>
>I am using i86 Solaris 8 and perl 5.6.0.
>
>Any ideas? Maybe its a port setting?
I don't think your modem knows anything about parity. The only time you
would use anything other than 8 bit, no parity would be after the modem
has connected to an old classic CompuServe account that you have not
changed to 8 bit, and you need to use the old 7 bit, even parity to login.
Or maybe if you connect to a BBS or something else that uses parity, but
only after you receive the CONNECT string.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 20 Oct 2000 22:23:40 GMT
From: Michael Hoffman <mrh@panix.com>
Subject: Dynamic Regex building?
Message-Id: <8sqglc$3o8$1@news.panix.com>
Hi,
I'm a longtime programmer, but brand-new to Perl, so any pointers
to relevant info would be appreciated. I've scoured the docs and this
newsgroup, but couldn;t find an answer.
PROBLEM SYNOPSIS: I need to build a Replace regex based on given criteria.
PROBLEM DETAIL: I am updating a database table dump ("|" delimited) based on
the differences between the current table schema and a new table layout. New
fields will be added, but never deleted.
SPECIFICS: I read and compare both schema and build a Search and a Replace
Regex based on their differences. Then I read in the data file and replace
the data with the new format.
I've included my entire code in case anyone wants to show me faster ways to
carry out the procedures. Everything seems to work until the final steps.
My code: (with comments)
----------------------------------------------------------------
#!/usr/local/bin/perl -w
#
#
my @newst="";
my @oldst="";
my @cols="";
my $in=" ";
my $sysline=" ";
my $orig=" ";
my $repl=" ";
my $z=0;
open(SCH_FILE, "$sch_file") or die "Can't open Schema File";
while (<SCH_FILE>){
chomp;
if (/PRIMARY KEY/i) {
last;
} else { # schema layout: Fieldname datatype
@cols=split(" "); # skip blank and ( lines
if ($cols[0]=~ /\(/ || $cols[0] eq "") { next };
push(@oldst,$cols[0]); # push fieldname onto list
}
}
close SCH_FILE;
open(TAB_FILE, "$tabfile") or die "Can't open New Table File";
while (<TAB_FILE>){
chomp;
if (/PRIMARY KEY/i) {
last;
} else {
@cols=split(" ");
if ($cols[0]=~ /\(/ || $cols[0] eq "") { next };
push(@newst,$cols[0]);
}
}
close TAB_FILE;
shift @oldst; # needed b/c blank character is first record
shift @newst; # needed b/c blank character is first record
## The data looks like: field1|field2|field3|.....|
## We want to place | in between fields to represent the new ones.
##
## Compare the two field lists. If the fieldname is in both, then add
## the regex to trap its data into @orig and add the regex to use that
## data into @repl. The () will link to $1,$2,... so that is what is
## placed into @repl.
##
my @orig="^";
my @repl="";
for ($x=$y=0;$x<@oldst;$x++) { # handle case of fields added in middle
push(@orig,"([^\\|]*)\\|");
while ($oldst[$x] ne $newst[$y] && $y<@newst) { # found new field
push(@repl,"\\|");
$y++;
}
$z=$x+1;
push(@repl,"\$$z\\|");
$y++;
}
for (;$y<@newst;$y++) { # handle case where fields added at end
push(@repl,"\\|");
}
push(@orig,"\$");
shift @repl; # get rid of blank first element
$orig=join("",@orig); # make lists to strings
$repl=join("",@repl);
$tab_out="$tab\.load";
open(OUT_FILE, ">$tab_out") or die "Can't open Output File";
open(UNL_FILE, "$unl_file") or die "Can't open Data File";
while ($in=<UNL_FILE>) {
$in=~ s/$orig/$repl/; # SOMETHING WRONG HERE!! BUT WHAT???
$in .= "\n";
print OUT_FILE $in;
}
exit;
--------------------------------------------------------------
Lets say I want to add 3 new fields between the 2nd and 3rd field.
$orig = ^([^\|]*)\|([^\|]*)\|([^\|]*)\|$
$repl = $1|$2||||$3|
Given Data like: Hi|Hello|Howdy|
I am returned: $1|$2||||$3|
How do I get Perl to recognize the $repl string as a Regex? Before you
suggest using "/e", I did that already with no change in results.
Thanks for any help! I was really proud of myself for creating this script
since I've only been looking at Perl for 2 weeks. Now I'm stuck and have
no idea where to turn next.
Michael Hoffman
mrh@panix.com
------------------------------
Date: Fri, 20 Oct 2000 15:56:19 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Dynamic Regex building?
Message-Id: <39F0CD93.144D3AAF@stomp.stomp.tokyo>
Michael Hoffman wrote:
(snipped 3,591,274 lines of unrelated comments and code)
> $in=~ s/$orig/$repl/; # SOMETHING WRONG HERE!! BUT WHAT???
Why don't you print each of those variables before
your substitution and find out what is wrong?
print " IN: $in\n ORIG: $orig\n REPL: $repl\n\n";
Of course this code snippet is extremely complex
and difficult to understand. Nonetheless, I am
certain you will figure out how to use this code.
Godzilla!
------------------------------
Date: Fri, 20 Oct 2000 17:04:34 -0500
From: "Henry" <usequity@mindspring.com>
Subject: getting the file w/ enctype=multipart/form-data
Message-Id: <8sqff3$aoo$1@slb3.atl.mindspring.net>
Can someone point me in the right direction?
I have a web form where users can submit a file to be uploaded to the
server. The HTML looks like this, which I'm pretty sure is a correct
example:
<form method="POST" action="../cgi-bin/get_file.pl"
enctype="multipart/form-data">
<input type="file" name="file" size="20"><input type="submit"></form>
The script is receiving the file. I can even put the contents of the file in
a variable and print it if it's a text file. But how do i grab the file and
save it if it's not a text file
Thanks in advance,
Henry
------------------------------
Date: Fri, 20 Oct 2000 15:22:29 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: getting the file w/ enctype=multipart/form-data
Message-Id: <39F0C5A5.855EFD3B@vpservices.com>
Henry wrote:
>
> Can someone point me in the right direction?
> I have a web form where users can submit a file to be uploaded to the
> server. The HTML looks like this, which I'm pretty sure is a correct
> example:
>
> <form method="POST" action="../cgi-bin/get_file.pl"
> enctype="multipart/form-data">
> <input type="file" name="file" size="20"><input type="submit"></form>
>
> The script is receiving the file. I can even put the contents of the file in
> a variable and print it if it's a text file. But how do i grab the file and
> save it if it's not a text file
Use the CGI.pm module. It has methods to safely and easily handle file
uploads. It comes with Perl and includes ample documentation.
--
Jeff
------------------------------
Date: Fri, 20 Oct 2000 12:52:32 GMT
From: a_hertz@removethis.yahoo.com (Anders Hertz)
Subject: Re: Help DBI/ DBD mysql
Message-Id: <39f03fa1.11051242@news.internord.dk>
On Fri, 20 Oct 2000 09:49:43 GMT, ghorghor@my-deja.com wrote:
>i have test that on an other machine and it works
>so it seems to be the DBD versions that doesn't work
>
>but i have an old version of perl 5.0004
>and DBI : 0.93
>
>but i can't install a new version of perl for compatibility
>and i not sure that installing a new version of with old perl will
>work ??
>
>can you help me ?
There I can´t help you, sorry. Maybe in a linux group there are
some REAL geniouses .-).
Anders
------------------------------
Date: Fri, 20 Oct 2000 15:42:48 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Help With Split... I think... :)
Message-Id: <MPG.145a6a46a91772c498ae51@nntp.hpl.hp.com>
In article <8sl167$6ob@library2.airnews.net> on Wed, 18 Oct 2000
15:31:00 -0500, TEst <mezmoria@hotmail.com> says...
> Ok, I admit it I suck as a programmer. I guess thats why I dont program full
> time :). Anyway I need help from you experts out there.
>
> I am trying to create an array from a line of text that has no formatting
> and I cannot figure out how to seperate the fields.
It seems as though you are trying to create a string joined with commas.
But if you want the array, assign the list output of the regex to an
array, instead of joining it as I did below.
> Here is the original text.. (including spaces)
> 1111111111 00000011111110000001111111TEST COMPANY
> 11111111111636459802000101700
>
> This is how I want it to look...
> 1111111111,0000001111111,0000001111111,TEST
> COMPANY,11111111111,63645980,2000101700
This gives the output you request, but it is partly guesswork and partly
intuition, because you didn't specify the field definitions very
clearly.
print join ',' => /(\d+)\s+(\d{13})(\d+)(\D+)\s(\d{11})(\d+)(\d{10})/;
Read perlre for details of the regex.
If the columns are fixed, you might do better with unpack(). But in no
event does split() seem appropriate (despite your Subject), because what
is there to split on?
> Thank You Very Much..
You're welcome.
> Mez
>
>
> PS... I am posting this to three perl groups cuz I am not sure which one is
> correct for this type of question.......
Well, at least you crossposted, instead of posting three time. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 20 Oct 2000 17:20:56 -0700
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: Help with Split....
Message-Id: <201020001720565236%lincmad001@telecom-digest.zzn.com>
In article
<26DE04D162000843.66E7BAAE4D9CF447.64BB1EAAD984A22D@lp.airnews.net>,
Mezmoria <mezmoria@hotmail.com> wrote:
> Ok, I admit it I suck as a programmer. I guess thats why I dont
> program full time :). Anyway I need help from you experts out there.
>
> I am trying to create an array from a line of text that has no
> formatting and I cannot figure out how to separate the fields.
>
>
> Here is the original text.. (including spaces)
> 1111111111 00000011111110000001111111TEST
> COMPANY11111111111636459802000101700
>
> This is how I want it to look...
> 1111111111,0000001111111,0000001111111,TESTCOMPANY,11111111111,
> 63645980,2000101700
You haven't given enough information about the general format of the
data to fully answer the question.
For instance, are the data fields a fixed number of characters? If so,
you're probably better off with "unpack" rather than "split". My guess
is that's where you should be looking.
If you use the "A" specifier instead of "a", you'll strip out trailing
spaces and nulls in each field.
------------------------------
Date: Sat, 21 Oct 2000 11:07:17 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how can I get data from a file into variable?
Message-Id: <slrn8v1nhl.fji.mgjv@martien.heliotrope.home>
On Fri, 20 Oct 2000 14:12:19 -0700,
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <slrn8v06in.fji.mgjv@martien.heliotrope.home> on Fri, 20 Oct
> 2000 21:11:35 +1100, Martien Verbruggen <mgjv@tradingpost.com.au>
> says...
>
> ...
>
> > open(FILE, $file) or die "Cannot open $file: $!";
> > my $line = (<FILE>)[-1];
> > close FILE;
> > chomp $line;
>
> Compulsive use of chomp()!
>
> > my $val = (split /\t/, $line)[-1];
> >
The OP's question was:
>>>How can I retreive the number 2000 into a variable
Not removing the newline would leave the newline in $val. I know that
for numerical operations that doesn't matter, but it also doesn't answer
the question. The OP might very well call this a number, and continue to
use it as a string. I could have split on whitespace, with ' ', but that
also wasn't according to spec. Specified was that data was separated by
a tab. I can't assume that other pieces of data won't have embedded
whitespace.
The chomp was used with deliberation, not compulsively. But I might be
missing something? How do you suggest I fremove it, if not with a chomp?
> > If the line is of intermediate length, and you have little memory:
> >
> > open(FILE, $file) or die "Cannot open $file: $!";
> > my $line = (<FILE>)[-1];
> > close FILE;
>
> You inadvertantly copied the above two lines into this snippet.
Indeed. they shouldn't be there.
> > my $line;
> > $line = $_ while <FILE>;
> > chomp $line;
>
> Compulsive use of chomp()!
See above :)
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Sat, 21 Oct 2000 11:54:46 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how do i find file size?
Message-Id: <slrn8v1qam.fji.mgjv@martien.heliotrope.home>
On Fri, 20 Oct 2000 16:27:52 GMT,
EM <me@privacy.net> wrote:
>
> <SNIPPED SCRIPT CODE>
>
> Thats great but that script is a command line script
> I aleady have a command line script for this
Well, then maybe you should rewrite it to use CGI, if that's what you
want. I'll help you a bit more, but after that you're on your own. I
don't mind helping people to become programmers, but I do mind writing
programs for other people when they should be doing it themselves, or
paying another professional to do it.
> Basically i want a script that i enter the urls to download and it transfers
> the file
Where do you want the file to be saved? On the server? Or on the browser
side?
If the last, then I have to ask: What is the use of this? What are you
going to win by having a form where people put in a URL, and then
download that file for them? Why don't you tell them to type the URL
directly in their browser? So, what I'll do is assume that it does need
to be saved on the server, because otherwise it makes no sense.
> I have done all this but i would like to know
> How do i set what i want the http referer to be?
Huh? That was already in the code you put in this post. Why are you
asking if you already know?
> How do i set the useragent (not that important)?
Ditto?
Listen, you are trying my patience. it's fine that you don't know these
things, but PLEASE do SOME work yourself. Read the documentation. Read
the scripts, and try to understand them.
> Now i figured out how to do this with LWP but it loads the file into memory
> & then writes to a file
I just showed you how to do that.
> If you could show me how to modify it so that the download is not stored in
> memory like getstore
I will give you one more script. The main reason is that I don't like
you getting in the bad habits that this script is getting you in. But
that's the last of it. You'll just have to do the rest yourself, or get
someone else's time.
But DO read documentation:
# perldoc CGI
# perldoc lwp-cook
# perldoc LWP::UserAgent
# perldoc HTTP::Request
# perldoc HTTP::Message
# perldoc -f open
Ok, I quickly hacked up the following. It is up to YOU to adapt it to
your needs, and to make it do exactly what you want. It's not as clean
as can be, but at least it hopefully will get you started, using some
decent security (and yes, security is VERY important here).
Always use -wT for a CGI program in Perl. Always use strict. Always[1].
For your own sanity: Always use the CGI module. It'll prevent you from
making all the errors that are so easy to make.
#!/usr/local/bin/perl -wT
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
my $ERROR;
print header(),
start_html(-title => 'Example form');
if (param('url'))
{
my $url = param('url');
my $file = param('file');
# Untaint $file, only allow word characters, / and .
# Adapt to your needs, but THINK about it.
$file = "/some_path/download.$$" unless $file;
$file =~ m#([/\w.]+)#;
my $success = download_url($url, $1);
print "Download of '$url' to '$file' was ",
($success ? '' : 'not '),
"successful",
br,
($ERROR ? $ERROR : ''),
hr;
}
print
start_form,
'URL to download: ',
textfield(-name => 'url'),
br,
'Save as File: ',
textfield(-name => 'file'),
submit,
end_form,
end_html;
sub download_url
{
my ($url, $file) = @_;
local (*FILE);
open(FILE, ">$file") or
$ERROR = "Couldn't open $file: $!", return;
binmode FILE;
my $ua = new LWP::UserAgent;
$ua->agent('LWP::UserAgent');
my $req = HTTP::Request->new(GET => $url);
$req->referer('http://www.server.com/links.html');
my $res = $ua->request($req, \&callback, 4096);
close FILE;
$ERROR = $res->status_line unless $res->is_success;
return $res->is_success;
}
sub callback
{
my ($data, $response, $protocol) = @_;
print FILE $data;
}
Martien
[1] Unless you know why you don't need to use it.
--
Martien Verbruggen |
Interactive Media Division | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: Fri, 20 Oct 2000 22:37:10 GMT
From: "Seth" <sbearden@houston.rr.com>
Subject: Need help again with my script
Message-Id: <qO3I5.9830$Fe4.255520@typhoon.austin.rr.com>
check out the datae file:
|10/20/2000|18:32:21|nothing[aTm]|In Flames|31|21|silver|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|32|22|titanium|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|33|23|platinum|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|34|24|gold|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|35|25|titanium|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|36|26|silver|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|37|27|gold|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|38|28|silver|lpb|
|10/20/2000|18:32:21|nothing[aTm]|In Flames|39|29|platinum|lpb|
here is the script:
ftp://ftp.fragilis.net/pub/1.txt
here is the script in action:
http://rangers.tc/testing.shtml
You'll notice that it only outputs 4 entries. I want it to output all the
datafile entries.
Thanks.
------------------------------
Date: Fri, 20 Oct 2000 22:28:35 GMT
From: tmg123@hotmail.com
Subject: New at perl, help needed
Message-Id: <8sqgud$v1u$1@nnrp1.deja.com>
I have already asks this today, but i figure with no real examples i
couldn't make myself clear.. I have been looking at a bunch of examples
and cannot figure out what the module Use Strict does, for example
something small so you could get the idea
#!/usr/bin/perl
use strict;
sub reddata{
open(PH, "file.txt") || die "cannot open file: $!";
my(@data)=<PH>;
chomp @data;
close(PHP);
return(@data);
}
say something like that, i am unsure of exactly what that module does..
Tynan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 20 Oct 2000 23:41:23 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: New at perl, help needed
Message-Id: <slrn8v1m13.anj.clay@panix2.panix.com>
On Fri, 20 Oct 2000 22:28:35 GMT, tmg123@hotmail.com <tmg123@hotmail.com> wrote:
>I have already asks this today, but i figure with no real examples i
>couldn't make myself clear.. I have been looking at a bunch of examples
>and cannot figure out what the module Use Strict does, for example
>something small so you could get the idea
>
>#!/usr/bin/perl
>
>use strict;
>
>sub reddata{
> open(PH, "file.txt") || die "cannot open file: $!";
Open the file...
> my(@data)=<PH>;
Put it into an array called @data...
> chomp @data;
This doesn't make sense -- You're chopping a newline off the end of the
arrary?
> close(PHP);
You're closing a filehandle you never opened (you openned PH).
> return(@data);
Return the array.
>}
>
>say something like that, i am unsure of exactly what that module does..
It's not a module -- It's a subroutine.
--
Clay Irving <clay@panix.com>
FAQ (fah-Q)
------------------------------
Date: Sat, 21 Oct 2000 00:14:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: New at perl, help needed
Message-Id: <m6n1vsoeoqbmvlf4cua34tmjaqqg5u323h@4ax.com>
tmg123@hotmail.com wrote:
>I have been looking at a bunch of examples
>and cannot figure out what the module Use Strict does
It's "use strict". Perl is case sensitive. strict.pm is a pragma module,
that's why it starts with a lower case latter.
So WTH is a pragma? If you look at the source of the mopdule, all you'll
see is that some bits of a variable are being set, or reset. The
variable is $^H.
Now, this is a special variable, in that Perl the Compiler checks its
value (the bits) to change its behaviour. For example, for "use strict
'refs'", it's bit 1 (hex value of the mask is 2). You can compare this
to the command line switches of traditional command line compilers
(like, for example, for C). What is special is that Perl saves the old
value of this variable when entering the compilation of a block, before
it's changed by any pragma's; and restored when exited. That's why the
effect of any "use somepragma" statement in a block, is limited to that
block.
So that's how it works. Now, what's it for? Looking at the module's
source, you can see that there are three bit maks being defined: one for
'refs', on for 'subs', one for 'vars'.
'vars' is the best known. This one allows the compiler to complain when
it encounters an unqualified variable (no package name) that it doesn't
know yet. Declaring such a variable with my() or our() makes sure the
compiler knows it.
'subs' is a simple one: this one makes barewords illegal. ORdinarily
Perl treats these as strings. Now, all barewords will be treated as sub
names.
Finally: 'refs' makes symbolic references illegal. That way,
@{$hash{foo}} will refuse to work is $hash{foo} contains a string.
You see? All change the behaviour of the compiler. Err... all allow the
compiler to change its behaviour. The new behaviour is already built
into the compiler, only, it's not activated by default.
--
Bart.
------------------------------
Date: Fri, 20 Oct 2000 17:27:18 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: New at perl, help needed
Message-Id: <39F0E2E5.65EA8981@ipac.caltech.edu>
Clay Irving wrote:
>
> On Fri, 20 Oct 2000 22:28:35 GMT, tmg123@hotmail.com <tmg123@hotmail.com> wrote:
>
> > chomp @data;
>
> This doesn't make sense -- You're chopping a newline off the end of the
> arrary?
From 'perldoc -f chomp':
"If you chomp a list, each element is chomped, and the total number of
characters removed is returned."
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: 21 Oct 2000 00:40:22 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: New at perl, help needed
Message-Id: <slrn8v1pfm.fh3.clay@panix2.panix.com>
On Fri, 20 Oct 2000 17:27:18 -0700, Tim Conrow <tim@ipac.caltech.edu> wrote:
>
>From 'perldoc -f chomp':
>
>"If you chomp a list, each element is chomped, and the total number of
>characters removed is returned."
Ding! Thanks for the correction.
--
Clay Irving <clay@panix.com>
My mother taught me about TIME TRAVEL:
"If you don't straighten up, I'm going to knock you into the middle of
next week!"
------------------------------
Date: Fri, 20 Oct 2000 23:55:48 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Perl for PalmOS?
Message-Id: <1eitx1j.ahv6dy18wophxN%tony@svanstrom.com>
[Followup-To: comp.sys.palmtops.pilot]
Steven Whatley <swhatley@blkbox.com> wrote:
> In comp.sys.palmtops.pilot Tony L. Svanstrom <tony@svanstrom.com> wrote:
> > Jon Davis <joncdavis@attglobal.net> wrote:
> >> Or why would I want to???
>
> > Don't have me for saying this, but I'd love to run a pure Perl webserver
> > on my Palm Vx.
>
> It's coming I'm sure. Wouldn't be surprised to see this within two years.
> That would be way cool to carry my web server with me? Am I a geek or am
> I a geek? :)
There already exists a webserver for PalmOS.
/Tony
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Fri, 20 Oct 2000 23:41:12 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: perldoc equivalent
Message-Id: <ant2022120b0fNdQ@oakseed.demon.co.uk>
Not a single thread in this group goes by without someone posting a
perldoc reference. This has long been a frustration to me because I do
not have perldoc on my RISC OS machine or my EPOC device, even though
I have Perl for both.
I have downloaded the "gigantic GNU-zipped tarfile" with all the docs
in HTML format. Can someone tell me what the various incantations of
perldoc actually do so that I can write a Perl program to launch the
appropriate HTML document and scroll it the correct location?
Perhaps there is already a version of perldoc written in Perl which
I could adapt to work with my OS. I'm surprised that such a thing
does not already exist for those of us not running UNIX or Wintel.
Without *some* kind of perldoc equivalent many of the answers given
on this group are completely unhelpful, and I can't be the only one
in this position. If you can give me enough detail to completely
duplicate perldoc for use with the HTML docs, then my resulting
program may be useful to many.
Thanks.
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: 20 Oct 2000 23:01:49 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: perldoc equivalent
Message-Id: <8sqist$grn$1@internal-news.uu.net>
James Taylor <james@nospam.demon.co.uk> wrote:
> Perhaps there is already a version of perldoc written in Perl which
> I could adapt to work with my OS. I'm surprised that such a thing
> does not already exist for those of us not running UNIX or Wintel.
Eh? As far as I can see perldoc _is_ written in Perl ...
Check out the 'utils' subdirectory in a source distribution.
Erik
------------------------------
Date: Sat, 21 Oct 2000 00:49:35 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: perldoc equivalent
Message-Id: <ant202335d07fNdQ@oakseed.demon.co.uk>
In article <8sqist$grn$1@internal-news.uu.net>, Erik van Roode
<URL:mailto:newsposter@cthulhu.demon.nl> wrote:
> James Taylor <james@nospam.demon.co.uk> wrote:
>
> > Perhaps there is already a version of perldoc written in Perl which
> > I could adapt to work with my OS. I'm surprised that such a thing
> > does not already exist for those of us not running UNIX or Wintel.
>
> Eh? As far as I can see perldoc _is_ written in Perl ...
> Check out the 'utils' subdirectory in a source distribution.
Oh good, I'll seek it out and decipher the intended behaviour from the
source then modify it to work with the HTML docs. Can I assume there
is no reason why this would not be possible, such as for instance
there not being the same material in the HTML docs as is accessible
using perldoc?
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Fri, 20 Oct 2000 23:50:14 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: SSI and Perl
Message-Id: <slrn8v1mj3.13e.efflandt@efflandt.xnet.com>
On Fri, 20 Oct 2000, David Scally <david.scally@scallynet.co.uk> wrote:
>
>Is it possible to create a Server Side Include using a Perl subroutine?
>
>I want to include a global include file (A header that appears all over the
>site) that needs to be included on the news database at:
>www.mancity.net
If it is a static file, you don't need Perl for that at all. Just see the
docs about how to include a file for your webserver.
If it is dynamic data, you could include it by using mod_perl if your
server supports it (but I am not familiar with it) or by including a CGI
(which could be Perl or anything else).
And if you want to include anything in a CGI, you simply open and print it
wherever you want it inserted.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4680
**************************************