[22384] in Perl-Users-Digest
Perl-Users Digest, Issue: 4605 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 22 09:05:47 2003
Date: Sat, 22 Feb 2003 06:05:09 -0800 (PST)
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, 22 Feb 2003 Volume: 10 Number: 4605
Today's topics:
Creating a variable from 3 other variables <PleaseDontThrowSpam@Me.com>
Re: Creating a variable from 3 other variables <mpapec@yahoo.com>
Re: Creating a variable from 3 other variables <PleaseDontThrowSpam@Me.com>
Re: Get Public IP Address of Linux Machine <jc_va@hotmail.com>
Re: having PERL respond to a key press <usenet_poster_a@tranzoa.com>
Re: having PERL respond to a key press <mgjv@tradingpost.com.au>
Re: having PERL respond to a key press <tyrannous@o-space.com>
Re: LWP Requests <mbudash@sonic.net>
Re: LWP Requests <smiley@uvgotemail.com>
Re: LWP Requests <Ingo_Wiarda@web.de>
Mail::POP3Client password <vze2368uDELME@verizon.net>
map two lists <johannes.fuernkranz@t-online.de>
parens () <racsw@frontiernet.net>
Re: parens () <andy@misk.co.uk>
Re: parens () <abigail@abigail.nl>
Re: parens () <krahnj@acm.org>
Re: parens () <tore@aursand.no>
Re: parens () (Tad McClellan)
Re: pipe() + fork() + exit() == problem? <gordan@_NOSPAM_bobich.net>
POSTing data to JHTML page <hrishikeshagashe@hotmail.com>
Reading tab delimited files into a hash. (Charles R. Thompson)
Re: Reading tab delimited files into a hash. (Jay Tilton)
Re: Reading tab delimited files into a hash. (Tad McClellan)
Re: setting permissions on my server for cgi (Jay Tilton)
Re: setting permissions on my server for cgi <noreply@gunnar.cc>
Re: Switch order of sprintf conversions <flavell@mail.cern.ch>
Re: Switch order of sprintf conversions (Gunnar Hjalmarsson)
Re: Switch order of sprintf conversions <noreply@gunnar.cc>
Re: Switch order of sprintf conversions (Gunnar Hjalmarsson)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 22 Feb 2003 13:10:28 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Creating a variable from 3 other variables
Message-Id: <b37sp8$r6h$1@wisteria.csv.warwick.ac.uk>
Hi,
I'd like to create a variable from 3 other variables.
The following will do this:
my $date = "$year $month $day";
BUT
$date will include two spaces. I do not want spaces.
If I try the following, I will get errors:
my $date = "$year$month$day";
How can I create the $date variable from the 3 other variables with any
spaces? I would like it as one continuous string YYYYMMDD.
Thanks for your help,
Mikey
------------------------------
Date: Sat, 22 Feb 2003 14:28:51 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: Creating a variable from 3 other variables
Message-Id: <dhue5v44gv4i4gpamcjmgl86vtolr89avp@4ax.com>
X-Ftn-To: Mikey
"Mikey" <PleaseDontThrowSpam@Me.com> wrote:
>I'd like to create a variable from 3 other variables.
>
>The following will do this:
>my $date = "$year $month $day";
>
>BUT
>
>$date will include two spaces. I do not want spaces.
>
>If I try the following, I will get errors:
>my $date = "$year$month$day";
Which error exactly? This should work but as alternative you can use
my $date = $year . $month . $day;
or:
my $date = "${year}${month}${day}";
--
$_=$2.$1,s sg s sgmx,$/.=$_,while q mnagdaLrrgysiHgsihgca
ek r=m=~m m(. ) (. ) mmxg;print"There is only one God,$/"
------------------------------
Date: Sat, 22 Feb 2003 13:53:29 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Re: Creating a variable from 3 other variables
Message-Id: <b37v9t$seg$1@wisteria.csv.warwick.ac.uk>
"Matija Papec" <mpapec@yahoo.com> wrote in message
news:dhue5v44gv4i4gpamcjmgl86vtolr89avp@4ax.com...
> X-Ftn-To: Mikey
>
> "Mikey" <PleaseDontThrowSpam@Me.com> wrote:
> >I'd like to create a variable from 3 other variables.
> >
> >The following will do this:
> >my $date = "$year $month $day";
> >
> >BUT
> >
> >$date will include two spaces. I do not want spaces.
> >
> >If I try the following, I will get errors:
> >my $date = "$year$month$day";
>
> Which error exactly? This should work but as alternative you can use
> my $date = $year . $month . $day;
> or:
> my $date = "${year}${month}${day}";
>
:)
Thanks,
Mikey
------------------------------
Date: Sat, 22 Feb 2003 12:20:17 GMT
From: "Buck Turgidson" <jc_va@hotmail.com>
Subject: Re: Get Public IP Address of Linux Machine
Message-Id: <5WJ5a.48083$P1.3207392@news1.east.cox.net>
I found and modified a java program to do this. I thought I would share
it to save the next guy the trouble.
import java.net.*;
import java.util.*;
import java.io.*;
public class GetLinkSysIP {
public static void main (String[] argv) throws Exception {
GetLinkSysIP me = new GetLinkSysIP();
me.workIt();
}
public void workIt() throws Exception {
System.getProperties().put("proxySet", "true");
String authString = "user:pass";
String auth = "Basic " + new
sun.misc.BASE64Encoder().encode(authString.getBytes());
URL url = new URL("http://192.168.1.1/Status.htm");
URLConnection conn = url.openConnection();
conn.setRequestProperty("Proxy-Authorization", auth);
DataInputStream input = new DataInputStream(
conn.getInputStream() );
StringBuffer sb = new StringBuffer();
for ( int c = input.read(); c != -1; c = input.read() ) {
sb.append( (char)c );
}
input.close();
int start = sb.toString().lastIndexOf("IP Address");
System.out.println(sb.substring(start,start + 60));
}
}
------------------------------
Date: Sat, 22 Feb 2003 03:15:03 -0800
From: Alex <usenet_poster_a@tranzoa.com>
Subject: Re: having PERL respond to a key press
Message-Id: <p_GdnSS6aKMNwcqjXTWc-g@speakeasy.net>
tyrannous@o-space.com wrote:
> I want to have perl exit from a WHILE loop when the user presses a certain
> key on the keyboard
>
> for example of what i want:
>
> while(not $something)
> {
>
> if($keypress eq "a")
> {
>
> do something
>
> }
>
> }
>
> before you answer this question, remember that i have already tried
> Term::ReadKey and it wont work on my MS-DOS system. plz help me if you can
>
>
>
Right, it's often said in this newsgroup that Term::ReadKey works on Win
systems. Such is not the case, though. Might be a Win9x compatability situation.
Anyway, the following module complains at startup time on 9x systems, but works
just fine anyway on Linux/Win9x/Win2k. The Win systems are Active State Perl. Be
careful with line-broken comments. Hope this helps.
require 5.002;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 1.00;
@ISA = qw(Exporter);
#
# This way the using program need not put KeyReady:: in front of stand-alone
subroutine names.
#
@EXPORT = qw(
tz_key_ready
);
my $win32_keybrd;
# print "OS name: ".$^O."\n"; # 'linux' / 'MSWin32'
BEGIN
{
my $mod = "Term::ReadKey"; # $^O is $OSNAME
$mod = "Win32::Console" if ($^O =~ m/Win/o);
if ($mod eq "Win32::Console") {
die "Could not 'use' $mod!\n" if (eval "use $mod");
#
# Finally not true!
# I've found no way to get around the warning/bitch about not-numeric -
The code works, though.
#
#
# $win32_keybrd = Win32::Console->new(Win32::Console->STD_INPUT_HANDLE);
open SAVEERR, ">&STDERR";
my $redirected = 0;
$redirected = 1 if (open STDERR, ">/dev/nul");
$win32_keybrd = Win32::Console->new(Win32::Console->STD_INPUT_HANDLE);
open STDERR, ">&SAVEERR" if ($redirected);
close(SAVEERR);
sub Win32ReadKey
{
return(undef) if (!$win32_keybrd->GetEvents);
my @event;
@event = $win32_keybrd->Input();
return(undef) if (!defined($event[0]) || ($event[0] ne "1") ||
!$event[1] || !$event[5]);
return(chr($event[5]));
}
}
else {
die "Could not 'use' $mod!\n" if (eval("use $mod"));
}
}
#
#
# Check the keyboard for operator input.
#
# Returns undef if no key is ready for input.
# Otherwise, returns the key.
#
#
sub tz_key_ready()
{
#
#
# Check for some user interaction - a key from him
#
#
my $key;
if (defined($win32_keybrd)) {
$key = Win32ReadKey();
}
else {
ReadMode('cbreak');
$key = ReadKey(-1);
ReadMode('normal');
}
return($key);
}
1;
------------------------------
Date: Sat, 22 Feb 2003 23:17:45 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: having PERL respond to a key press
Message-Id: <slrnb5eqj8.2fm.mgjv@martien.heliotrope.home>
On Sat, 22 Feb 2003 03:15:03 -0800,
Alex <usenet_poster_a@tranzoa.com> wrote:
> tyrannous@o-space.com wrote:
>> I want to have perl exit from a WHILE loop when the user presses a certain
>> key on the keyboard
>>
>> for example of what i want:
>>
>> while(not $something)
>> {
>>
>> if($keypress eq "a")
>> {
>>
>> do something
>>
>> }
>>
>> }
>>
>> before you answer this question, remember that i have already tried
>> Term::ReadKey and it wont work on my MS-DOS system. plz help me if you can
>
> Right, it's often said in this newsgroup that Term::ReadKey works on
> Win systems. Such is not the case, though.
Term::ReadKey does work under windows, with some limitations, and its
own documentation describes these. Also, ActiveState distributes the
module as a ppm, and wouldn't do so if it didn't test correctly.
The README file claims support for win32 since version 2.10, which came
out somewhere late in 1997. The README says:
The module has support for Win32 since version 2.10. Version 2.17
has been tested with ActivePerl build 623 and Visual Studio 6 and
found to work as expected, but do not be surprised if it fails with
another compiler or distribution.
Note that there is no claim that DOS is supported.
> Might be a Win9x
> compatability situation.
The documentation does not mention any of this, but some people don't
reckon win98 to be a Win32 system. I don't use any of them, so I don't
know whether or not it is supposed to be one. If not, then the author
never claimed it worked on 98. If it is, then the author needs to fix
the documentation, or the module, I suppose.
If you believe that there are issues, you should file a bug report with
the author, or at rt.cpan.org, so that it can be fixed, or at least
documented.
> Anyway, the following module complains at startup time on 9x systems,
> but works just fine anyway on Linux/Win9x/Win2k. The Win systems are
> Active State Perl. Be careful with line-broken comments. Hope this
> helps.
Complains how, and what is the complaint?
If you are going to report this with the author, try to be a bit more
complete and informative about what the problem is. "The following
module complains" is not a good description of a problem, because a
module can't complain, and because it states nothing about the error or
warning message you get, and when you get it.
It would also be a good idea if you provided a _small_ snippet of code
that works on, say, Win NT or 2000, and not on 98. Not a complete
module.
[large SNIP]
Martien
--
|
Martien Verbruggen |
| "Mr Kaplan. Paging Mr Kaplan..."
|
------------------------------
Date: Sat, 22 Feb 2003 12:40:23 -0000
From: <tyrannous@o-space.com>
Subject: Re: having PERL respond to a key press
Message-Id: <b37r2b$hko$1@news8.svr.pol.co.uk>
it is already installed in the lib directory in perl, thank you very much
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns9329E00E01517sdn.comcast@216.166.71.239...
> <tyrannous@o-space.com> wrote in news:b363e3$b40$1@news8.svr.pol.co.uk:
>
> > yes i tried it
> > i tried the following:
> >
> > #!c:\perl\bin\perl.exe
> >
> > use Term::ReadKey;
> >
> > blah blah
> >
> > says cannot find Term::ReadKey in @INC or something like that
>
> Well then, you should go find it or something like that. Maybe find it on
> the Internet or something like that.
>
> --
> Eric
> print scalar reverse sort qw p ekca lre reh
> ts uJ p, $/.r, map $_.$", qw e p h tona e;
>
------------------------------
Date: Sat, 22 Feb 2003 09:05:46 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: LWP Requests
Message-Id: <mbudash-699FB4.01054622022003@typhoon.sonic.net>
In article <v5e8635er9paa5@corp.supernews.com>,
"Smiley" <smiley@uvgotemail.com> wrote:
> This is regarding the subject of my earlier post titled 'Retrieving
> Information'
>
> I set up my script to access information from the webpages search engine. I
> was able to use LWP to get the information through Post for the first page,
> then changed the settings that should bring up the information on the
> second, third, and so on pages. The problem is that I only kept on getting
> repeats of the first page, couldn't get to the rest of them.
>
> Does anybody know why this might be?
>
>
you're not telling us enough... elaborate a little and perhaps we can
help...
------------------------------
Date: Sat, 22 Feb 2003 05:47:25 -0500
From: "Smiley" <smiley@uvgotemail.com>
Subject: Re: LWP Requests
Message-Id: <v5elafall1sea8@corp.supernews.com>
> you're not telling us enough... elaborate a little and perhaps we can
> help...
Well, I've explained some of this in my earlier post. The website is set up
with a searchable database which I would like to grab information from. The
online script only accepts Post, and uses form buttons using Post to take
users to the Next and Previous screens in the search results.
I'm using LWP to grab that information, putting in the necessary variables
via Post, and this works for the first screen of the search results.
However, I can't seem to retrieve the subsequent pages. It seems that the
first page keeps repeating and I'm not sure what I need to change in order
to correct that.
The first page of the results is actually not the same script as for the
second page. It links to a new script called results.asp, and ads a new
variable for each page called intCurrentpage and also Action=Next+Items.
I've got my Perl script set up to loop through the number of pages in the
results and change intCurrentpage each time. At the end of the loop it
changes $req to point to results.asp, changes the content, and updates $res
appropriately (variable names taken from perldoc)
Yet it's still pulling in the same data from the same page at each loop.
Is that enough information for you?
------------------------------
Date: Sat, 22 Feb 2003 12:41:49 +0100
From: Ingo Wiarda <Ingo_Wiarda@web.de>
Subject: Re: LWP Requests
Message-Id: <b37neq$1jl2o4$1@ID-40614.news.dfncis.de>
Smiley wrote:
>> you're not telling us enough... elaborate a little and perhaps we can
>> help...
>
> Well, I've explained some of this in my earlier post. The website is set
> up
> with a searchable database which I would like to grab information from.
> The online script only accepts Post, and uses form buttons using Post to
> take users to the Next and Previous screens in the search results.
>
> I'm using LWP to grab that information, putting in the necessary variables
> via Post, and this works for the first screen of the search results.
> However, I can't seem to retrieve the subsequent pages. It seems that the
> first page keeps repeating and I'm not sure what I need to change in order
> to correct that.
>
> The first page of the results is actually not the same script as for the
> second page. It links to a new script called results.asp, and ads a new
> variable for each page called intCurrentpage and also Action=Next+Items.
>
> I've got my Perl script set up to loop through the number of pages in the
> results and change intCurrentpage each time. At the end of the loop it
> changes $req to point to results.asp, changes the content, and updates
> $res appropriately (variable names taken from perldoc)
>
> Yet it's still pulling in the same data from the same page at each loop.
>
> Is that enough information for you?
If the first page keeps repeating it could be because:
a) You do not change the URL (by accident)?
b) The page is protected / buggy? Eg, I have encountered pages which would
not accept an LWP-Bot, but would work if I changed the user agent to
"Internet Explorer" etc. Some pages may only work if called with a correct
referrer, cookies etc.
c) Is the $req-url correct? Check for spelling - I just discovered that
go$number."tga" is in fact not equal go$number.".tga"...:)
Does the result.asp expect POST like search.asp?
What kind of "content" do you change?
Could you post your current code again please, provided it is not too long?
Ingo
------------------------------
Date: Sat, 22 Feb 2003 13:26:12 GMT
From: Veera Venkataramani <vze2368uDELME@verizon.net>
Subject: Mail::POP3Client password
Message-Id: <4r6wwa8t.fsf@verizon.net>
I want to write a simple script (not necessarily in perl) that queries
a pop server and gets the number of messages in my inbox (I use
Xemacs/vm to read my mail).
I downloaded and installed the Mail:POP3Client package. Then I found
this script in the perldoc.
use Mail::POP3Client;
$pop = new Mail::POP3Client( USER => "me",
PASSWORD => "mypassword",
HOST => "pop3.do.main" );
for( $i = 1; $i <= $pop->Count(); $i++ ) {
foreach( $pop->Head( $i ) ) {
/^(From|Subject):\s+/i && print $_, "\n";
}
}
$pop->Close();
However, if I dont replace "mypassword" with my cleartext password,
this doesnt work. I dont think this is how people use this
package. How do I use this without having my password in cleartext in
a script file?
Thanks!
Veera.
--
------------------------------
Date: Sat, 22 Feb 2003 14:46:22 +0100
From: =?ISO-8859-1?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: map two lists
Message-Id: <b37uvi$9an$01$1@news.t-online.com>
Hi,
I frequently have the following problem:
I would like to run a map over two lists that are aligned, i.e.,
something like:
@result = map2 { function($1,$2} } @list1, @list2;
This, of course, doesn't work, but maybe there is something similar?
($1 and $2 are meant to refer to corresponding arguments in the two lists).
I also thought of the possibility of first forming a combined list,
i.e., a list that consists of references of two-element lists, one from
each original list. This list should look like:
@combined = ( [ $list1[0], $list2[0] ],
[ $list1[1], $list2[1] ],
...
);
Then I could call
@result = map { function($_->[0],$_->[1]) } @combined;
But again, I don't know how to efficiently construct @combined.
[ I do know how to construct it with a for-loop and push, but I keep
thinking there must be a more elegant and more efficient way to do this,
preferrably in a single statement. ]
thanks, Juffi
------------------------------
Date: Sat, 22 Feb 2003 06:36:19 -0500
From: Robert Krueger <racsw@frontiernet.net>
Subject: parens ()
Message-Id: <v5eo5jtf5oe4b8@corp.supernews.com>
Hi,
Why does this work:
print (( 2 * 3 ) * 8 );
and this doesn't?
print ( 2 * 3 ) * 8;
Thanks,
Robert
------------------------------
Date: Sat, 22 Feb 2003 11:45:15 +0000
From: Andrew McGregor <andy@misk.co.uk>
Subject: Re: parens ()
Message-Id: <3E5762CB.1090008@misk.co.uk>
Robert Krueger wrote:
> Hi,
> Why does this work:
> print (( 2 * 3 ) * 8 );
>
> and this doesn't?
> print ( 2 * 3 ) * 8;
>
> Thanks,
> Robert
did you use warnings; or -w?
i suspect `print' will bind tighter than `*'.
------------------------------
Date: 22 Feb 2003 12:02:06 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: parens ()
Message-Id: <slrnb5eplu.9s4.abigail@alexandra.abigail.nl>
Robert Krueger (racsw@frontiernet.net) wrote on MMMCDLXII September
MCMXCIII in <URL:news:v5eo5jtf5oe4b8@corp.supernews.com>:
.. Hi,
.. Why does this work:
.. print (( 2 * 3 ) * 8 );
..
.. and this doesn't?
.. print ( 2 * 3 ) * 8;
perldoc -f print
It "doesn't work" for the same reason "lc ('FOO') . 'BAR'" "doesn't work".
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
------------------------------
Date: Sat, 22 Feb 2003 12:04:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: parens ()
Message-Id: <3E576743.E2DBFE7A@acm.org>
Robert Krueger wrote:
>
> Why does this work:
> print (( 2 * 3 ) * 8 );
For the same reason that this works:
print 2 * 3 * 8;
And this works:
print 8 * ( 2 * 3 );
> and this doesn't?
> print ( 2 * 3 ) * 8;
The print function has the argument ( 2 * 3 ) which it prints and then
the return value from print is multiplied by 8, the same as:
8 * print( 2 * 3 );
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 22 Feb 2003 13:27:34 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: parens ()
Message-Id: <pan.2003.02.22.11.45.01.170141@aursand.no>
On Sat, 22 Feb 2003 06:36:19 -0500, Robert Krueger wrote:
> Why does this work:
> print (( 2 * 3 ) * 8 );
>
> and this doesn't?
> print ( 2 * 3 ) * 8;
Both of them works for me. What's the error message you receive?
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: Sat, 22 Feb 2003 06:35:49 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: parens ()
Message-Id: <slrnb5erl5.9vr.tadmc@magna.augustmail.com>
Robert Krueger <racsw@frontiernet.net> wrote:
> Why does this work:
> print (( 2 * 3 ) * 8 );
>
> and this doesn't?
> print ( 2 * 3 ) * 8;
You should always enable warnings when developing Perl code!
For a more in-depth explanation than is given in the warnings,
search for the ID below at:
http://groups.google.com/advanced_group_search
Message-Id: <slrnatq036.2q2.tadmc@magna.augustmail.com>
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 22 Feb 2003 09:40:10 +0000
From: Gordan <gordan@_NOSPAM_bobich.net>
Subject: Re: pipe() + fork() + exit() == problem?
Message-Id: <1045906809.633757@auth2.dns.griffin.net.uk>
Benjamin Goldberg wrote:
>> > HUH? Are you doing something funky like making your pipes
>> > nonblocking?
>>
>> Effectively, I'm doing something like this:
>>
>> while (1)
>> {
>> flock($Pipe, LOCK_EX);
>> if (-s $Pipe)
>> {
>> $Job = DeQueue($Pipe);
>> Process($Job);
>> }
>> else
>> {
>> sleep(5);
>> }
>> flock($Pipe, LOCK_UN);
>> }
>
> Change this to code like:
>
> for( 1 ... $num_jobs_to_process ) {
> flock($Pipe, LOCK_EX);
> $Job = DeQueue($Pipe);
> flock($Pipe, LOCK_UN);
> Process($Job);
> }
>
> You shouldn't be processing the job while holding onto the lock -- if
> you do that, you don't get any parallelism, which is half the purpose
> having a parent process/worker processes (you still get the other
> half, which is avoiding memory leaks, though).
The above example I gave was bad. Of course I already do it as you
suggested. Only the DeQueue() is performed while the lock is in place.
:-)
> Also, it's a simpler, programmatically, to say "process $x jobs" than
> "process jobs for $x amount of time." Not to mention, the amount of
> memory leaking is probably dependent upon the number of jobs
> processed, rather than for the number of seconds the worker has been
> alive.
That is indeed what I do. TTL signifies the number of jobs between
re-forking.
>> > You should *never* need to sleep() until a job is ready -- simply
>> > try reading from the pipe, and if you haven't made the pipe
>> > nonblocking, it will *automaticaly* go to sleep until something is
>> > available.
>>
>> Hmm... I might play with that in a bit. It seems like a sensible way
>> to do it. At the moment, I just have an array mapped into a shared
>> memory segment that keeps track of status of each thread. If all the
>> jobs are done, thenthe pipe may never get filled. So, I guess I could
>> check for an EOF, and make the queue process the first one to exit.
>> It would save a bit on overhead. Thanks, I think I'll do that. :-)
>
> I don't see the need for a shared memory segment -- it would be more
> portable to have a second pipe, from the child processes to the parent
> process, for indicating status/changes in status. When the status of
> a worker process changes, it would lock the to_parent pipe, write it's
> pid and it's new status to the pipe, then unlock the pipe.
I could do that, but the method I use works well, and I don't
particularly care about portability to systems that don't have the
concept of shared memory. :-)
Thanks.
Gordan
------------------------------
Date: Sat, 22 Feb 2003 18:06:46 +0530
From: "Hrishikesh Agashe" <hrishikeshagashe@hotmail.com>
Subject: POSTing data to JHTML page
Message-Id: <b37qdh$c38$1@news.vsnl.net.in>
Hi,
I am trying to POST the data through Perl code to JHTML page
But every time I execute the program, what I get back is the same jhtml page
!!
Is there any way to solve this problem ?
--Hrishi
------------------------------
Date: 22 Feb 2003 04:42:27 -0800
From: design@raincloud-studios.com (Charles R. Thompson)
Subject: Reading tab delimited files into a hash.
Message-Id: <471883c2.0302220442.48627880@posting.google.com>
I constantly find myself reading tab delimited files into a hash in a
method similar to below. I'm realizing now that it's probably not the
best way to do it but reading through the docs I haven't come across
anything new:
use File::Slurp;
my $hostsfile = &read_file('D:/WEB_LOG_PROCESSING/HOSTS.TXT');
my %hosts = ();
while ($hostsfile =~
s/^CLIENT:(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\n//)
{
$hosts{$1} = { host => $2,
username => $3,
password => $4,
serverfile => $5,
clientfile => $6,
logdirectory => $7,
firstname => $8,
lastname => $9,
email => $10,
clientcode => $11,
sysimg => $12,
logo => $13,
hostfilter => $14,};
}
Surely there is a more efficient way to deal with the tabs and
whatnot. I'm not familiar with map or grep... never used them but they
appear from perldoc.com to deal more with arrays or simple hashes so
I'm not sure how to take the hash method shown to this level. If map
or grep would help with this, any assistance would be appreciated.
CT
------------------------------
Date: Sat, 22 Feb 2003 13:49:54 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Reading tab delimited files into a hash.
Message-Id: <3e577bcd.46061052@news.erols.com>
design@raincloud-studios.com (Charles R. Thompson) wrote:
: I constantly find myself reading tab delimited files into a hash in a
: method similar to below. I'm realizing now that it's probably not the
: best way to do it but reading through the docs I haven't come across
: anything new:
:
: use File::Slurp;
: my $hostsfile = &read_file('D:/WEB_LOG_PROCESSING/HOSTS.TXT');
If you must slurp the file (and you probably don't), slurp into an
array instead of a single scalar. It will make line-by-line
processing easier than having to do that s/^CLIENT:....\n// jazz.
my @hostsfile = read_file('D:/WEB_LOG_PROCESSING/HOSTS.TXT');
: my %hosts = ();
: while ($hostsfile =~
: s/^CLIENT:(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\n//)
: {
: $hosts{$1} = { host => $2,
: username => $3,
: password => $4,
: serverfile => $5,
: clientfile => $6,
: logdirectory => $7,
: firstname => $8,
: lastname => $9,
: email => $10,
: clientcode => $11,
: sysimg => $12,
: logo => $13,
: hostfilter => $14,};
: }
:
: Surely there is a more efficient way to deal with the tabs and
: whatnot.
Check out hash slicing and split().
for( @hostsfile ) {
if( /^CLIENT:(.*)$/ ) {
my( $key, @vals ) = split /\t/, $1;
@{ $hosts{$key} }
{qw/
host username password serverfile
clientfile logdirectory firstname
lastname email clientcode sysimg
logo hostfilter
/} = @vals;
}
}
Well, the hash slice part is hardly clear there. It lets you assign a
list of values to a list of keys. A simplified example.
my %hash;
@hash{'key1', 'key2'} = ('value1', 'value2');
------------------------------
Date: Sat, 22 Feb 2003 07:52:56 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Reading tab delimited files into a hash.
Message-Id: <slrnb5f05o.a1q.tadmc@magna.augustmail.com>
Charles R. Thompson <design@raincloud-studios.com> wrote:
> I constantly find myself reading
Please read the Posting Guidelines at least once in a while,
constantly won't be necessary... :-)
> tab delimited files into a hash in a
> method similar to below.
But not similar enough. Your code will find either zero or one
tab-separated set of data. You probably want to get all of them?
Please test your code before posting it.
Did you mean s///m instead?
First make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having. People should be able
to run your program by copy/pasting the code from your article.
Please provide the data needed to run your code, if you require
the answerer to do that for you in addition to answering your
question, they may just move on to help someone else who has
made the effort to make it easier for them to provide an answer.
> use File::Slurp;
Why slurp the file when you never need more than a single
line anyway?
This could potentially be a much larger inefficiency than
the subject of your post...
> my $hostsfile = &read_file('D:/WEB_LOG_PROCESSING/HOSTS.TXT');
^
^
Do you know what semantics you are requesting when you call
a function like that?
I doubt that you want the meaning the ampersand provides.
For info on the difference, see:
perldoc perlsub
> $hosts{$1} = { host => $2,
> username => $3,
> password => $4,
> Surely there is a more efficient way to deal with the tabs and
> whatnot.
split() or Text::CSV_XS.
> I'm not familiar with map or grep... never used them but they
> appear from perldoc.com
The docs on your very old hard disk will be more applicable
to your situation than those at perldoc.com, so you should
use those as your first choice.
> to deal more with arrays or simple hashes so
> I'm not sure how to take the hash method shown to this level.
They are for processing lists.
grep() filters a list.
map() transforms a list.
Either one can always be rewritten as a plain old foreach loop.
> If map
> or grep would help with this, any assistance would be appreciated.
But any assistance would not be appreciated if map/grep will
not help with this?
When a waitress says:
My name is Julie if you need anything else.
I always mutter:
And your name is George if I don't need anything else? <grin>
I'm bored this morning, so I jumped through the hoops that you
required of me, better to require less hoop-jumping...
-----------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @names = qw/ host username password /;
my %hosts;
while ( <DATA> ) {
next unless s/^CLIENT://;
chomp;
my($key, @values) = split /\t/;
# apply "Use Rule 1" from perldoc perlreftut.pod
# @hash{@names} = @values pretend it's a plain hash slice
# @{ }{@names} = @values replace hash name with a block
# @{ $hosts{$key} }{@names} = @values fill block with a ref to a hash
@{ $hosts{$key} }{@names} = @values; # hash slice plus autovivification
}
print Dumper( \%hosts );
__DATA__
other stuff
CLIENT:key host username password
CLIENT:Key Host Username Password
dont care about this line...
CLIENT:KEY HOST USERNAME PASSWORD
more other stuff
-----------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 22 Feb 2003 08:23:48 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: setting permissions on my server for cgi
Message-Id: <3e57328b.27304485@news.erols.com>
"chris" <cpb6043@osfmail.rit.edu> wrote:
: i tried doing use cgi; that didn't work.
^^^^^^^^
Did you write
use cgi;
or did you write
use CGI;
Case matters.
------------------------------
Date: Sat, 22 Feb 2003 13:33:26 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: setting permissions on my server for cgi
Message-Id: <G_K5a.11733$FF4.632440@newsb.telia.net>
chris wrote:
> i am having a few problems getting cgi scripts to work on my server.
> ...
> i have checked to make sure that the path to perl is right. it is.
>
> i have checked to make sure that this is the proper way to send the header. it is.
Even if I agree with Bob that this is off topic here, let me give you a
tip. Assuming that you upload your scripts to a *nix server from a
Windows PC: Ensure that you upload them in ASCII transfer mode!
Bob Walton wrote:
> BTW, conspicuously absent from your CGI script is the statement:
>
> use CGI;
Load CGI.pm in order to print "HELLO"? ;-)
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 22 Feb 2003 11:33:30 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Switch order of sprintf conversions
Message-Id: <Pine.LNX.4.53.0302221123510.762@lxplus073.cern.ch>
On Sat, Feb 21, Mona Wuerz inscribed on the eternal scroll:
> I wouldn't be surprised that rearranging word order in sentences isn't
> all that frequently needed, and therefore more an afterthought, maybe
> only brought up by the occasional exotic native speaker after the
> project has already been released. But I'm guessing wildly.
Just as a data point: for most of the time that I was a user of the
IBM VM operating system, error messages were hard coded. In a later
release, 'internationalization' support produced a scheme whereby
error reports were called out with a code (like ABCXYZ1234E for
error-severity message 1234 from minor component XYZ of major
component ABC) accompanied by a number of parameters, and each
supported language would have a file of associated texts which
included numbered tokens to insert the appropriate parameter from the
parameter list. Thus the parameters could be referenced in whichever
sequence came naturally in each language - just as this thread is
discussing, no?
------------------------------
Date: 22 Feb 2003 04:29:58 -0800
From: noreply@gunnar.cc (Gunnar Hjalmarsson)
Subject: Re: Switch order of sprintf conversions
Message-Id: <3fcbff18.0302220429.58bf807a@posting.google.com>
Mona Wuerz <wuerz@yahoo.com> wrote in message news:<m3y9495me6.fsf@karrooite.njitdm.campus.njit.edu>...
> > > It would probably be worthwhile to write a substitute for sprintf that
> > > supports the "%2$d" notation of the C sprintf.
>
> As a first stab at it, I came up with
>
> #!perl -w
> use strict;
>
> sub fmt {
> my $fmt = shift;
> my @fmts;
> my $i=0;
> while ($fmt =~ s/(\%\d?\$?\d?\.?\d?[%csduoxefgXEGbpn])/\$fmts[$i]/) {
> push @fmts, $1; $i++;
> }
> @fmts = map { $_->[0] }
> sort { $a->[1] <=> $b->[1] }
> map { [ $_, s/\%(\d*)\$/\%/?$1:0 ] } @fmts;
> $fmt =~ s/\$fmts\[(\d+)\]/$fmts[$1]/g;
> $fmt =~ s/\\n/\n/g; # etc...
> $fmt
> }
Hmm.. That rearranges the order of the conversions, while my need is
rather about rearranging the order of the arguments represented by the
conversions. (I realize now that the subject line for this thread
isn't 100% accurate...)
A few words about gettext: A gettext language file consists of pairs
of untranslated and translated strings. A string passed to the gettext
function I'm using in my program is an untranslated string, and the
function returns the corresponding translated string.
The order of the *conversions* should better be taken care of by
respective translator via the translated strings. What the function
that would substitute sprintf would do, is to see to it that the
*arguments* are picked in the order indicated by the translators
through the special notations.
Nevertheless, I think that your suggestion will help me get started,
Mona. Thanks!
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 22 Feb 2003 12:33:17 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Switch order of sprintf conversions
Message-Id: <h6K5a.11728$FF4.632394@newsb.telia.net>
Anno Siegel wrote:
>>>>> I'm amazed the need to rearrange arguments hasn't come up
>>>>> earlier.
>>
>> As a matter of fact, it has - in de.clpm. See, e.g.
>> <jktao9.8sn.ln@al.brain.de> and the ensuing thread (in German).
>
> My (ambiguous) use of "earlier" was aimed at the history of the
> particular program, not Perl groups in general. I would have thought
> that in a multilingual system described as "mature" the need (or at
> least a wish) to rearrange word order would have come up before.
I misunderstood it first, too.
As I'm sure you understand, it's strings that are translated, not
individual words, so all translators are free to rearrange the word
order within a string. The only restriction, up to now, is those rather
few cases where sprintf functions include more than one argument. Note,
also, that the arguments often consist of user IDs, URLs, etc. rather
than words. I don't think it is very amazing, after all.
Btw, if you want to visit the homepage for the program you are helping
me improve, please go to http://www.ringlink.org/ :)
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 22 Feb 2003 05:16:26 -0800
From: noreply@gunnar.cc (Gunnar Hjalmarsson)
Subject: Re: Switch order of sprintf conversions
Message-Id: <3fcbff18.0302220516.7e571564@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3E571764.68DE835@earthlink.net>...
> Gunnar Hjalmarsson wrote:
> > I understand from the gettext documentation that if it
> > had been a C program, $string could have been assigned (the
> > equivalent of) "There Is %2$s Than %1$s Way To Do It".
> >
> > Is there a way in Perl to achieve the same thing?
>
> Here's a summary of what's been suggested:
>
> [snip]
>
> 3/ Write a parser for sprintf formats which handles '2$' and '1$'
> thingies, and permutes the argument list and reformats the format
> string, to produce an ordinary sprintf format string, and then use
> perl's builtin sprintf.
>
> And my own idea, which noone seems to have mentioned:
>
> 4/ Have gettext return a string which would be eval()ed into a coderef,
> calling that coderef with the args produces an appropriate string. eg:
> $code = gettext(
> 'sub { qq[There Is $_[0] Than $_[1] Way To Do It] }');
> $more = gettext("More");
> $one = gettext("One");
> print eval($code)->($more, $one);
> And, for the argument-reversed thingie, gettext would put into $code a
> string like:
> 'sub { qq[There Is $_[1] Than $_[0] Way To Do It] }'
Thanks for this additional idea! I see at least one disadvantage with
it, though: It would mean a deviation from the gettext convention.
Gettext provides a well-established framework for i18n, and I have
found it convenient to be able to refer to the gettext documentation
when instructing the translators.
I'm still inclined to go for suggestion 3/ in your summary. It would
mean a one-time program change, leaving the rest to the translators to
handle via the translated strings. It would also be the best
preparation for the ability introduced in Perl 5.8.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 4605
***************************************