[18807] in Perl-Users-Digest
Perl-Users Digest, Issue: 975 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 24 09:05:38 2001
Date: Thu, 24 May 2001 06: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: <990709512-v10-i975@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 24 May 2001 Volume: 10 Number: 975
Today's topics:
2 simple question on Getopt and Ftp <kennylim@techie.com>
Re: 2 simple question on Getopt and Ftp <alexis.roda@si.urv.es>
Re: 2 simple question on Getopt and Ftp <krahnj@acm.org>
Re: [Solved!] How to match the password created in Linu <flavell@mail.cern.ch>
Calling function reference <kris.verbeeck@chello.be>
Re: CGI with conditional GET <flavell@mail.cern.ch>
Re: connect timeouts <goldbb2@earthlink.net>
date question <CalinG@cfgroup.ca>
DB_File <rajesh_gupta@mailcity.com>
Detecting compile-time errors in embedded Perl (Dave Weaver)
Re: fork <goldbb2@earthlink.net>
Re: fork <ilya@math.ohio-state.edu>
Help please with sourcing an environment variable (Simon Barnard)
Re: Help please with sourcing an environment variable (Abigail)
Re: Help slim down Perl code <goldbb2@earthlink.net>
How to install perl modules as local user (Eric Smith)
Re: How to match the password created in Linux shadow s <joelh@juniper.net>
Re: Match Parsing Glitch <nospam@xx.com>
Re: Problem using "use constant => ..." with mod_perl ( <c.manley@_NO_SPAM_chello.nl>
Re: Problem using "use constant => ..." with mod_perl ( (Andreas Schmitz)
Re: Problem with scalar variables <mark.patton@program-products.co.uk>
Re: realpath(), abs_path() (Anno Siegel)
Re: Redirecting STDERR to sendmail <john@princenaseem.com>
Re: Regexp to match IP Address (Abigail)
Re: Selectively output records from delimited file? (Abigail)
Re: sessions and closures <goldbb2@earthlink.net>
Re: setting priority from perl on linux (Abigail)
Re: setting priority from perl on linux (Abigail)
Re: Sorting data file on numerical field (Graham Cox)
Re: Who's Going to the Perl Conference in San Diego thi <comdog@panix.com>
Re: Writing file in Perl <somewhere@in.paradise.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 May 2001 01:52:01 -0700
From: "Student" <kennylim@techie.com>
Subject: 2 simple question on Getopt and Ftp
Message-Id: <9eihpu$b2t$1@nntp9.atl.mindspring.net>
Hi Guys,
I have 2 simple/straighforward questions
and are wondering if anyone out
there would be kind enough to point me
to the correct directions.
Any advise or pointers would be greatly appreciated.
Thanks in advance.
Kenny-
Question 1:
========
How can I parse a long arguments via the command lines
(e.g. for a select statements) ?
Snippets of a test example:
-----------------------------
getopts( 'q:');
$Query = $opt_q ;
print "$Query\n";
perl t1.pl -q select col1, col2 from tableA where col1 = 100 and col2 = 200
order by col1
Question 2:
=========
How can I retrieve a filename without fully specifying the filename
using Net::FTP module. So far this module seem to only recognize
get and not mget and Get doesn't seem to accept wildcard. Is there
a work around or have a package that accepts wildcard ?
Snippets of an example:
-----------------------------
$remotetracefile = "*$process_id.trc";
$localtracefile = "trace-$instance_name-$date-$process_id.trc";
$ftp->get($remotetracefile, $localtracefile)
or die "Cannot Get File!.\n";
Note: I have a bunch of *.trc file and I would only like to retrieve the
file based on the $process_id given.
(e.g. *1234.trc and the complete filename is sun_trace_1234.trc)
------------------------------
Date: Thu, 24 May 2001 10:52:21 +0200
From: Alexis Roda <alexis.roda@si.urv.es>
Subject: Re: 2 simple question on Getopt and Ftp
Message-Id: <3B0CCBC5.8BC83D87@si.urv.es>
Student wrote:
>
> Hi Guys,
> Question 1:
> ========
>
> How can I parse a long arguments via the command lines
> (e.g. for a select statements) ?
>
> Snippets of a test example:
> -----------------------------
>
> getopts( 'q:');
> $Query = $opt_q ;
> print "$Query\n";
>
> perl t1.pl -q select col1, col2 from tableA where col1 = 100 and col2 = 200
> order by col1
Shell will split the args list, so you need to enclose it in quotes.
perl t1.pl -q "select col1 ...."
> Question 2:
> =========
>
> How can I retrieve a filename without fully specifying the filename
> using Net::FTP module. So far this module seem to only recognize
> get and not mget and Get doesn't seem to accept wildcard. Is there
> a work around or have a package that accepts wildcard ?
filter the output from $ftp->ls("/some/dir")
HTH
--
////
(@ @)
---------------------------oOO----(_)----OOo------------------------
Los pecados de los tres mundos desapareceran conmigo.
Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain)
--------------------------------------------------------------------
------------------------------
Date: Thu, 24 May 2001 09:10:24 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: 2 simple question on Getopt and Ftp
Message-Id: <3B0CD01D.7FA35FC6@acm.org>
Student wrote:
>
> Hi Guys,
>
> I have 2 simple/straighforward questions
> and are wondering if anyone out
> there would be kind enough to point me
> to the correct directions.
>
> Any advise or pointers would be greatly appreciated.
>
> Question 1:
> ========
> How can I parse a long arguments via the command lines
> (e.g. for a select statements) ?
>
> Snippets of a test example:
> -----------------------------
>
> getopts( 'q:');
> $Query = $opt_q ;
> print "$Query\n";
>
> perl t1.pl -q select col1, col2 from tableA where col1 = 100 and col2 = 200 order by col1
Enclose the entire statement in quotes:
perl t1.pl -q 'select col1, col2 from tableA where col1 = 100 and col2 =
200 order by col1'
> Question 2:
> =========
>
> How can I retrieve a filename without fully specifying the filename
> using Net::FTP module. So far this module seem to only recognize
> get and not mget and Get doesn't seem to accept wildcard. Is there
> a work around or have a package that accepts wildcard ?
>
> Snippets of an example:
> -----------------------------
>
> $remotetracefile = "*$process_id.trc";
> $localtracefile = "trace-$instance_name-$date-$process_id.trc";
>
> $ftp->get($remotetracefile, $localtracefile)
> or die "Cannot Get File!.\n";
>
> Note: I have a bunch of *.trc file and I would only like to retrieve the
> file based on the $process_id given.
> (e.g. *1234.trc and the complete filename is sun_trace_1234.trc)
my @files = $ftp->ls( $remotetracefile );
foreach my $file ( @files ) {
$ftp->get( $file, "trace-$instance_name-$date-$file" );
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 24 May 2001 13:06:41 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: [Solved!] How to match the password created in Linux shadow suite?
Message-Id: <Pine.LNX.4.30.0105241259230.23102-100000@lxplus003.cern.ch>
On 23 May 2001, Joseph Chen wrote:
[officially-obsolete group comp.lang.perl removed from f'ups]
> Please ignore my previous reply. It works perfectly.
[followed by a comprehensive quote]
It's nice of you to update the group on the status of your problem,
but it would be MUCH more helpful if the readers could learn something
from your experience. Can't you summarise briefly _what_ is now
working, and if possible indicate the nature of whatever it was that
you were doing wrong before? Nobody's perfect, and it's entirely
honourable to admit to having made a mistake. After the readership
has gone to the trouble of reading about your earlier difficulties,
it's most frustrating as a reader to find oneself left in this vacuum
of "it works perfectly". Maybe the reason is buried somewhere in that
comprehensive quote, but it would be much nicer to have it summarised
clearly.
IMHO.
------------------------------
Date: Thu, 24 May 2001 12:21:36 GMT
From: Kris Verbeeck <kris.verbeeck@chello.be>
Subject: Calling function reference
Message-Id: <3B0CFDC3.2CFECF1D@chello.be>
Hi,
I got a small problem. I'm just experimenting a bit with calling
subroutines dynamically. I have a class (package) in which one of
the object fields is the name of a function that needs to be called.
When I try calling this function, then perl complains that it
doesn't find the function &class::func. This function does not
exist in the class, but it exist in the global namespace. How can
I have a method in the class call that global function?
Code snippet:
-----
package Test;
sub process {
my $self = shift;
$self->{FUNC}->()
}
-----
FUNC is defined as "doit", the name of an existing global function.
When I execute this piece of code, perl responds with:
Undefined subroutine &Test::doit called at Test.pm line xx.
Any suggestions?
thx in advance
------------------------------
Date: Thu, 24 May 2001 12:57:39 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI with conditional GET
Message-Id: <Pine.LNX.4.30.0105241243410.23102-100000@lxplus003.cern.ch>
On Wed, 23 May 2001, Benjamin Goldberg wrote:
> http() method. The last item listed there for fetching environment
> variables is request_method(). Some other documentation which I found
> via google showed content_type(), http() and https() methods, listed
> after request_method().
The author of CGI.pm maintains the documentation for it in HTML. The
documentation for his current version is at
http://stein.cshl.org/WWW/software/CGI/
The Perl distribution maintains documentation in POD format, and this
is what you get as part of your Perl distribution, which includes a
version of CGI.pm. There is also a procedure for HTML-ifying the
PODs, which, confusingly, can create a different HTML-format
documentation for CGI.pm (and this, in its Perl 5.6 form, seems to be
what you are seeing at perldoc.com). This had me mightily confused at
one time. I'm told that the Perl porters are aware of this
discrepancy and will be addressing it somehow.
Of course, for most purposes you can use either form of the
documentation. It's only when you get to the finer details that
the differences matter.
------------------------------
Date: Thu, 24 May 2001 04:12:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: connect timeouts
Message-Id: <3B0CC265.BE0574B8@earthlink.net>
nobull@mail.com wrote:
>
> "Paul Brown" <paul.brown@ukinternetsites.com> writes:
>
> > I use connect(S, $serverhostname) to connect to the other server,
> > however if the server is down and not responding very fast, then it
> > can sit there for a long time. I want to setup some kind of
> > timeout, so it trys to connect and if it hasn't connected in 30
> > seconds (for example), it exits.
> >
> > Any solutions to create a timeout? Thanks in advance!
>
> See FAQ: "How do I timeout a slow event?"
>
> Also you may consider moving to the Perl5 OO idiom for sockets
> (IO::Socket). Appart from numerous other advantages it supports
> timeouts on connects.
You can set the timeout on a socket for connecting even without using
the OO interface.
However, I don't recall offhand how to do it. You would have to read
quite a bit of perl and unix man pages to figure out how. Or, you could
look at how the timeout is impelemented in the OO version, and use that
in your code.
--
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."
------------------------------
Date: Thu, 24 May 2001 08:27:45 -0400
From: "Calin Guga" <CalinG@cfgroup.ca>
Subject: date question
Message-Id: <227P6.240891$Z2.2673447@nnrp1.uunet.ca>
Hello there,
Does anybody know how to convert a date in Perl, for ex. 01/01/2001 and
to tell what day of the week that was(like Monday...Sunday)?
Thanks a lot for your help,
Calin
------------------------------
Date: Thu, 24 May 2001 15:23:14 +0530
From: "Rajesh Gupta" <rajesh_gupta@mailcity.com>
Subject: DB_File
Message-Id: <9eiljf$20b$1@newshost.mot.com>
Hi,
I am facing problem in installation of DB_File on solaris. Could anybody
please send me complert precompiled binaries(On solaris) for this module ??
Thanks
Rajesh Gupta
------------------------------
Date: 24 May 2001 01:15:33 -0700
From: davew@wsieurope.com (Dave Weaver)
Subject: Detecting compile-time errors in embedded Perl
Message-Id: <bbbfa68d.0105240015.46d28034@posting.google.com>
I'm attempting to embed Perl within a large application. I have a basic
C application 'my_perl' (source below) which takes a Perl expression
on the command line and evaluates it using the Perl API routine eval_sv().
The code is adapted from a sample in the perlembed manpage, and seems to
work fine in all but one respect; I can't seem to detect Perl compile-time
errors (although Perl run-time errors are spotted quite nicely).
Sample session:
% my_perl "12+12"
Eval OK: 24
%
% my_perl "12/0"
Eval error: Illegal division by zero at (eval 1) line 2.
Eval failed!
%
% my_perl "12=12"
Eval OK: 0
%
% perl -e "12=12"
Can't modify constant item in scalar assignment at -e line 1, at EOF
Execution of -e aborted due to compilation errors.
%
What am I doing wrong? How do I catch compilation errors?
Thanks in advance!
-----8<---------------------------------------
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int eval_perl(char *str, int *return_value)
{
int result;
SV* sv = newSVpv(str, 0);
dSP;
PUSHMARK(sp);
result = eval_sv(sv, G_SCALAR);
SPAGAIN;
if (SvTRUE(ERRSV)) {
fprintf (stderr, "Eval error: %s", SvPV(ERRSV, PL_na)) ;
return -1;
}
SvREFCNT_dec(sv);
*return_value = POPi;
PUTBACK;
return result;
}
int main(int argc, char **argv, char **env)
{
char *dummy_argv[] = { "", "-e", "0" };
int value;
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, 3, dummy_argv, env);
if (eval_perl(argv[1], &value) == -1) {
fprintf(stderr, "Eval failed!\n");
return -1;
}
printf("Eval OK: %d\n", value);
perl_destruct(my_perl);
perl_free(my_perl);
return 0;
}
-----8<---------------------------------------
--
Dave
davew@wsieurope.com
------------------------------
Date: Thu, 24 May 2001 03:38:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: fork
Message-Id: <3B0CBA5A.1573A327@earthlink.net>
Gwyn Judd wrote:
>
> "Mein Lufkissenfahrzeug ist voller Aale"
> said Benjamin Goldberg (goldbb2@earthlink.net) in
> <3B0C701F.59A26A56@earthlink.net>:
> >Mark Jason Dominus wrote:
> >
> >I would love if someone could explain to me what this sig does (besides
> >the obvious fact of print ing out "Just another Perl / Unix hacker").
> >
> >> @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
> >> @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
> >> ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
> >> close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
>
> It is the most convoluted piece of code I've ever read in any language.
> Normally I don't much like obfuscated code since as a rule it tends to
> rely more on using horrible syntax and strange variable names to hide
> it's true purpose. The above piece of code is one of the few that
> impressed me with the fact that even once you look at it, with helpful
> variable names and comments, it is still difficult to understand :) This
> comes from the fact that the algorithm is even more obfuscated than the
> code. There is an explanation on his webpage somewhere, which offhand I don't
> remember.
Upon learning that an explanation for the code existed somewhere, I did
a google search. The location is:
http://perl.plover.com/obfuscated/
Well, actually the explanation is at
http://perl.plover.com/obfuscated/solution.html
but you might want to look at the hints and try to figure it out yourself.
--
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."
------------------------------
Date: 24 May 2001 07:49:03 GMT
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: fork
Message-Id: <9eiedf$7pu$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Mark Jason Dominus
<mjd@plover.com>], who wrote in article <3af198d5.6ba6$7e@news.op.net>:
> If you want the main process to continue with your code without
> waiting, use
>
> system("mpg123 $somsong &");
>
> fork() is only for unusual circumstances.
Both version will work on legacy systems only. More agile OSes allow
either one of
$pid = system(1, "mpg123 $somsong");
$pid = system(1, "mpg123", $somsong);
However my proposal on making this work on *nix too (so make a
portable way to do this) were not warmly accepted... The only
portable way to do this I know of is
$pid = open3 undef, undef, undef, "mpg123", $somsong;
Ilya
------------------------------
Date: 24 May 2001 02:06:39 -0700
From: sbarnard@dial.pipex.com (Simon Barnard)
Subject: Help please with sourcing an environment variable
Message-Id: <18e528da.0105240106.6a04fab2@posting.google.com>
Hi, I hope someone can help me
I need to read the value of an environment variable from a shell script in a
perl cgi. The reason being that it uses a DBI call to Oracle and we need to
make the Oracle password non static, the actual password is held centrally
in the shell script that gets run by normal binaries.
I am aware of the issues around trying to do this kind of thing, using
system etc won't work. I have searched the newsgroups and found a couple of
suggestions and also asked at the office, but I have been unable to get any
of them working.
I'll say now, I am not experienced with perl, but I have programming
experience and basic unix knowledge and some html
The perl script gets called from a java applet, puts up a search screen,
accepts the input and generates another page with the results.
First thing I tried was a shell wrapper eg.
#!/bin/sh
. /export/home/...........
exec <path to perl script> $@
However when the script does the post the mime type seems to get changed and
the browser prompts me to save a file (which is the html page that should
get displayed)
Next one was an untested suggestion, eg
in the script use something like
$ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
$ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;
however this just returns what looks like a newline character, no strings.
Final thing I tried is a bit of a hack, which apparently is part shell, part
perl
at the top of the perl script
eval '. <path to shell script>; exec /usr/local/bin/perl "$0" "$@"' if 0;
I get an error in the apache log complaining about a bad exec format.
Apart from loading the shell script and parsing the values is there any
other way of achieving what I am trying to do?
Many thanks
Simon Barnard
Technical Support Services
Solect, A Division of Amdocs
simon.barnard@amdocs.com
------------------------------
Date: Thu, 24 May 2001 11:43:53 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Help please with sourcing an environment variable
Message-Id: <slrn9gpsvp.mud.abigail@tsathoggua.rlyeh.net>
Simon Barnard (sbarnard@dial.pipex.com) wrote on MMDCCCXXIII September
MCMXCIII in <URL:news:18e528da.0105240106.6a04fab2@posting.google.com>:
&&
&& $ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
&& $ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;
$DB_USER and $DB_PASSWD are interpolated by Perl before the line is passed
to the shell. You would need to escape the $ signs with a backslash.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Thu, 24 May 2001 07:11:07 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help slim down Perl code
Message-Id: <3B0CEC4B.61F5CE21@earthlink.net>
Falc2199 wrote:
>
> I have here a lot of reduntant code. I need a way to slim it down. It
> bascially does the same thing over and over, open and a file and read
> the contents into an array....
foreach (qw( l o b )) {
open my $fh, "<", "${_}Choice.txt"
or die "can't open ${_}Choice.txt: $!";
@{ $_ . "Carray" } = <$fh>;
}
This [untested] code should have the exact same effects as your code:
that of sticking the contents of lChoice.txt, oChoice.txt, and
bChoice.txt into the arrays named @lCarray, @oCarray, and @bCarray.
--
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."
------------------------------
Date: 24 May 2001 09:46:56 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: How to install perl modules as local user
Message-Id: <slrn9gpm4d.3sm.eric@apple.fruitcom.com>
like I can install a C application with
./configure --prefix=/home/foo
--
Eric Smith
------------------------------
Date: 24 May 2001 00:52:33 -0700
From: Joel Ray Holveck <joelh@juniper.net>
Subject: Re: How to match the password created in Linux shadow suite?
Message-Id: <y7c66erp4ji.fsf@sindri.juniper.net>
>> Variable $p is my login password and $passwd is my encripted password
>> in /etc/shadow, after I run the script, I got ...
>> % shadow_match.pl
>> $1$QR/J8Kwx$l8A4IHdLZylsCALdmhy30.,$1p327sCxfpMs
>> no match
>> Am I doing it correctly?
> Sorta.
> You're using a DES crypt routine to match an MD5 password.
> Use Crypt::PasswordMD5 or something similar from the CPAN.
I thought that Perl crypt used the system's libc crypt so it would get
MD5, etc for free. Am I mistaken?
Thanks,
joelh
------------------------------
Date: Thu, 24 May 2001 00:51:41 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B0CBD8D.E83F5495@xx.com>
Tad McClellan wrote:
> Eric <nospam@xx.com> wrote:
> >5.003_07 which I must use as is
> If you stick with that version, then you will need to be a better
> programmer than if you upgrade, because you will not be able to
> reuse OPC without these backward-version "repairs". If you show
> up here often trying to get help with such an endeavor, the
> readership of your articles will decline.
Tnx for all the tips. I was out-of-perl for the past 2 years, but
downloaded build 626 however am having difficulty getting it installed.
If I am "RTFM" (readme) it looks like I need to buy a compiler??? I
don't recall having to do this to install what I do have (On my WIN32
machine). Confusing.
The unpack solution for the posted problem works great...tnx again to
you, Jay & John.
I'm trying to further tweak this unpack approach for a more detailed
derivation to parse across some multi-lines of an expanded record
offshute of the simple one-liner, but am in a glitch again.
If this will, in fact, work...I'm having difficulty seeing how to write
the ascii .csv file so that all 5 pieces of data will end up in a single
line in the output file, since it appears I'm going to have to write the
output before I loop to the next line in the in-file data record???
Here's what I've done thus far, but would like to know if I am barking
up the wrong tree by attempting to combine unpack functionality across
multiple lines *and* be able to write the .csv file in one whack???
Code follows (below)
Thank you very much.
Eric
----
# OBJECTIVES TO PARSE, CAPTURE & WRITE TO ASCII .csv FILE
#
# (Example above ... lines involved indicated by #(& Line #) at
beginning)
# 1. S Code (1 number) ... in 1st line ... the "5" in 1/5
# 2. Address (25 characters) ... in 1st line ... follows 1/5 plus 2
spaces
# 3. SP ($x,xxx,xxx) ... at end of 1st line as "SP:"$x,xxx,xxx)
# 4. SA (17 characters ... on 2nd line following "SA:"
# 5. LA (17 characters) ... on 12th line following "LA:"
#
# START OF PERL SCRIPT
$R=1; #start number for record counter
print "Enter File Name To Parse: "; #instructions for entering file
name
$filename = <STDIN>; #enter file name to parse
print "Enter Output File Name: "; #instructions to enter out file name
$datafile = <STDIN>; #enter output file name
open (INFILE, "$filename")
or die "Could not open $filename as read: $!"; #open input file
while ($line = <INFILE>) #primary loop
{
if ($line =~ m//#\d{6}/) || ($line =~ m/^SO:.*) || ($line =~ m/^LA:.*)
if ($line =~ m//#\d{6}/)
{
my ( $status, $addr, $price ) =
unpack 'x13 A1 x2 A25 x28 A10', $line; #acquire/parse stats,
address,price
$price =~ tr/$,//d; #remove $ and comma on price
$addr =~ s/^\s+|\s+$//g; #whitespace cleanup on address
#and skip all other lines
}
if $(line =~ m/^SO.*)
{
my ( $sa ) =
unpack 'x18 A17', $line; #acquire/parse "LA:" (name)
$sa =~ s/^\s+|\s+$//g; #whitespace cleanup on name
}
if ($line =~ m/^LA.*/)
{
my ( $la ) =
unpack 'x3 A17', $line; #acauire/parse "SA:" (name)
$la =~ s/^\s+|\s+$//g; #whitespace cleanup on name
}
&writedatafile ($status, $addr, $price, $sa, $la)
unless ($line !~ m//#\d{6}/) || ($line =~ m/^SO:.*) || ($line =~
m/^LA:.*)
#only call subroutine if valid
#lines being parsed
}
}
close (INFILE); #close input file
### SUBROUTINE TO PARSED DATA TO ASCII .CSV FILE
sub writedatafile
{
my ($status, $addr, $price, $sa, $la ) = @_;
open (FILE ,">>$datafile"); #open output file for append
print FILE "$R,$status,\"$addr\",$price,$sa,$la\n"; #write data to file
$R++; #increment record counter
close (FILE); #close output file
}
# END OF PERL SCRIPT
------------------------------
Date: Thu, 24 May 2001 08:06:36 GMT
From: Craig Manley <c.manley@_NO_SPAM_chello.nl>
Subject: Re: Problem using "use constant => ..." with mod_perl (Apache).
Message-Id: <3B0CC17A.90FE7FB2@_NO_SPAM_chello.nl>
Hi Shay,
Shay Harding wrote:
>
> "Craig Manley" <c.manley@_NO_SPAM_chello.nl> wrote in message
> news:3B0BB363.4EEF421B@_NO_SPAM_chello.nl...
> >
> > Hi all,
> >
> > I've got a CGI application that uses some constants exported from some
> > .pm files. When running this application in mod_perl I keep getting
> > this error in the httpd errorlog:
> >
> > Prototype mismatch: sub Apache::ROOT::CSD::mod_2dperl::test_2ecgi::BLA
> > vs () at /usr/lib/perl5/5.6.0/constant.pm line 91.
> >
> >
> > This is my test script that causes the error above:
> >
> > #############################
> > use strict;
> > use constant BLA => '?';
> >
> > print "Content-type: text/plain\n\n";
> > print BLA . "\n";
> > #############################
> >
> > Can anybody explain what's going wrong and how to solve this problem?
>
> If I take the exact code above and run it under under Apache 1.3.19, perl
> 5.6.0, mod_perl 1.25 on my Mandrake 7.2 box it works fine. I get the
> expected output.
Check the httpd errorlog and execute the script more than once and see
what happens.
-Craig.
------------------------------
Date: Thu, 24 May 2001 12:06:54 GMT
From: webmaster@kreativhaus-online.de (Andreas Schmitz)
Subject: Re: Problem using "use constant => ..." with mod_perl (Apache).
Message-Id: <3b0ce0d5.6375596@news.rus.uni-stuttgart.de>
On Wed, 23 May 2001 12:55:07 GMT, Craig Manley
<c.manley@_NO_SPAM_chello.nl> wrote:
Hy,
>Prototype mismatch: sub Apache::ROOT::CSD::mod_2dperl::test_2ecgi::BLA
>vs () at /usr/lib/perl5/5.6.0/constant.pm line 91.
>#############################
>use strict;
use Apache::Constants qw(...);
>use constant BLA => '?';
>
>print "Content-type: text/plain\n\n";
>print BLA . "\n";
>#############################
hth
--
#!C:\perl\bin\perl.exe -wT
print map {chr(ord($_)-3)} split //, "Dqguhdv0Vfkplw}Cw0rqolqh1gh";
------------------------------
Date: Thu, 24 May 2001 09:17:45 +0100
From: Mark Patton <mark.patton@program-products.co.uk>
Subject: Re: Problem with scalar variables
Message-Id: <3B0CC3A9.AD270434@program-products.co.uk>
Thank you kindly for the guidance. Obviously spoon feeding is preferable
for babies, but I appreciate being pointed in the right direction to
start looking. (I'd only reached page 4 of perlref but I wasn't aware
the answer to my problem was in there).
Thanks again.
Mark
------------------------------
Date: 24 May 2001 09:17:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: realpath(), abs_path()
Message-Id: <9eijj1$srk$1@mamenchi.zrz.TU-Berlin.DE>
According to /dev/null <postmaster@god.edu>:
> Greetings!
>
> Last year I wrote a realpath() function in Perl. Recently I discovered
> Cwd::abs_path(). When I tried to use it, I discovered that abs_path()
> barfs if its argument is not a directory. This is more than mildly
> annoying. Did the author(s) of abs_path() not see value in
> being able to feed the function something like "/var/mail/extasia"
> and get back "/var/spool/mail/extasia"? Am I missing something?
>
> Does there exist in Perl a function to do an absolute (or "real")
> path on a given path representing *any* type of file?
>
> If not, should I submit my realpath() function?
The rel2abs() function in File::Spec doesn't have this limitation.
Cwd is explicitly designed to deal with directories.
Anno
------------------------------
Date: Thu, 24 May 2001 12:02:28 +0100
From: "JohnShep" <john@princenaseem.com>
Subject: Re: Redirecting STDERR to sendmail
Message-Id: <OT5P6.127$hD.4014@NewsReader>
> On Wed, 23 May 2001 15:15:19 +0100, M <mike@gatrell.org> wrote:
> >On Tue, 22 May 2001 18:41:24 +0100, "Unknown" <nobull@mail.com> wrote:
> >
> ><snip>
> >> BTW: You never use $date.
> >
> >why not??
> >
> That was an observation, not an advise, as far as I can read. Setting the
> $date to some value and not using it later doesn't make much sense.
>
I put $date in there as an unreferenced variable which should generate a
warning to test the script.
John
------------------------------
Date: Thu, 24 May 2001 11:48:03 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Regexp to match IP Address
Message-Id: <slrn9gpt7j.mud.abigail@tsathoggua.rlyeh.net>
James Coupe (james@zephyr.org.uk) wrote on MMDCCCXXI September MCMXCIII
in <URL:news:nDYJ9FJKbcC7Ewg9@obeah.demon.co.uk>:
** In message <tgje6rrb7arjf3@corp.supernews.com>, Craig Berry
** <cberry@cinenet.net> writes
** >See Friedl's _Mastering Regular Expressions_ for a great discussion of
** >this very problem. In brief, you can write a reasonably compact regex
** >that will match only valid IP addresses, but it's easier to do it using
** >numeric range comparisons on the dotted-quad components.
**
** Of course, it gets more interesting when you do things like:
**
** $ ping 127.1
**
** or a similar expression, where it doesn't have to be a dotted *quad* to
** work, which further complicates matters.
Of course, there's a difference between valid IP addresses, and things
you can give ping as an argument.
ping 0x7F.0000000000000000001
works just fine. Depending on your C library, you can mix decimal, hex
and octal "quad"s in your addresses without any problem.
Wanna write a regex for that?
Abigail
--
:;$:=~s:
-:;another Perl Hacker
:;chop
$:;$:=~y
:;::d;print+Just.
$:;
------------------------------
Date: Thu, 24 May 2001 11:53:22 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Selectively output records from delimited file?
Message-Id: <slrn9gpthi.mud.abigail@tsathoggua.rlyeh.net>
Chris Ashley (chris.ashley@NOSPAMblueyonder.co.uk) wrote on MMDCCCXXI
September MCMXCIII in <URL:news:mkhlgt4l6lbga4pps6l3rlvvob4g7va6id@4ax.com>:
{} I'm in the middle of developing a CGI quiz application at the moment.
{} I'm at the stage where I have the input being sent to my script from
{} POST, which then caclulates the result and appends it (along with
{} other details) to the bottom of a comma delimited text file like so:
{}
{} name,email,result
{} newname,newemail,newresult
{}
{} This works fine for me, but I'm now looking to do a high score table
{} of sorts - I need to read that file with perl, and only output the top
{} 10 results fields along with the other details. I can make it output
{} the entire file, but any kind of arrangement of results seems to be
{} above me. I'm really a perl beginner (but learning!), and would be
{} grateful for any help with the above - where do I start? :)
You would be better off storing the results in a database, and put an
index on the result.
If you insist on putting everything in a file, to get the "top 10", you
open the file, lock it, read in the first 10 lines, put them in a buffer
(preferably sorted), and then you read in the rest of the lines, compare
each line with the lowest value in the buffer. If the current line has
a larger result, put it in the buffer, deleting the lowest result from
the buffer. After reading all the line, close the file.
You now have the top 10 in your buffer. Don't forget to special case the
case of less than 10 lines in your file.
Abigail
--
perl -Mstrict -we '$_ = "goto _.print chop;\n=rekcaH lreP rehtona tsuJ";_1:eval'
------------------------------
Date: Thu, 24 May 2001 07:58:04 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sessions and closures
Message-Id: <3B0CF74C.78AF21D3@earthlink.net>
Mark Jason Dominus wrote:
>
> In article <3af7945a.863921@news.iddeo.es>,
> F. Xavier Noria <fxn@isoco.com> wrote:
> >One could store a hash in a request dispatcher which would know
> >how to deal with the stored closures. Do you see any drawbacks in
> >this schema?
>
> I see a big one: I don't know how to write 'a request dispatcher which
> would know how to deal with the stored closures', and I don't think
> anyone else does either.
>
> How do you get the closures over the network the the dispatcher? Perl
> has no way to send a closure as a string.
>
> OK, let's try to work around that: Use the bytecode dumper to dump out
> the closure as bytecode, or use B::Deparse to generate Perl code; send
> the result over the network. This is extremely complicated and still
> buggy.
Of course, if instead of using what we normally think of a perl closure,
we use a blessed object with some callable methods, we can very easily
send it over the network... use Storable; then freeze, transmit, and
thaw the data; then, call the appropriate method.
Here's a simple function which creates closures:
sub mkclosure {
my $foo = 0;
return sub { return ++$foo };
}
Obviously, this would be quite difficult to send over the network,
unless we use the bytecode dumper etc.
OTOH, this works fine:
package mkclosure;
sub new {
my $class = shift;
my $self = 0;
bless \$self, $class;
}
sub interact {
return ++${ shift };
}
We can send instances of mkclosure over the network using Storable.
Sure, it's an "object" rather than a "closure" but that's just
semantics... the effect is the same.
> In Lisp, it's completely trivial because a Lisp program is just like
> any other piece of Lisp data.
Not really. In any decent lisp environment, functions are compiled
internally into an optomized form [bytecode], or even into native
machine code, just as perl does. However, perl throws away the original
text which made the function, while lisp keeps it as a list, even if
it's *using* the bytecode version of the function. Thus, in lisp, you
can always retrieve the list, while in perl you can't.
> In Perl, there's no way to find out the environment and dump it.
It's called Storable. Ok, it doesn't send the *entire* environment, but
neither do you, when you send an S-expression.
> Even if there was, you'd have to dump a huge amount of nonsense like
> $", $/, $\, $;, and so on.
No. These are globals. They don't become parts of closures.
In normal perl closure syntax, the only things which become umm, closed?
are lexicals in the surrounding block, and only when they go out of
scope. Globals are not lexicals.
The only reason that Lisp might be better than perl for this application
is if you are generating parts of your functions based on user data.
Consider the situation where you have 5 different functions, each closed
with 100s of different users' data. Further, suppose that the data for
each item takes up 8 bytes, and the definition of the function takes up
100 bytes in both lisp and perl, and the name of the class takes up 10
bytes in perl. Let's further suppose that the name of the In lisp,
you would have 500 S-expressions, which might be 500*(100+8). Perl, on
the other hand, would do this as 5*100 + 500*(10+8). As you can see,
500 class instances take up less room than 500 S-expressions.
The only need for storing all those S-expressions would be if each one
was different... If they're not all different, then the intelligent
thing to do is send just the data and the function name, *not* the
entire function/S-expression.
--
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."
------------------------------
Date: Thu, 24 May 2001 11:57:08 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: setting priority from perl on linux
Message-Id: <slrn9gptok.mud.abigail@tsathoggua.rlyeh.net>
David Ball (dball@bnb-lp.com) wrote on MMDCCCXXII September MCMXCIII in
<URL:news:3r0mgt812pitutfsdoim8jj2jget9c4tt4@4ax.com>:
,, Hello,
,,
,, I have a perl cgi script that searches 5000 documents for a text
,, phrase. I'd like to set it to run with a low priority so it doesn't
,, interfere with other things on the server. Is there a way for a perl
,, CGI script running on linux to change it's priority ?
exec nice => 19 => $0 => @ARGV;
Of course, you have to make sure you don't do this when already niced.
Abigail
--
$=-=4*++$|;{print$"x--$==>"\@\x7Fy~*kde~box*Zoxf*Bkiaox \r"
^
$/x24if!select$,,$,,$,,join+q=.==>$^W=>$|;$=&&redo}sleep$|;
------------------------------
Date: Thu, 24 May 2001 11:58:52 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: setting priority from perl on linux
Message-Id: <slrn9gptrs.mud.abigail@tsathoggua.rlyeh.net>
David Ball (dball@bnb-lp.com) wrote on MMDCCCXXII September MCMXCIII in
<URL:news:h53mgtk7tpkcr8baq78mpl8r8qpuj3hcap@4ax.com>:
@@
@@ Do you know of any scripts that will build an index of html pages
@@ and then search it from a CGI ?
Yes.
Please use a web search to find such programs. Discussing of such programs
(which have nothing to do with Perl) don't belong in this group, just
like discussing your favourite brand of toilet paper doesn't.
Abigail
--
perl -wle '$, = " "; print grep {(1 x $_) !~ /^(11+)\1+$/} 2 .. shift'
------------------------------
Date: 24 May 2001 04:56:26 -0700
From: usenet@cox99.screaming.net (Graham Cox)
Subject: Re: Sorting data file on numerical field
Message-Id: <47822576.0105240356.2170a1b1@posting.google.com>
Tony Curtis <tony_curtis32@yahoo.com> wrote in message news:<87heycki6k.fsf@limey.hpcc.uh.edu>...
> Well, it's rather difficult without seeing any code (hint)
Sorry - My mistake. The code I've got so far is at the end of this
post. I've also tried the code Vinny posted, but i I couldn't get that
to work either :(
The datafile "test.txt" contains exactly what I posted last time.
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "<html>";
print "<body>";
open (FILE, "< test.txt") or die("File not Found");
{
local $/="\|";
@spare=<FILE>;
}
my @teamdetails;
my $count=0;
foreach (@spare)
{
chop($_);
$count++;
if ($count eq 1)
{
$line = $_;
}
else
{
$line .= '</td><td>';
$line .= $_;
}
if ($count eq 6)
{
$count=0;
push (@teamdetails,$line);
}
}
close (FILE);
# These are the attempts that I've made, none of which actually
worked :(
#@sorted =
# sort { $b->[5] <=> $a->[5] }
# map { [ $_, (split /<\/td><td>/)[5] ] } @teamdetails;
#@sorted = map { $_->[0] }
# sort { $b->[5]-0 <=> $a->[5]-0 or $a->[1] cmp $b->[1] }
# @sorted = sort {$@teamdetails[$a][5] <=>
$@teamdetails[$b][5]}@teamdetails;
# map { [ $_, (split /\|/)[5] ] } @teamdetails;
#$, = "\n";
print "<table border=1>"
foreach $sortres(@sorted)
{
print "<tr><td>";
print "$sortres";
print "</td></tr>";
}
print "</table></body>";
print "</html>";
--
Graham
An' Ye harm none,
do as Ye will.
------------------------------
Date: Thu, 24 May 2001 04:18:44 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Who's Going to the Perl Conference in San Diego this year?
Message-Id: <comdog-BEE591.04184424052001@news.panix.com>
In article <ywWO6.4580$r61.35931@typhoon.sonic.net>, "Dave"
<djm@spamfree.mcoe.k12.ca.us> wrote:
> http://conferences.oreilly.com/perl/
>
>
> I'm going and perhaps might wanna hook up with some of you guys, provided
> you arnt mental...
isn't that at the same time and place as the Damian Conference?
--
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: Thu, 24 May 2001 17:37:54 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Writing file in Perl
Message-Id: <oT2P6.10$513.393316@news.interact.net.au>
"terminalsplash" <shino_korah@yahoo.com> wrote in message
news:9egvq0$8rb@news.or.intel.com...
> Hi
>
> I want to read and write to a file..
> but open(FP,"+>$filename") doesn't seem to work
> and more over when I tried to do
> open(FP,">$filename")
> nothing inside
> close(FP);
> my full data inside the file is gone.
>
> What am I doing wrong?
Error checking.
open(FP,">$filename") or die "Can not open $filename $!\n";
------------------------------
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 975
**************************************