[16873] in Perl-Users-Digest
Perl-Users Digest, Issue: 4285 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 11 14:05:44 2000
Date: Mon, 11 Sep 2000 11:05:26 -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: <968695526-v9-i4285@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 11 Sep 2000 Volume: 9 Number: 4285
Today's topics:
(HELP) Socket.pm script -- what am i doing wrong ??? cyberlurker@my-deja.com
ActivePerl 613 dropping # from directory name <johnroth@ameritech.net>
Adding filename to top of file <vibrato@my-deja.com>
Re: Adding filename to top of file (Tom Christiansen)
Re: Adding filename to top of file <aqumsieh@hyperchip.com>
C&C: Apche: How can I prevent denial of service? nobull@mail.com
Call another CGI-Script with POST Method <lu@bbi.ch>
Re: Call another CGI-Script with POST Method nobull@mail.com
Re: Compression Assistance <bart.lateur@skynet.be>
File::Basename and file upload problem with Macs <gnielson@charlotte.infi.net>
Re: Getting started w/Perl~fao Lincoln <lincolnmarr@nospam.europem01.nt.com>
Re: Help with number formatting needed... <sariq@texas.net>
Holy moly! Substitution on 10-kb scalar takes over *one (Sean McAfee)
Re: Holy moly! Substitution on 10-kb scalar takes over (Craig Berry)
How do I generate methods on the fly? djberg96@my-deja.com
Re: How do I generate methods on the fly? <jeffp@crusoe.net>
Re: How do I generate methods on the fly? (Tom Christiansen)
Re: How long does flock take? cfedde@sl3d.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Sep 2000 17:25:43 GMT
From: cyberlurker@my-deja.com
Subject: (HELP) Socket.pm script -- what am i doing wrong ???
Message-Id: <8pj4hr$qit$1@nnrp1.deja.com>
hello, this script was supposed to automate my process of
checking a list of HTTP proxy servers, from a bash;
for some reason it blocks while waiting for data from the server...
could anyone point me ***why***, please ?!?!?!
( BTW,i have rewritten this to use IO:Socket, but i can't figure
out how to catch the local_addr in an IO::Socket script... )
my big problem is: i cant stand to not understand *why* this one
doesn't work ( dumb programmer for sure...;o/ )............
Source:
#!/usr/bin/perl -w
#http://www.deny.de/cgi-bin/prxjdg.cgi
#
use Socket;
$infile = $ARGV[0];
$url = $ARGV[1];
if (!$infile) { $infile = "parsedproxy.txt"; }
if (!$url ) { $url="www.deny.de:80/cgi-bin/prxjdg.cgi"; }
open (IN,$infile);# this file has one entry ( ip:port ) per line
&parse_url; #retorna ($server,$port,$path)
print "\t###$server###$port###$path###\n\n";
#---------------------------------------
$HTTP_request = "GET http://$url HTTP/1.0\n".
"User-Agent: Mozilla/4.73\n".
"Host: $server:$port\n".
"Accept: */*\n".
"\n";
print "--- HTTP_request ---\n$HTTP_request--------------------\n";
#---------------------------------------
while ( $proxy = <IN> )
{
&parse_proxy;#returns ($proxyserver,$proxyport)
print "\t###$proxyserver###$proxyport###\n\n";
$iaddr = inet_aton($proxyserver)||die"no host $proxyserver!!!";
$proxyaddr = sockaddr_in($proxyport,$iaddr);
$tcp = getprotobyname("tcp");
socket(SOCK,PF_INET,SOCK_STREAM,$tcp);
connect(SOCK,$proxyaddr);
#---------------------------------------UGLY!!!
$line = getsockname(SOCK);
($localport,$localaddr)=unpack_sockaddr_in($line);
($a0,$a1,$a2,$a3)=unpack("C4",$localaddr);
$localaddr = "$a0.$a1.$a2.$a3";
print "********** LOCAL_ADDR: $localaddr\n";
#---------------------------------------
print"checkpoint 1\n";
print SOCK "$HTTP_request";
$HTTP_response="";
print "checkpoint 2\n";
while ($line=<SOCK>) ###### the damn thing blocks here until
"connection time out" #######
{
print"\t#$line";
$HTTP_response .= $line;
}
close(SOCK);
#print $HTTP_response;
}#while proxy
close(IN);
exit;
sub parse_proxy
{
($proxyserver,$proxyport) = split(/:/,$proxy);
chop($proxyport);
}#parse_proxy
sub parse_url
{
my $a;
my @b;
$port = 80;
($a,@b)=split(/\//,$url);
$path = join("/",@b);
$path = "/".$path;
if ($a =~ /:/)
{
($server,$port) = split(/:/,$a);
}
else
{
$server = $a;
}
}#parse_url
many Thanks!!!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Sep 2000 08:45:26 -0500
From: "John Roth" <johnroth@ameritech.net>
Subject: ActivePerl 613 dropping # from directory name
Message-Id: <Pn5v5.22$pB3.6049@nntp0.chicago.il.ameritech.net>
I've been doing a little file work on Win 98 with Active Perl,
and I found, to my chagrin, that it silently deletes the # character
from the file name. I'm using the 613 build.
The relevant chunk of code is as follows:
opendir( DIRHAND, ".") or die "cannot open directory";
@dirlist = readdir DIRHAND;
closedir DIRHAND;
@shortlist = grep /^TimeOut/, @dirlist;
@sortedfiles = sort @shortlist;
foreach $infile (@sortedfiles) {
print "$infile\n";
}
*** end chunk of code!
The print shows the file names without the #! Note - the
# precedes a digit in all cases. This may be relevant.
John H. Roth Jr.
------------------------------
Date: Mon, 11 Sep 2000 15:37:24 GMT
From: Lance Hoffmeyer <vibrato@my-deja.com>
Subject: Adding filename to top of file
Message-Id: <8piu7h$ibb$1@nnrp1.deja.com>
I have a number of ASCII files that I am going to import into a program.
To keep them seperate after I have them in this program I want to
insert the file's filename in the first row. My initial thought was
something along:
# Get all file names in directory
@AllFiles = glob("*.txt");
#for each file name process
foreach $file (@AllFiles){
# Open new file and original file
open(FILE,"$file") || die "cannot open file \n";
@all = <$file>;
foreach $line (@all){
print FILE "$file \n";
print $_; }
close(FILE);
Please ignore any simple errors in this code. I have not checked it yet
because I was thinking there might be a one-liner that I could run from
command prompt instead of creating a file.
Lance
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 11 Sep 2000 10:29:57 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Adding filename to top of file
Message-Id: <39bd0885@cs.colorado.edu>
In article <8piu7h$ibb$1@nnrp1.deja.com>,
Lance Hoffmeyer <vibrato@my-deja.com> wrote:
>I have a number of ASCII files that I am going to import into a program.
Files don't have import methods. Modules do. Are we talking
about modules?
>To keep them seperate after I have them in this program I want to
>insert the file's filename in the first row. My initial thought was
>something along:
>
>
># Get all file names in directory
>@AllFiles = glob("*.txt");
That's not all file names in directory. That's all the files
whose names end in the four charcters ".txt" but which do not
start with a dot.
And typically you do this on the command line. It's much
more flexible that way.
>#for each file name process
>foreach $file (@AllFiles){
># Open new file and original file
>open(FILE,"$file") || die "cannot open file \n";
"Why" "do" "you" "quote" "things" "that" "you" "do" "not" "need"
"to" "quote"?
>@all = <$file>;
That's not the way to process each line in a file. It doesn't
scale. It's nasty. The "do something with each line paradigm"
while get a line,
do something with it
Typically written
while (<FH>) { .... }
or sometimes
while (my $line = <FH>) { .... }
or even
while (local $_ = <FH>) { .... }
>foreach $line (@all){
>print FILE "$file \n";
Why have you added a space to the filename?
That will come back to haunt you. And do you really
want the filename each and every time?
>print $_; }
If you're going to use a named argument, perhaps it should
have a name?
>
>close(FILE);
>Please ignore any simple errors in this code. I have not checked it yet
>because I was thinking there might be a one-liner that I could run from
>command prompt instead of creating a file.
This is a trivial shell application. Using Perl for it is silly.
$ ( for file in *.whatever; do
echo $file
cat $file
done ) > wherever
If you're committed to using Perl, you should learn, I suppose,
you could do this:
$ perl -lpe '$. == 1 && print $ARGV; eof && close ARGV' *.whatever > wherever
Historically, you could use more for this:
$ more *.whatever > wherever
Which would put "::::filename::::\n" in front of each of multiple files.
I suppose you could figure something these days with less.
--tom
------------------------------
Date: Mon, 11 Sep 2000 16:40:23 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Adding filename to top of file
Message-Id: <7a8zsy287b.fsf@merlin.hyperchip.com>
Lance Hoffmeyer <vibrato@my-deja.com> writes:
> I have a number of ASCII files that I am going to import into a program.
> To keep them seperate after I have them in this program I want to
> insert the file's filename in the first row. My initial thought was
> something along:
Wrong. Your initial thought should always be to consult the docs and
FAQs. Checkout perlfaq5:
How do I change one line in a file/
delete a line in a file/
insert a line in the middle of a file/
append to the beginning of a file?
--Ala
------------------------------
Date: 11 Sep 2000 18:10:32 +0100
From: nobull@mail.com
Subject: C&C: Apche: How can I prevent denial of service?
Message-Id: <u9em2qc0s7.fsf@wcl-l.bham.ac.uk>
nl1753@my-deja.com writes:
> Hi here!
> How can i limit the number of connections or sockets that one IP-Adress
> is allowed to open on Port 80?
> I wrote a little Perl script that opens 1000 Sockets without closing
> them, and it made Apache not working any more. That´s why I´am asking.
So let's get this straight you are asking how to protect Apache from a
DOS attack. You are choosing to ask this is a Perl newsgroup because
you used a test program written in Perl to confirm that Apache was
vulnerable.
We've seen some pretty daft attempted justifications for off-topic
posting but this has to be one of the funniest to date.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 11 Sep 2000 18:47:15 +0200
From: Yves Lustenberger <lu@bbi.ch>
Subject: Call another CGI-Script with POST Method
Message-Id: <39BD0C93.40060925@bbi.ch>
I need some help frome you.
I don't find any solution to call from a Perl-CGI Script another
CGI-Script with the POST Method.
Could anyone please tell me how this works.
By the way, both Scripts are on the same Server.
Is there maybe another solution than use the Webinterface ?
If you cold show me an example-Code, this would be enough.
Thank you for your help.
Sunny Greetings.
Yves
------------------------------
Date: 11 Sep 2000 18:04:42 +0100
From: nobull@mail.com
Subject: Re: Call another CGI-Script with POST Method
Message-Id: <u9g0n6c11x.fsf@wcl-l.bham.ac.uk>
Yves Lustenberger <lu@bbi.ch> writes:
> I don't find any solution to call from a Perl-CGI Script another
> CGI-Script with the POST Method.
LWP
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 11 Sep 2000 17:13:31 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Compression Assistance
Message-Id: <584qrsovoqpssqdqbbvg8qjn12uc51u21n@4ax.com>
spurcell wrote:
>The program is
>an Asset Management System that allows the end-users to download
>hi-resolution TIFF files. The end-users for the most part are on
>Macintosh-based systems. I have been given a spec, to somehow have the files
>compressed in a way that Stuffit Deluxe will open. (EG. a .sea files would
>be the best. That would be a self-extracting archive.).
.SEA files are not "flat", i.e. they exist of both a data forak and a
resource fork. Not only will the server pose problems, but if the user's
browser is on PC (as in my case), downloading these files are
problematic.
Well... o be entirely honest, the resource fork is not really relevant.
It mainly contains the program of the self-extracting archive. The data
itself is in the data fork, i.e. as if it was a flat file. Newer
versions of Stuffit Expander can indeed still process the data-fork-only
file, but older versions have some troubles with it. Same with .SIT
files, which is the non-selfextracting version.
>So my thoughts are
>when someone requests a file, I would go locate the hi-res on the server,
>then compress it, and show them a link to download the file.
I don't get it. If people aren't *creating* hi-res files on the server,
why don't you simply save these files compressed? A lot faster than
on-the-fly compression, and it saves space.
>So my questions is, does anyone know if there is a module for creating a
>.sea files that would be compliant on the Mac, or if anyone has any
>suggestions that may work for this situation.
Some TIFF file formats have built-in compression. Trying to compress
these even more doesn't work.
--
Bart.
------------------------------
Date: Mon, 11 Sep 2000 13:18:02 -0400
From: Gary Nielson <gnielson@charlotte.infi.net>
Subject: File::Basename and file upload problem with Macs
Message-Id: <39BD13CA.D0830410@charlotte.infi.net>
I wish we had a Macintosh here! I am using a module I found on the Net
so that I can take a form variable ( <input type="file" name="file_type"
value=$file_type> ) and upload a file to a directory through a Web
browser. I am using File::Basename to parse the name of the file being
uploaded. Works great... except when the user's computer is a Macintosh.
I have a problem getting access to a Macintosh, though I know that file
paths and names on Macs are pretty different. I am looking for advice
from someone who has set up file upload scripts who might know how to
make the upload compatible with Macs. Not having a Mac to play around
with makes this problem harder to solve. I have listed the script I
wrote below and included the CGI_LIB module as well. Any advice
appreciated.
Gary
#############################################
The script here:
use FileHandle;
use File::Basename;
use CGI::Carp qw(fatalsToBrowser);
use CGI_LIB;
my($cgi) = new CGI_LIB;
my @B = " ";
my $os_string = "MacOS";
# my $os_string = "MSDOS"; # was sset to MSDOS for PCs. Man page says
can use MacOS but my tests show this is not # working
my @suffixlist = " ";
$fullname = "$cgi->{'file_type'}->{'filename'}";
$page = "$cgi->{'page'}";
## EDIT CONFIG
$fulldir = "/infinet/www/gametimenews/centerpiece/"; # don't forget
ending forward slash
$webdir = "/updates/centerpiece/";
$art = "art/";
$html = "pub/";
## END EDIT CONFIG
$|++;
$old_handle = select( STDERR );
$|++;
select( $old_handle );
($name,$path,$suffix) = fileparse($fullname,@suffixlist);
fileparse_set_fstype($os_string);
$basename = basename($fullname,@suffixlist);
$dirname = dirname($fullname);
my($filename) = $cgi->{'file_type'}->{'filename'} =~
/[\/\\]([^\/\\]+)$/;
if ($cgi->{'headline'} ne "")
{
open (PAGE, ">$fulldir$html$page\.htm") || die "Failed to create file
$page: $!";
print PAGE "<font face=\"arial,helvetica\" size=\"+1\"><B>\n";
print PAGE "$cgi->{'headline'}</font></B><BR>\n";
# if there's a file to upload, include a nice, little table with img src
info
if ($cgi->{'file_type'}->{'filename'} ne "") {
print PAGE "<table border=\"0\" hspace=2 vspace=0
width=\"$cgi->{'art_width'}\" align=\"$cgi->{'placement'}\">\n";
print PAGE "<tr><td valign=\"top\">\n";
print PAGE "<img src=\"$webdir$art$basename\"
alt=\"$filename\" border=\"1\"><BR>\n";
print PAGE "<font face=\"verdana, arial, geneva\" size=\"1\"
color=\"#666666\">$cgi->{'cutline'}\n</font><BR>\n";
print PAGE "</td></tr></table>\n";
print PAGE "$cgi->{'summary'}<BR>\n";
print PAGE "<img src=\"/grafix/reddot.gif\" width=\"8\" height=\"8\"
border=\"0\" hspace=\"5\">";
print PAGE "<a href=\"$cgi->{'url'}\">Full story</a><BR><BR
clear=all>\n";
open (FILE, ">$fulldir$art$filename") || die "Failed to create file
$filename: $!";
print FILE "$cgi->{'file_type'}->{'contents'}";
close (FILE);
# if there's no file to upload, don't write file stuff to the page.html
} else {
print PAGE "$cgi->{'summary'}<BR>\n";
print PAGE "<img src=\"/grafix/reddot.gif\" width=\"8\" height=\"8\"
border=\"0\" hspace=\"5\">";
print PAGE "<a href=\"$cgi->{'url'}\" target=\"new\">Full
story</a><BR><BR clear=all>\n";
}
close (PAGE);
&success;
} else {
print "Content-type: text/html\n\n";
print "<html><head><title>Mmmm....!</title></head><body>\n";
print "<h2>$page not updated.</h2>\n";
print "</body></html>\n";
$logEntry = "$page not updated\n";
&logging ($logEntry);
}
sub displayfile
{
open (A, "$fulldir$html$page\.htm");
@B = <A>;
print @B;
print "<BR>";
}
#############################################
CGI_LIB.pm script here:
#
# CGI_LIB package.
#
package CGI_LIB;
#===============================================================================
#
# Constructor:
# $obj = new CGI_LIB;
#
# Methods:
# $obj->getFormMethod();
# $obj->getSubmittedData();
# $obj->processData();
# $obj->processURLEncodedData();
# $obj->processMultiPartData();
#
# *p/s: For more details, please refer to the description below.
#
#===============================================================================
use strict;
use vars qw($FormMethod $VERSION);
$VERSION = '1.01';
#===============================================================================
#
# CONSTRUCTOR: $obj = new CGI_LIB;
#
# DESCRIPTION: This is the constructor of the CGI_LIB object.
# The constructor will process the data according to the form
# method used, and set the data into the object.
#
#===============================================================================
sub new {
my($pkg) = shift;
my($self) = {};
bless $self, $pkg;
$FormMethod = $self->getFormMethod();
$self->processData();
return $self;
}
#===============================================================================
#
# METHOD: $obj->getFormMethod();
#
# DESCRIPTION: This method will return the form method that has been
used.
#
#===============================================================================
sub getFormMethod {
my($self) = shift;
return $ENV{'REQUEST_METHOD'};
}
#===============================================================================
#
# METHOD: $obj->getSubmittedData();
#
# DESCRIPTION: This method will return the submitted form data.
#
#===============================================================================
sub getSubmittedData {
my($self) = shift;
if ($FormMethod eq "POST") {
my($buffer);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
return $buffer;
}
elsif ($FormMethod eq "GET") {
return $ENV{'QUERY_STRING'};
}
else {
return $ENV{'QUERY_STRING'};
}
}
#===============================================================================
#
# METHOD: $obj->processData();
#
# DESCRIPTION: According to different type of submitted data, this
method will
# call different subroutine to process the data and set them into
# the object.
#
#===============================================================================
sub processData {
my($self) = shift;
if ($ENV{'CONTENT_TYPE'} =~ /^multipart\/form-data;/) {
$self->processMultiPartData();
}
elsif ($ENV{'CONTENT_TYPE'} =~
/^application\/x-www-form-urlencoded$/) {
$self->processURLEncodedData();
}
else {
$self->processURLEncodedData();
}
if ($FormMethod ne "GET" && $ENV{'QUERY_STRING'} ne "") {
$FormMethod = "GET";
$self->processURLEncodedData();
}
}
#===============================================================================
#
# METHOD: $obj->processURLEncodedData();
#
# DESCRIPTION: The submitted data is in
application/x-www-form-urlencoded
# format.
#
#===============================================================================
sub processURLEncodedData {
my($self) = shift;
my($submittedData) = $self->getSubmittedData();
my(@fields) = split('&', $submittedData);
for (@fields) {
tr/+/ /;
my($fieldName, $fieldValue) = split('=', $_, 2);
# The %xx hex numbers are converted to alphanumeric.
$fieldName =~ s/%(..)/pack("C", hex($1))/eg;
$fieldValue =~ s/%(..)/pack("C", hex($1))/eg;
if (exists $self->{$fieldName}) {
if (ref($self->{$fieldName}) eq "ARRAY") {
push(@{$self->{$fieldName}}, $fieldValue);
}
else {
my($tempValue) = $self->{$fieldName};
delete $self->{$fieldName};
push(@{$self->{$fieldName}}, $tempValue);
push(@{$self->{$fieldName}}, $fieldValue);
}
}
else {
$self->{$fieldName} = $fieldValue;
}
}
}
#===============================================================================
#
# METHOD: $obj->processMultiPartData();
#
# DESCRIPTION: The submitted data is in multipart/form-data format.
# We only using this format when we want to do HTTP file upload.
#
#===============================================================================
sub processMultiPartData {
my($self) = shift;
my($submittedData) = $self->getSubmittedData();
my($boundary) = $ENV{'CONTENT_TYPE'} =~ /^.*boundary=(.*)$/;
my(@partsArray) = split(/--$boundary/, $submittedData);
@partsArray = splice(@partsArray, 1, (scalar(@partsArray) - 2));
my($aPart);
foreach $aPart (@partsArray) {
$aPart =~ s/(\r|)\n$//g;
my($dump, $firstline, $fieldValue) = split(/[\r]\n/, $aPart, 3);
next if $firstline =~ /filename=\"\"/;
$firstline =~ s/^Content-Disposition: form-data; //;
my(@columns) = split(/;\s+/, $firstline);
my($fieldName) = $columns[0] =~ /^name=\"([^\"]+)\"$/;
my(%dataHash);
if (scalar(@columns) > 1) {
my($contentType, $blankline);
($contentType, $blankline, $fieldValue) = split(/[\r]\n/,
$fieldValue, 3);
($dataHash{'content-type'}) = $contentType =~ /^Content-Type:
([^\s]+)$/;
}
else {
my($blankline);
($blankline, $fieldValue) = split(/[\r]\n/, $fieldValue, 2);
if (exists $self->{$fieldName}) {
if (ref($self->{$fieldName}) eq "ARRAY") {
push(@{$self->{$fieldName}}, $fieldValue);
}
else {
my($tempValue) = $self->{$fieldName};
delete $self->{$fieldName};
push(@{$self->{$fieldName}}, $tempValue);
push(@{$self->{$fieldName}}, $fieldValue);
}
}
else {
next if $fieldValue =~ /^\s*$/;
$self->{$fieldName} = $fieldValue;
}
next;
}
my($currentColumn);
for $currentColumn (@columns) {
my($currentHeader, $currentValue) = $currentColumn =~
/^([^=]+)="([^"]+)"$/;
$dataHash{"$currentHeader"} = $currentValue;
}
$dataHash{'contents'} = $fieldValue;
$dataHash{'size'} = length($fieldValue);
$self->{$fieldName} = \%dataHash;
}
}
1;
__END__
=head1 NAME
CGI_LIB -- This is a perl module which will help you to manipulate the
CGI input.
=head1 SYNOPSIS
use CGI_LIB;
$obj = new CGI_LIB();
=head1 DESCRIPTION
For more details about this module, please visit to
http://www.tneoh.zoneit.com/perl/CGI_LIB/
=head1 AUTHOR
Simon Tneoh Chee-Boon tneohcb@pc.jaring.my
Copyright (c) 1998 Simon Tneoh Chee-Boon. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 VERSION
Version 1.01 21 August 1999
------------------------------
Date: Mon, 11 Sep 2000 17:20:45 +0200
From: "Lincoln Marr" <lincolnmarr@nospam.europem01.nt.com>
Subject: Re: Getting started w/Perl~fao Lincoln
Message-Id: <8pit86$ppu$1@qnsgh006.europe.nortel.com>
> > I started learning Perl about 2 and a half months ago (I'm working full
time
> > on it though) and in 2 days time my first complete Perl project will be
up
> > and running - a web-interfaced flat file database system. Previous to
perl I
> > knew only html and javascript, and I didn't have too much trouble
picking up
> > the basic concepts behind how it works. But i would highly recommend
> > (perhaps even insist) that you get yourself a copy of O'Reilly's
'Learning
> > Perl' and 'Programming Perl' - these books really got me on my way.
>
> Did it take you long to find a job that would let you use Perl as a
beginner?
> I'm from the same HTML JavaScript background as you and I'm currently
learning
> Perl, but finding a job to let me Perl (as a beginner) with my
HTML/JavaScript
> in the UK is proving hard!!
>
I got a lucky break as I had a contact within the company who got me a
placement. I'm only a student so I work for the summers, but I worked for
the company 2 years ago, and learnt html & javascript, and they were
impressed with what I did so let me loose on Perl.
Having done this though, I can understand why generally employers don't let
people learn perl on the job. If you get a basic design flaw in your
program, which isn't difficult to do as a beginner, your months of work may
prove to be useless (as indeed happened to another student colleague!) -
which wastes a lot of the company's money.
But if you can't find somewhere in the UK, then move to Europe!! There's a
serious shortage of IT people over here and although a qualification is
always desirable, if you are comfortable with Perl and are confident you
could do web/cgi perl, then that would be a big advantage.
------------------------------
Date: Mon, 11 Sep 2000 10:41:33 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Help with number formatting needed...
Message-Id: <39BCFD2D.C11E0C6F@texas.net>
Jeff Johnson wrote:
>
> I have managed to re-write the basic formmail.pl, found on many sites and at
> Matt's Script Archive, to include a "confirmation page" that shows users the
> data they have input on a form, totals their order, and asks them to
> finalize the order by selecting a "Purchase" button. Since I know a bit
> about database but nothing about PERL
I don't know anything about PERL, either. I know a smattering of Perl,
though.
perldoc -q difference
> it took me a while to write. I am left
> with two final problems to solve.
>
> 1.) How do I format numbers to always appear with two figures after the
> decimal point?
> Example: 15.90 appears as 15.9
Clinton Pierce answered your Perl question, but didn't point out that:
When dealing with currency you should *always* deal in integer values of
the small unit (e.g., cents), then translate to fractions of the large
unit (e.g., dollars) only when you print.
- Tom
------------------------------
Date: Mon, 11 Sep 2000 15:57:21 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Holy moly! Substitution on 10-kb scalar takes over *one second*!
Message-Id: <Bh7v5.2869$O5.58769@news.itd.umich.edu>
Observe this program:
----------------------------------------------------------------------
$a = do { local (@ARGV, $/) = 'OUT'; <> };
$a =~ s/(.*?)\t(\t*)/ /g;
$a .= "\t";
$a =~ s/(.*?)\t(\t*)/ /g;
----------------------------------------------------------------------
"OUT" is a file, approximately 10 kilobytes in size, which contains an
e-mail message with no tab characters. I've simplified the replacement
part of the substitution operation; originally, it did tab expansion, but
the behavior I'm about to complain about persists even in this simple case.
By using Time::HiRes to time the pair of substitutions, I've found that the
first one takes about 0.00028 seconds to complete, while the second one
takes a staggering 1.40 seconds. This is using Perl 5.6.0 on a 300 MHz
Ultrasparc. When I switch to Perl 5.005_03 on the same machine, the time
for the second substitution drops to 0.007 seconds.
One word: DAMN!
What the heck happened between 5.005 and 5.6 to cause this dramatic
performance degradation?
Anyone?
--
Sean McAfee mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!
------------------------------
Date: Mon, 11 Sep 2000 17:47:06 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Holy moly! Substitution on 10-kb scalar takes over *one second*!
Message-Id: <srq6kq28ct669@corp.supernews.com>
Sean McAfee (mcafee@waits.facilities.med.umich.edu) wrote:
: Observe this program:
:
: ----------------------------------------------------------------------
: $a = do { local (@ARGV, $/) = 'OUT'; <> };
: $a =~ s/(.*?)\t(\t*)/ /g;
This could be more efficiently written as
$a =~ s/.*?\t+/ /g;
It will result in the string being transformed such that everything up to
and including the last tab will be replaced with a number of spaced equal
to the number of sequential-tab groups encountered.
: $a .= "\t";
: $a =~ s/(.*?)\t(\t*)/ /g;
The rewrite above applies, but here we're guaranteed to have $a with no
tabs in it other than the final one appended above, so $a
deterministically becomes a single space.
I doubt this is what you really want to do, but...
: By using Time::HiRes to time the pair of substitutions, I've found that the
: first one takes about 0.00028 seconds to complete, while the second one
: takes a staggering 1.40 seconds.
Very odd. The substitution shouldn't involve a lot of backtracking or
anything like that.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Every force evolves a form."
| - Shriekback
------------------------------
Date: Mon, 11 Sep 2000 14:57:58 GMT
From: djberg96@my-deja.com
Subject: How do I generate methods on the fly?
Message-Id: <8pirt8$fai$1@nnrp1.deja.com>
Hi all,
I've got the following code to generate a right-click menu in Tk. I
want to be able to automatically generate a get & set method for each
item in a list.
foreach $item (@$menuItems){
$menu->command(-label=>$item);
$self->{"_RCentry$item"} = $defaults{"_RC$item"};
sub $self->get_$item{ $_[0]->{"_RCentry$entryLabel"} } # ???
}
My problem is: what is the syntax for such an operation? What would
the third line be in the foreach loop?
Thanks in advance for any help.
Regards,
DJB
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Sep 2000 12:05:11 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: How do I generate methods on the fly?
Message-Id: <Pine.GSO.4.21.0009111203070.12441-100000@crusoe.crusoe.net>
[posted & mailed]
On Sep 11, djberg96@my-deja.com said:
>foreach $item (@$menuItems){
> $menu->command(-label=>$item);
> $self->{"_RCentry$item"} = $defaults{"_RC$item"};
> sub $self->get_$item{ $_[0]->{"_RCentry$entryLabel"} } # ???
>}
>My problem is: what is the syntax for such an operation? What would
>the third line be in the foreach loop?
You'd want to turn off strict 'refs' momentarily:
no strict 'refs';
*{ref($self) . "::get_$item"} = sub {
$_[0]->{"_RCentry$entryLabel"}
};
For more information on symbol table munging, read 'perlref'.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: 11 Sep 2000 10:38:45 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: How do I generate methods on the fly?
Message-Id: <39bd0a95$1@cs.colorado.edu>
In article <8pirt8$fai$1@nnrp1.deja.com>, <djberg96@my-deja.com> wrote:
>foreach $item (@$menuItems){
> $menu->command(-label=>$item);
> $self->{"_RCentry$item"} = $defaults{"_RC$item"};
> sub $self->get_$item{ $_[0]->{"_RCentry$entryLabel"} } # ???
>}
>
>My problem is: what is the syntax for such an operation? What would
>the third line be in the foreach loop?
You don't need "syntax". Well, unless you want to be taught the
syntax of the assignment operator. Here it is:
TARGET = SOURCE
But I think you don't want syntax.
From the new edition of the Camel comes this example that should
prove illustrative:
for my $field (qw(name race aliases)) {
my $slot = __PACKAGE__ . "::$field";
no strict "refs"; # So symbolic ref to typeglob works.
*$field = sub {
my $self = shift;
$self->{$slot} = shift if @_;
return $self->{$slot};
};
}
--tom
------------------------------
Date: Mon, 11 Sep 2000 17:26:35 GMT
From: cfedde@sl3d.com
Subject: Re: How long does flock take?
Message-Id: <fB8v5.83$W3.171109888@news.frii.net>
In article <8phlko$sqn$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Chris Fedde
><cfedde@u.i.sl3d.com>],
>
>> I think that your guess is off by around 3 orders of magnitude.
>> At least on common pentium boxen.
>
>I do not see what the processor has to do with this - unless you use
>something like Linux, which (wrongly) use CPU cycle count for time
>measurements. But it looks like on Solaris Ultra5 the results are
divert(-1)
My comment about pentium boxen has more to do with motherboard
architecture used on these critters. It was my intent to point
out that most of these systems have similar hardware to count
passage of realtime. Typically that hardware has a resolution
around 100 pico seconds. I suppose that this could lead to a
discussion of Nyquist and sampling theory but that is getting way
way off topic for this group.
divert(0)
OB Perl:
print '8phlko$sqn$1@charm.magnus.acs.ohio-state.edu'^
pack'h*',join('',c681902000c14051e1c14005c2f08451a180
,e0a1e090a001108441f035e500b1d160344170d445c224c15045)
thanks
chris
--
This space intentionally left blank
chris fedde 773 9134
------------------------------
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 4285
**************************************