[16586] in Perl-Users-Digest
Perl-Users Digest, Issue: 3998 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 12 14:10:29 2000
Date: Sat, 12 Aug 2000 11:10:15 -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: <966103815-v9-i3998@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 12 Aug 2000 Volume: 9 Number: 3998
Today's topics:
Re: Posting to an secure server (Keith Calvert Ivey)
Problems creating a new module based off HTML::Parser <shawn@secludedgrove.com>
Re: Problems creating a new module based off HTML::Pars (Keith Calvert Ivey)
Re: problems with ^= (Abigail)
Re: ps on NT <carvdawg@patriot.net>
Re: reg expressions - protect html (Abigail)
Re: s/// and symbolic references (Keith Calvert Ivey)
Re: setting cookie twice in same script (Keith Calvert Ivey)
Re: Sharing a cookie between two domains..? (u2orange)
Re: Sharing a cookie between two domains..? (u2orange)
Re: Sharing a cookie between two domains..? (u2orange)
Re: Sort data from text file <mauldin@netstorm.net>
Re: Sort data from text file <ivoz@starmail.com>
Re: Sort data from text file <mauldin@netstorm.net>
Re: User-defined hash... (Colin Keith)
Re: warning/var weirdness (or is it?) <bkennedy99@home.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 12 Aug 2000 15:08:54 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Posting to an secure server
Message-Id: <399966c2.6728857@news.newsguy.com>
"Christopher M. Jones" <christopher_j@uswest.net> wrote:
>Silly, you can't use LWP for SSL.
Silly, the LWP documentation disagrees with you. Of course, you
may have to install something else first, but after that all you
have to do is change "http" to "https" in your URLs.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Sat, 12 Aug 2000 15:34:45 GMT
From: "Shawn W. Devlin" <shawn@secludedgrove.com>
Subject: Problems creating a new module based off HTML::Parser
Message-Id: <39956E76.29E02229@secludedgrove.com>
Hello all,
I am having problems creating a module based off HTML::Parser. I can get
HTML::Parser to work correctly in a Perl script, but when I move my code
into a .pm file and access it from a Perl script, I get an error
message. The problem occurs with the call to the parse() method in the
getSecurity method for my package.
If I use the line
$this->SUPER::parse($content);
Then I get an error informing me that the comment method is not defined.
If I use the line
$this->parse($content);
Then I get an error informing me that there is no parse method.
I am new to Perl and just cannot see what I am doing wrong. Any ideas?
My (trimmed) module code
#!/usr/bin/perl
use strict;
package MarketWatch;
require Exporter;
require HTML::Parser;
@MarketWatch::ISA = qw(HTML::Parser Exporter);
@MarketWatch::EXPORT = qw(getSecurity);
use URI::URL;
use LWP::Simple;
# Snip variables for accessing CBS Marketwatch
sub text {
my ($self, $text) = @_;
# trimmed the code
}
sub start {
my ($self, $tag, $attr, $attrseq, $origtext) = @_;
# trimmed the code
}
sub comment {
my ($self, $comment) = @_;
# trimmed the code
}
sub end {
my ($self, $tag, $origtext) = @_;
# trimmed the code
}
sub getSecurity {
my $this = shift;
$TickerSymbol = shift;
my $url =
url('http://www2.marketwatch.com/quotes/quotes.asp?source=htx/http2_mw&symb='
. $TickerSymbol);
my $content = get($url);
# $this->SUPER::parse($content);
$this->parse($content);
# trimmed code
}
sub new {
my $class = shift;
my $self = HTML::Parser->new();
bless $self, $class;
return $self;
}
1; # Package terminator
The Perl script that uses this module is
#!/usr/bin/perl
# Add the current folder to the include path
# This can be removed once the MarketWatch module is debugged and
placed in the proper Perl folder
push (@INC, 'pwd');
use MarketWatch;
my $mw = MarketWatch::new();
# Grab the security values for Inprise. Must pass valid MarketWatch
symbol
my %securityValues = $mw->getSecurity("\$COMPQ");
--
Shawn W. Devlin
Unicorn Software
Custom Software Development
C++, Delphi, Perl, HTML, XML, Director
v:(613) 623-6159
f:(613) 622-7933
------------------------------
Date: Sat, 12 Aug 2000 16:10:16 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Problems creating a new module based off HTML::Parser
Message-Id: <399c7628.10671026@news.newsguy.com>
"Shawn W. Devlin" <shawn@secludedgrove.com> wrote:
>#!/usr/bin/perl
If you'd made that
#!/usr/bin/perl -w
you'd have gotten a clue about what was going on.
[snip]
>my $mw = MarketWatch::new();
That should be
my $mw = MarketWatch->new();
The way you're calling it, new() doesn't get the class name --
it doesn't get any arguments at all.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: 12 Aug 2000 14:14:49 GMT
From: abigail@foad.org (Abigail)
Subject: Re: problems with ^=
Message-Id: <slrn8pamtq.cro.abigail@alexandra.foad.org>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDXXXVI
September MCMXCIII in <URL:news:8mugua$68e$1@lublin.zrz.tu-berlin.de>:
~~ <toddbe@my-deja.com> wrote in comp.lang.perl.misc:
~~ >I'm running this bit of code on an HPUX 10.20 system and a linux system
~~ >and get very different resaults. On the HP $h1 get the correct value on
~~ >the linux box $h1 becomes 0.
~~ >
~~ >Is ^= not working under linux?
~~ >
~~ >$h0 += 9804392444;
~~ >$h1 += 15433492645;
~~ >$h2 += 2607314627;
~~ >$h3 += 859226588;
~~ >$h4 += 4989140090;
~~
~~ Why are you assinging values via +=? Not that it matters, but
~~ you make everyone look twice (or not at all).
~~
~~ >$h1 ^= $h0; #$h1 goes to 0 on linux
~~ >$h2 ^= $h0;
~~ >$h3 ^= $h0;
~~ >$h4 ^= $h0;
~~
~~ Your $h1 is > 2**32. Probably HPUX is running on a 64 bit machine and
~~ Linux isn't.
It works on Linux and non-64 bit CPUs as well:
#!/opt/perl/bin/perl -w
use strict;
my $h0 += 9804392444;
my $h1 += 15433492645;
my $h2 += 2607314627;
my $h3 += 859226588;
my $h4 += 4989140090;
$h1 ^= $h0;
$h2 ^= $h0;
$h3 ^= $h0;
$h4 ^= $h0;
print "The OS is $^O.\n";
open my $info => "/proc/cpuinfo" or die $!;
while (<$info>) {
if (/model name/) {
print "The CPU is a", (split /[:\n]/) [1], ".\n";
last;
}
}
close $info or die $!;
print "\$h1 = $h1", "\n";
print "\$h2 = $h2", "\n";
print "\$h3 = $h3", "\n";
print "\$h4 = $h4", "\n";
__END__
The OS is linux.
The CPU is a Pentium II (Deschutes).
$h1 = 8045416281
$h2 = 12130668863
$h3 = 10659161632
$h4 = 14512495494
Of course, you need to a Perl that uses 64 bit integers.
Abigail
--
$_ = "\112\165\163\1648\141\156\157\164\150\145\1628\120\145"
. "\162\1548\110\141\143\153\145\162\0128\177" and &japh;
sub japh {print "@_" and return if pop; split /\d/ and &japh}
------------------------------
Date: Sat, 12 Aug 2000 13:59:04 -0400
From: H C <carvdawg@patriot.net>
Subject: Re: ps on NT
Message-Id: <39959068.A11945C5@patriot.net>
This is a multi-part message in MIME format.
--------------429B3BB68A6C24E9E65A71AD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I've attached a script called "wmi.pl". I wrote it to demonstrate the use of
Microsoft's
WMI classes and Perl on NT.
To run the script on NT, you need to install the WMI classes from
Microsoft...it's not a
huge download.
The script also demonstrates how to retrieve other info, as well. I have a
separate script
to pull the EventLogs from remote systems using WMI....
Carv
Baris wrote:
> Hello,
> Inside my perl program I want to be able to get the current process list on
> winNT . On unix I am doing:
> @list = `ps -e`;
> (which probably is not the best way to do it. I am open to suggestions).
> On windows I want to access the same list, but probably with a native perl
> function since it looks like there is no system command similar to ps. I
> looked at Win32::xxx modules at Activestate, but I am not sure if any of
> them is doing this.
> Any ideas?
> Thanks,
> Baris.
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----== Over 80,000 Newsgroups - 16 Different Servers! =-----
--------------429B3BB68A6C24E9E65A71AD
Content-Type: application/x-perl;
name="wmi.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="wmi.pl"
#! c:\perl\bin\perl.exe
# Script to demonstrate using WMI
# Requires that WMI core classes be installed
# from http://www.microsoft.com/management/wmi
# Retrieves info from the local system
use strict;
use Win32::OLE qw(in with);
my $wmi = Win32::OLE->GetObject("winmgmts:");
print "Computer System\n";
print "-" x 20,"\n";
my $sys_set = $wmi->InstancesOf("Win32_ComputerSystem");
foreach my $sys (in($sys_set)) {
print "Caption: ".$sys->{'Caption'}."\n";
print "PriOwner: ".$sys->{'PrimaryOwnerName'}."\n";
print "SysType: ".$sys->{'SystemType'}."\n";
print "Domain: ".$sys->{'Domain'}."\n";
}
print "\n";
print "Operating System\n";
print "-" x 30,"\n";
my $os_set = $wmi->InstancesOf("Win32_OperatingSystem");
foreach my $os (in($os_set)) {
print "Caption: ".$os->{'Caption'}."\n";
print "Manuf: ".$os->{'Manufacturer'}."\n";
print "BootDevice: ".$os->{'BootDevice'}."\n";
print "System Dir: ".$os->{'SystemDirectory'}."\n";
print "Organization: ".$os->{'Organization'}."\n";
print "BuildNum: ".$os->{'BuildNumber'}."\n";
print "Build: ".$os->{'BuildType'}."\n";
print "Version: ".$os->{'Version'}."\n";
print "CSDVersion: ".$os->{'CSDVersion'}."\n";
print "Locale: ".$os->{'Locale'}."\n";
print "WinDir: ".$os->{'WindowsDirectory'}."\n";
print "TotMem: ".$os->{'TotalVisibleMemorySize'}." bytes\n";
print "SerNum: ".$os->{'SerialNumber'}."\n";
}
print "\n";
print "PageFile Settings\n";
print "-" x 30,"\n";
my $pf_set = $wmi->InstancesOf("Win32_PageFile");
foreach my $pf (in($pf_set)) {
print "Name: ".$pf->{'Name'}."\n";
print "Initial: ".$pf->{'InitialSize'}." MB\n";
print "Max: ".$pf->{'MaximumSize'}." MB\n";
}
print "\n";
print "Services\n";
print "-" x 20,"\n";
my $serv_set = $wmi->InstancesOf("Win32_Service");
foreach my $serv (in($serv_set)) {
print "Service => ".$serv->{'DisplayName'}." [".$serv->{'Name'}."]\n";
print "\tState: ".$serv->{'State'}."\n";
print "\tStatus: ".$serv->{'Status'}."\n";
print "\tExecuteable: ".$serv->{'PathName'}."\n";
print "\tStart Name: ".$serv->{'StateName'}."\n";
print "\tPID: ".$serv->{'ProcessID'}."\n";
print "\n";
}
print "\n";
print "Processes\n";
print "-" x 20,"\n";
my $proc_set = $wmi->InstancesOf("Win32_Process");
printf "%-10s %-40s\n","PID","Name";
printf "%-10s %-40s\n","-" x 5,"-" x 20;
foreach my $proc (in($proc_set)) {
printf "%-10s %-40s\n",$proc->{'ProcessID'},$proc->{'Name'};
}
print "\n";
print "Print Jobs\n";
print "-" x 20,"\n";
my $print_set = $wmi->InstancesOf("Win32_PrintJob");
if ($print_set->{'Count'} eq 0) {
print "No print jobs.\n";
}
else {
foreach my $print (in($print_set)) {
print "Name: ".$print->{'Name'}."\n";
print "\tJobID: ".$print->{'JobID'}."\n";
print "\tStatus: ".$print->{'Status'}."\n";
print "\tTotal Pages: ".$print->{'TotalPages'}."\n";
print "\n";
}
}
print "\n";
print "Network Connections\n";
print "-" x 20,"\n";
my $conn_set = $wmi->InstancesOf("Win32_NetworkConnection");
foreach my $conn (in($conn_set)) {
printf "%-40s %-10s\n",$conn->{'Name'},$conn->{'Caption'};
}
print "\n";
print "Logical Disks\n";
print "-" x 20,"\n";
my $disk_set = $wmi->InstancesOf("Win32_LogicalDisk");
foreach my $disk (in($disk_set)) {
printf "%-7s %-25s %-8s %-5s\n",$disk->{'DeviceID'},$disk->{'Description'},$disk->{'FileSystem'},$disk->{'DriveType'};
}
print "\n";
print "Network Adapters\n";
print "-" x 20,"\n";
my $adapt_set = $wmi->InstancesOf("Win32_NetworkAdapter");
foreach my $adapt (in($adapt_set)) {
print $adapt->{'Name'}."\n";
print "\tType: ".$adapt->{'AdapterType'}."\n";
print "\tDesc: ".$adapt->{'Description'}."\n";
print "\tDeviceID: ".$adapt->{'DeviceID'}."\n";
print "\tStatus: ".$adapt->{'Status'}."\n";
print "\tManuf: ".$adapt->{'Manufacturer'}."\n";
print "\tMAC: ".$adapt->{'MACAddress'}."\n";
print "\tInstall Date: ".$adapt->{'InstallDate'}."\n";
print "\n";
}
print "\n";
print "Desktop\n";
print "-" x 20,"\n";
my $dt_set = $wmi->InstancesOf("Win32_Desktop");
foreach my $dt (in($dt_set)) {
print $dt->{'Name'}."\n";
print "\tScreenSave active: ".$dt->{'ScreenSaverActive'}."\n";
print "\tScreenSaver .exe: ".$dt->{'ScreenSaverExecutable'}."\n";
print "\tScreenSaver secure: ".$dt->{'ScreenSaverSecure'}."\n";
print "\tScreenSaver timeout: ".$dt->{'ScreenSaverTimeout'}." sec\n";
print "\n";
}
print "\n";
print "User Accounts\n";
print "-" x 20,"\n";
my $user_set = $wmi->InstancesOf("Win32_UserAccount");
foreach my $user (in($user_set)) {
print $user->{'Name'}."\n";
print "\tDomain: ".$user->{'Domain'}."\n";
print "\tSID: ".$user->{'SID'}."\n";
print "\tCaption: ".$user->{'Caption'}."\n";
print "\tDescription: ".$user->{'Description'}."\n";
print "\tDisabled: ".$user->{'Disabled'}."\n";
print "\tStatus: ".$user->{'Status'}."\n";
print "\tLockout: ".$user->{'Lockout'}."\n";
print "\t***Password Settings***\n";
print "\t\tChangeable: ".$user->{'PasswordChangeable'}."\n";
print "\t\tRequired: ".$user->{'PasswordRequired'}."\n";
print "\t\tExpires: ".$user->{'PasswordExpires'}."\n";
print "\n";
}
--------------429B3BB68A6C24E9E65A71AD--
------------------------------
Date: 12 Aug 2000 14:20:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: reg expressions - protect html
Message-Id: <slrn8pan7m.cro.abigail@alexandra.foad.org>
Drew Simonis (care227@attglobal.net) wrote on MMDXXXIV September MCMXCIII
in <URL:news:39906A47.F2EAF9E5@attglobal.net>:
,, Larry Rosler wrote:
,, >
,, > Thanks for responding with specifics. I was beginning to wonder if I
,, > was in a vacuum, the only one in all of Usenet bothering to read and
,, > respond to this blather.
,, >
,,
,, Hopefully its because s/he does no more than clutter kill files at
,, this point...
She has been in my killfile shortly after she arrived. But she keeps
popping up due to people who can't get enough of her and who keep
responding.
It's so tempting to killfile anyone replying to her.
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
------------------------------
Date: Sat, 12 Aug 2000 14:43:03 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: s/// and symbolic references
Message-Id: <399861ed.5490912@news.newsguy.com>
nobull@mail.com wrote, quoting perldiag:
> However, the developers of Perl 5.004 could not fix
> this bug completely, because at least two widely-used
> modules depend on the old meaning of "$$0" in a
> string. So Perl 5.004 still interprets "$$<digit>" in
> the old (broken) way inside strings; but it generates
> this message as a warning. And in Perl 5.005, this
> special treatment will cease.
The special treatment didn't cease. I'm using 5.005_03
(ActiveState build 522), and I get results like the original
poster's.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Sat, 12 Aug 2000 15:31:51 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: setting cookie twice in same script
Message-Id: <399a6d40.8390628@news.newsguy.com>
Chovy <johndoyle33@hotmail.com> wrote:
>Prior to the loop iteration I print "Content-Type: text/html".
>
>However, I cannot set a cookie in the same script because the CGI.pm
>cookie method uses the header() method which again prints
>"Content-Type"...
>
>So when I actually do try to set the cookie at the end of the script, it
>just prints to the browser "Set-cookie: ....etc..."
>instead of actually setting the cookie.
>
>Is there a way around this?
Yes: don't do that. You can't print the header lines until
you've figured out what they're going to be. Wait to print the
header until you've determined the value of the cookie you want
to set. That's the way HTTP works. It's the same regardless of
what language you're using.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Sat, 12 Aug 2000 17:55:00 GMT
From: u2o@u2orange.co.uk (u2orange)
Subject: Re: Sharing a cookie between two domains..?
Message-Id: <39958f2e.7417830@news.freeserve.net>
Ok, thanks..! Stopped me in my tracks.
Mat
On 11 Aug 2000 09:05:16 -0500, Kent Perrier <kperrier@blkbox.com>
wrote:
>mat@designsolution.co.uk (Mat) writes:
>
>> Hi,
>>
>> I am having a few problems trying to share a cookie between
>> two domains
>
>have read the cookie spec? It is not possible to share cookies between
>two different cookie domains. Cookies were designed so that machines in
>cookie domain .domainA.com cannot access cookies set by machines in
>cookie domain .domainB.com
>
>Kent
>--
>We are in fact well and truly doomed.
> -- Jamie Zawinski
> http://www.jwz.org/gruntle/nscpdorm.html
------------------------------
Date: Sat, 12 Aug 2000 17:56:45 GMT
From: u2o@u2orange.co.uk (u2orange)
Subject: Re: Sharing a cookie between two domains..?
Message-Id: <39958f82.7501326@news.freeserve.net>
Blimey mate, you ate a large one didnt you..?
Is it or is it not Perl related..?
Relax, you will live longer.
Mat.
On Fri, 11 Aug 2000 11:36:49 GMT, jason <elephant@squirrelgroup.com>
wrote:
>Mat wrote ..
>> I am having a few problems trying to share a cookie between
>>two domains using Matt Wrights cookie.lib. As far as I can
>>understand, this is possible by using the function
>>&SetCookieDomain('.host.xxx').
>>
>> Any ideas where I am going wrong..?
>
>if there's one thing that this newsgroup certainly is NOT it's a support
>forum for Matt Wright's attempts at programming .. ask Matt Wright if
>you have a problem with something that he supplied
>
>--
> jason -- elephant@squirrelgroup.com --
------------------------------
Date: Sat, 12 Aug 2000 17:57:34 GMT
From: u2o@u2orange.co.uk (u2orange)
Subject: Re: Sharing a cookie between two domains..?
Message-Id: <39958fe8.7603958@news.freeserve.net>
Thanks for putting me on track, info was most appreciated..!
Mat
On Fri, 11 Aug 2000 13:32:33 GMT, kcivey@cpcug.org (Keith Calvert
Ivey) wrote:
>mat@designsolution.co.uk (Mat) wrote:
>
>> I am having a few problems trying to share a cookie between
>>two domains using Matt Wrights cookie.lib. As far as I can
>>understand, this is possible by using the function
>>&SetCookieDomain('.host.xxx').
>
>Matt Wright doesn't determine how cookies work (fortunately).
>The cookie specification (along with the way it's implemented by
>browsers) does.
>
>If you can read cookies from other domains, it indicates that
>the browser being used has a serious security flaw. Think about
>it -- do you really want any site to be able to read cookies
>from any other site?
>
>The function in question presumably is designed to allow you to
>share cookies between hosts in a single domain, not between
>domains.
>
>--
>Keith C. Ivey <kcivey@cpcug.org>
>Washington, DC
------------------------------
Date: Sat, 12 Aug 2000 14:20:17 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: Sort data from text file
Message-Id: <39955C86.8B89EA33@netstorm.net>
stu265@my-deja.com wrote:
>
> I am new to Perl and am trying to find a solution to a problem.
> I have a text file that contains dates with a description and I need to
> sort the lines in date order. The follwing is an example of a line of
> date, 8/11/2000 - Description. I know I need to split off the date and
> create a sort function but I'm not sure the best way to do it. Any
> ideas?
>
See:
perldoc -f sort
perldoc perlre
perldoc perlop # look for "Regexp Quote-Like Operators"
and look into Date::Manip
or you can roll your own:
If you start with a file data.txt like this:
8/11/2000 - description 1
7/13/1999 - description 2
12/12/1944 - description 3
1/1/2000 - description 4
4/5/1998 - description 5
#!/usr/bin/perl -w
use strict;
my $file = 'data.txt';
open (DATA, $file) or die "Can't open file: $!\n";
my @data;
while (<DATA>) {
s/(\d+)\/(\d+)\/(\d+)/sprintf "$3".'%02d'x2,$2,$1/e;
push @data,$_;
}
close T;
print for (sort @data);
will give this output
19441212 - description 3
19980504 - description 5
19991307 - description 2
20000101 - description 4
20001108 - description 1
-- Jim
------------------------------
Date: Sat, 12 Aug 2000 17:25:35 +0300
From: "Ivo Zdravkov" <ivoz@starmail.com>
Subject: Re: Sort data from text file
Message-Id: <39955ef0_2@news.nwlink.com>
<stu265@my-deja.com> wrote in message news:8n2ldt$q75$1@nnrp1.deja.com...
> I am new to Perl and am trying to find a solution to a problem.
> I have a text file that contains dates with a description and I need to
> sort the lines in date order. The follwing is an example of a line of
> date, 8/11/2000 - Description. I know I need to split off the date and
> create a sort function but I'm not sure the best way to do it. Any
> ideas?
declare function named date_from_line($line),
that returns date from line in this format: YYYYMMDD
then this code must sort the file:
@lines=<file_name>;
@sorted=sort {
date_from_line($a) <=> date_from_line($b)
} @lines;
I hope this helps
Ivo Z.
------------------------------
Date: Sat, 12 Aug 2000 14:39:46 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: Sort data from text file
Message-Id: <39956117.381D74FB@netstorm.net>
I wrote:
>s/(\d+)\/(\d+)\/(\d+)/sprintf "$3".'%02d'x2,$2,$1/e;
^^^^^
oops - sorry, I lived a long time in a (French) place where 8/11/2000
meant "8 November 2000" instead of August 11, 2000, so above line should
have been:
s/(\d+)\/(\d+)\/(\d+)/sprintf "$3".'%02d'x2,$1,$2/e;
^^^^^
-- Jim
------------------------------
Date: Sat, 12 Aug 2000 16:55:19 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: User-defined hash...
Message-Id: <Xjfl5.106$DT4.3381758@nnrp2.clara.net>
In article <3994B292.53420020@hotmail.com>, Scoot <scoot99@hotmail.com> wrote:
>I want to set an user-defined hash in the client side, this hash should
>be used by other scripts for reference, and it will be stored until the
>browser in the client side is closed.
Please *please* read your post and try and understand what it means. Does it
make sense? Does it make sense if you stop thinking "Yes you fool, that's
what I want my program to do, are you going to stop blathering and answer?"
and instead think "Right, what has this person posted.. 'I want to set a..'"
I'm sorry, but their is no context here. You obviously know what you're
talking about, but we don't. I would assume by your references to "client
side" scripts and cookies that you're talking about CGI scripts but Perl
isn't just used for that so there's ambiguity here ..
Secondly, by "client side", do you mean a user agent (aka a web browser) ?
If so, it is up to whatever that user agent supports to be able to define a
hash structure, and it is unlikely (though possible) that you will be using
Perl for that. The rest of your statement *suggests* that you want to make a
temporary database based on input from the users of your CGI scripts who is
'logged in' to your server. I.e. they connect an initiate a session (and
thus generate a unique ID embedded as a form value or by othermeans such as
a valid username/password), when they opt to 'logout' this database file is
then removed ... ?
Its dubious because "the client side is closed" doesn't make sense
since HTTP does not use constant connections like, say, FTP. That makes
things less easy because you then have to consider "what if they don't hit
log out, what if they kick the power switch on their PC instead" Then
they would never have the same session ID but you'd never have the DB file
removal script being run. You then have to think about things like "When
accessing a DB, how long ago did they accessed this file. Was it 10 seconds
ago, or yesterday?" That should influence your coding.
You can easily plonk a simple hash on disk using tie() (or dbmopen(), it
does the same thing, but is depreciated (afaicr)). Since you are accessing
this file via the web, you should create an ID, perhaps based on their
username if authenticating, or based on a unique number if not. You can then
use that ID as the filename for your DB on disk.
use Fcntl;
use DB_File;
use CGI;
my($cgi) = CGI->new();
my($unique_id) = $cgi->param('uid') || get_unique_id();
if($cgi->param('logout')){
unlink("/db/$unique_id");
$cgi->redirect('http://my.host.com/thanks.html');
exit(0);
}
die "Failed to tie" if(!tie(%formdata, 'DB_File',
"/db/$unique_id", O_CREAT|O_EXCL|O_RDWR, 0600));
$formdata{lastpage} = $cgi->param('page');
$cgi->param('name', $formdata{custname} || 'Unknown');
sub get_unique_id(){ return 1; } # cus its a demo
If you want to use something more complex than perl's inbuilt hash then
tie() will support it too by allowing you to implement your own functions
that are called when creating an entry in the hash, deleting it, etc. and
you can use these to decide how you access the file on disk. So
tie(%book, 'BookTieHash', 'http_cgi_perl');
if($book{'chpt1:sec2'}){
...
}
might end up being used to access 'sec2' in /books/http_cgi_perl/chpt1
using: (untested code, play with/pull apart at your own risk)
sub TIEHASH {
my($class) = ref($_[0]) || $_[0];
my($this) = bless( { }, $class);
$this->{BOOK} = $_[1];
return $this;
}
sub FETCH {
my($this) = shift(@_);
my($book) = $this->{BOOK};
$_[0] =~ /^(.*):(.*)$/;
my($chpt, $sec) = ($1, $2);
open(FH, "</books/$book/$chpt");
{$_ = <FH>} until(/^$sec/);
....
return ..;
}
If that still doesn't cut the mustard (okay, someone tell me where that
phrase comes from, plz?:) as far as the data structures, then have a look at
the modules Data::Dumper and FreezeThaw (I believe there are other modules
for data serialization but I can't remember their names)
>
>I don't want to use cookies.
Okay, but there are only 2 ways to get data back from a user agent that
identifies it as the same user agent, cookies and form data that it
resubmits. There is nothing in the HTTP protocol for token passing and you
can't use IP addresses since many people are on dynamically assigned IP
addresses or use proxy servers. Since the connection is closed every time
you have to reauthenticate users. If you don't want to see URLS with query
string data (Ie "?uid=3933i3ie") then cookies are your alternative ... or
some kind of server side scripting, but that's even less global. If you
don't want to use them because they're complex, look at the docs for
CGI::Cookie
my($cookie) = CGI::Cookie->new(-name=>'ID',-value=>123456);
If not, you're stuck with creating all anchors as '/logout?uid=32423' or if
you're just using form submission,
$cgi->hidden('uid', '234234');
*phew*
Perhaps some help ?
Col. - Off to play Tome raider 3 now whilst the newsgroup recovers :)
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Sat, 12 Aug 2000 16:14:07 GMT
From: "Ben Kennedy" <bkennedy99@home.com>
Subject: Re: warning/var weirdness (or is it?)
Message-Id: <jJel5.97359$A%3.1306770@news1.rdc2.pa.home.com>
I got the scoop on {} -
If {} contains a bareword, it is used to disambiguation for lexical vars,
then goes to global, so ${x} points for first lexical $x then global
$main::x
if the {} contains a scalar, it does a symbolic ref lookup, so
$bleh = 'x';
${$bleh}, ${'x'} are the same since 'x' is a scalar (not a bareword)
I guess an exception would be when $bleh contains a hard reference, where it
will do a straight dereference
I was also told that ${x}[ and even ${x}[1] is most likely a bug. The
theory was that it looked first looks for @x in the lexical namespace, finds
nothing, then looks for @main::x in the global namespace, finds nothing, but
by that point its too late to reenter the lexical namespace, turning ${x}[1]
into $main::x . "[1]" and passing over the lexical x. Sounds like a
possibility at least.
--Ben Kennedy
------------------------------
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 3998
**************************************