[7119] in Perl-Users-Digest
Perl-Users Digest, Issue: 744 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 18 15:18:03 1997
Date: Fri, 18 Jul 97 12:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 18 Jul 1997 Volume: 8 Number: 744
Today's topics:
Re: ? typeglob of a hash in a hash. woo! (Charles DeRykus)
Back button <dantin@icp.grenet.fr>
Re: How to embed a gif source in perl script ?? <sehynes@cise.ufl.edu>
Re: Merging large complex data structures <che@imsa.edu>
Re: online tutorial (Abigail)
Re: Passing hash of hashes from subroutine? (Jeff Stampes)
Re: regular expressions help needed :-) <eglamkowski@mathematica-mpr.com>
Re: Retrieving multiple hash elements at once (Chris Schleicher)
Re: Seeing if a pipe worked (Charles DeRykus)
Solution (+ patches): perldb & emacs under Windows 95/N <soup@ampersand.com>
Re: Sorting, case-insensitive...How? (Andrew M. Langmead)
Re: Strings (Even Holen)
Re: subroutine arguments <sfairey@adc.metrica.co.uk>
Re: Trimming leading and trailing spaces. (Jeff Fisher)
webfinder script needed (Mark Kilarjian)
Re: Where are the Win95 ports? (Chris Schleicher)
Re: Why: @{$_[0]} for arg in subroutine (Sajjad Lateef)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 17 Jul 1997 18:12:50 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: ? typeglob of a hash in a hash. woo!
Message-Id: <EDH6LF.48C@bcstec.ca.boeing.com>
In article <33CD1924.41C67EA6@lauren.surfsouth.com>,
Chad <cm0x1a@lauren.surfsouth.com> wrote:
> I call myself a semi-well-versed perl theologean, but I'm stumped.
>
> My paradox inside an enigma within a riddle involves a typeglob of
> a hash of a hash.
>
>
> I want
>
> $idhash{$id}{"element2"}
>
> to be a synonym of
>
> $idhash{$id}{"element1"}
>
>
> Just to show how interesting this is, $idhash{$id){"element1"} is
> [tense?] a list, which isn't yet defined anyway, in a way. I could
> push a dummy value into it, if it'll make things easier (pronounced
> "possible").
>
There have been some reasonable approaches already mentioned but
they're too tame :)
Of course, you'd have to be able to parameterize element2, e.g,
*element2 = \element1;
Now $element2 will have the constant value "element1" and
won't compile if there are any further assignments to
$element2.
This makes $idhash{$id}{element1} and $idhash{$id}{$element2}
synonymns.
But, I'd advise a tamer approach :)
HTH,
--
Charles DeRykus
ced@carios2.ca.remove_this.boeing.com # remove you know what
------------------------------
Date: Wed, 16 Jul 1997 10:17:45 +0200
From: Joelle D'Antin & Nicolas Gregoire <dantin@icp.grenet.fr>
Subject: Back button
Message-Id: <33CC83A9.23B8@icp.grenet.fr>
Hi,
here a question that a lot of people asked before me but:
How to do a back button (like the one in Netscape, not a href) in my
HTML page.
Thanks
------------------------------
Date: Thu, 17 Jul 1997 12:03:41 -0400
From: sean hynes <sehynes@cise.ufl.edu>
To: lmfhava@lmf.ericsson.se
Subject: Re: How to embed a gif source in perl script ??
Message-Id: <33CE425D.62C8BFA4@cise.ufl.edu>
Harri Vainio wrote:
> Hey!
>
> Got this job from my boss, and I'm a bit puzzled.
>
> I have to do a perl script (been there) that creates a page (done
> that)
> so that the single image on the page would be embedded in the perl
> source (never done that).
>
> My idea would be to include the hex code of the image(Gif) in the perl
>
> source, but how to tell this to the browser ?? I would be filled with
> thanx to anyone with any information to my problem...
>
> Harri Vainio
> Ericsson LMF/T/FI, Finland
> lmfhava@lmf.ericsson.se
I'm kinda new at this stuff. But can't you just put the image on the
server where the perl code resides and provide a link to it in the HTML
page that the perl script returns, same as you would in a regular home
page? (i.e. <IMG SRC="images/image.gif">)
------------------------------
Date: 17 Jul 1997 16:09:34 -0500
From: Ben Gertzfield <che@imsa.edu>
Subject: Re: Merging large complex data structures
Message-Id: <y8sg1tdv10x.fsf@imsa.edu>
>>>>> "Chris" == Chris Sherman <sherman@unx.sas.com> writes:
Chris> Sometimes, I just don't see it... I want to merge two
Chris> complex data structures into a new variable.
(snip)
Chris> So, in effect, I want to do:
Chris> %TV = %TV1 + %TV2; # thinking of '+' as a union operator
Try %TV = (%TV1, %TV2);
When you refer to hashes in a list context, they flatten out into a
regular list. This example would make one extra-long list out of %TV1
and %TV2, and then assign all that back into %TV.
--
Brought to you by the letters P and J and the number 9.
"Tahiti is not in Europe." -- Sneakers
Ben Gertzfield <http://www.imsa.edu/~wilwonka/> Finger me for my public
PGP key. I'm on FurryMUCK as Che, and EFNet and YiffNet IRC as Che_Fox.
------------------------------
Date: Fri, 18 Jul 1997 15:17:22 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: online tutorial
Message-Id: <EDIt4y.yo@nonexistent.com>
Randal Schwartz (merlyn@stonehenge.com) wrote on 1413 September 1993 in
<URL: news:8cwwmtn8uq.fsf@gadget.cscaper.com>:
++ >>>>> "Matthew" == Matthew Burnham <danew@enterprise.net> writes:
++
++ Matthew> print '#' . join("\n#", @lines); is one of many ways.
++
++ Although I would find:
++
++ print map "#$_", @lines;
But that doesn't add the new lines. You could try
print map {"#$_\n";} @lines;
but that adds a newline at the end, something the join doesn't do.
You could do:
{local $" = "\n#"; print "#@lines";}
but I'm not sure if that's very readable.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=$]*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: 17 Jul 1997 22:11:50 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: Passing hash of hashes from subroutine?
Message-Id: <5qm5b7$8pb$1@neocad.com>
Trey Valenta (trey@zipcon.net) wrote:
: to be filled globally but when I declare the hash in the beginning like
: my %hash;
: I have a feeling I only declare a single depth hash and I can't pass it.
: Can someone point me in the right direction since the book isn't
: helping?
Whether it's a my or a global, %hash only declares a single
depth structure. If you have carefully created your ultimate
data structure though, you can return \%hash no matter how
many levels deep it is.
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Thu, 17 Jul 1997 17:48:34 -0400
From: the count <eglamkowski@mathematica-mpr.com>
Subject: Re: regular expressions help needed :-)
Message-Id: <33CE9332.622C@mathematica-mpr.com>
Tad McClellan wrote:
> Seems to work for me with the complete program posted below (you
> really should try and post a real program that illustrates the problem
> you are having).
Well, I dunno, but it wasn't working. Now it is. (It always does
work when someone else is looking at it ;-)
Actually, I came across a case I wasn't expecting, where it might
be [# ...] (the extra # being the new twist), as well as another
problem where there may be some non-\w character in the word (like
a '&' or a '*' or '+'). I went back and re-read the relevent sections
of Programming Perl several times, and finally came up with (using also
your comments in your reply):
s|\[(#)?(\s*)(<i>)?(\S+)(\s*)([^\]]*)\]|\[$1<tt>$2$3$4$5$6</tt>\]|g;
Which seems to be working ok. Or at least, I haven't noticed any
problems yet! ;-)
Sheesh - regular expression are so useful, yet so annoying...
------------------------------
Date: 17 Jul 1997 14:39:10 -0700
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: Retrieving multiple hash elements at once
Message-Id: <5qm3du$qjs@psychotix.cs.uoregon.edu>
In article <5qe31m$q0a$1@news.or.intel.com>,
Scott Grosch <grosch@ichips.intel.com> wrote:
>Is there a way to do that with less typing? For example, something like:
>
>@_ = $$ref{ (one, two, three) };
Yup:
@_ = @_{$ref}{one,two,three};
--chris
--
Chris Schleicher Office: 541/346-3998
Univ of Oregon CIS GTF email: chrissch@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~chrissch/
------------------------------
Date: Thu, 17 Jul 1997 20:03:14 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Seeing if a pipe worked
Message-Id: <EDHBpE.Dx8@bcstec.ca.boeing.com>
In article <33CE349C.41C6@cd.co.uk>, Philip M Jones <philip@cd.co.uk> wrote:
>
> I am doing a pipe in perl which looks like this:
>
> $prostar="pro-xm -batch";
> open(PROSTAR,"|$prostar")
>
> Now I would like to see if the pipe has worked so I thought that
>
> open(PROSTAR,"|$prostar") or die "Cannot find prostar";
>
> may work. I get a fail:
>
> Can't exec "pro-xm": No such file or directory at sincurvemesh.pl line
> 89
>
> but I get no die. What do I need to do?
>
The problem is that a piped open actually just forks
another process and will fail only if the fork fails.
You could sneak in an executable (-x) test perhaps:
die $! unless -x $prostar and open(PROSTART,"|$prostar);
HTH,
--
Charles DeRykus
ced@carios2.ca.remove_it.boeing.com # remove you know what
------------------------------
Date: 17 Jul 1997 18:23:00 -0400
From: Doug Campbell <soup@ampersand.com>
Subject: Solution (+ patches): perldb & emacs under Windows 95/NT
Message-Id: <wklo3548u3.fsf@ampersand.com>
Summary
-------
Here I show how to use the perl debugger with emacs under Windows 95
and/or NT. See "Directions" below to get started with this.
Config Mgmt. Issues
-------------------
I had to patch both perl5db.pl and perldb.el. Because perl5db.pl is
included with the perl distribution, I assume that sending this
message to the perl porters will suffice to reach the official
maintainer(s).
However, I cannot determine who is currently supporting perldb.el.
Can anyone help me find the correct maintainer so that this can be
patched for the next release (wherever and whenever that is)?
Directions
----------
The following directions work for perl 5.004_01 and emacs 19.34.2
binary releases for Windows 95/NT. These can be obtained from:
perl:
ftp://ftp.digital.com/pub/plan/perl/CPAN/authors/Gurusamy_Sarathy/perl5.00401-bindist02-bc.tar.gz
emacs:
ftp.cs.washington.edu/pub/ntemacs/latest/i386/emacs-19.34.1-bin.tar.gz
ftp.cs.washington.edu/pub/ntemacs/latest/i386/emacs-19.34.1-lisp.tar.gz
ftp.cs.washington.edu/pub/ntemacs/latest/i386/emacs-19.34.2-update.zip
1. Set the following emacs parameters (in your .emacs or whatever)
(load "compile" t t)
(setq compilation-error-regexp "\\([^ :\n]+\\(: *\\|, line \\|(\\)[0-9]+\\)\\|\\([0-9]+ *of *[^ \n]+\\|[^ \n]+ \\(at \\)*line [0-9]+\\)")
(setq binary-process-output t)
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)
2. In <perl5lib>/perl5db.pl, apply this patch:
*** perl5db.FCS Wed Jul 16 19:16:13 1997
--- perl5db.pl Wed Jul 16 19:14:47 1997
***************
*** 297,303 ****
}
# Around a bug:
! if (defined $ENV{OS2_SHELL} and ($emacs or $ENV{WINDOWID})) { # In OS/2
$console = undef;
}
--- 297,303 ----
}
# Around a bug:
! if ((defined $ENV{OS2_SHELL} or $^O eq 'MSWin32') and ($emacs or $ENV{WINDOWID})) { # In OS/2
$console = undef;
}
3. In perldb.el, apply this patch:
*** perldb.el.FCS Tue Jul 15 16:15:07 1997
--- perldb.el Thu Jul 17 16:22:15 1997
***************
*** 234,240 ****
(progn
(let* ((first-colon (string-match ":" string 2))
(second-colon
! (string-match ":" string (1+ first-colon))))
(setq perldb-last-frame
(cons (substring string 2 first-colon)
(string-to-int
--- 234,247 ----
(progn
(let* ((first-colon (string-match ":" string 2))
(second-colon
! (string-match ":" string (1+ first-colon)))
! (third-colon
! (string-match ":" string (1+ second-colon))))
! (if (and (not (null third-colon))
! (= first-colon 3))
! (progn
! (setq first-colon second-colon)
! (setq second-colon third-colon)))
(setq perldb-last-frame
(cons (substring string 2 first-colon)
(string-to-int
***************
*** 592,598 ****
(read (current-buffer)))
(buffer-substring (point)
(progn
! (skip-chars-forward "^ :,\n\t(")
(point)))))
(define-key ctl-x-map "~" 'perldb-next-error)
--- 599,606 ----
(read (current-buffer)))
(buffer-substring (point)
(progn
! (skip-chars-forward "^ ,\n\t(")
! (skip-chars-backward ":")
(point)))))
(define-key ctl-x-map "~" 'perldb-next-error)
What the Patches Do
-------------------
In step 1 above, the first two lines of lisp allow compile mode to
handle perl style errors. The next line allows ^Z characters to be
passed from perl to emacs (these otherwise cause an apparent hang
because text mode stops data flow). The last line tries to remove
^M's from the output, but it doesn't appear to be a complete success.
The patch to perl5db.pl in step 2 above makes perl use stdout for
debugger messages instead of a console if it's running on Windows
under emacs.
The patch to perldb.el in step 3 above allows emacs to handle Windows
style file paths, namely those that start with a drive letter and a
colon.
Enjoy,
Doug Campbell
soup@ampersand.com
------------------------------
Date: Thu, 17 Jul 1997 19:04:59 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Sorting, case-insensitive...How?
Message-Id: <EDH90C.49u@world.std.com>
Doug Seay <seay@absyss.fr> writes:
>Benjamin Kyan wrote:
>> How about this instead:
>>
>> sub my_way { lc($a) cmp lc($b); }
>>
>> It's a lot more compact and does the same thing. (I think...)
>Your way works better. You don't make copies of $a and $b, you use lc()
>which respects LOCALE settings
It is still has to be making a copy. It just isn't assigning it to a
named variable. And it is still performing N * log(N) lowercasing
operations.
Which makes it better than Brian wrote, but there are still some
advantages to the one listed in the FAQ. <URL:http://www.perl.com/
CPAN/doc/manual/html/pod/perlfaq4/How_do_I_sort_an_aray_by_anyth.html>
and the man pages.
--
Andrew Langmead
------------------------------
Date: 18 Jul 1997 18:14:20 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: Strings
Message-Id: <slrn5svcgb.na6.evenh@ra.pvv.ntnu.no>
In article <33cfa1c4.0@news.total.net>, Brian Shepard wrote:
>I am trying to evaluate a string that contains a variable. For example:
>
>
>$lcuser = 'Frank';
>
>$x = "search.pl?user=$lcuser";
>
>print "x=" . $x;
>
>I want the output to be: x=search.pl?user=Frank
The code snippet you gave does give the output you want... Please
specify what happens in your end or what goes wrong...
>I have tried using the eval($x) function, but it was returning a empty
>string.
No need to use eval in the problem you've stated here...
Regards,
Even Holen
--
<>< Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/ :-)
------------------------------
Date: Fri, 18 Jul 1997 14:56:58 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Uwe Lammers <Uwe.Lammers@astro.estec.esa.nl>
Subject: Re: subroutine arguments
Message-Id: <33CF7629.79E762CB@adc.metrica.co.uk>
Uwe Lammers wrote:
> Hi,
>
> a newbie question for you experts out there. I want to have a
> subroutine which receives two arguments (the last of which is
> optional),
> a list of strings and one additional string:
>
> sub f {
> (@list, $string) = @_;
>
The @list will swallow up everything from @_ leaving nothing for
$string.
> print "1: @list\n";
> print "2: $string\n";
> }
>
> When I call:
>
> &f(('a', 'b'), 'c')
>
> I expect to see:
>
> 1: a b
> 2: c
>
> but I get:
>
> 1: a b c
> 2:
>
Not surprising.
> Suggestions? (as said, $string should be optional, i.e.,
> &f(('a', 'b')) -> 1: a b 2: )
>
You want to pass a reference to the array through to the function, i.e:
@list = ( 'a', 'b', 'c' );
f( \@list, 'something' );
f( \@list );
sub f {
my( $ref, $string ) = @_;
print ........etc
}
Look at the perlref manpage for further details, the above is not really
a very nice way
to do it as you will get an undef $string when none is passed whichwill
generate warnings
depending on your runtime options.
Simon
------------------------------
Date: 17 Jul 1997 04:12:21 GMT
From: rzxtlg@dogbert.ies-energy.com (Jeff Fisher)
Subject: Re: Trimming leading and trailing spaces.
Message-Id: <slrn5sr6t5.3sb.rzxtlg@dogbert.ies-energy.com>
On Wed, 16 Jul 1997 23:42:51 GMT, rkn said:
> Is there a simole way to trim leading and trailing spaces?
>
> Note: the string could have embeded spaces. These are required.
>
> Thanks in advance.
s/^\s*(\S+.*\S)\s*$/$1/;
Untested, of course.
--
Jeff Fisher | Opinions expressed within this
UNIX Sys Admin - IES Industries | document are strictly my own.
http://opus.ies-energy.com/jeff/ |
------------------------------
Date: 18 Jul 1997 17:00:43 GMT
From: mkilar@newshost.li.net (Mark Kilarjian)
Subject: webfinder script needed
Message-Id: <5qo7fr$akk$1@news01.li.net>
Hello All -
I'm a relative newcomer to perl, and need a script to locate and identify
all of the web servers on my network. Since many users have created their own
web pages using iss, and most of them are not registered in my dns, I'd need
to do a blanket scan such that port 80 is scanned on a range of addresses, say
145.5.1.1 to 145.5.1.255, and the home page string is returned and saved.
I could thereby create a list of web servers on my net by address, and the
category of each based on the socket call to 80.
If anyone knows of such a utility, please let me know. Remember, I must search
by range of addresses, due to the lack of dns entries.
thanks very much.
--
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Mark Kilarjian _
e-mail: mkilar@li.net IHS
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
------------------------------
Date: 16 Jul 1997 10:57:08 -0700
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: Where are the Win95 ports?
Message-Id: <5qj21k$jb1@psychotix.cs.uoregon.edu>
In article <33CA24D0.78B3@see.my.signature.file>,
William Smith <wism@see.my.signature.file> wrote:
>Does anyone have info on where there are
>Win95 ports available?
http://www.activeware.com
http://www.perl.com/CPAN/ports/win95
Hope this helps,
--Chris
--
Chris Schleicher Office: 541/346-3998
Univ of Oregon CIS GTF email: chrissch@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~chrissch/
------------------------------
Date: 18 Jul 1997 02:23:13 GMT
From: sajjad@uic.edu (Sajjad Lateef)
Subject: Re: Why: @{$_[0]} for arg in subroutine
Message-Id: <5qmk2h$2ec4$1@piglet.cc.uic.edu>
I realized a few hours after posting the my problem was the array
initialization - I should have used () instead of []. Duh!
Part of the learning process, I guess. Apologies for wasting the
bandwidth.
Thanks all,
Sajjad
]
Sajjad Lateef (sajjad@uic.edu) wrote:
: Hi,
: Check this out:
: #main
: my @color_array = [ 'Red', 'Blue', 'Yellow'];
: &callsub(@color_array);
: ...
: sub callsub {
: my @list = @{$_[0]};
: # mess with @list
: }
: Now, according to the Camel Book, I can do 'my @list = @_' and then I should
: be able to use @list. I just cannot do that! If I do that, then @list contains
: a hard reference of the type ARRAY(0x12345678).
: I can only use @list if I dereference $_[0] using @{...}.
: What am I doing wrong here? Since I am beginning perl programmer, it is
: something really small and dumb.
: perl is v5.002 on Irix 5.3 - I am using '-w' and 'use strict'.
: Any help is appreciated. I want to know why this is happening.
: Thanks,
: Sajjad
: sajjad@uic.edu
: --
: Sajjad Lateef http://www.eecs.uic.edu/~slateef/
: sajjad <at> acm.org
--
Sajjad Lateef http://www.eecs.uic.edu/~slateef/
sajjad <at> acm.org
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 744
*************************************