[19534] in Perl-Users-Digest
Perl-Users Digest, Issue: 1729 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 11 03:05:32 2001
Date: Tue, 11 Sep 2001 00:05:11 -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: <1000191910-v10-i1729@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 11 Sep 2001 Volume: 10 Number: 1729
Today's topics:
Re: AoH - continued <goldbb2@earthlink.net>
Re: can this be done with regex? (stupid question proba (Tim Hammerquist)
Re: Can't fork on certain computers? <me@REMOVETHIStoao.net>
Re: Can't fork on certain computers? <me@REMOVETHIStoao.net>
Re: Cannot overload operator <> ? <c.hintze@gmx.net>
concatenating files with the same name (soumitra bhattacharya)
Re: HELP: Capture a page? <goldbb2@earthlink.net>
Re: HELP: Capture a page? (Martien Verbruggen)
Re: How can I popup a info window in perltk, and have e (Eric Bohlman)
How do you use <> and @ARGV with 4nt? (Adi Inbar)
Re: how to get the length of string <wsegrave@mindspring.com>
Re: how to get the length of string (Tad McClellan)
how to substitute letters within a string <pauls_spam_no@pauls.seanet.com>
Re: how to substitute letters within a string (Tim Hammerquist)
Re: how to substitute letters within a string <godzilla@stomp.stomp.tokyo>
Re: how to substitute letters within a string <godzilla@stomp.stomp.tokyo>
Re: mysql connection. <mfrick@chariot.net.au>
Re: Probelm with undefined atgumnets (Stan Brown)
Re: recognize MS Windows with perl (Jonadab the Unsightly One)
Re: references, slices, voodoo (Seymour J.)
Re: references, slices, voodoo (Damian James)
Re: references, slices, voodoo (Logan Shaw)
Re: start a script when a process exits <godzilla@stomp.stomp.tokyo>
Re: start a script when a process exits (Garry Williams)
Re: start a script when a process exits (Joe Smith)
Re: strange Win32 IO behavior! (Jonadab the Unsightly One)
Re: terminal Emulator <goldbb2@earthlink.net>
Re: terminal Emulator (Joe Smith)
Where Can I Find the path to the desktop on Win9X/2K an (Admin T.)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 10 Sep 2001 23:26:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: AoH - continued
Message-Id: <3B9D845D.FDF873C5@earthlink.net>
jason wrote:
>
> Benjamin Goldberg wrote:
[snip]
> > Have you considered simplifying your data?
> > A fixed order, and just have the values, not the keys.
> >
> > music|very good|mp3
> > video|too long|mpeg
> >
> > Then the program becomes *much* simpler:
> [/snip]
>
> The point in the program is to *pretend* I don't know anything(no need
> for security comments, I'm creating the data) about the data.
I'm assuming that the data is in a file on your disk. When this is so,
there's no reason to *not* assume it's in a particular format.
> With this program, the data can have any number of fields, and you can
> change the order in which they are returned by simply changing the key
> in the first row.
Ahh. In this case, you should have your file's format as:
category|info|type
music|very good|mp3
video|too long|mpeg
You can have any number of fields, easily, and while it's not *just* the
first line which needs to be changed to change the order in which
they're returned, it's not difficult, either.
Plus, using this, your data is in a nearly standard CSV [comma seperated
value] format, the only difference being pipes "|" instead of commas ","
This means that you can use a package designed for dealing with CSVs can
be used for reading from and writing to the file. Just read the first
line for the field names and their order, and then the rest of the file
as the data.
> This allows me to create any size DB file and use the same script to
> produce my output. I'm using it explicitly with CGI.pm to create HTML
> tables. Like this:
> http://www.gimptroll.com/cgi-bin/
> sort.cgi?sortby=date&db_file=calls.dat
Now that I know that it's for CGI, that introduces a number of other
important things you need to be careful of. In particular, what happens
if the user specifies sort.cg?db_file=/etc/passwd [ok, not that, since
that would be : seperated, not | seperated, but *something*].
You really, really, really should make sure your program runs with -T,
otherwise it's much too easy to make security holes.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Tue, 11 Sep 2001 04:00:17 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: can this be done with regex? (stupid question probably)
Message-Id: <slrn9pr3q0.20i.tim@vegeta.ath.cx>
Me parece que crow <kick.me@love.me> dijo:
> if this is an easy one then just tell me to go read some manual but for now
> i couldn't solve it. just got some basic knowledge.
>
> suppose you have a string like this "6542{"
> now the last character (always the last one) needs to be substituted.
> { to 0, A to 1, B to 2 and so on.
>
> i was thinking of
> s/[{ABCDEFGH]$/[0123456789]/
> but of course that doesn't work. the last char will be mapped but replaced
> by [0123456789].
It sounds like you were thinking of the tr/// operator, but even that
doesn't work the way you seem to want it to.
s/[{ABCDEFGHI]$/[0123456789]/
\__________/ \__________/
A B
The []'s in the part A act like a character class, matching the last
character of the string _only if_ it's in the character class.
However, the []'s in part B aren't special; they're treated literally,
so if the last character of the string is in part A's character class,
it's replaced by the whole of part B (as you've noticed). This is the
way it's supposed to work.
Using
tr/{ABCDEFGHI/0123456789/;
will work for the test string you gave us, and if none of the rest of
the characters of the string are _ever_ in the class [{A-I], it will
work consistently. Unfortunately, tr/// can't be anchored to work on
just the last character.... at least not without help. Use the substr()
function to limit it to just the last character. You can even modify it
in place (a luxury that I miss in Python).
$str = "6542{";
# grab last character and change it in place
substr($str1, -1, 1) =~ tr/{A-I/0-9/;
# now $str == "65420"
--
Me? Lady, I'm your worst nightmare -- a pumpkin with a gun.
-- Mervyn Pumpkinhead, The Sandman
------------------------------
Date: Tue, 11 Sep 2001 04:35:26 GMT
From: "Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net>
Subject: Re: Can't fork on certain computers?
Message-Id: <iwgn7.159789$B37.3575493@news1.rdc1.bc.home.com>
Oops, forgot to say, I did do that. That's when it told me about the chunk
6 error. It told me the line number, too, which is how I knew it was the
fork that was causing the problem.
Sorry about that
GWB
> You should always print the error reason, e.g.
>
> $ perl -e 'open BLAH, ">/hello" or die "Failed: $!"'
> Failed: Permission denied at -e line 1.
>
> Then you might know why it failed.
------------------------------
Date: Tue, 11 Sep 2001 04:38:21 GMT
From: "Graham W. Boyes - TOAO.net" <me@REMOVETHIStoao.net>
Subject: Re: Can't fork on certain computers?
Message-Id: <1zgn7.159807$B37.3580148@news1.rdc1.bc.home.com>
I figured it out. It was because the IBM machines had NTFS formatted drives
and the fork apparently needs to use a hard drive to store a temporary file.
When I tried it on machines with FAT32 formatted drives, it was fine. When
I tried it on a machine without a hard drive at all, the problem occured.
Back to square one I guess...a lot of machine I will run this program on
don't have hard drives.
Still don't know what the heck "chunk 6" means. ????? "Can't write to
disk" or even "Permission denied" would have saved me a bit of grief!
Graham W. Boyes
> I want to capture the output of a program called mem.exe and use it in
> my program. I have this code:
>
> open FORK, "MEM |" or die "Doesn't work";
>
> It works on most computers (I tried an NEC and two custom built
> machines) but on certain IBM machines it gives the error "Doesn't
> work! at a:\myfile.pl line 66, <STDIN> chunk 6."
------------------------------
Date: Tue, 11 Sep 2001 07:45:03 +0200
From: Clemens Hintze <c.hintze@gmx.net>
Subject: Re: Cannot overload operator <> ?
Message-Id: <3B9DA4DF.DB1E3E30@gmx.net>
Bob Walton wrote:
>
> Clemens Hintze wrote:
(...)
> So it looks like an issue with either your OS or your version of Perl.
Gnark! As the error happens also on a Solaris box, I guess the only
thing remaining is, that Perl 5.005_03 is broken in that respect. Or
both I (for the Solaris box) and the guys packaging FreeBSD has done
something wrong during configuring Perl before building it (if it could
be influenced by configuring).
Perhaps I should consider upgrading ...
Thanks anyway for your response.
Ciao,
Clemens.
> --
> Bob Walton
------------------------------
Date: 10 Sep 2001 23:51:12 -0700
From: soumitra@mailandnews.com (soumitra bhattacharya)
Subject: concatenating files with the same name
Message-Id: <72fd0cf4.0109102251.27c0e142@posting.google.com>
Hi!
I have files with the same name but in different directories.
I have four directories a,b,c,d
within each directory I have files with the same name.
Like within "a" directory I have
k.txt (100Kb),l.txt(50Kb),m.txt(70Kb)
again within "b" directory I have
k.txt(77Kb),l.txt(70Kb),m.txt(770Kb)
again within "c" directory I have
k.txt(200Kb),l.txt(100Kb),m.txt(10Kb)
I want to make a new directory "concatenated"
where I will have files
k.txt(file size= 100+77+200).....
l.txt(file size = 50+7++100).....
k.txt(377Kb),l.txt(220Kb),m.txt(850Kb)
these files will contain the
concatenated data of all the
files with the same name from all the directories.
I need to do this recursively as there are 10000+ files in each directory.
Any help will be appreciated.
Regards,
Soumitra
------------------------------
Date: Tue, 11 Sep 2001 00:19:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: HELP: Capture a page?
Message-Id: <3B9D90CC.9A26AF42@earthlink.net>
Malcolm Dew-Jones wrote:
[snip]
> Please explain to us which part of the perl faq tells us how to render
> javascript from within perl, because this would be useful to do and I
> seem to have missed that part.
The faq contains answers to frequently asked questions. Most people can
figure out that to produce javascript from within perl, you do:
print "<script language=javascript><!--\n";
..... lots more print statements here
print "\n // --></script>";
Get it?
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Tue, 11 Sep 2001 05:06:41 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: HELP: Capture a page?
Message-Id: <slrn9pr6v1.9as.mgjv@verbruggen.comdyn.com.au>
On Tue, 11 Sep 2001 00:19:24 -0400,
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> Malcolm Dew-Jones wrote:
> [snip]
>> Please explain to us which part of the perl faq tells us how to render
>> javascript from within perl, because this would be useful to do and I
>> seem to have missed that part.
>
> The faq contains answers to frequently asked questions. Most people can
> figure out that to produce javascript from within perl, you do:
>
> print "<script language=javascript><!--\n";
> ..... lots more print statements here
> print "\n // --></script>";
>
> Get it?
I don't think the point was what you think it was. The OP doesn't want
to generate HTML, possibly containing some JavaScript, but more the
opposite.
I believe (too lazy to recall the original article) they were asking
to 'capture the displayed page from a browser'. It looks like what
they want is what the browser displays _after_ all the JavaScript
stuff has been done etc.
Now, to get the HTTP response is simple, and answered in the FAQ. How
to parse HTML is also answered in the FAQ. How to automate form
submissions is also answered int he FAQ. However, how to make your
custom webby client do the same thing as 'a browser' (which is too
vague anyway) with respect to JavaScript, Java, and all kinds of other
content, is of course not answered in the FAQ. The main reason is of
course that it ain't easy. Writing a full-fledged JavaScript parser is
a bit of work, and AFAIK hasn't been done for Perl, and maybe it
shouldn't be done.
The OP's question was stated unclearly, and unprecisely, which is why
there seems to be quite some confusion about what exactly was meant
(my interpretation may be wrong as well). If the OP still wants to
solve their problem, maybe they could clarify what _exactly_ they
want/need to do, bearing in mind that Perl normally doesn't interact
with a browser.
Martien
--
Martien Verbruggen |
Interactive Media Division | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd. | Universe and Reboot +++
NSW, Australia |
------------------------------
Date: 11 Sep 2001 04:57:33 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: How can I popup a info window in perltk, and have executuon continue?
Message-Id: <9nk5jt$mma$2@bob.news.rcn.net>
Stan Brown <stanb@panix.com> wrote:
> I have a perlTK script which does a (potenialy long) db query. I would like
> to popup n information window to advise the user that this may take a
> whi;e. I would like this window to popup, and have the main executuin
> return to the TK mainloop. I will dismiss this opoup when the process is
> done. Or the user can dismiss it.
> The only way I see to do this is to spawn a child process. Is this really
> necessary? is there a simpler way?
Just create a Tk::Toplevel child of your main window and display your
progress information there.
------------------------------
Date: Tue, 11 Sep 2001 03:46:28 GMT
From: bis@world.std.com (Adi Inbar)
Subject: How do you use <> and @ARGV with 4nt?
Message-Id: <GJHBtH.BAF@world.std.com>
It looks like @ARGV doesn't work with 4NT.
I tried to run a Perl script that I wrote on a Unix system on a
Windows 2000 system. I invoked the script at the 4NT 3.02B command
prompt, and the line
my @input = <>;
produced this error:
Can't open %*: Invalid argument at E:\Data Files\Perl\ex6-3.pl line 6.
I added a line to print the contents of @ARGV, and sure enough, the
result was "%*". @ARGV contains %* whether I supply command line
arguments or not. I tried invoking the script from the Windows 2000
command prompt, and it did what it was supposed to do. So, apparently
the problem is that 4NT passes %* to @ARGV no matter what you put on
the command line. Is there a solution or workaround? I'd really hate
to have to use Windows 2000's idiot command prompt instead of 4NT.
(Are there any 4NT newsgroups? I couldn't find any...)
------------------------------
Date: Mon, 10 Sep 2001 20:36:54 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: how to get the length of string
Message-Id: <9njqci$hd6$1@nntp9.atl.mindspring.net>
"Jon Ericson" <Jon.Ericson@jpl.nasa.gov> wrote in message
news:86elpfav2x.fsf@jon_ericson.jpl.nasa.gov...
> "Admin UsePad" <spam@funnybytes.com> writes:
>
> > 2 days ago,.. I was asking myself the same question,...
> > I tried something for the fun,..
> >
> > $lenght = lenght($string);
> >
> > It worked!
>
> I find that hard to believe:
>
> $ perl -e '$string="Hi!\n"; $lenght = lenght($string);print $lenght'
> Undefined subroutine &main::lenght called at -e line 1.
>
I expect the OP would find the diagnostics more helpful if the word "length"
were spelled correctly.
Bill Segraves
Auburn, AL
------------------------------
Date: Tue, 11 Sep 2001 04:17:50 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to get the length of string
Message-Id: <slrn9pqtv4.3h4.tadmc@tadmc26.august.net>
Admin UsePad <spam@funnybytes.com> wrote:
>2 days ago,.. I was asking myself the same question,...
>I tried something for the fun,..
>
>$lenght = lenght($string);
>
>It worked!
I gotta say that I don't believe you there. Looks like a
syntax error from where I'm sitting...
>How do I get rid of this jeopardy quoted text?
Delete it with a program called an "editor".
You've managed to work in 3 of the "bad things to do" mentioned in:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
Please take a moment to look that over, it will help you get
answers to your Perl questions.
>I'm using Outlook
That's too bad.
[ snip *more* Jeopardy-quoted text...]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 10 Sep 2001 19:59:52 -0700
From: Paul Spitalny <pauls_spam_no@pauls.seanet.com>
Subject: how to substitute letters within a string
Message-Id: <3B9D7E28.FECFE14B@pauls.seanet.com>
Hi,
I wish to substitute any occurrences of an uppercase I in a variable
with the lower case i. I am familiar with using:
s/I/i/g;
but this operates on the standard input $_
whereas I have a variable ( $fred) who's value is a string with
possible occurrences of "I" within it. SO, how do I get the substitute
command to work on $fred ??
Any ideas?
Thanks
Paul
--
To respond to this posting, remove -nospam- from my email address.
Sorry for the inconvenience
------------------------------
Date: Tue, 11 Sep 2001 03:01:45 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: how to substitute letters within a string
Message-Id: <slrn9pr0ch.1uk.tim@vegeta.ath.cx>
Me parece que Paul Spitalny <pauls_spam_no@pauls.seanet.com> dijo:
> Hi,
> I wish to substitute any occurrences of an uppercase I in a variable
> with the lower case i. I am familiar with using:
>
> s/I/i/g;
>
> but this operates on the standard input $_
>
> whereas I have a variable ( $fred) who's value is a string with
> possible occurrences of "I" within it. SO, how do I get the substitute
> command to work on $fred ??
$fred =~ s/I/i/g;
See `perldoc perlop` under 'Binding Operators'.
--
Me? Lady, I'm your worst nightmare -- a pumpkin with a gun.
-- Mervyn Pumpkinhead, The Sandman
------------------------------
Date: Mon, 10 Sep 2001 20:09:48 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: how to substitute letters within a string
Message-Id: <3B9D807C.80EA030E@stomp.stomp.tokyo>
Paul Spitalny wrote:
> I wish to substitute any occurrences of an uppercase I in a variable
> with the lower case i. I am familiar with using:
> s/I/i/g;
> but this operates on the standard input $_
> whereas I have a variable ( $fred) who's value is a string with
> possible occurrences of "I" within it. SO, how do I get the substitute
> command to work on $fred ??
$fred =~ tr/I/i/;
Godzilla!
--
Looking up [pauls.seanet.com]
Server: krim.seanet.com
Address: 199.181.164.11
*** krim.seanet.com can't find pauls.seanet.com: No response from server
[End Query]
Error accessing name server.
Reasons may include:
Invalid domain name.
MX records not found for this domain.
Name server not responding correctly or off-line.
------------------------------
Date: Mon, 10 Sep 2001 20:36:20 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: how to substitute letters within a string
Message-Id: <3B9D86B4.1711DB5C@stomp.stomp.tokyo>
Godzilla! wrote:
> Paul Spitalny wrote:
(snipped)
> > I wish to substitute any occurrences of an uppercase I in a variable
> > with the lower case i. I am familiar with using:
> > s/I/i/g;
> $fred =~ tr/I/i/;
Godzilla!
--
GODZILLA DOS BENCHMARK:
_______________________
test1.pl
________
#!perl
$godzilla = "GodzIlla Is an Igenious InventIve InnovatIve Perl Programmer";
$godzilla =~ tr/I/i/;
exit;
test2.pl
________
#!perl
$godzilla = "GodzIlla Is an Igenious InventIve InnovatIve Perl Programmer";
$godzilla =~ s/I/i/g;
exit;
PRINTED RESULTS:
________________
C:\APACHE\USERS\TEST>godzilla -N10 perl test1.pl
Average Time: 50 ms
C:\APACHE\USERS\TEST>godzilla -N10 perl test2.pl
Average Time: 77 ms
BENCHMARK TESTING:
__________________
#!perl
print "Content-type: text/plain\n\n";
use Benchmark;
print "Run One:\n\n";
&Time;
print "\n\nRun Two:\n\n";
&Time;
print "\n\nRun Three:\n\n";
&Time;
sub Time
{
timethese (1000000,
{
'name1' =>
'$godzilla = "GodzIlla Is an IgenIous InventIve InnovatIve Perl Programmer";
$godzilla =~ tr/I/i/;',
'name2' =>
'$godzilla = "GodzIlla Is an IgenIous InventIve InnovatIve Perl Programmer";
$godzilla =~ s/I/i/g;',
} );
}
PRINTED RESULTS:
________________
Run One:
Benchmark: timing 1000000 iterations of name1, name2...
name1: 1 wallclock secs ( 2.47 usr + 0.00 sys = 2.47 CPU) @ 404858.30/s
name2: 12 wallclock secs (11.42 usr + 0.00 sys = 11.42 CPU) @ 87565.67/s
Run Two:
Benchmark: timing 1000000 iterations of name1, name2...
name1: 2 wallclock secs ( 2.47 usr + 0.00 sys = 2.47 CPU) @ 404858.30/s
name2: 12 wallclock secs (11.37 usr + 0.00 sys = 11.37 CPU) @ 87950.75/s
Run Three:
Benchmark: timing 1000000 iterations of name1, name2...
name1: 2 wallclock secs ( 2.47 usr + 0.00 sys = 2.47 CPU) @ 404858.30/s
name2: 12 wallclock secs (11.31 usr + 0.00 sys = 11.31 CPU) @ 88417.33/s
------------------------------
Date: Tue, 11 Sep 2001 10:53:08 +0930
From: "Matthew Frick" <mfrick@chariot.net.au>
Subject: Re: mysql connection.
Message-Id: <3b9d669e$1_7@news.chariot.net.au>
Thanks for your swift response guys.
I will be looking at both of those things.
ohh yeah and I am writing in perl which is why the post was in this
newsgroup.
"Matthew Frick" <mfrick@chariot.net.au> wrote in message
news:3b9d5072$1_6@news.chariot.net.au...
> Can anyone give me a clue as to what I need to do to go about getting a
> connection to a mysql db (on a lynix server) from an NT server?
>
> Thanks in advance.
>
> Matthew Frick.
>
>
>
------------------------------
Date: 10 Sep 2001 21:45:45 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: Probelm with undefined atgumnets
Message-Id: <9njqc9$e2m$1@panix2.panix.com>
In <9nj09f$bum$1@mamenchi.zrz.TU-Berlin.DE> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>According to Stan Brown <stanb@panix.com>:
>> A kind member of this group showed me a neat trick to print out the
>> arguments to a given function. It goes like this:
>>
>> join ', ', map { "Arg$_ ->$_[$_]<-" } 0 .. $#_;
>>
>> This works great _except_ when I pass in undef for an argumentm then I get
>> a warning about concatenating an unitliazed variable.
>>
>> How can I improve thsi to allow for this case?
> join ', ', map "Arg$_ " . ( defined $_[$_] ? "->$_[$_]<-" : '-undef-'),
> 0 .. $#_;
>Or switch off the offending warning locally, but then you won't see
>the difference between "" and undef.
Cool!
Thnaks for the help!
------------------------------
Date: Tue, 11 Sep 2001 05:01:06 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: recognize MS Windows with perl
Message-Id: <3b9d9943.8816028@news.bright.net>
Alex Hart <news@althepal#nospam#.com> wrote:
> What is the best way to determine whether my program is being run on a
> MS Windows box? Is there a sure fire way?
Parse `ver`
- jonadab
------------------------------
Date: Mon, 10 Sep 2001 21:35:55 -0400
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: Re: references, slices, voodoo
Message-Id: <3b9d6a7b$1$fuzhry$mr2ice@news.patriot.net>
In <qo67ptkej2sqqfkm9imteu4hohmrca3gfk@4ax.com>, on 09/03/2001
at 03:12 PM, Bart Lateur <bart.lateur@skynet.be> said:
>As for the array slice:
> @ary[2, 4] = @ary[4, 2];
>is functionally equivalent to
> ($ary[2], $ary[4]) = ($ary[4], $ary[2]);
That doesn't explain the @ and $ back-to-back in
@$array[$i,$j] = @$array[$j,$i] unless $i == $j; # ???
$array($i,$j) is a slice of @array, but what is @$array?
--
-----------------------------------------------------------
Shmuel (Seymour J.) Metz, SysProg and JOAT
Atid/2
Team OS/2
Team PL/I
Any unsolicited commercial junk E-mail will be subject to legal
action. I reserve the right to publicly post or ridicule any
abusive E-mail.
I mangled my E-mail address to foil automated spammers; reply to
domain acm dot org user shmuel to contact me. Do not reply to
spamtrap@library.lspace.org
-----------------------------------------------------------
------------------------------
Date: 11 Sep 2001 02:46:22 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: references, slices, voodoo
Message-Id: <slrn9pqukb.2fv.damian@puma.qimr.edu.au>
Shmuel (Seymour J.) Metz chose Mon, 10 Sep 2001 21:35:55 -0400 to say this:
>In <qo67ptkej2sqqfkm9imteu4hohmrca3gfk@4ax.com>, on 09/03/2001
> at 03:12 PM, Bart Lateur <bart.lateur@skynet.be> said:
>
>>As for the array slice:
>
>> @ary[2, 4] = @ary[4, 2];
>
>>is functionally equivalent to
>
>> ($ary[2], $ary[4]) = ($ary[4], $ary[2]);
>
>That doesn't explain the @ and $ back-to-back in
> @$array[$i,$j] = @$array[$j,$i] unless $i == $j; # ???
>
>$array($i,$j) is a slice of @array, but what is @$array?
>
No, @array[$i,$j] is a slice -- see the perldata manpage.
@$array is another kind of beast -- equivalent to @{$array}, where the @{}
implies that $array is a reference to an array. Not very helpful unless $array
is in fact a reference to an array. In this case @$array[$i,$j] is equivalent
to:
@{$array}[$i, $j]
which is equivalent to:
( $array->[$i], $array->[$j] )
or
( ${$array}[$i], ${$array}[$j] )
or
( $$array[$i], $$array[$j] )
See perlref, perlreftut and perldsc.
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker, # damian@qimr.edu.au
------------------------------
Date: 10 Sep 2001 22:32:00 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: references, slices, voodoo
Message-Id: <9nk0jg$806$1@charity.cs.utexas.edu>
In article <3b9d6a7b$1$fuzhry$mr2ice@news.patriot.net>,
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid> wrote:
>In <qo67ptkej2sqqfkm9imteu4hohmrca3gfk@4ax.com>, on 09/03/2001
> at 03:12 PM, Bart Lateur <bart.lateur@skynet.be> said:
>
>>As for the array slice:
>
>> @ary[2, 4] = @ary[4, 2];
>
>>is functionally equivalent to
>
>> ($ary[2], $ary[4]) = ($ary[4], $ary[2]);
>
>That doesn't explain the @ and $ back-to-back in
> @$array[$i,$j] = @$array[$j,$i] unless $i == $j; # ???
>
>$array($i,$j) is a slice of @array, but what is @$array?
No, $array($i,$j) is invalid Perl code, unless you intentionally do
some really goofy stuff involving globs to make it valid.
@$array is, in fact, an array. It's the array that $array is a
reference to. @$array[1,2,3] would be a slice of that array.
Just remember that you can put an expression where you'd normally put a
variable name (not including the "$" or whatever). If you do that,
then instead of looking up the variable name in the symbol table, Perl
evaluates the expression and uses the expression's value (which should
be a reference) to indicate what variable should be operated on.
That means that this:
@x = 0 .. 9;
print @x, "\n";
does the same as this:
@x = 0 .. 9;
$ref_to_x = \@x;
print @$ref_to_x, "\n";
And since braces can be used for grouping, that last line could be
written like this:
print @{$ref_to_x}, "\n";
You can avoid the scalar variable altogether and do this
if you want:
@x = 0 .. 9;
print @{ \@x }, "\n";
For more info, do a "perldoc perlreftut" or "perldoc perlref".
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: Mon, 10 Sep 2001 19:45:19 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: start a script when a process exits
Message-Id: <3B9D7ABF.E4A5E01B@stomp.stomp.tokyo>
Luke Vanderfluit wrote:
(snipped)
> How do I get the exit of a process to trigger another process to run?
> Can it be done in perl?
You may do this in a stereotypical Perl 5 Cargo Cult manner or,
use a rather creative rogue method which annoys Sissified Geeks.
Three DOS based syntax for your dubious edification:
if (`perl exit.pl`) { exit; }
exit if `perl exit.pl`;
exit if `perl exit.pl` or die "Some Sissified Geek Screamed: $!";
First method, if (`perl exit.pl`) { exit; } is a very
typical safe and sane method although this method does
not trigger an exit if a system call fails. This method
will, however, exit upon "falling off the end." Is there
truly any difference? A program exits, regardless.
Last two methods are quite roguish and will cause many
Perl 5 Cargo Cultists to make the Sign Of The P, wig-out,
then most likely tug at their hair and scream, if not
toss temper tantrums and post copious complaint trolls.
My exit if `perl exit.pl`; works very nice and results
in perl core complaining. Add an or die for some humor.
Use of or die might trick Perl 5 Cargo Cultists into
thinking all is Perl Perl Land pleasant; she used or die.
Test scripts are below my internationally infamous signature
should you be inspired to range into the rogue region. I have
added a double exit simply to be doubly annoying. My double
exit also makes perl core stop its complaining. We women do
know well how to manage men and their boy toys.
Boys and their toys. Gurls and their curls, yes?
Godzilla! Queen Of Perl Heretics.
--
TEST SCRIPT:
____________
#!perl
print "Script Engaged\n\n";
exit if `perl exit.pl`;
exit;
EXIT.PL
_______
#!perl
open (EXIT, ">test.txt");
print EXIT "Successful Exit Call";
close (EXIT);
exit;
------------------------------
Date: Tue, 11 Sep 2001 04:36:47 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: start a script when a process exits
Message-Id: <slrn9pr56v.3lp.garry@zfw.zvolve.net>
On Tue, 11 Sep 2001 09:07:57 +0930, Luke Vanderfluit
<luke@chipcity.com.au> wrote:
> I want to start a script when a program terminates (triggered by the
> program exiting).
> more specifically:
> I am running linux. I have a prgram called wvdial that connects me to
> the internet.
> when it exits, I want to run a script (perl or other) that I have
> written.
>
> How do I get the exit of a process to trigger another process to run?
> Can it be done in perl?
Yes.
END { exec "other_script"; }
--
Garry Williams
------------------------------
Date: Tue, 11 Sep 2001 06:12:31 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: start a script when a process exits
Message-Id: <9nka0f$13eo$1@nntp1.ba.best.com>
>Luke Vanderfluit chose Tue, 11 Sep 2001 09:07:57 +0930 to say this:
>...
>I am running linux. I have a prgram called wvdial that connects me to
>the internet. when it exits, I want to run a script (perl or other)
>that I have written.
>
>How do I get the exit of a process to trigger another process to run?
>Can it be done in perl?
print localtime() . " $0 starting 'wvdial'\n";
$error_code = system "wvdial";
print localtime() . " 'wvdial' exited with error code $error_code\n";
if ($error_code == 0) { # Zero means no errors detected
system "wvdial-2"; # Run second script
print localtime() . " $0 finished\n";
} else {
die "Aborting";
}
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Tue, 11 Sep 2001 04:55:08 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: strange Win32 IO behavior!
Message-Id: <3b9d95bb.7912296@news.bright.net>
youradmirer@onebox.com (Newbie) wrote:
> While playing with dupping filehandles, I was puzzled by strange win32
> io behavior. The following few lines work fine on Linux as intended
> (captured STDOUT & STDERR and send the output to a file), but not on
> Win32. The output of a "dir" command was sent directly the screen
> which shouldn't be expected. Could anyone with Win32 experience
> explain? Thanks.
For starters, Windows doesn't have a standard error stream per
se in the same sense that Unix does. Traditionally in DOS
culture, fatal errors are sent straight to the console, and
anything less is logged to a file unless the user needs to
interact with it. Windows augmented this with a tendency to
use annoyingly-many superfluous dialogue boxes instead of
logging the trivial errors to a file. The tendency to use
annoyingly-many dialogue boxes reached its peak in Win3.1
and has fortunately been in decline since circa 1995.
Most C compilers (in DOS and subsequently in Windoze) solve
the lack of a real stderr by sending it to the console window
directly, which works fine for short fatal error messages but
is totally inappropriate for warnings, since it is abnormally
difficult for the user to redirect. (It *is* possible, contrary
to popular belief, but it requires a wrapper app; there's no
magic command-line syntax for it, unless you get a bash port
or 4DOS or something.) Perl does whatever the C compiler does
that was used to compile Perl.
The specifics of your script are beyond me; I've never dealt
with fork or select in Perl.
You might try running it out of bash instead of COMMAND.COM,
to see if that makes any difference to how stderr is treated.
If you don't have bash for Windows and want it, try cygwin.
- jonadab
------------------------------
Date: Mon, 10 Sep 2001 23:12:37 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: terminal Emulator
Message-Id: <3B9D8125.BD681697@earthlink.net>
Doyle Rivers wrote:
[snip]
> Forgive the incomplete description of my problem. Here is a bit more
> detail:
>
> I would like to be able to connect to a telnet server with full
> interaction (as if I were running a unix/dos telnet session), having
> all data from the server printed to the screen as I receive it, and
> sending all data I input (via STDIN)to the server. Further more I
> would like to be able to invoke scripts to automate various task while
> connected. These scripts would basically be expect code.
Then use either Expect.pm, or the original expect program.
> If such an emulator is not already in existence Would using pipes
> to/from the telnet command (win32 or unix) be effective for this?
Pipes to/from the telnet command would likely not be effective, since
the telnet command tries to change terminal settings [like cooked/raw
mode, echo/noecho, etc]. You need to use a real psuedo terminal to
interact with it, like Expect.pm provides.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Tue, 11 Sep 2001 04:35:55 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: terminal Emulator
Message-Id: <9nk4bb$1322$1@nntp1.ba.best.com>
In article <3b9c4273.5544943@news.cableone.net>,
Doyle Rivers <doylerivers@home.com> wrote:
>Does anyone know of an existing perl terminal emulator program?
>I would like to be able to connect to a server via telnet and run
>various scripts, however the Net::Telnet module is not sufficient for
>my needs.
>
>Anyway, if you know of a perl terminal emulator out there please let
>me know, it will save me a lot of time having to figure out how to
>write one myself.
A terminal emulator accepts characters and ESCape sequences and puts
them on the screen. You don't need perl to do that.
But I'm guessing that you aren't looking for a generic terminal
emulator, but something more specific. Such as something that
knows how to interpret VT100 ESCape sequences, recognize when a
particular strings is placed at a particular row & column address,
and then send an appropriate response.
You could use Expect.pm to look for a regular expression matching
ESCape + left-square-bracket + (digits) + semicolon + (digits) + capital-H
where the "(digits)" match the row and column of interest.
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: 10 Sep 2001 23:53:31 -0700
From: perlquestion@hotmail.com (Admin T.)
Subject: Where Can I Find the path to the desktop on Win9X/2K and NT?
Message-Id: <c58c442c.0109102253.13af1d4@posting.google.com>
I never thought something so simple be so hard. Is there a ENV.
variable that I can access in Perl that contains the path to the
desktop? Is there any where I can find the path to the desktop?
Thankful for any help;
-A
------------------------------
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 1729
***************************************