[23396] in Perl-Users-Digest
Perl-Users Digest, Issue: 5614 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 4 09:05:53 2003
Date: Sat, 4 Oct 2003 06:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 4 Oct 2003 Volume: 10 Number: 5614
Today's topics:
CGI: redirect some value to the previous URL (Wenjie)
Re: data varification code logic <king21122@yahoo.com>
Re: DBI <pkent77tea@yahoo.com.tea>
Re: hack a telnet server? <smackdab1@hotmail.com>
Re: hack a telnet server? (Greg Bacon)
Re: IsSorted @list ? 1 : 0 <king21122@yahoo.com>
Re: Newbie Q - Nicer way to lc something? <chris@FLARBLEinfinitemonkeys.org.uk>
OLE automation : unable to extract column data (Mahesh)
Re: out of memory during excecution <jurgenex@hotmail.com>
Re: REGEX (Not allowing file extenstions) or the dot <jurgenex@hotmail.com>
Re: REGEX (Not allowing file extenstions) or the dot (Tad McClellan)
Re: Trouble with throttling fork() <sfandino@yahoo.com>
two regexs <perl@my-header.org>
Re: WWW::Mechanize .. anyone? <cent@optushome.com.au>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Oct 2003 01:44:28 -0700
From: gokkog@yahoo.com (Wenjie)
Subject: CGI: redirect some value to the previous URL
Message-Id: <d2804eb3.0310040044.7bdc1de9@posting.google.com>
Hello,
I add an upload file feature to a BBS using perl. The
difficult thing is how I manage to integrate the upload
and message posting: the BBS is written using CGI.pm but
the posting code block is mainly HTML and javascripts
with perl variables, so my standalone upload.pl won't
work. Now I provided the URL of upload.pl for the user
to use the uploading function. But the user have to
copy and paste the uploaded file name and 'back' to
previous page. My question is: could I use some trick
to redirect the upload.pl result to the previous page
automatically?
Thanks and best regards,
Wenjie
------------------------------
Date: Sat, 04 Oct 2003 19:25:33 +1000
From: King <king21122@yahoo.com>
Subject: Re: data varification code logic
Message-Id: <3F7E920D.2050008@yahoo.com>
Tad McClellan wrote:
> King <king21122@yahoo.com> wrote:
>
>
>
>>Subject: Re: data varification code logic
>
>
>
> I do not see any data validation going on...
>
>
>
>>I have a data file and need to build another file with the data sorted
>>and douplicated data removed based on the first column value.
>
>
>
> This should get you most of the way there:
>
> ----------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> # Schwartzian Transform from FAQ: How do I sort an array by (anything)?
> my %seen;
> my @sorted = map { $_->[0] }
> sort { $a->[1] cmp $b->[1] }
> map { my $key = (split)[0]; # do the split() only once
> $seen{$key}++ ? () # empty list (skip duplicates)
> : [ $_, $key ]; # or reference to array
> } <DATA>;
>
> print @sorted; # sorted & uniqified lines
>
> print "----\n";
> print "$_ seen $seen{$_} times\n" for sort keys %seen;
>
> __DATA__
> one two
> one two
> One Two
> one three
> Two five
> two three
> Two three
> ----------------------------------------
>
>
>
>
>>while (<DATA>) {
>> my @L = split;
>> push @col_1, $L[0]; #could those 2 lines be combined in one?
>>}
>
>
>
> Yes, by using a "list slice", see perldata.pod:
>
> push @col_1, (split)[0];
>
> But you can combine the whole while loop too:
>
> my @col_1 = map { (split)[0] } <DATA>; # untested
>
>
thanks for your code, I understood it after many 'go over it' thinking.
my @col = map { (split)[0] } <DATA>; # untested
print @col;
this code will not work if it is in the same program with another
statement which is also using the <DATA> . if I comment the first
block(s) then it works. where do I find some reading about this if this
is the correct behaviour, if not then what is going on?
another point:
since I need to write DATA to another file FH, should I make an array
with those $seen{key} > 1 and then as I loop through the DATA check each
key to see weather to write this line out or to ask for <STDIN> to
choose which line to keep and ignore the rest of the duplicates? or
someother logic is better to do this?
notice I changed the __DATA__ below in-order to better reflect what I am
trying to explain, I am trying to get the code to show me the whole
lines of DATA with the same keys and allow me to select which line to
keep and disregard the rest. so according to the DATA it should say
1: one two1
2: one two2
please select the line to keep:
if <STDIN> = 2 then donot copy "one two1" to the new file and do next
my %seenmany
open FH, "> $filename" or die $!;
while (<DATA>) {
( (split)[0] ) == for each keys %seenmany ? print @{seenmany{$_}},
please select the line to keep, chomp (my $line = <STDIN>) : next
print FH $_; # this needs to be changed as well as the lines above, just
my brain dump but don't know how to put it in the correct code.
}
------------------------------
Date: Sat, 04 Oct 2003 12:11:05 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: DBI
Message-Id: <pkent77tea-1B4F8A.12110304102003@pth-usenet-02.plus.net>
In article <pan.2003.10.02.12.40.42.160229@aursand.no>,
Tore Aursand <tore@aursand.no> wrote:
> Problems occur when the data you insert into the SQL query contain single
> quotes (or other non-escaped special characters).
>
> The easiest way to deal with problems like this is to _always_ bind
> variables into your SQL query. I recommend this way of doing it even when
> you are 110% sure that the data you're about to insert into the SQL is
> "clean";
And so do I. For a start you dispense with any mucking about trying to
ensure your data really really is clean. Also you can make wins in
efficiency and speed (but probably depending on your database engine and
exact requirements) if you use placeholders. E.g. here's a trivial
example; imagine I want to select all the customer codes where the
customer's region is 'southwest', and I also want to select them where
the region is 'north'.
# $dbh is a database handle
my $sth = $dbh->prepare('select cust_id
from customers
where region = ?');
$sth->execute('southwest');
# do stuff with data
$sth->execute('north');
# do stuff with data, but I used the same statement handle
That statement handle can be cached and used again and again, which is a
good thing. There's also the prepare_cached method.
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Fri, 3 Oct 2003 23:40:03 -0700
From: "smackdab" <smackdab1@hotmail.com>
Subject: Re: hack a telnet server?
Message-Id: <2Utfb.5291$hp5.386@fed1read04>
> > Oh, I thought if you used a Telnet client, then the server side of
> > your application (IO::Socket, accept(), etc.) needed to understand
> > and negotiate binary "stuff" to sync up. Is this not necessary?
>
> To some extent, no.
>
> I've tested simple ASCII "servers" with a generic telnet client. The
> only real problem I've run into is that without the binary negotiation,
> most clients will default to "line mode" and only deliver a line of data
> to the server. A telnet man page might mention that.
>
> In your case, that might be just fine. However if you were looking for
> the user to type 'g' (and not return), you'd never see the data. Some
> telnet clients may be able to modify that behavior locally.
>
> Don't let that behavior make you lazy on the server side. Be sure to
> read data with the possibility of reading only partial lines at a time
> in mind.
>
Cool, it did work. Wish I would have tried it earlier!!!
What I am doing is echoing the data back and now I see the data.
(I imagine that some telent clients will not work...I guess I'll deal with
it when I come to it...)
thanks!
------------------------------
Date: Sat, 04 Oct 2003 13:00:28 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: hack a telnet server?
Message-Id: <vnth3cs1af209@corp.supernews.com>
In article <2Utfb.5291$hp5.386@fed1read04>,
smackdab <smackdab1@hotmail.com> wrote:
: [...]
:
: Cool, it did work. Wish I would have tried it earlier!!!
: What I am doing is echoing the data back and now I see the data.
:
: (I imagine that some telent clients will not work...I guess I'll deal with
: it when I come to it...)
Read the Telnet RFCs, especially RFC 1116[*] that deals with the
LINEMODE option.
[*] http://www.faqs.org/rfcs/rfc1116.html
Greg
--
If possible, so far as it depends on you, be at peace with all men.
-- Romans 12:18 (NASB)
------------------------------
Date: Sat, 04 Oct 2003 19:32:00 +1000
From: King <king21122@yahoo.com>
Subject: Re: IsSorted @list ? 1 : 0
Message-Id: <3F7E9390.5070307@yahoo.com>
Tore Aursand wrote:
> On Fri, 03 Oct 2003 01:22:21 +1000, King wrote:
>
>>I need to find out if a data file is sorted by it's first column
>
>
> Well. Define "sorted", please. There are several ways of sorting
> something, depending on what type of data we're dealing with.
>
>
numeric data
------------------------------
Date: Sat, 04 Oct 2003 10:45:33 +0100
From: Chris Smith <chris@FLARBLEinfinitemonkeys.org.uk>
Subject: Re: Newbie Q - Nicer way to lc something?
Message-Id: <blm52e$omb$1$8302bc10@news.demon.co.uk>
Matija Papec wrote:
> $a = "\L$a"; #also fine
Thank you - just what I was after!
--
Chris Smith
http://www.infinitemonkeys.org.uk/
------------------------------
Date: 3 Oct 2003 21:11:11 -0700
From: tambolim123@yahoo.com (Mahesh)
Subject: OLE automation : unable to extract column data
Message-Id: <a2573a2.0310032011.5ea45f28@posting.google.com>
Hi,
I was interested in been able to write a perl script to extract,for
example,all values from column 2 of an excel file, where column number
is specified as an argument.
Is there a way to extract all the values without explicitly putting
the range into the code.
Below is my code.One can see i need to specify the cells (B1:B24)
explicitly into the code.The problem is i know which column i need to
extract but the number of records in it changes from file to file.So i
wanted to automate the task and not code the value of cells in my
script.
## Start of code
use Win32::OLE;
$xlfile ="C:\\perl\\learning\\test.xls";
# Create OLE object - Excel Application Pointer
$xl_app = Win32::OLE->new('Excel.Application') or die $!;
# Set Application Visibility
# 0 = Not Visible
# 1 = Visible
$xl_app->{'Visible'} = 0;
# Open Excel File
$workbook = $xl_app->Workbooks->Open($xlfile);
# setup active worksheet
$worksheet = $workbook->Worksheets(1);
# retrieve value from worksheet
my $array = $worksheet->Range("B1:B24")->{'Value'};# get the contents
foreach my $ref_array (@$array) { # loop through the array
# referenced by $array
foreach my $scalar (@$ref_array) {
print "$scalar\t";
}
print "\n";
}
# Close It Up
$xl_app->ActiveWorkbook->Close(0);
$xl_app->Quit();
## End
Thanks,
Mahesh
------------------------------
Date: Sat, 04 Oct 2003 04:27:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: out of memory during excecution
Message-Id: <s_rfb.9669$3b7.4248@nwrddc02.gnilink.net>
fred wrote:
> my perl program is going out of memory during its exceution ( sbrk()
> is ... )
In a normal program this is very unlikely unless you are working with really
large data sets.
It is more likely that you got an endless loop or recursion.
If I were you I would check for that first.
If that doesn't help, then post your code (better a minimum subset that
still exposes the problem) and I'm sure someone will point out how to
optimize it.
jue
------------------------------
Date: Sat, 04 Oct 2003 04:35:14 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: REGEX (Not allowing file extenstions) or the dot
Message-Id: <66sfb.9695$3b7.4375@nwrddc02.gnilink.net>
sts@news.sts wrote:
> REGULAR EXPRESSION
>
> PROGRAM: Quake2
> CODE: C+
>
[long convoluted explanation of some syntax snipped]
You may not realize it as such but to me this sounds like you want to write
a parser and context checker for a language that you created.
And you are not even sure how the language works.
My advice would be to
- first define a formal language, just as you would define any programming
language
- then write a parser for it, starting with lexical and syntax analysis
- then your test for the file extensions or not file extensions will become
just one simple context condition among many others. And it will be easy to
test because you know that at that point in the tree you need to test for
exactly that condition and nothing else and you don't need to test for that
condition anywhere else, either.
As this is not really related to Perl you may get more detailed advice in a
NG that actually deals with artificial languages and parsing, e.g a compiler
construction NG.
jue
------------------------------
Date: Fri, 3 Oct 2003 23:21:45 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: REGEX (Not allowing file extenstions) or the dot
Message-Id: <slrnbnsimp.2tc.tadmc@magna.augustmail.com>
sts <sts@news.sts> wrote:
> Yes as a matter of fact it does.
_what_ does?
> I am in the proecess of compiling PERL into
> Quake
Then to discard any part of a filename after a dot character:
$filename =~ s/\..*//s;
[snip TOFU]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 04 Oct 2003 12:44:23 +0100
From: Salvador Fandino <sfandino@yahoo.com>
Subject: Re: Trouble with throttling fork()
Message-Id: <blmbqt$8ta$01$1@news.t-online.com>
I wrote:
>>
>> Take a look at Proc::Queue
>> http://search.cpan.org/~salva/Proc-Queue-1.13/Queue.pm
>
> Proc::Queue doesn't work on Windows, sorry :-(
Well, it does now ;-)
I have uploaded a new beta version 1.14_01 with windows support to CPAN.
I will appreciate feedback about how it works for "real" windows apps.
Bye,
- Salva
------------------------------
Date: Sat, 04 Oct 2003 11:26:21 +0200
From: Matija Papec <perl@my-header.org>
Subject: two regexs
Message-Id: <nh4tnvk2dch5sogntfd3gi5qgm5tnmmhf2@4ax.com>
my @str = (
'="foo bar" ..',
'=foobar ..',
);
for (@str) {
if (/="(.+?)"/) { print $1 }
elsif (/=(\S+)/) { print $1 }
print "\n";
}
I would like to match each value from @str with only one regex. I come to,
if ( /="(.+?)"|=(\S+)/ ) { print $1 || $2 }
but I'm not sure if this is the best matching solution?
--
Matija
------------------------------
Date: Sat, 4 Oct 2003 14:18:44 +1000
From: "Ryan" <cent@optushome.com.au>
Subject: Re: WWW::Mechanize .. anyone?
Message-Id: <3f7e4a23$0$30274$afc38c87@news.optusnet.com.au>
well the weird thing is, it is fetching images! and I have no idea how to
stop it or turn it off, it's not saving the images anywhere but it is
getting the contents of the images...
"Iain Truskett" <ict@eh.org> wrote in message
news:slrnbno9bg.tqk.ict@dellah.org...
> * Ryan <cent@optushome.com.au>:
> > anyone here used this module before? I really need to stop
> > it from downloading images .... it's eating up all my bw
> > and I cant find a way to stop it from doing so ....... not
> > that i know if it is or not, but it's downloading
> > something
>
> It fetches exactly what you tell it to. If you don't want
> it to download images, then don't tell it to download
> images.
>
> If you tell it to fetch a page, it fetches the page. It
> does not fetch images on the page unless you then tell it
> to.
>
>
> cheers,
> --
> Iain. <http://eh.org/~koschei/>
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5614
***************************************