[19863] in Perl-Users-Digest
Perl-Users Digest, Issue: 2058 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 3 09:05:31 2001
Date: Sat, 3 Nov 2001 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004796308-v10-i2058@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 3 Nov 2001 Volume: 10 Number: 2058
Today's topics:
Adding Null Values into a Tied HashRef (E. Moore)
Re: beginner perlist <jurgenex@hotmail.com>
Re: beginner perlist (F. Xavier Noria)
Re: fwdport from Perl Cookbook recipe 17.18 - hangs on (stephen peterson)
Handling file in perl.....please help <fail006@hotmail.com>
Re: Help modifying a sort routine <markbright@optusnet.com.au>
how to print out every second value of an array <infullflight@12000rpm.com>
Re: how to print out every second value of an array <Laocoon@eudoramail.com>
Re: how to print out every second value of an array <echang@netstorm.net>
Re: how to print out every second value of an array (Garry Williams)
PerlQT and QListView <news@27b-6.de>
Re: reading flat-file db and replacing a word <stuart@otenet.gr>
Re: Serving HTML images (Maarten)
Split output into multiple pages? (Charles King)
Re: Tainting with Tad <was Taint problem with BEGIN blo (BUCK NAKED1)
Re: Tainting with Tad <was Taint problem with BEGIN blo benhopkins@mindspring.com
Untainting globally with regular expression? <spamfree@go-away.net>
W98 Perl parser that supports flock() ? <headless@dna.ie>
Re: win32-adminmisc.ppd <jimbo@soundimages.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Nov 2001 05:21:27 -0800
From: emoore@cofs.net (E. Moore)
Subject: Adding Null Values into a Tied HashRef
Message-Id: <f024c24d.0111030521.1708c81e@posting.google.com>
Can one add a null value into tied hasref?
I am using the Vars method from CGI.pm. According to the docs, when
Vars is use in scalar context, it returns a tied HashRef.
use strict;
use CGI qw/param header/;
my $q = new CGI;
my $in = $q->Vars;
When I try to add a null value to the hasref
$in->{lastname} = '';
and immediately check the result
if(!defined $in->{lastname}){
print "\$in->{lastname} =>not defined<br>"
}
$in->{lastname} 'is not defined.
I am not familiar with tied hashes. I've checked the Camel books, but
can't see if I am doing some wrong, or by definition a null value can
not go into a tied hash. Any suggestions? Thanks. Eric
------------------------------
Date: Fri, 2 Nov 2001 21:53:28 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: beginner perlist
Message-Id: <3be3865a$1@news.microsoft.com>
"flanney" <weinisfrog@aol.com> wrote in message
news:d5be1a52.0111021845.5ebd1586@posting.google.com...
> i just started perl and i was wondering do i have to compile my code
> to a cgi file or do i just name a file with cgi extension that has my
> code in clear text
Short answer: Yes.
Longer answer: this totally depends on how you set up your CGI server.
Long answer:
Perl is a scripting language. That means there is no need to explicitely
compile a Perl program in advance. This happens automatically at runtime.
However, there are also tools available (e.g perl2exe) which convert a Perl
script into a standalone program which then can be executed without having
to install Perl first.
So, it all depends on what you want to do.
jue
------------------------------
Date: 3 Nov 2001 08:24:52 GMT
From: fxn@retemail.es (F. Xavier Noria)
Subject: Re: beginner perlist
Message-Id: <9s09kk$2vqjs3@news1s.iddeo2.es>
On 2 Nov 2001 18:46:00 -0800, flanney <weinisfrog@aol.com> wrote:
: i just started perl and i was wondering do i have to compile my code
: to a cgi file or do i just name a file with cgi extension that has my
: code in clear text
You do not need to compile the code as in C, the very source file is
what is executed, to say it somehow. From there, what to do with that
file is not a question about Perl, but about how CGIs work in the web
server and operating system you are using, so off topic here. You may
find the answer in the documentation of the web server.
-- fxn
------------------------------
Date: 3 Nov 2001 03:52:31 -0800
From: cspeter8@yahoo.com (stephen peterson)
Subject: Re: fwdport from Perl Cookbook recipe 17.18 - hangs on read from first syn IP packet
Message-Id: <999a2faf.0111030352.69c69cca@posting.google.com>
By the way, if you don't have ready access to O'Reilly's Perl Cookbook
publication, Tom Christiansen did post the source to this recipe 2-1/2
years ago - and it can be seen here:
http://groups.google.com/groups?q=fwdport&hl=en&group=comp.lang.perl.misc&rnum=2&selm=36cd7c73%40csnews
(searched groups.google.com for string 'fwdport')
------------------------------
Date: Sat, 3 Nov 2001 18:22:53 +1300
From: "fail006" <fail006@hotmail.com>
Subject: Handling file in perl.....please help
Message-Id: <9rvuir$q4u$1@lust.ihug.co.nz>
Hi,
I am using my script write the output to a file. I have noticed when the
file is already open, and if i run my script, there is nothing written to
the file. Although this is fine, but i would like to use my script to detect
if the file is currently open or not. If it is open than a message so be
printed out telling the use to close the file and rerun the script.....
So my question is how do i know if the file is currently open by notepad or
any other application
I programming on Win32 platform (win98)
Thanks for your help.
------------------------------
Date: Sun, 4 Nov 2001 00:33:24 +1100
From: "Mark Bright" <markbright@optusnet.com.au>
Subject: Re: Help modifying a sort routine
Message-Id: <3be3f28b$0$375$afc38c87@news.optusnet.com.au>
Thanks guys, I really appreciate your time.
Give me a day or two to take all this in and do some more reading (I'm very
much a novice at this... but trying hard) so I can understand exactly what
you are saying and I will let you know how it all goes.
Thanks again guys, I mean it, I really do appreciate you guys helping me
with this.
------------------------------
Date: Sat, 3 Nov 2001 23:16:58 +1100
From: "gixxer600" <infullflight@12000rpm.com>
Subject: how to print out every second value of an array
Message-Id: <3be3e052@news.iprimus.com.au>
Hi all,
Could someone please help me out with this problem:
My datafile has the following lines:-
line1: 000000 XXXX CC FFFF
line2: 000000000000000 XXXX CC FFFF GGGGGGGGGGG HHHHHHHH
line3: 000000 XXXX CC FFFF
line4: 000000000000000 XXXX CC FFFF GGGGGGGG HHHHHHHH
...
The first field of every "odd numbered" lines is always made up of 6 digits.
The first field of every second line can be any length but is always longer
than 6 digits.
I wish to join line1 and line2, line3 and line4 and so on..
e.g.
000000 XXXX CC FFFF 000000000000000 XXXX CC FFFF GGGGGGGGGGG HHHHHHHH
000000 XXXX CC FFFF 000000000000000 XXXX CC FFFF GGGGGGGG HHHHHHHH
I tried to load the content of the whole file into an array and then tried
to use pattern matching to obtain the different lines but I'm not having any
success. Could someone offer some ideas on how this can be done??
Thanks
------------------------------
Date: Sat, 3 Nov 2001 13:39:06 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: how to print out every second value of an array
Message-Id: <Xns914E8AE43E266Laocooneudoramailcom@62.153.159.134>
example :
my $c = 0;
while($i <= $#data) {
$joined[$c++] = $data[$i++] . $data [$i++];
}
------------------------------
Date: Sat, 03 Nov 2001 13:09:24 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: how to print out every second value of an array
Message-Id: <Xns914E53F73D50Aechangnetstormnet@207.106.93.86>
"gixxer600" <infullflight@12000rpm.com> wrote in
news:3be3e052@news.iprimus.com.au:
> Hi all,
>
> Could someone please help me out with this problem:
>
> My datafile has the following lines:-
>
> line1: 000000 XXXX CC FFFF
> line2: 000000000000000 XXXX CC FFFF GGGGGGGGGGG HHHHHHHH
> line3: 000000 XXXX CC FFFF
> line4: 000000000000000 XXXX CC FFFF GGGGGGGG HHHHHHHH
> ...
>
> The first field of every "odd numbered" lines is always made up of
> 6 digits. The first field of every second line can be any length
> but is always longer than 6 digits.
>
> I wish to join line1 and line2, line3 and line4 and so on..
>
> e.g.
>
> 000000 XXXX CC FFFF 000000000000000 XXXX CC FFFF GGGGGGGGGGG
> HHHHHHHH 000000 XXXX CC FFFF 000000000000000 XXXX CC FFFF
> GGGGGGGG HHHHHHHH
> I tried to load the content of the whole file into an array and
> then tried to use pattern matching to obtain the different lines
> but I'm not having any success. Could someone offer some ideas on
> how this can be done??
Unless there's more to the problem than you're indicated, just keep
track of the lines two at a time. For example
#!perl -w
use strict;
while (my $odd = <DATA>) {
chomp $odd;
my $even = <DATA>;
print $odd.$even;
}
__DATA__
000000 XXXX CC FFFF
000000000000000 XXXX CC FFFF GGGGGGGGGGG
000000 XXXX CC FFFF
000000000000000 XXXX CC FFFF GGGGGGGG
Output
000000 XXXX CC FFFF000000000000000 XXXX CC FFFF GGGGGGGGGGG
000000 XXXX CC FFFF000000000000000 XXXX CC FFFF GGGGGGGG
--
EBC
------------------------------
Date: Sat, 03 Nov 2001 13:47:49 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: how to print out every second value of an array
Message-Id: <slrn9u7tbv.24t.garry@zfw.zvolve.net>
On Sat, 3 Nov 2001 23:16:58 +1100, gixxer600
<infullflight@12000rpm.com> wrote:
> My datafile has the following lines:-
>
> line1: 000000 XXXX CC FFFF
> line2: 000000000000000 XXXX CC FFFF GGGGGGGGGGG HHHHHHHH
> line3: 000000 XXXX CC FFFF
> line4: 000000000000000 XXXX CC FFFF GGGGGGGG HHHHHHHH
> ...
>
> The first field of every "odd numbered" lines is always made up of 6 digits.
> The first field of every second line can be any length but is always longer
> than 6 digits.
>
> I wish to join line1 and line2, line3 and line4 and so on..
>
> e.g.
>
> 000000 XXXX CC FFFF 000000000000000 XXXX CC FFFF GGGGGGGGGGG HHHHHHHH
> 000000 XXXX CC FFFF 000000000000000 XXXX CC FFFF GGGGGGGG HHHHHHHH
You seem to be saying that all of the data is in pairs of lines. If
that is so, then why not this?
$ perl -wpe 'chomp; $_ .= <>' filename
Why do you need to pattern match anything?
--
Garry Williams
------------------------------
Date: Sat, 03 Nov 2001 13:34:04 +0100
From: Magnus Schmidt <news@27b-6.de>
Subject: PerlQT and QListView
Message-Id: <9s0o7i$v1qiq$1@ID-71174.news.dfncis.de>
Hi there,
I've got a problem with qt (using Ashley Winters PerlQT). I want to use
the signal clicked(*QListViewItem) from QListView, which is sent when an
item is clicked on in a QListView. This works, however I cannot access the
QListViewItem, which is sent as parameter. I've tried to reduce the
sample-code as far as possible:
#!/usr/bin/perl -w
package Window;
use Qt 2.0;
import Qt::app;
use Qt::slots 'listviewClicked(QListViewItem)';
@ISA = 'Qt::Widget';
sub new {
# Main Window
my $self = shift->SUPER::new("Test");
$self->show();
$app->connect ($app,'lastWindowClosed()','quit()');
# Listview
my $listView = Qt::ListView->new ($self);
$listView->setGeometry (10,10,100,100);
$listView->show();
$listView->addColumn ("Test Column");
$listView->insertItem(Qt::ListViewItem->new($listView,'hello'));
$self->connect ($listView,'clicked(QListViewItem)',
'listviewClicked(QListViewItem)');
return $self;
}
sub listviewClicked (QListViewItem) {
my $self = shift;
my $item = shift;
print STDOUT "Listview clicked\n";
# $item->text(0) should return 'hello', but fails with:
# Can't locate object method "text" via package "QListViewItem"
print STDOUT $item->text(0)."\n";
}
package main;
use strict;
use Qt 2.0;
use Qt::app 'app';
my $window = Window->new();
exit $app->exec();
btw ... PerlQT is rather old, and I wasn't able to find much information
about PerlQT on the net ... does nobody use this module anymore ?!
Thanks,
Magnus Schmidt
------------------------------
Date: Sat, 3 Nov 2001 12:16:42 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: reading flat-file db and replacing a word
Message-Id: <9s0h12$rll$1@usenet.otenet.gr>
"Carsten Menke" <bootsy52@gmx.net> wrote in message
news:pan.2001.11.03.03.39.22.75.2700@gmx.net...
> So I wonder if there is a way of replacing or deleting a whole line in the
text file
> without making temporary copies and reading in the whole content into an
> array. But as I said, it's too late for today, and I will reread the FAQ.
This is just physics, if the length of the file doesn't change you can seek
and write over the top of the bytes. If the length of the file changes then
you must make a gap or close a gap.
That means moving all the data after this point.
You can close a gap by moving the data after back in blocks then pad out the
file.
T open a gap you need to read the bit you are going to clobber each time
before you clobber it.
You can avoid this by using fixed length fields like most databases do.
Or you can design your data structure with a delete flag so that to make a
line bigger you overwrite the start with XXXXX or whatever then stick the
new longer data at the end. Then do a garbage collection at the weekend.
You can make a copy in memory or in another file.
None of this is difficult to do it is just tedious. There are no magical
solutions the data must be moved one way or another. Any high(er) level
language which gives you an INSERT INTO or what ever still has to adopt one
of the strategies, to do it. it is just abstracted from the programmer.
Well there is one magical solution which I use you put each record in a
different file with the index field as the file name. That way the OS does
all the work for you. I admit this is not always a good solution but
sometimes it is.
--
Stuart Gall
------------------------------------------------
This message is not provable.
------------------------------
Date: Sat, 03 Nov 2001 13:07:30 GMT
From: desulfovibrio@hotmail.com (Maarten)
Subject: Re: Serving HTML images
Message-Id: <914E87AF012547@24.132.65.7>
stuart@otenet.gr (Stuart Gall) wrote on Fri, 02 Nov 2001 23:01:48
GMT:
>> Using perl I'm not sure whether this is the right group to ask,
>> but anyway: does anybody know how to get a browser to not load a
>> image from the cache but from the server instead while using the
>> html IMG tag?
>Ahh I tried by email, your email is invalid
Sorry, this one should be valid.
>you need
>
><META HTTP-EQUIV="pragma" CONTENT="no-cache">
>In the header
That's probably not going to do. The idea is to let 'normal'
viewers take full advantage of the cache, while yet allowing those
who provide new images by submitting an url from which a new image
will be loaded into a database, to view the result immediately --
which seems to implies updating/invalidating the cache.
But when an URL is already in the cache due to a previous 'normal'
view, the picture shown (with the same URL) seems to be drawn from
the cache without the header (with 'last-modified' and/or
'no-cache') of the new one ever being read. (Depenting on the
policy, of course.)
What appears to be needed is something like the javascript
document.reload() command controlled by a parameter sent with a
request which emanates from a previous page. But reload() doesn't
seem to apply to embedded images called by the <IMG> tag.
Of course, the easy way out is probably to provide an additional
dummy parameter that chances when a picture is updated so the
client's cache will recognize it as a new URL. But that would
potentially result in unnecessary cache rotation, and this is a bit
of a theoretical problem that I stumbled upon.
------------------------------
Date: 3 Nov 2001 03:18:42 -0800
From: ccking@consultant.com (Charles King)
Subject: Split output into multiple pages?
Message-Id: <f0da46f7.0111030318.70c0850e@posting.google.com>
Have a problem with a script which prints designated fields from
*all records* in a flat file database. The problem is how to
split what gets printed into multiple pages with links at the
bottom to the other pages. (btw, I'm not a CGI programmer [in case
that's not obvious from my question]).
$limit_of_records_per_page = 30;
if ($form {'display-all-records'})
{
&table_header;
$count=1;
open (DATABASE, "$database");
while (<DATABASE>)
{
$row = $_;
chop $row;
@stuff = split (/\|/, $row);
&table_row; # prints designated fields in the record
$count++;
}
close (DATABASE);
$count--;
&table_footer;
}
print "$footertemplate";
____________________________________________________________________
The following code works well to split the pages in a Search script.
I'm hoping it could be adapted, or maybe there's a much simpler way?
$limit_of_search_results = 30;
$starting_point = $form{'starting_point'};
!$starting_point and $starting_point = 1;
$current_page_number =
int($form{'starting_point'}/$limit_of_search_results) +1;
$end_point = ($current_page_number * $limit_of_search_results);
if (%search_results)
{
&table_header;
$result = $starting_point;
for $result($starting_point..$end_point)
{
!$search_results{$result_map{$result}} and next;
$last_displayed = $result;
@stuff = split (/\|/, $search_results{$result_map{$result}});
&table_row;
}
&table_footer;
}
else
{
print "<TABLE WIDTH=100% BGCOLOR=\"$bgcolorbkgd\"><TR><TD
ALIGN=CENTER><FONT FACE=\"ARIAL\" SIZE=2>No matches found. Please try
again.</FONT></TD></TR></TABLE>";
}
$results_counter--;
$results_counter > $limit_of_search_results and do{
$page_count = int($results_counter/$limit_of_search_results) +1;
($results_counter/$limit_of_search_results) ==
int($results_counter/$limit_of_search_results) and $page_count--;
$next_starting_point = ($last_displayed + 1);
$count =1;
$starting_point = 1;
until ($count > $page_count)
{
$count == $current_page_number and $next_results_link .=
qq~<b>$count</b> | ~;
$count != $current_page_number and $next_results_link .= qq~<a
href="display.cgi?$search_query&starting_point=$starting_point">$count</a>
| ~;
$starting_point += $limit_of_search_results;
$count++;
}
$next_starting_point > $results_counter and $next_starting_point = 1;
$next_results_link .= qq~<a
href="display.cgi?$search_query&starting_point=$next_starting_point">Next
Page</a>~;
print "<P><CENTER>$next_results_link</CENTER></P>";
};#end do
print "$footertemplate";
______________________________
Thanks for any advice,
Charles King
ccking@consultant.com
------------------------------
Date: Sat, 3 Nov 2001 01:56:37 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Tainting with Tad <was Taint problem with BEGIN block>
Message-Id: <2700-3BE3A335-254@storefull-242.iap.bryant.webtv.net>
I followed Tad's advise and fixed my BEGIN block. I think the below is
correct now.
BEGIN {
$ENV{PATH} = "/usr/bin:/bin:/usr/local/bin";
my $dir = "wkdir";
opendir(DIR, $dir) || die "can't opendir $dir: $!";
my @dirs = grep { /^(\d{4})$/
&& -d "$dir/$_" } readdir(DIR); closedir DIR;
foreach my $f (@dirs) {
$f =~ /^(\d{4})$/ or die "$f is tainted: $!<BR>\n";
$f = $1;
my $age = time() - 3600;
my $stats = stat("$dir/$f") or die "Can't stat: $!";
if ( $stats->mtime < $age ) {
system("rm", "-r", "$dir/$f");
};
};
1;
}
Thanks, Tad.
Regards,
--Dennis
------------------------------
Date: Sat, 3 Nov 2001 00:37:36 -0800
From: benhopkins@mindspring.com
Subject: Re: Tainting with Tad <was Taint problem with BEGIN block>
Message-Id: <gca0s9.hnc.ln@127.0.0.1>
BUCK NAKED1 <dennis100@webtv.net> wrote:
> I followed Tad's advise and fixed my BEGIN block. I think the below is
> correct now.
> BEGIN {
> $ENV{PATH} = "/usr/bin:/bin:/usr/local/bin";
> my $dir = "wkdir";
> opendir(DIR, $dir) || die "can't opendir $dir: $!";
> my @dirs = grep { /^(\d{4})$/
> && -d "$dir/$_" } readdir(DIR); closedir DIR;
> foreach my $f (@dirs) {
> $f =~ /^(\d{4})$/ or die "$f is tainted: $!<BR>\n";
> $f = $1;
> my $age = time() - 3600;
> my $stats = stat("$dir/$f") or die "Can't stat: $!";
> if ( $stats->mtime < $age ) {
> system("rm", "-r", "$dir/$f");
> };
> };
> 1;
> }
It may be just coincidental, but as I read this
post, I was listening to an old tune, Jimmie
Lunceford & His Orchestra, "Taint What Ya Do."
------------------------------
Date: Sat, 03 Nov 2001 10:03:07 GMT
From: "spamfree" <spamfree@go-away.net>
Subject: Untainting globally with regular expression?
Message-Id: <vhPE7.30196$4x3.3000700@news1.cableinet.net>
I want to throw in some code which untaints input from all params in one
foul swoop...
$all_variables = "$firstname, $familyname, $email"; #etc.
#untaint
unless ($all_variables =~ /^([^<]*$/) { #disallow < char
die "Couldn't untaint all variables: $all_variables\n";
}
$all_variables = $1;
Is this possible globally? or do I have to laboriously untaint each variable
individually?
Would i first have to substitute the (<) tag $firstname =~ s/</</g;
Thanks
--
millside
_____________
------------------------------
Date: Sat, 03 Nov 2001 11:41:50 +0000
From: Headless <headless@dna.ie>
Subject: W98 Perl parser that supports flock() ?
Message-Id: <e0c7utgp40sgh115fl4co3qqpdnrkaq7l1@4ax.com>
Is there a W98 Perl parser that allows flock() ?
I installed ActivePerl build 629 for Windows, but on W95/98 flock() is
not supported.
I'd like to add Perl to my Apache setup for local offline testing.
Headless
------------------------------
Date: Sat, 3 Nov 2001 09:28:19 -0000
From: "jimbo" <jimbo@soundimages.co.uk>
Subject: Re: win32-adminmisc.ppd
Message-Id: <TMOE7.25984$l57.235605@NewsReader>
> http://www.activestate.com/PPMpackages/5.6/Win32-AdminMisc.ppd
This is more likely to get results
http://www.roth.net/perl/packages/
jimbo
;-)
------------------------------
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 2058
***************************************