[7389] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1014 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 12 00:08:45 1997

Date: Thu, 11 Sep 97 21:00:26 -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           Thu, 11 Sep 1997     Volume: 8 Number: 1014

Today's topics:
     Re: A simpler perl question. (Andrew M. Langmead)
     Re: Add elements to %hash (Colin Kuskie)
     Calling perl (Stan Cheng)
     Clearing formats and a problem with spaces (Colin Kuskie)
     Detecting NFS outage while <> (Bradley K. Sherman)
     Editor in perl (o-su ken'ichi )
     Re: Flushing STDOUT? (dave)
     Re: grepping for parens <mobrien@cello.hp.hpl.com>
     Re: Help! cron&perl ! <dorfmanr@netlabs.net>
     Illegal character \015 (carriage returns) -- HELP <pittelli@ehsct7.envmed.rochester.edu>
     Is there a more efficient way to interweave 2 arrays? (Nim Chu)
     Re: Loading modules or subroutines at execution (M.J.T. Guy)
     Re: manipulating chars inside strings? <mobrien@cello.hp.hpl.com>
     module installation.. <ptrainor@aura.title14.com>
     NEWBIE: Getting environmental variables (Vijay Veeranna)
     Re: NEWBIE: Getting environmental variables (brian d foy)
     Re: NEWBIE: Getting environmental variables (Martien Verbruggen)
     Perl Lib Path with Sybase Libraris (Navishtha Sirisena)
     Re: ping and catching output <Philip.Abercrombie@MCS.VUW.AC.NZ>
     Re: Pipes in perl <youngej@magpage.com>
     printer port -- "Permission denied" (me)
     printer port -- "Permission denied" jwbacon@ix.netcom.com
     Re: Problem importing vars from package <Philip.Abercrombie@MCS.VUW.AC.NZ>
     Re: Problems using typeglobs to export arrays (M.J.T. Guy)
     Re: Recursive sorting (David Alan Black)
     Re: Returning Hashes from Sub (newbie question) (dave)
     Re: script to change htpasswd (Michael Fuhr)
     Re: Strip spaces in filenames <daftary@cisco.com>
     unpack and install Perl <Larry_P_Nguyen@qmail2.sp.trw.com>
     Re: Using Pipes (Steve Monson)
     Why don't my <<HERE documents work?  Attempt #2! (Faust Gertz)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 12 Sep 1997 00:31:46 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: A simpler perl question.
Message-Id: <EGDDGy.Goy@world.std.com>

"Aaron" <aaron@soltec.net> writes:

>how do you get it to spit out the file names recursively

use File::Find;
my $topdir = shift @ARGV;
find(sub {print "$File::Find::name\n";}, $topdir);
-- 
Andrew Langmead


------------------------------

Date: 11 Sep 1997 16:24:48 -0700
From: colink@latticesemi.com (Colin Kuskie)
Subject: Re: Add elements to %hash
Message-Id: <5v9uk0$rbd@sarek.latticesemi.com>

In article <341848d2.1178563@eunetnews.germany.eu.net>,
Jan Gruber <jgr@tpnet.de> wrote:
>How do i push new elements to this  %hash.
>
>%hash ( user => password);
>
>push %hash, ($user,$password) doesnt work
>The compiler complains with:  type of arg .....

You get an error because you can only push arrays, not hashes.

Usually to add elements to a hash, you would do this:
$hash{$user} = $password;

And this of course will overwrite any previous users with the
exace same name.

Hope this helped,
Colin Kuskie


------------------------------

Date: Thu, 11 Sep 1997 21:55:33 GMT
From: hobo@alumni.stanford.org (Stan Cheng)
Subject: Calling perl
Message-Id: <34186864.16518469@news.ricochet.net>

Can anyone help me call a perl script  from Visual Basic

Stan


------------------------------

Date: 11 Sep 1997 16:18:07 -0700
From: colink@latticesemi.com (Colin Kuskie)
Subject: Clearing formats and a problem with spaces
Message-Id: <5v9u7f$r6d@sarek.latticesemi.com>

I have two questions about using formats.

1) I have a program that generates a format on the fly based on user
input for displaying data.  I'd like to be able to reuse that same
format name, since the user may ask for several different sets of
output, yet if I try to re-assign to the format I get an warning from
my script (I always run under -w and 'use strict')  If there any way to
clear the format so that I can use it again?

I understand that I can always turn the warnings off locally, or
generate format names on the fly, but I'd prefer a cleaner solution.

2) Now suppose that I have the following program:
#!/usr/local/bin/perl5 -w
use strict;
use FileHandle;
my ($a, $b, $c, $d, $e, $f, $g, $h);

$a = "     one"; $e = ".....one";
$b = "     two"; $f = ".....two";
$c = "    four"; $g = "....four";
$d = "nineteen"; $h = "nineteen";

#
# define 2 formats, one with
# spaces (BAD), and one with periods (GOOD)
format BADFORM = 
^    ^    ^    ^~~
$a,$b,$c,$d
 .

format GOODFORM = 
^    ^    ^    ^~~
$e,$f,$g,$h
 .

#
# write both formats to STDOUT
format_name STDOUT 'GOODFORM'; write;
print "\n\n";
format_name STDOUT 'BADFORM'; write;

It generates this output:
 .    .    .    n
 .    .    .    i
 .    .    .    n
 .    .    .    e
 .    .    f    t
o    t    o    e
n    w    u    e
e    o    r    n
 
 
               n
o    t    f    i
n    w    o    n
e    o    u    e
          r    t
               e
               e
               n

Can anyone tell me why the spaces get treated differently than the 
periods?

Thanks for your time,
Colin Kuskie
colink@latticesemi.com


------------------------------

Date: Fri, 12 Sep 1997 01:31:20 GMT
From: bks@netcom.com (Bradley K. Sherman)
Subject: Detecting NFS outage while <>
Message-Id: <bksEGDG88.LsK@netcom.com>



If I am reading a file from an NFS mounted disk and
the plug is pulled on the remote machine, can I tell
the difference between this error condition and EOF?

More generally will $! be set in a way that allows
me to distinguish between EOF and an error like
ferror() & feof() in C?

    Thanks,
    --bks



------------------------------

Date: 12 Sep 1997 00:37:39 GMT
From: t95129ku@sfc.keio.ac.jp (o-su ken'ichi )
Subject: Editor in perl
Message-Id: <5va2sj$10f$1@news.sfc.keio.ac.jp>


Hello, 
I'm thinking about how to code the editor in perl, like Unix's emacs 
or Machintosh's simpletext, or Windows' wordpad.  
The editor which I wanna build is a simple one, 
just having the basic edit operation will do.
Is there any usable modules or example source codes? 
Please give me information..................

Thank you very much in advance!
9:30 AM, Tokyo 


------------------------------

Date: Thu, 11 Sep 1997 23:31:46 GMT
From: over@the.net (dave)
Subject: Re: Flushing STDOUT?
Message-Id: <34187e00.188008@news.one.net>

ckc@dmi.min.dk wrote:

I really like the FileHandle module cause it lets me treat a
filehandle just like another variable.  It works more like a C fopen
than a Perl "open" function does, even though the terminology is
different.  I.E.  Think about using it for more than just autoflush.


Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________


------------------------------

Date: Thu, 11 Sep 1997 18:41:18 -0700
From: Marty O'Brien <mobrien@cello.hp.hpl.com>
Subject: Re: grepping for parens
Message-Id: <34189DBE.6B66@cello.hp.hpl.com>


Jeremy L. Mordkoff wrote:
> 
> This seems simple, but it's driving me batty.
> 
> I used to use
> 
>         next if ( $team && ! /\b$team\b/;
> 
> to see if the current line contained the team I was interested in when
> specified. The problem occurs if $team (and $_) has parens in it. For
> instance, if $team is "Merrimac (MA)" and $_ is "10/12:Merrimac
> (MA):Peabody", this test apparently passes (i.e /\b$team\b/ is false ).
> I thought it was misinterpreting the parens in $team as the text to be
> captured in $1, so I added
> 
>         if ( $team ) {
>                 $team =~ s/\(/\\\(/g;
>                 $team =~ s/\)/\\\)/g;
>         }
> 
> so that "Merrimac (MA)" would become "Merrimac \(MA\)" but this did not
> help. Is there a simple way to turn off ()'s in a search?
> 
> JLM
> --
> Jeremy L. Mordkoff
> http://www.net1plus.com/users/jom/pictel.htm

Yep. In perl 5, say

	next if ( $team && ! /\b\Q$team\E\b/ );

See perlre for details.

Regards,
Marty O'Brien


------------------------------

Date: Thu, 11 Sep 1997 20:53:06 -0400
From: Robert Dorfman <dorfmanr@netlabs.net>
Subject: Re: Help! cron&perl !
Message-Id: <34189271.BE893A93@netlabs.net>

I've had this problem also with ksh scripts. Usually it's because cron
doesn't have any of your personal environment set. A good way to test
what you need to provide (in the manner of ENV and full filespecs) is to
execute the script (command) using 'remsh'. This will mimic the
environment cron provides. One caveat is that you need to have a
'.rhost' file set so you can loop back to your system using remsh.

Good luck.
Robert




------------------------------

Date: Thu, 11 Sep 1997 22:51:44 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
Subject: Illegal character \015 (carriage returns) -- HELP
Message-Id: <874035814.11389@dejanews.com>

With perl -c in a shell, all the cgi scripts on a client's Unix Apache
server, JUST upgraded to Perl 5.004_01, return:

"Illegal character \015 (carriage return) at ...
(maybe you didn't strip carriage returns after a network transfer)"

 ...when they ALL worked in 5.002.
I undertand the error, read the FAQ on \n versus \r and different
platforms, BUT:

1) How do I actually strip the carriage returns in all of those scripts?
Even a manual {:-< edit with PICO (sp?) doesn't catch those hidden
critters. Or is there a way to PREVENT the occurrence BEFORE file
transfer (development and transfer using Win95/WS-FTP)?

2) Why is this only a problem now? I've installed several hundred scripts
on all sorts of Unix servers w/all versions of Perl, but have gotten two
of this particular report (another 5.004 Unix machine), only in the past
week. Is this something particular to 5.004?! Why did they work before?

Thanks
-Randy
Please cc: pittelli@envmed.rochester.edu

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


------------------------------

Date: Fri, 12 Sep 1997 06:06:13 GMT
From: nimchu@hal-pc.org (Nim Chu)
Subject: Is there a more efficient way to interweave 2 arrays?
Message-Id: <5vabj2$ktf$1@news.hal-pc.org>

Is there a more efficient way (less cpu, and/or no need to generate a
third array) to do the equivalent of following code:

@odd=(1,3,5,7);
@even=(2,4,6,8);
foreach $i (0..$#even) {
push @all, $odd[$i], $even[$i];
}




------------------------------

Date: 12 Sep 1997 02:03:17 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Loading modules or subroutines at execution
Message-Id: <5va7t5$452$1@lyra.csx.cam.ac.uk>

Mike Stok <mike@stok.co.uk> wrote:
>If you want to selectively require a module then I guess you could use
>eval.

No need for eval.   "require" is done at run time, so you can just
put it in a conditional.    A paradigm I use all the time is

       if (things are bad) {
            require Carp;
            Carp::croak("some message");
       };


Mike Guy


------------------------------

Date: Thu, 11 Sep 1997 19:02:27 -0700
From: Marty O'Brien <mobrien@cello.hp.hpl.com>
Subject: Re: manipulating chars inside strings?
Message-Id: <3418A2B3.593C@cello.hp.hpl.com>

Yoav Zach wrote:
> 
> Hi,
>         Can anyone tell me how to manipulate single chars inside
> strings, something like 'str[j]  = c;' in C?
> thanks,
> Yoav.

Yes, but you will be a better person for figuring it
out for yourself   ;-)

See the perlfunc page about using substr as an lvalue.

Regards,
Marty O'Brien


------------------------------

Date: Thu, 11 Sep 1997 21:24:46 -0400
From: Pat Trainor <ptrainor@aura.title14.com>
Subject: module installation..
Message-Id: <Pine.LNX.3.95.970911212351.6133B-100000@aura>


	Can any module be installed by copying it to the /usr/lib/perl5
tree (IO, Net, etc..) ?


pat 	
:)
  	
#        ptrainor@aura.title14.com (PT46) ptrainor@bbnplanet.net
#  Perl, PHP/FI, *NIX, HTML, CGI, SQL, RDBMS, NT*, Security, Admin, ... 
# "I've got LOTS of experience doing practically nothing!" -Heffer Wolfe



------------------------------

Date: 11 Sep 1997 22:26:14 GMT
From: vv@dickens (Vijay Veeranna)
Subject: NEWBIE: Getting environmental variables
Message-Id: <5v9r66$4io@cbisinet.cbis.com>

Hi!!

I am new to PERl, and I am trying to find out how
to obtain the  environmental variables from 
my perl script. 

For eg if my Environmental has variables 
FILE_LOC= /tmp/xx
TERM=sun-cmd
DOMAIN=test
ORACLE_HOME=/tools/oracle/7.2.3
 ...

If I just need to access the DOMAIN variable
how do I do it?

Thanks
vijay






------------------------------

Date: Thu, 11 Sep 1997 21:09:52 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: NEWBIE: Getting environmental variables
Message-Id: <comdog-ya02408000R1109972109520001@news.panix.com>

In article <5v9r66$4io@cbisinet.cbis.com>, vv@dickens (Vijay Veeranna) wrote:

>I am new to PERl, and I am trying to find out how
>to obtain the  environmental variables from 
>my perl script. 

the environment of the process (not necessarily your login 
enviroment!) is stored in the %ENV hash

>If I just need to access the DOMAIN variable
>how do I do it?

   $domain = $ENV{'DOMAIN'};


good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>


------------------------------

Date: 12 Sep 1997 00:57:09 GMT
From: mgjv@mali.comdyn.com.au (Martien Verbruggen)
Subject: Re: NEWBIE: Getting environmental variables
Message-Id: <5va415$sug$2@comdyn.comdyn.com.au>

In article <5v9r66$4io@cbisinet.cbis.com>,
	vv@dickens (Vijay Veeranna) writes:

> If I just need to access the DOMAIN variable
> how do I do it?

my $domain = $ENV{'DOMAIN'};

Also check out the 'perlvar' documentation, and look for ENV

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 02:24:06 GMT
From: navi@sci.ccny.cuny.edu (Navishtha Sirisena)
Subject: Perl Lib Path with Sybase Libraris
Message-Id: <EGDIo6.66y@scisun.sci.ccny.cuny.edu>


Hello,
I have installed perl5.003 with sybperl extensions ( sybperl2.7 ). I have Sybase Libraris ( OpenClient 10.004) Installed. However, when I use sypberl routins, perl cannot find the sybase libraris since it is not inthe path. I have precompiled perl for Solaris2.5.1. How can I set up perl , so it can use the sybase libs? I cannot use $export LD_LIBRARY_PATH since these are cgi's. If I set LD_LIBRARY_PATH to the location of sybase libs the scripts work. Any help will begreately appreciated.
Thanx in advance and please e-mail
Navi


------------------------------

Date: 12 Sep 1997 10:59:12 +1200
From: Phil Abercrombie <Philip.Abercrombie@MCS.VUW.AC.NZ>
Subject: Re: ping and catching output
Message-Id: <6wlo13bgov.fsf@bats.mcs.vuw.ac.nz>


tom <tom.van.mierlo@ordina.be> writes:


[...]


> use lib 'c:\perl\lib';
> use Net::Ping;
> 
> $ip_adres = "192.92.130.6";
> $timeout = 10;
> 
> print "yes\n" if pingecho($ip_adres, $timeout);
> 
> What could this error message mean ?


That's not the error message I get - using Guru's native port I get 
"The Unsupported function alarm functioo is unimplemented"...., which
is certainly clearer.

I have a perl ICMP ping, but it doesn't work under win32 (presumably
the ICMP api is not via sockets under windows?)

> I also tried to use the ping command that comes with windows.
> but the problem with this is, i don't know how to check if the server is
> online or not. The yes is always printed out!
> 
> perl script for this :
> 
> $ip_adres = "192.92.130.6";
> $ping="ping";
> 
> open(PING, "|$ping $ip_adres");
> close(PING);
> if (!$?) { print "yes" };
> 
> I'm just a beginner, please help me

Exit statuses are, um, unreliable under win32.  You should use the
text from the ping.  Somthing like

print 'yes' if (`ping $ip_adres` =~ /bytes=/)

        -phil


------------------------------

Date: 12 Sep 1997 00:42:40 GMT
From: Ed Young <youngej@magpage.com>
To: mark@goags.com
Subject: Re: Pipes in perl
Message-Id: <5va360$1re$0@204.179.92.205>

Mark Cervarich wrote:
> 
> I am sending 4 lines of data to an IRR program (iterative rate of return)
> to determine the annualized performance of said stock data.  I have
> figured out how to send the data to the pipe, but I don't know how to
> capture it.  Here's what I've got
> -----------cut here------------
> [mark@serge]$ more t2
> $data="1/1/97 1000.00\n2/1/97 1000.00\n3/1/97 1000.00\n4/1/97 -3300.00";
> open TEST, "| /home1/mark/tmp/irr/irr";

  open(TEST, "| /home1/mark/tmp/irr/irr >/tmp/answer") or die "error\n";

> print TEST $data;
> close TEST;

  open(ANS, "</tmp/answer") or die "appropriate error msg\n";
  $answer = <ANS>;
  close ANS;
  unlink "/tmp/answer";

> $answer = $?;
> print "answer is [$answer]\n";
> 
> [mark@serge]$ perl t2
> 77.786194 % (annualized)
> answer is [0]
> -----------cut here------------
> The answer "77.786194 % (annualized)" is being dumped to STDOUT.
> Arghh.
> I'm sure the answer is real easy--so if you know what I'm doing wrong,
> could you please tell me.
> 
> thanks,
> mark

pipe your answer to a file like /tmp/answer (see above)
open and read the file to get the answer.  You can use 
IPC::Open2, but that can get you into deadlocking problems.


------------------------------

Date: 12 Sep 1997 03:17:07 GMT
From: email@here.now (me)
Subject: printer port -- "Permission denied"
Message-Id: <5vac7j$co9@dfw-ixnews4.ix.netcom.com>


I just installed Activeware's build 3.10 on my Windows '95 machine.  I can't 
seem to print to the printer port (using the SAME perl program I use at work 
on a similar machine).

I wrote a small test program as follows:

open (FHANDL, ">filtst.txt") or die ("Fail: $!");
print FHANDL "This was a test line from ".$0."\n";
close FHANDL;
open (PHANDL, ">LPT1") or die ("Fail: $!");
close PHANDL;

The FHANDL (to a text file) works fine; the program dies at line 4 with the 
message:
           Fail: Permission denied at ptst.pl line 4

I can type the DOS command "copy filtst.txt lpt1:" and the printer dutifully 
spits out a page with "this was a test line from ptst.pl".

Any help on this would be appreciated.  I am totally baffled.






------------------------------

Date: 12 Sep 1997 03:39:43 GMT
From: jwbacon@ix.netcom.com
Subject: printer port -- "Permission denied"
Message-Id: <5vadhv$136@dfw-ixnews12.ix.netcom.com>

This is a repost -- I just read my article and noticed I didn't fill in the 
winVN header stuff.  How embarassing.

I just installed Activeware's build 3.10 on my Windows '95 machine.  I can't 
seem to print to the printer port (using the SAME perl program I use at work 
on a similar machine).

I wrote a small test program as follows:

open (FHANDL, ">filtst.txt") or die ("Fail: $!");
print FHANDL "This was a test line from ".$0."\n";
close FHANDL;
open (PHANDL, ">LPT1") or die ("Fail: $!");
close PHANDL;

The FHANDL (to a text file) works fine; the program dies at line 4 with the 
message:
           Fail: Permission denied at ptst.pl line 4

I can type the DOS command "copy filtst.txt lpt1:" and the printer dutifully 
spits out a page with "this was a test line from ptst.pl".

Any help on this would be appreciated.  I am totally baffled.

Jim Bacon                    .(o)   (o).  / +  +  +\
jwbacon@ix.netcom.com        .   ___   . / +  +  + /
303-581-9635 ext 329 (work)   ..|   |.. / +  +  + / 
303-581-0960 (FAX)(w)           |_|_|  /_________/    W5-62-93



------------------------------

Date: 12 Sep 1997 11:08:16 +1200
From: Phil Abercrombie <Philip.Abercrombie@MCS.VUW.AC.NZ>
Subject: Re: Problem importing vars from package
Message-Id: <6wiuw7bg9r.fsf@bats.mcs.vuw.ac.nz>



"Drew Marold" <foo@bar> writes:


[...]


> @EXPORT = qw(NMC Channel_List);
> 
> @Channel_List = ("17c", "18c", "19c", "20c", "21c", "17b");
> 
> $NMC = {
> 	"17c.1" => 22.8620, "18c.1" => 7.5440, "19c.1" => 4.2780,
> #lots more of these
> };

[...]

> If I use @Nmc::Channel_List and $Nmc::NMC I
> get the values.  Why aren't they importing into my programs main namespace
> ?

You need to say @EXPORT = qw($NMC @Channel_List)

The default is to export subs only.

        -phil

-- 
 Phil Abercrombie
 Victoria University of Wellington
 +64 4 495 5126


------------------------------

Date: 12 Sep 1997 02:06:00 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Problems using typeglobs to export arrays
Message-Id: <5va828$484$1@lyra.csx.cam.ac.uk>

Andrew M. Langmead <aml@world.std.com> wrote:
>
>If you say:
>
>                   use vars qw/@array/;
>
>At the top of your script, then you give perl a hint that @array is
>really an array. (Since you snuck it in behind its back though
>typeglobbing)

Not at the top of the script  -  that would declare @main::array.
Put it immediately after the "package b;" line.


Mike Guy


------------------------------

Date: 11 Sep 1997 23:11:44 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: Recursive sorting
Message-Id: <5v9trg$bt0@pirate.shu.edu>


Hello -

snapfisher@worldnet.att.net (Paul Fisher) writes:

>Can the sort function be called resursively?

No.  See Camel, p. 218: "... the subroutine may not be a recursive
subroutine..."  (and there's even some explanation :-)
 
>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";

my @sorted_list =
   map  { @$_ }
   sort { @{$a}[0] cmp @{$b}[0] }
   sort { @{$a}[1] <=> @{$b}[1] }
   map  { [ /(\w+)\.(\d+)/ ] }
   split ':', $string;

print join "\n", (@sorted_list,"");

__END__

Reading from the bottom up:

split on :, returning a list of "xxx.###" elements

map... = iterate through that list, grabbing the xxx and ###
  via pattern matching.  Do this inside list reference
  operators ([]).  This yields a list of list
  references, each reference's list containing a
  (xxx,###) pair.

sort that list of list references on numerical comparison of the ###'s
  (note the dereferencing of the lists, and the [1] subscript,
  which yields what was the (\d+) match)

sort again, on alphanumerical comparison of the xxx's.

Dereference the list references


The result will be:

alpha
444
letters
222
letters
1111
string
555
string
666

all in one list, which may not be what you want, but you can
modify the code as required.

Randal will now show you how to do it in thirty or fewer
keystrokes.... :-)

David Black
dblack@icarus.shu.edu


------------------------------

Date: Thu, 11 Sep 1997 23:40:45 GMT
From: over@the.net (dave)
Subject: Re: Returning Hashes from Sub (newbie question)
Message-Id: <34187fb7.626474@news.one.net>

Gip <nospam.gibsonc@aztec.asu.edu> wrote:

>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;
>
>}

This is what I would use:



( $bigref, $smallref ) = &a();

print "$bigref->{...}, $smallref->{...}\n";

sub a
{
    my( $hashAref, $hashBref ) = ( undef, undef );
    $hashAref->{...} = ...;
    $hashBref->{...} = ...;
    return $hashAref, $hashBref;
}



Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________


------------------------------

Date: 11 Sep 1997 18:52:01 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: script to change htpasswd
Message-Id: <5va3nh$pgo@flatland.dimensional.com>

st93yjls@dunx1.ocs.drexel.edu (William Hall) writes:

> I'm trying to find a way to allow users to change their password for the 
> .htpasswd file from a web page.  I'm new to perl and cgi and can't seem 
> to find an example, but I know it can be done.  Please email the below 
> address.  Thank you.

Check out the HTTPD-Tools module on the Comprehensive Perl Archive
Network (CPAN).  A good entry point to CPAN is:

    http://www.perl.com/CPAN/CPAN.html

-- 
Michael Fuhr
http://www.dimensional.com/~mfuhr/


------------------------------

Date: Thu, 11 Sep 1997 16:48:36 -0700
From: Kuntal Daftary <daftary@cisco.com>
To: Mukund Rao <mrao@trincoll.edu>
Subject: Re: Strip spaces in filenames
Message-Id: <34188354.5B03@cisco.com>

Mukund Rao wrote:
 
> #!/bin/ksh
> # find and replace all occurrences of $1 with $2
> # from current directory onwards (ie. all files/subdirectories below)
> 
> perl -pi -e 's/$1/$2/;' `find . -type f -print`

here is a fluke:

perl -pi -e 's/$1/$2/;' `find . -type f -print | sed 's/ /\\ /g'`

test before use
-- 
Kuntal M. Daftary   Cisco Systems Inc 
Ph: 408 527 9789    170 W. Tasman Dr 
daftary@cisco.com   San Jose CA 95134


------------------------------

Date: Thu, 11 Sep 1997 19:45:35 -0700
From: Larry Nguyen <Larry_P_Nguyen@qmail2.sp.trw.com>
Subject: unpack and install Perl
Message-Id: <3418ACCF.19EC@qmail2.sp.trw.com>

What format is the perl's code (ie. latest.tar.gz) packed in?
How do I unpack it?
thanks


------------------------------

Date: 10 Sep 1997 09:41:23 -0500
From: smonson@tri.sbc.com (Steve Monson)
Subject: Re: Using Pipes
Message-Id: <5v6bij$1ke@euphony.tri.sbc.com>


In article <341632AA.F11AEBB@poolpros.com>,
Ryan Rose  <ryanr@poolpros.com> wrote:
>I have a program called lu that prints out the following in shell.
>
> 0 *                 Meera :     66 :  182 :      0 : 207.79.35.34
> 1 *               Boomer :     35 :   32 :      0 : 199.246.132.78
> 2 *                   ejana :     -4 :   17 :      0 : 142.58.110.2
> 3 *                   Eeze :      3 :   21 :      0 : 194.237.142.4
> 4 *                    nats :    -15 :   11 :      0 : 206.206.120.10
> 5 *          snowbabie :      0 :   68 :      0 : 208.148.249.138
> 6 *                   dean :     14 :    8 :      0 : 205.217.61.200
> 7 *                   todd :      0 :   44 :      0 : 24.113.36.176
> 8 *                  Anna :    -11 :   64 :      0 : 203.2.75.92
>  9                       Me :   2475 :   20 :      0 : 203.14.111.8
>10 *         supersonic :     -7 :   66 :      0 : 209.54.96.15
 
 
 My perl program should just display the Names on all lines containing a
 '*'
 here's the code.
 
 open (INPUT, "lu|");
 while (<INPUT>) {
     $line = <INPUT>;
      chop ($line);
      if ($line =~ /\*/)  {
             $line =~ s/^\ ?\d*\ \*\ +(\w+)\ :.*/\1/;
             print ("User: $line\n");
      }
 }
 
 But here's the output.  Look what happens, it skips every other line.



Every time you do <INPUT> you get a line. So, "while <INPUT>"
reads a line, and then "$line = <INPUT>" reads a line.

When you do the "while" the input line is stored in $_ for you
to use. So, your loop could be:

while (<INPUT>) {
  print "User: $1\n" if /^ *\d+ *\* *([a-z]\w+)/i;
}



Steve Monson
-- 
Did you hear about the big collision at sea? A ship loaded with blue dye,
en route from San Francisco to Hong Kong collided with a shipload of red
dye going from Japan to Los Angeles. Both crews were marooned.


------------------------------

Date: Fri, 12 Sep 1997 02:09:21 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Why don't my <<HERE documents work?  Attempt #2!
Message-Id: <341aa433.14149064@news.wwa.com>

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).


TIA

Faust Gertz
Philosopher at Large


------------------------------

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 1014
**************************************

home help back first fref pref prev next nref lref last post