[7390] in Perl-Users-Digest
Perl-Users Digest, Issue: 1015 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 12 05:07:13 1997
Date: Fri, 12 Sep 97 02:00:27 -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, 12 Sep 1997 Volume: 8 Number: 1015
Today's topics:
Binary AND and OR in Perl (Tan Shao Yi)
Re: Binary AND and OR in Perl (Tom Grydeland)
Re: CGI: Installing "Adverts" <pittelli@ehsct7.envmed.rochester.edu>
Re: Converting text to Excel data with UNIX <kenlo@hk.super.net>
Declaring dynamically named lexical variables (Dan Sumption)
Re: Execution speed, looping <Gunnar.Evermann@dbag.ulm.DaimlerBenz.com>
Re: flock in Win32? <tlawallANTISPAM@concentric.net>
Globbing does not work on HP-UX 10.20 with perl 5.003 <bjoern_nordmann@hp.com>
Re: How to check if a file exits! <pittelli@ehsct7.envmed.rochester.edu>
Re: How to email text file (Jeff Stampes)
Re: Is there a simpler syntax for: defined $a && $a ne <pittelli@ehsct7.envmed.rochester.edu>
Re: make: *** File Makefile' has modification time in t <qdtcall@esb.ericsson.se>
Re: module installation.. (Michael Fuhr)
Re: Net::Whois unsetting $/? <ghowland@hotlava.com>
Re: NT 4.0 <pittelli@ehsct7.envmed.rochester.edu>
Re: Perl and Nt 4.0 <pittelli@ehsct7.envmed.rochester.edu>
Re: Perl Lib Path with Sybase Libraris (Martien Verbruggen)
Re: Recursive sorting <ajohnson@gpu.srv.ualberta.ca>
Re: returning hashes from sub (Dave Cross)
Re: Why don't my <<HERE documents work? Attempt #2! (brian d foy)
Re: Why don't my <<HERE documents work? Attempt #2! <rovf@earthling.net>
Re: Why don't my <<HERE documents work? Attempt #2! (Mike Heins)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Sep 1997 05:26:07 GMT
From: tansympp@pacific.net.sg (Tan Shao Yi)
Subject: Binary AND and OR in Perl
Message-Id: <5vajpf$6jh$1@newton.pacific.net.sg>
Hallo all. :)
Just a short question, may I know if anyone has managed to perform a
successfuly binary AND or OR operation on two binary numbers in Perl? :)
Something like: 10110100 AND 11111100 = 10110100
or even: 10110100 OR 11111100 = 11111100
Have given it a try with the "&" operator and it gives me an incorrect
output. :)
Has anyone had success in performing these operations on binary numbers? :)
Thanks. :)
Cheers,
Tan Shao Yi
------------------------------
Date: 12 Sep 1997 08:38:42 GMT
From: tom@mitra.phys.uit.no (Tom Grydeland)
Subject: Re: Binary AND and OR in Perl
Message-Id: <slrn61hvsi.ap9.tom@mitra.phys.uit.no>
On 12 Sep 1997 05:26:07 GMT,
Tan Shao Yi <tansympp@pacific.net.sg> wrote:
> Something like: 10110100 AND 11111100 = 10110100
> or even: 10110100 OR 11111100 = 11111100
You need to translate this representation to an (ordinary) integer,
using pack.
> Have given it a try with the "&" operator and it gives me an incorrect
> output. :)
& would either see your numbers as 10,110,100 (ten million +), or as the
string "10110100", neither of which is what you want.
> Has anyone had success in performing these operations on binary numbers? :)
Oh, yes.
> Tan Shao Yi
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: Thu, 11 Sep 1997 23:02:35 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
Subject: Re: CGI: Installing "Adverts"
Message-Id: <874036278.11828@dejanews.com>
It sounds like the server is treating your scripts as content/html.
If your web server allows CGI anywhere, it's likely that they must be
renamed *.cgi (but change only the actual CGI scripts, not the 'require'd
ones, to make life easier), in order to tell the server to `execute`
them.
If your web server doesn't allow CGI scripts everywhere, put them in your
actual cgi dir, typically cgi-bin, but i've also seen cgi-pg and some
others. You may still have to rename them to *.cgi.
Also make sure the first line points to the perl.exe (`which perl` in
shell) -Randy Pittelly
In article <5v69c1$gpu@bgtnsc03.worldnet.att.net>,
swspain@value1.com (Scott W. Spain) wrote:
>
> I'm hoping somebody here knows something about this script. The
> script is "Adverts" and can be found at:
>
> http://awsd.com/scripts/webadverts/index.shtml
>
> I'm setting it up as a link exchange, so I'm using the non-ssi method.
> The problem is that when I run the ads_admin.pl file, it doesn't run.
> I just get a display of the script. It is chmoded to 755.
>
> This is how I have the variables set up:
>
> $adverts_dir = "/u/web/resea2/cgi-adverts";
> $admin_cgi = "http://www.researchinfo.com/cgi-adverts/ads_admin.pl";
> $nonssi_cgi = "http://www.researchinfo.com/cgi-adverts/ads_nonssi.pl";
>
> Here are the results of the Perl Script Checker in the Control Panel
>
> Can't find string terminator '"' anywhere before EOF at
> /u/web/resea2/cgi-adverts/ads_admin.pl line 1750.
>
> The script itself can be viewed (unfortunatly) at:
>
> http://www.researchinfo.com/cgi-adverts/ads_admin.pl
>
> In fact, all scripts can be viewed (again, unfortunately) at:
>
> http://www.researchinfo.com/cgi-adverts/
>
> Thanks in advance to anybody who can help me with this.
>
> Scott W. Spain
> Valuenet
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 12 Sep 1997 15:26:46 +0800
From: Kenneth LO <kenlo@hk.super.net>
Subject: Re: Converting text to Excel data with UNIX
Message-Id: <3418EEB6.539EDBA0@hk.super.net>
Wotsit's File Format Collection (http://www.wotsit.demon.co.uk/#index)
may have the file format you wanted.
David Tauzell wrote:
>
> Nathan Stanford <nathan@cyberservices.com> writes:
>
> >Don't pay someone to do it get a perl book it is not that hard to do.
>
> Converting text data to tab delimited isn't very difficult. However,
> it seems that Joe wants to convert into or from native Excel format.
> This will be *much* more difficult. I once saw a book that described all
> of the Microsoft formats, however they might be somewhat out of date by
> now.
>
> Dave.
>
> >Joe Petrow wrote:
>
> >> Could somebody point me to some information on a Perl routine that
> >> converts tab delimited text data in native Excel format?
> >>
> >> Or if not that, to a place that specifies exactly what native Excel
> >> format
> >> is?
> >>
> >> Thank you.
> >>
> >> Joe Petrow
> >> joepet@server.berkeley.edu
> >> http://server.berkeley.edu/~joepet
>
> --
> ---
> David Tauzell. I like unix.
------------------------------
Date: Fri, 12 Sep 1997 08:03:34 GMT
From: dan@gulch.demon.co.uk (Dan Sumption)
Subject: Declaring dynamically named lexical variables
Message-Id: <3418f5bd.724111@news.demon.co.uk>
Can someone tell me how I would declare a lexical variable whose name
is determined by another variable. I had thought that placing a
variable name inside a block would return a variable whose name was
the product of the block, e.g.
$varname1 = 'foo';
$varname2 = 'bar';
my ${$varname1} = ${$varname2};
would be the equivalent of saying:
my $foo = $bar;
However, it seems I was wrong, and that this produces a reference,
generating the error 'Can't declare scalar deref in my'
Can someone tell me how I would declare the my variables correctly?
While I'm at it, I also need to call a dynamically named object
method. Assuming that the name of the method is in $_, how do I call
$self->$_ ?
Dan Sumption, Technical Director dan@gulch.demon.co.uk
Hard Reality, Canary Wharf, London E14 dan@hardnet.co.uk
http://www.hardnet.co.uk/dan/
------------------------------
Date: Fri, 12 Sep 1997 10:14:01 +0200
From: Gunnar Evermann <Gunnar.Evermann@dbag.ulm.DaimlerBenz.com>
Subject: Re: Execution speed, looping
Message-Id: <3418F9C9.5589B7F5@dbag.ulm.DaimlerBenz.com>
Douglas McNaught wrote:
> "stevearm@ix.netcom.com" <stevearm@ix.netcom.com> writes:
>
> > Loops in perl seem to run much slower than in C. This
> > for loop: for ( $i=0;$i<10000000;$i++) { } takes over
> > 20 seconds to run on a pentium II. In C it takes less than
> > a second. There seems to be even more difference on a
> > sparcII. The C code runs about the same, and after letting
> > the perl code run for over a minute, I hit ctrl-c.
> >
> This is a pretty useless benchmark.
I agree! Using SUN's cc it takes no time at all: :-)
-------------------------------
evermann@bradbury:~/tmp $ cc -xO4 tmp.c
evermann@bradbury:~/tmp $ time a.out
real 0.0
user 0.0
sys 0.0
evermann@bradbury:~/tmp $ cc tmp.c
evermann@bradbury:~/tmp $ time a.out
real 1.5
user 1.0
sys 0.0
--------------------------------
Gunnar.
------------------------------
Date: Fri, 12 Sep 1997 00:28:08 -0600
From: "T. LaWall" <tlawallANTISPAM@concentric.net>
Subject: Re: flock in Win32?
Message-Id: <3418E0F8.67F2@concentric.net>
Cameron Dorey wrote:
> Petri Backstrom wrote:
> > Cameron Dorey wrote:
> > > Is there any way to simulate/substitute/work around the flock()
> > > function
> > > in Win32 Perl? <snip>
>
> > flock() most definitely is "there" on Win32 (at least on
> > Windows NT).
> >
> > If it isn't "there" for you (or the Perl release you happen
> > to have - did you try? ;-), then get a newer release:
> > The ActiveState/ActiveWare port known as Perl for Win32:
> > http://www.activestate.com
> > The "core" Perl release/build for Win32 platforms:
> > http://www.perl.com
> > regards,
> > ...petri.backstrom@icl.fi
> > ICL Data Oy
> > Finland
> Petri, I'm using Sarathy's port 5.004.01, not the ActiveState port
> (5.3-whatever). But, Im using a Win95 machine, not WinNT, and this
> apparently makes the difference. (program gives a message similar to
> "flock() not implemented in this installation(?)".
> Stuart, I'm now trying a semaphore (flag) file, and I get over this
> problem.
> Unfortunately, I'm modifying somebody else's script and, from further
> troubles down the line, it appears that there must be some other file
> handling commands that are not implemented in PerlWin32 on a Win95
> machine (which are valid on a WinNT machine, but do not give me errors).
> Does anyone know of a list of unsupported functions in PerlWin32
> specifically for a Win95 box?
>
> Cameron Dorey
> camerond@mail.uca.edu
Some answers to the above questions (someone out there check my accuracy
please):
The Perl Release from ActiveState does not have flock()
or fcntl() implemented. A peek at nt.cpp shows us that
there is a test for WinNT vs. Win95. If you have Win95,
well, you are "up the proverbial waterway without a propulsion
device". Of course, you could go through the trouble of a
workaround like you have. Or (more ingeniously) someone could
put the time into producing a solution for the Win95 flock().
Within the next week, if I get enough spare time, I just might
hack out a solution. We'll see, I don't think it'd be too hard.
Snippet out of nt.cpp:
if(pPerl->IsWin95())
{
pPerl->CROAK("flock() is not available on Win95!\n");
return -1;
}
As for the unimplemented functions, ActiveState provides this list:
<WARNING>This list is from the 307 build, and some of the functions
may be implemented by now. I've been too busy(lazy) to get 310.
</WARNING>
============================BEGIN TEXT INSERT===========================
You are reading: STATUS.TXT
---------------------------
Only a subset of the standard Perl 5 Kit has been implemented, as there
is
usually no direct equivalent of the functionality in Win32.
Any functions marked with '**' will NOT warn that they are not
implemented.
Providing this 'warn facility' would require changes to the Perl 5 UNIX
Distribution.
Following are the unsupported functions:
Unsupported network routines
============================
getnetbyname() getnetbyaddr() getnetent()
getprotoent() getservent() sethostent()
setnetent() setprotoent() setservent()
endhostent() endnetent() endprotoent()
endservent() socketpair()
Unsupported System V compatible IPC routines
============================================
msgctl() msgrcv() msgget()
msgsnd() semctl() semget()
semop() shmctl() shmget()
shmread() shmwrite()
Unsupported I/O routines
========================
ioctl()**
Unsupported filesystem routines
===============================
chroot() fcntl()** link()
lstat()** readlink()** symlink()
umask()**
Unsupported security-related routines
=====================================
getpgrp() getppid() getpriority()
getpwnam() getgrnam() getpwuid()
getgrgid() getpwent() getgrent()
setpwent() setgrent() endpwent()
endgrent() setpgrp()
Unsupported process-related routines
====================================
fork() setpriority() times()
wait() waitpid()
Unsupported miscellaneous routines
==================================
alarm() dump()** syscall()
============================END TEXT INSERT===========================
Later
Todd
--
-------------------------------------------------
T. LaWall
To reply, remove ANTISPAM from my address
-------------------------------------------------
Where do I want to go today?
With Linux, Anywhere I want, TOLL FREE!
-------------------------------------------------
------------------------------
Date: Fri, 12 Sep 1997 09:13:23 +0200
From: Bjoern Nordmann <bjoern_nordmann@hp.com>
Subject: Globbing does not work on HP-UX 10.20 with perl 5.003
Message-Id: <3418EB93.4700CF68@hp.com>
Execution of below mentioned code does not work when called as normal
user,
however produces useful output when called as user root.
@filenames =<$dir/.*> ;
foreach $x (@filenames) {
print "$x \n";
}
Any ideas to come around this problem ?
The program works on HP-UX 10.10 with perl 5.002 (any user)
------------------------------
Date: Thu, 11 Sep 1997 23:21:12 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
To: mikeg@slpma8.ed.ray.com
Subject: Re: How to check if a file exits!
Message-Id: <874037543.12901@dejanews.com>
Try:
if (-e "filename") {
...
}
-or-
if (-d "dirname") {
}
for a directory
-Randy Pittelli
In article <3417F392.546F@slpma8.ed.ray.com>,
Michael Genovese <mikeg@slpma8.ed.ray.com> wrote:
>
> This is problably a fairly simple question, but I can't
> seem to find a "nice" way to do it in perl ...
>
> how do I check to see if a file EXISTS ?
>
> I don't need to read it, but I do need to know if it exists.
>
> --
> Mike Genovese, Sr. S/W Engineer
> Software Engineering Laboratory, Raytheon, Marlborough, MA
> 508-490-3891
>
> My opinions are my own, and NOT necessarily those of my employer.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 12 Sep 1997 04:43:55 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: How to email text file
Message-Id: <5vahac$p4j$1@neocad.com>
Gerry Buzzell (gbuzzell@hardlink.com) wrote:
: gbuzzell@hardlink.com[Gerry Buzzell] wrote:
: Here is another way to do it:
Everyone wants to reinvent the wheel ;)
TMTOWTDI
I prefer using Mail::Send and letting it muck around with all the
pipes for me. It checks 3 or 4 standard mail configurations and
uses whatever it can find (sendmail, mailx, etc). It's OO,
easy to use, and has been working reliably for me. Get a copy
from CPAN and read the man page for it. Took me about 5 minutes
to download, install, grok and write my first use for it.
HTH,
Jeff
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Thu, 11 Sep 1997 23:21:23 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
To: Brett.W.Denner@lmtas.lmco.com
Subject: Re: Is there a simpler syntax for: defined $a && $a ne ''
Message-Id: <874037829.13089@dejanews.com>
As long as you don't anticipate a value of 0 (zero), say:
if ($a) {
...
}
$a will be true unless undefined, empty, or 0.
-Randy Pittelli
In article <34180652.41C6@lmtas.lmco.com>,
Brett Denner <Brett.W.Denner@lmtas.lmco.com> wrote:
>
> I frequently need to ensure that a scalar contains "something"; i.e.,
> that it is defined and that it contains some non-empty value. I usually
> try something like this:
>
> $a = 1 unless (defined $a and $a ne '');
>
> Is there a simpler, more concise syntax for the "unless" part of this
> expression? I've tried things like:
>
> $a = 1 unless length $a;
>
> and
>
> $a = 1 unless $a =~ /./;
>
> but these don't work unless $a is already defined. Also, I can't just
> test for true or false, because '0' is false, but would be acceptable
> under my criterion.
>
> I know this is not exactly a matter of earth-shattering importance,
> but it would be nice to find a cleaner (shorter) idiom to express this
> test.
>
> Thanks,
> Brett
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Brett W. Denner Lockheed Martin TAS
> Brett.W.Denner@lmtas.lmco.com P.O. Box
> 748
> (817) 935-1144 (voice) Fort Worth, TX 76101
> (817) 935-1212 (fax) MZ 9333
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 12 Sep 1997 09:06:30 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: make: *** File Makefile' has modification time in the future
Message-Id: <isg1rb6mfd.fsf@godzilla.kiere.ericsson.se>
Clark Dorman <clark@s3i.com> writes:
> Heres a little program that I use to figure out how the times are
> going on my computers. You'll need to change the first line and
> change the computer names:
Here's a smaller program which tells you the (rough) difference
between the time on the machine you're using and the time on the
machine that holds your files (over NFS, presumably). If it gives
times in excess of 3-4 seconds it's time to complain (politely!) to
your sysadmin.
#!/usr/bin/perl -w
$file = "./lagtmp".$$;
open(FILE,">".$file) or die "Failed to create $file: $!\n";
close FILE;
$my_time = time;
$file_time = ((stat $file)[10]);
unlink $file;
print "Diff: ",($file_time - $my_time), " seconds.\n";
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esb.ericsson.se http://www.lysator.liu.se/~calle/
------------------------------
Date: 11 Sep 1997 22:33:55 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: module installation..
Message-Id: <5vagnj$1ps@flatland.dimensional.com>
Pat Trainor <ptrainor@aura.title14.com> writes:
> Can any module be installed by copying it to the /usr/lib/perl5
> tree (IO, Net, etc..) ?
If the module you're trying to install doesn't work this way:
perl Makefile.PL
make
make test
make install
then contact the module's author and ask them to fix it. Or else
something is hosed with your Perl installation.
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: Fri, 12 Sep 1997 10:00:32 +0200
From: Gary Howland <ghowland@hotlava.com>
Subject: Re: Net::Whois unsetting $/?
Message-Id: <3418F6A0.76D8@hotlava.com>
Tony Bowden wrote:
>
> Whilst using Net::Whois within a while loop that was reading from a file,
> I noticed that the while loop seemed to terminate after the first call
> to Net::Whois.
>
> I eventually traced this to the fact that Net::Whois is undef-ing
> $/, thus the next iteration of the loop was slurping in the remainder
> of the file.
>
> Surely it should, upon exit, reset $/ to whatever it was when called?
It should set a local $/ in its own block, like this:
{ local $/ = undef; my $whole_file = <FH>; }
This will leave your $/ untouched.
In an ideal world we could use: FH->$/ = undef ...
Gary
------------------------------
Date: Thu, 11 Sep 1997 23:11:16 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
To: webadmin@prestel.net
Subject: Re: NT 4.0
Message-Id: <874036956.12403@dejanews.com>
Try:
ftp://ftp.cs.colorado.edu/pub/perl/CPAN/ports/winNT/
If you use IIS, read: http://128.151.21.16/wwwrlp/perlcal/support.htm and
also if IIS or another server using PerlIS, read up on ISAPI (some of the
HTTP headers are different for ISAPI -- I can also backchannel the
particular changes).
I've found that as long as you don't use any modules not included with
the package (i have no experience with cgi.pm though, i do that stuff by
hand to reduce overhead), then porting between the two is simple and
requires nothing special as long as you use '/' rather than '\' in file
paths, and you avoid use of file locks (i also don't use pipes, so not
sure about that one).
In article <3417CC08.658661BE@prestel.net>,
webadmin <webadmin@prestel.net> wrote:
>
> Hi
>
> Is there perl for NT 4.0 on the web somewhere.
>
> Also are there any helpful guides. i can do perl on unix, I just need to
> know if theres anything special/different that I should know about
>
> Iqbal
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Thu, 11 Sep 1997 23:11:52 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
To: macdick@primax.com
Subject: Re: Perl and Nt 4.0
Message-Id: <874037286.12740@dejanews.com>
Try:
http://128.151.21.16/wwwrlp/perlcal/support.htm
for some help with Perl installation and a couple notes.
Once perl works (try the echo.pl at above site to test perl cgi), make
sure your script doesn't have any file locking, and keep in mind that the
default dir when running cgi is probably c:\winnt !!
-Randy Pittelli
In article <macdick-1109970811220001@babar.access.one.net>,
macdick@primax.com (Dick Lankes) wrote:
>
> We are setting up an NT 4.0 server and have need to use Perl for an index
> and search capability. We have been using Perl 5 on BSDI Unix with the
> index and search (ICE-2) and all works great. Migrating to NT has been a
> hassle and we cannot get Perl 5 or the script to work.
>
> Any help would be greatly appreciated!
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 12 Sep 1997 05:14:59 GMT
From: mgjv@mali.comdyn.com.au (Martien Verbruggen)
To: navi@sci.ccny.cuny.edu (Navishtha Sirisena)
Subject: Re: Perl Lib Path with Sybase Libraris
Message-Id: <5vaj4j$u9$1@comdyn.comdyn.com.au>
[Posted and Mailed]
In article <EGDIo6.66y@scisun.sci.ccny.cuny.edu>,
navi@sci.ccny.cuny.edu (Navishtha Sirisena) writes:
> If I set LD_LIBRARY_PATH to the location of sybase libs the scripts
> work.
You can ask the web admin to start up his server from a script that
sets LD_LIBRARY_PATH (which will make it available in the environment
of CGIs), or you might be able to do it by setting LD_LIBRARY_PATH in
your scripts, like:
$ENV{'LD_LIBRARY_PATH'} = '/some/path/to/sybase';
HTH.
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Fri, 12 Sep 1997 01:39:54 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Recursive sorting
Message-Id: <3418E3BA.60652E29@gpu.srv.ualberta.ca>
David Alan Black wrote:
!
! snapfisher@worldnet.att.net (Paul Fisher) writes:
!
! > I have a gouup of strings of the form
! > xxxxx.#:xxxxx.#:xxxxx.# where xxx are alphabetic characters
! > and # is an ascii numerical representation (i.e. a number).
!
! > I wrote a sort subroutine to be used by the sort function,
! > as in "sort by_myfunc()". This routine breaks off the first
! > chunnk of the string and evaluates it. If the two
! > substrings are equal, I want it to recursively call itself
! > with the remaining string portions.
!
! You could do something Schwartizan Transformesque:
!
! #!/usr/local/bin/perl -w
!
! my $string = "letters.1111:alpha.444:letters.222:string.666:string.555";
!
! # Might as well be sure:
! $string =~ /^(\w+\.\d+)(:|$)/ or die "Malformed string $string";
that's not going to check very far...\w usually allows
[a-zA-Z0-9_] and the poster said alphabetic in the first
portion. Secondly, yours only really tests the first
xxxx.##, the rest can be malformed because you don't really
check to the end of the string...an alternate test might be:
$string =~ /^(?:[a-zA-Z]+\.\d+(?::|$))+$/ or die "Bad string $string";
! my @sorted_list =
! map { @$_ }
! sort { @{$a}[0] cmp @{$b}[0] }
! sort { @{$a}[1] <=> @{$b}[1] }
! map { [ /(\w+)\.(\d+)/ ] }
! split ':', $string;
this can be modified to use one sort and to output
the colon-separated fields still intact:
my @sorted_list =
map {$_->[0] }
sort {$a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]}
map {[$_,split /\./] }
split ':', $string;
! print join "\n", (@sorted_list,"");
however, I fear the original poster wanted to be able to sort
a list of such strings by their various parts, not sort out
the parts of one string ... there are a few ways to go about
that involving recursion (but not recursion inside the sort()
function), a couple of variations could be found by tracking
down the thread "Alphanumeric Sort Routine" in
comp.lang.perl.modules on dejanews, or you can check out the
"Sort-PolySort" or "SortVersions" modules on CPAN to see
if they can be made to do what you want.
hope it helps
regards
andrew
------------------------------
Date: Fri, 12 Sep 1997 07:53:02 GMT
From: Dave.Cross@gb.swissbank.com (Dave Cross)
Subject: Re: returning hashes from sub
Message-Id: <DAVE.CROSS.97Sep12085303@ln4d110swk.gb.swissbank.com>
In article <341807DE.91B83EF6@aztec.asu.edu> Gip <nospam.gibsonc@aztec.asu.edu> writes:
This really belongs in comp.kang.perl.misc. I've crossposted and set
followups appropriately.
> What's the right way for returning hashes for subroutines? I believe I
> need to reference the hashes with the ref operator "\", but I'm new to
> that...The following does NOT work, as big contains both hashA and
> hashB.
>
> :
>
> my(%big, %small);
>
> (%big, %small) = &a();
>
> :
>
> sub a {
>
> my(hash);
> $hashA{...} = ...;
> $hashB{...} = ...;
>
> %hashA, %hashB;
>
> }
You're right that you should be using references here. The reason that
%big contains both %hashA and %hashB is that array assignment is 'greedy'
so %big takes as much array stuff as it can find (i.e. all of it) leaving
nothing to go into %small.
Try rewriting it like this:
:
my($big, $small);
($big, $small) = &a();
:
sub a {
my(hash);
$hashA{...} = ...;
$hashB{...} = ...;
# These are now *references* to hashA and hashB
\%hashA, \%hashB;
}
References are scalars and therefore one goes into each of your variables
$big and $small.
Remember the you can't now access your hashes in the same way. Where you
would have previously written
$big{'key'}
You'll need to write
$big->{'key'}
hth
Dave... .. .
--
"...but Man created all gods equal."
Dave.Cross@gb.swissbank.com
------------------------------
Date: Fri, 12 Sep 1997 01:07:15 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Why don't my <<HERE documents work? Attempt #2!
Message-Id: <comdog-ya02408000R1209970107150001@news.panix.com>
In article <341aa433.14149064@news.wwa.com>, faust@wwa.com wrote:
>Why don't my <<HERE documents work? Here is a sample of my code.
>print <<EOF;
>This is a test!
>EOF
>Can't find string terminator "EOF" anywhere before EOF at da.pl line 3.
>1. There is no space after the << part.
>2. There is a semicolon at the end.
>3. There is no space in front of the tag.
is there anything after the (supposedly) terminating EOF? it must be
on a line by itself.
--
brian d foy <comdog@computerdog.com>
------------------------------
Date: 12 Sep 1997 08:28:55 +0200
From: Ronald Fischer <rovf@earthling.net>
To: faust@wwa.com
Subject: Re: Why don't my <<HERE documents work? Attempt #2!
Message-Id: <xz2yb53jba0.fsf@uebemc.siemens.de>
>>>>> On Fri, 12 Sep 1997 02:09:21 GMT
>>>>> "FG" == Faust Gertz <faust@wwa.com> wrote:
FG> Why don't my <<HERE documents work? Here is a sample of my code.
FG>
FG> #!/user/local/bin/perl -w
FG> use strict; # 'cause it's in the FAQ :-)
FG> print <<EOF;
FG> This is a test!
FG> EOF
FG> exit;
FG>
FG> The result is:
FG>
>> Can't find string terminator "EOF" anywhere before EOF at da.pl line 3.
FG>
Try this:
print <<EOF;
This is a test!
EOF; # <------ !!!!!
exit;
or this:
print <<EOF
This is a test!
EOF
; # <------ !!!!!
exit;
--
Ronald Fischer (rovf@Earthling.net) (PGP public key available)
http://ourworld.compuserve.com/homepages/ronald_fischer/
[When posting a followup, mailing a courtesy copy is fine, provided it is
clearly marked as such.]
------------------------------
Date: 12 Sep 1997 08:34:09 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: Why don't my <<HERE documents work? Attempt #2!
Message-Id: <5vauq1$srh$1@vixen.cso.uiuc.edu>
Faust Gertz (faust@wwa.com) wrote:
: I tried posting this before and no one responded.
:
: Why don't my <<HERE documents work? Here is a sample of my code.
:
: #!/user/local/bin/perl -w
: use strict; # 'cause it's in the FAQ :-)
: print <<EOF;
: This is a test!
: EOF
: exit;
:
: The result is:
:
: >Can't find string terminator "EOF" anywhere before EOF at da.pl line 3.
:
: Please note that:
:
: 1. There is no space after the << part.
: 2. There is a semicolon at the end.
: 3. There is no space in front of the tag.
:
: Much to my dismay, I am stuck with perl, version 5.001 on a Unix
: platform. I have tried to get my system administrator to upgrade, but
: it just doesn't seem to work (both the getting her to upgrade and my
: <<HERE documents).
:
You do need to update, but this is so basic that it shouldn't matter.
My guess is that you uploaded the script from a DOS machine in
binary mode, and that there is a ^M after the EOF. If this works
you can verify it:
print <<"EOF\r";
testing
EOF
--
Regards,
Mike Heins
This post reflects the
opinion of my employer.
------------------------------
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 1015
**************************************