[13272] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 682 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 30 19:07:19 1999

Date: Mon, 30 Aug 1999 16:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 30 Aug 1999     Volume: 9 Number: 682

Today's topics:
        A Question Of Modules.... <roco3d@softhome.net>
    Re: A Question Of Modules.... <makkulka@cisco.com>
    Re: Checking for multiple spaces <aqumsieh@matrox.com>
    Re: checking return status on system() <bmetcalf@nortelnetworks.com>
    Re: Desperately searching for perl lint <aqumsieh@matrox.com>
    Re: File listing (Scott Crevier)
    Re: File listing <meowing@banet.net>
    Re: How to do this... (Larry Rosler)
        How to have events like onBlur and onChange work with F <alister2NOxqSPAM@csc.co.nz>
    Re: How to have events like onBlur and onChange work wi <makkulka@cisco.com>
    Re: how to make sort() case insensitive? (Larry Rosler)
    Re: how to make sort() case insensitive? (Bill Moseley)
    Re: how to make sort() case insensitive? <makkulka@cisco.com>
    Re: how to make sort() case insensitive? (Larry Rosler)
    Re: How to store results of one query to use for anothe <makkulka@cisco.com>
        images with perl <paulreid@cableinet.co.uk>
    Re: images with perl <makkulka@cisco.com>
    Re: images with perl (Larry Rosler)
    Re: images with perl <paulreid@cableinet.co.uk>
    Re: Newbie RegEx question <aqumsieh@matrox.com>
        Octal Codes <webmaster@sendyourad.com>
    Re: Octal Codes (Larry Rosler)
    Re: PERL & EXCEL <gellyfish@gellyfish.com>
        perl equivalent of a Unix command line sort? (Paul L. Lussier)
    Re: perl equivalent of a Unix command line sort? (Larry Rosler)
        Searching with 2 input fields <ICEMOUNTAIN@prodigy.net>
        sending mail through perl on IIS 4.0 <centja1@nich-academic.nich.edu>
    Re: Subst text in file with variable contents <makkulka@cisco.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Mon, 30 Aug 1999 17:40:33 -0400
From: "Rodrigo Cortes" <roco3d@softhome.net>
Subject: A Question Of Modules....
Message-Id: <PRCy3.868$3r1.13875@maule>

How to use a module without it is installed in the server??????

--
Rodrigo Cortés
ROCO3D
ICQ: 35921840
http://roco3d.cjb.net




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

Date: Mon, 30 Aug 1999 15:55:52 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: A Question Of Modules....
Message-Id: <37CB0BF7.F18B1923@cisco.com>

[ Rodrigo Cortes wrote:

> How to use a module without it is installed in the server??????

I am assuming that your dilemma is that you do not have the
permissions to install the Perl Module you want.
You can install the module to any directory you want and then add
a  line  in your script ( or set PERL5LIB env variable ).
use lib /path/to/library;
You have to mention this alternate directory during the
installation process using a switch --
perl Makefile.PL INSTALLSITELIB=/path/to/library
--



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

Date: Mon, 30 Aug 1999 16:29:01 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Checking for multiple spaces
Message-Id: <x3yg111vwqa.fsf@tigre.matrox.com>


Kin Lum <kin@0011.com> writes:

> #!/usr/local/bin/perl
> 
> try("ha");
> try(" ha");
> try("ha ");
> try("ha\t");
> 
> sub try {
>     $v = shift;
>     if ($v =~ /^\s|\s$/) {
>         print "yeah dude '$v'\n";
>     }
> }

Please do not post code that will encourage bad habits, even if it was
only an example. You little piece does not enable warnings, and will
fail under the strict pragma.

--Ala



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

Date: Mon, 30 Aug 1999 15:23:43 -0700
From: Brandon Metcalf <bmetcalf@nortelnetworks.com>
Subject: Re: checking return status on system()
Message-Id: <37CB046F.1AC2E627@nortelnetworks.com>

Larry Rosler wrote:

> Naming a user subroutine wih a name beginning with an underscore is a
> Bad Thing.  By convention, it implies a reserved name, not to be used by
> an application.
>
>      system("$cmd") && die "system() call failed on $cmd\n";
>
> The quotes aroung $cmd in the argument are superfluous and misleading.
>
> You would achieve more generality by replacing $cmd by @cmd throughout
> your subroutine (and then the quotes in the subroutine call would be
> damaging as well).
>
> The diagnostic should include the reason for the failure, which is in
> $?, a special variable that you can learn about by reading perlvar.

Thanks for the input.

Brandon



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

Date: Mon, 30 Aug 1999 16:26:32 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Desperately searching for perl lint
Message-Id: <x3yhflhvwuf.fsf@tigre.matrox.com>


bart.lateur@skynet.be (Bart Lateur) writes:

> T. Alex Beamish wrote:
> 
> >Here's one thing that pops to mind: telling me that a variable that
> >I've declared is not used. Great for cleaning up variables that were
> >used in a previous version of the code.
> 
> Does the warning "Name "$foo" used only once: possible typo" mean
> anything to you?
> 
> It's part of standard Perl, assuming you enable -w.

Yes. But this only works on variables in the symbol table, and not on
lexically scoped vars.

Witness:

% perl -w
my $x;
__END__
% perl -w
local $x;
__END__
Name "main::x" used only once: possible typo at - line 1.


It will be nice to be able to check for that. Btw, is this a bug?

--Ala



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

Date: Mon, 30 Aug 1999 21:39:04 GMT
From: smc@smcnet.com (Scott Crevier)
Subject: Re: File listing
Message-Id: <37caf9aa.199516299@news.netnet.net>

On 30 Aug 1999 08:11:39 -0500, abigail@delanet.com (Abigail) wrote:

>Rolf Raven (rolf.raven@quantis.nl) wrote on MMCXC September MCMXCIII in
>|| > I'd like to get all files in a directory matching a specific criteria, ex
>|| > "*.txt", and maybe load them into an array, so that I can for example have a
>|| > drop down combo with all those files in it. How do I do?
>|| 
>|| In the Camel book, page 202:
>|| 
>|| readdir
>|| -------
>|| 
>|| 	opendir THISDIR, "." or die "$!";
>|| 	@allfiles = readdir THISDIR;
>|| 	closedir THISDIR;
>|| 	print "@allfiles\n";
>
>
>And that selects the files matching a specific criteria exactly how?

It selects all the files matching the criteria he used.
The criteria is "."

_____________________________________________________
Scott Crevier
http://www.crevier.org


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

Date: 30 Aug 1999 18:56:36 -0400
From: meow <meowing@banet.net>
Subject: Re: File listing
Message-Id: <877lmckhcr.fsf@slip-32-100-243-84.ma.us.ibm.net>

Rolf Raven <rolf.raven@quantis.nl> wrote:

> Abigail wrote:
>> 
>> Rolf Raven (rolf.raven@quantis.nl) wrote on MMCXC September MCMXCIII in
>> ||      opendir THISDIR, "." or die "$!";
>> ||      @allfiles = readdir THISDIR;
>> ||      closedir THISDIR;
>> ||      print "@allfiles\n";
>> 
>> And that selects the files matching a specific criteria exactly how?

> Well... you know... uhm... yeah... just write "*.txt" instead of "."

The "." was probably fine, if what you're looking to scan is the
current dir.  The above code thingy wasn't exactly wrong, but it's not
finished.  You've got an array of the files in the directory, now it's
time to filter out the ones you want.

#!/usr/local/bin/perl -w
use strict;

my $dirtosearch = '.';
my $findwhat = '\.txt$';

opendir(DIR, $dirtosearch) or die $!;
my @messofiles = grep { /$findwhat/ && -f "$dirtosearch/$_" } readdir(DIR);
closedir(DIR);

print join("\n", sort(@messofiles)), "\n";
__END__


> And yes, I know you should use 'glob'... 

You were on the right track with readdir.  Globbing calls an external
program, it doesn't get along with perl -T, and the dual personality
of <> is the kind of thing that should be saved for obfuscation
contests.


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

Date: Mon, 30 Aug 1999 13:50:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to do this...
Message-Id: <MPG.12348e63ec70909989ee0@nntp.hpl.hp.com>

In article <37CAEB63.2F71C5C2@quantis.nl> on Mon, 30 Aug 1999 22:36:51 
+0200, Rolf Raven <rolf.raven@quantis.nl> says...
> Eirik Johansen [netmaking.com] wrote:
> > I have a file opened using a filhandle called "MAILS". I'm
> > looping through the lines using a while loop. Well, this is what
> > I want the script to do. When it encounters a line in the
> > text-file which consists only of a newline, I want it to read the
> > next four lines (excluding the line which only consists of a
> > newline) into a variable for further editing. (The fifth line
> > always starts with "From:" if that's of any help to you.)
 ...
> while (<MAILS>) {
>     if ($_ eq "\n") {
>         for ($i=0;$i<4;$i++) { <MAILS>; }
>     } else { print $_; }
> }

That just throws four lines away.  He wanted them read into a variable.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 30 Aug 1999 14:23:59 -0700
From: Aaron Lister <alister2NOxqSPAM@csc.co.nz>
Subject: How to have events like onBlur and onChange work with Forms via CGI
Message-Id: <09920fb9.d5905ff0@usw-ex0102-013.remarq.com>

I have a Web page written with Perl and CGI and I want to 
add an action to some popup menu's like the onBlur or 
onChange events of JavaScript.  Can I do this with Perl and 
CGI?  The functions that will be called will be using DBI to 
query a database and populate my next popup menu.  Can 
anyone help?

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Mon, 30 Aug 1999 14:39:14 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: How to have events like onBlur and onChange work with Forms via CGI
Message-Id: <37CAFA01.8140BB2B@cisco.com>

[ Aaron Lister wrote:

> I have a Web page written with Perl and CGI and I want to
> add an action to some popup menu's like the onBlur or
> onChange events of JavaScript.  Can I do this with Perl and
> CGI?

No. Perl and CGI have nothing to do with Javascript. A CGI program can help
you generate a HTML document with the Javascript embedded.  But once
the page is sent to the browser Perl and CGI are out of the picture.
The way your program can embed javascript in the HTML depends on
how you are writing the CGI scripts. Modules like CGI.pm give some
convenient ways to handle this using named parameter passing --(for
more information refer to the CGI.pm documentation )

For example to create a javascript button and handle onClick event.
print $query->button(-name=>'button1',   -value=>'Click Me',
-onClick=>'doButton(this)');

--



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

Date: Mon, 30 Aug 1999 14:36:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how to make sort() case insensitive?
Message-Id: <MPG.12349922b6d80506989ee1@nntp.hpl.hp.com>

In article <2XBy3.1414$I5.142252@juliett.dax.net> on Mon, 30 Aug 1999 
20:36:14 GMT, [L] Vicious! <baal@c2i.net> says...
> Hi, simple question, the sort() function sorts the contents of an array

Of a list, in fact.

>           in
> this order a-z then A-Z (and then 0-9 I think, but thats not too important).

Perhaps not to you!  It's 0-9 A-Z a-z which is ASCII order.

> Is there a way to make the function case insensitive (a=A - z=Z)?

Yes.

Oh, you'd like to know how?  Then I suggest you read the wonderful 
documentation available right there on your local hard disk.  If you do 
`perldoc -f sort`, the answer will be revealed.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 30 Aug 1999 14:31:53 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: how to make sort() case insensitive?
Message-Id: <MPG.12349829263a0bb09896de@nntp1.ba.best.com>

[L] Vicious! (baal@c2i.net) seems to say...
> Hi, simple question, the sort() function sorts the contents of an array in
> this order a-z then A-Z (and then 0-9 I think, but thats not too important).
> Is there a way to make the function case insensitive (a=A - z=Z)?

Sure.  Perldoc -f sort gives a good description.




-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Mon, 30 Aug 1999 14:43:18 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: how to make sort() case insensitive?
Message-Id: <37CAFAF6.46EFEFA4@cisco.com>

[ "[L] Vicious!" wrote:

> Hi, simple question, the sort() function sorts the contents of an array in
> this order a-z then A-Z (and then 0-9 I think, but thats not too important).

This is the default behaviour. You can change it.

> Is there a way to make the function case insensitive (a=A - z=Z)?

Yes
@sorted_list  = sort {uc($a) cmp uc($b)}  @unsorted ;



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

Date: Mon, 30 Aug 1999 15:13:37 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how to make sort() case insensitive?
Message-Id: <MPG.1234a1ed589ea144989ee3@nntp.hpl.hp.com>

In article <37CAFAF6.46EFEFA4@cisco.com> on Mon, 30 Aug 1999 14:43:18 -
0700, Makarand Kulkarni <makkulka@cisco.com> says...
> [ "[L] Vicious!" wrote:
> 
> > Hi, simple question, the sort() function sorts the contents of an array in
> > this order a-z then A-Z (and then 0-9 I think, but thats not too important).
> 
> This is the default behaviour. You can change it.

No, it's not.  Yes, you can.

> > Is there a way to make the function case insensitive (a=A - z=Z)?
> 
> Yes
> @sorted_list  = sort {uc($a) cmp uc($b)}  @unsorted ;

Which proves that *you* know how to find things in the Perl 
documentation.  `perldoc -f sort`:

    # now case-insensitively
    @articles = sort {uc($a) cmp uc($b)} @files;

However,  many of us believe that it is better to give away fishing rods 
than to give away fish.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 30 Aug 1999 14:31:27 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: How to store results of one query to use for another - msql & perl
Message-Id: <37CAF82E.6999C399@cisco.com>

[ Brian Tully wrote:

> Is there any way I can make a query such as select Username, DealerName from
> users where DealerCode = $DealerCodes (where $DealerCodes is the results of
> the previous query)?

Simplest way is to combine both the queries like this --
select Username, DealerName from users where DealerCode IN ( select DealerCodes
from regions
where SalesRegions clike '8' );



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

Date: Mon, 30 Aug 1999 22:50:59 +0100
From: Paul Reid <paulreid@cableinet.co.uk>
Subject: images with perl
Message-Id: <37CAFCC3.463D8767@cableinet.co.uk>

hi I am trying to call a very simple Perl script from an img tag to
return a gif image onto my web page.
Its just a beginer thing then i can advance on to writing my program but
i cant even get the gif to appear on my page to start off.
heres the tag:
           <img src="cgi-bin/tester.pl>

and heres the script:
#!usr/bin/perl -w


require "cgi-lib.pl";

open(FILE, "java.gif") || &CgiDie ("Couldn't open file pic.gif: $!");
print "Content-type: image/gif\n\n";
while (read(FILE, $buf, 16384)) {
print $buf;
}

and my gif is in my cgi-bin dir.
Any advise please



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

Date: Mon, 30 Aug 1999 15:20:51 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: images with perl
Message-Id: <37CB03C3.621E0950@cisco.com>

[ Paul Reid wrote:

> and heres the script:
> #!usr/bin/perl -w

Did you miss as / before the usr ?

> require "cgi-lib.pl";
> open(FILE, "java.gif") || &CgiDie ("Couldn't open file pic.gif: $!");
> print "Content-type: image/gif\n\n";
> while (read(FILE, $buf, 16384)) {
> print $buf;
> }

Rest of the script worked for me. I could see the gif on my browser.



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

Date: Mon, 30 Aug 1999 15:26:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: images with perl
Message-Id: <MPG.1234a4d84d649e85989ee4@nntp.hpl.hp.com>

In article <37CAFCC3.463D8767@cableinet.co.uk> on Mon, 30 Aug 1999 
22:50:59 +0100, Paul Reid <paulreid@cableinet.co.uk> says...
> hi I am trying to call a very simple Perl script from an img tag to
> return a gif image onto my web page.
> Its just a beginer thing then i can advance on to writing my program but
> i cant even get the gif to appear on my page to start off.
> heres the tag:
>            <img src="cgi-bin/tester.pl>

There is an unbalanced quote there.  I assume you intend to use this tag 
to ask the server to execute the program below to send the image from 
another file, but the relative path to the program is unreliable, 
because the web root and the cgi-bin directory need not be related in 
any way.
  
> and heres the script:
> #!usr/bin/perl -w
> 
> 
> require "cgi-lib.pl";
> 
> open(FILE, "java.gif") || &CgiDie ("Couldn't open file pic.gif: $!");
> print "Content-type: image/gif\n\n";
> while (read(FILE, $buf, 16384)) {
> print $buf;
> }
> 
> and my gif is in my cgi-bin dir.
> Any advise please

1.  You have no assurance that your cgi-bin directory is the current 
directory.  That is up to the server and is unreliable.  It is better to 
use absolute filenames or to use chdir to set the current directory 
explicitly.

2.  As you seem to be using Windows 95, you should use binmode() on both 
the input file (FILE) and the output file (STDOUT).

3.  Your actual path in line 1 is probably irrelevant, but Unix people 
will squirm at the idea that your Perl compiler is located at 
'usr/bin/perl' relative to some starting directory.  Put in a leading 
slash, though it won't matter until your program is ported to Unix.  But 
good for you for using the '-w' flag!

4.  You might consider adding 'use strict;' as the second line of yur 
program, to force you to declare all variables.  You will never regret 
it.

5.  You should upgrade your perl if necessary and use CGI instead of 
cgi-lib.pl.  The former is more current and gets much more support.

Whew!  Have the Appropriate amount of fun!  (Larry Wall)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 31 Aug 1999 00:04:11 +0100
From: Paul Reid <paulreid@cableinet.co.uk>
Subject: Re: images with perl
Message-Id: <37CB0DEB.15648F1F@cableinet.co.uk>

ok Thanks I realise now i had a missed hyphen in my path

I tried the CGI.pm but am having problems and have contacted my ISP.
I did get one response when I tried it on the virtualave server so that gave
me a boost of encouragment.

Thanks for the help better not waste anymore bandwidth.






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

Date: Mon, 30 Aug 1999 16:38:34 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Newbie RegEx question
Message-Id: <x3yemglvwad.fsf@tigre.matrox.com>


"Doug Bennett" <dbennett@hsstelford.freeserve.co.uk> writes:


> I want to check whether a string includes the characters:
> tsj
> in it. I want this to be true only if the characters appear in that order,
> eg
> "this joint" would return true, whereas
> "short jump" would return false even though the three characters appear in
> this phrase. 

Ok.

> The check should be case insensitive.

Ok.

> Could someone help me with the expression for this. Thanks

Sure. What have you tried to do so far? Could you post some code?
How efficient do you want the solution to be?

Did you read perlre?

HTH,
--Ala



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

Date: Mon, 30 Aug 1999 16:47:34 -0400
From: webmaster <webmaster@sendyourad.com>
Subject: Octal Codes
Message-Id: <37CAEDE6.26D@sendyourad.com>

I am receiving a text feed from another system that is passing an octal
code of 32 within the text of the feed.  When I run my perl script to
manipulate some of the data in the text feed it comes to the place where
the octal 32 code is and moves 100+ plus lines down the feed and then
continues.  I can't see any visual representation of the of the octal
code nor can I use the chop command to get rid of it even though it
always appears at the end of a line.  Can anyone out there help me?


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

Date: Mon, 30 Aug 1999 14:39:35 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Octal Codes
Message-Id: <MPG.123499f6f5be352f989ee2@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <37CAEDE6.26D@sendyourad.com> on Mon, 30 Aug 1999 16:47:34 -
0400, webmaster <webmaster@sendyourad.com> says...
> I am receiving a text feed from another system that is passing an octal
> code of 32 within the text of the feed.  When I run my perl script to
> manipulate some of the data in the text feed it comes to the place where
> the octal 32 code is and moves 100+ plus lines down the feed and then
> continues.  I can't see any visual representation of the of the octal
> code nor can I use the chop command to get rid of it even though it
> always appears at the end of a line.  Can anyone out there help me?

Octal 32 is Control-Z, which is the end-of-file indicator on some 
systems, particularly Windows/DOS, which you seem to be using (at least 
for reading netnews).  I would suggest that before reading the file, you 
use binmode on its filehandle, and see if that fixes the problem.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 30 Aug 1999 21:33:00 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: PERL & EXCEL
Message-Id: <7qetac$5h5$1@gellyfish.btinternet.com>

On Tue, 24 Aug 1999 16:32:02 -0700 David Cassell wrote:
> Michael Hill wrote:
>> 
>> Will this run in unix or is this only for dos versin of perl?
>> 
>> Mike
>> 
>> Eduard Wulff wrote:
> [snip of code]
>> > use Win32::OLE;
>> > use Win32::OLE::Const 'Microsoft Excel';
> [more snippage]
> 
> This uses OLE and a functional copy of M$ Excel, so it will
> only work on a win32 system.
> 

I might add that if someone wants to experiment with reading Excel
files on Unix then they might want to try out something called LAOLA
which is referenced on the Win32 pages at <http://www.perl.com> it
is an attempt to read OLE storage files directly from Perl.  I cant
vouch any further for it I'm afraid.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 30 Aug 1999 18:16:25 -0400
From: plussier@baynetworks.com (Paul L. Lussier)
Subject: perl equivalent of a Unix command line sort?
Message-Id: <h67ogfo29ty.fsf@baynetworks.com>


Hi all,

I'm trying sort a lists of ip addresses in a script, and thought there
must be a perl way of doing it.  I'm can get exactly what I want from
the command line using this:

	sort -n -t. -k 1,1 -k 2,2 -k 3,3 -k 4,4

But the best I could come up with in perl is just calling this via opening
a pipe to sort::

  open (SORT, "| sort -n -t. -k 1,1 -k 2,2 -k 3,3 -k 4,4 >/tmp/Tmp$$");

  foreach (keys %subnet) {
    print SORT "$subnet{$_}{'ip'};$subnet{$_}{'mac'};$_\n";
  }

Then processing the temp file.  I've tried various ugly and cpu intensive 
ideas with hashes and for loops that seem to just take forever.  For instance:

#!/usr/bin/perl 

$hosts = "ypcat hosts|";
$ref_host_hash = read_hosts ($hosts);
$ref_sorted_hosts_array = sorthosts ($ref_host_hash);


sub read_hosts {
  open (FILE, "$file") || die "$prog: Can't open file: \"$file\" -> $!\n";
  while ($line = <FILE>) {
    next if ($line =~ /^\s*$|^\#/g );
    chomp ($line);
    ($line, $comment) = split /#/,$line;
    ($ip,$hostname,@aliases) = split (/\s+/, $line);
    ($subnet = $ip) =~  s/((((\d{0,3})\.){2})\d{0,3})\..*/$1/g;
    $ip =~ s/.*\.(\d+)/$1/g;

    %{$subnet{$subnet}{$hostname}} = ( 'ip'     => $ip,
					'aliases' => [ @aliases ],
			             );
    %{$subnet{$subnet}{$ip}} = ( 'hostname' => $hostname, );
  }
}

sub sorthosts {

  # Sort hosts based on IP address
  my ($host_hash) = shift;

  my (@subnets) = sort keys %{$host_hash};

  foreach $subnet (@subnets) {
    ($first_octet,$second_octet,$third_octet) = split (/\./, $subnet);

    $networks{$first_octet}{$second_octet}{$third_octet} = 1;
  }

  @octet_a = sort (numerically (keys (%networks)));
  foreach $oct (@octet_a) {
    push (@octet_b, sort (numerically (keys (%{$networks{$oct}}))) );
  }
  @octet_b = sort (numerically (@octet_b));

  foreach $octa (@octet_a) {
    foreach $octb (@octet_b) {
      push (@octet_c, sort numerically (keys (%{ $networks{$octa}{$octb}})));
    }
  }

  @octet_c = sort (numerically (@octet_c));

  foreach $octa (@octet_a) {
    foreach $octb (@octet_b) {
      foreach $octc (@octet_c) {
	if (defined $networks{$octa}{$octb}{$octc}) {
	  push (@sorted_subnets, join ('.', $octa, $octb, $octc));
	}
      }
    }
  }
  
  $prev = 'nonesuch';
  @sorted_subnets = grep($_ ne $prev && ($prev = $_), @sorted_subnets);

  print "Content-type: text/html";
  print "\n\n";

  foreach $subnet (@sorted_subnets) {
    @hosts = grep (/^\d+$/, keys %{${$host_hash}{$subnet}});
    @hosts = sort numerically @hosts;
    print "<FONT COLOR=#000000>";  
    print "<b>$subnet:</b>\n";
    print "<FONT COLOR=#0000FF>";
    print ("IP Adress		Hostname		Aliases\n");
    print ("---------------	--------------------	----------------------
---------\n");
    foreach $host (@hosts) {
      $ip = "$subnet.$host";
      $hostname = ${$host_hash}{$subnet}{$host}{hostname};
      $aliases = join (' ', @{${$host_hash}{$subnet}{$hostname}{aliases}});
      write ();
    }
    print "\n";
   }
}

sub numerically {
  
  $a <=> $b;
}

format =
@<<<<<<<<<<<<<<		@<<<<<<<<<<<<<<<<<<<<	@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$ip,$hostname,$aliases
 .

I either:

	a) don't know enough about sorting in perl
	b) have run out of creative ideas
	c) am making more of the problem than I should, and am missing 
	   a quite obvious and simple solution
	d) all of the above

Does anyone else have any more elegent, more efficient ways of doing this?
Thanks,

-- 
Seeya,
Paul


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

Date: Mon, 30 Aug 1999 15:46:49 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: perl equivalent of a Unix command line sort?
Message-Id: <MPG.1234a9afe408a9bc989ee5@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <h67ogfo29ty.fsf@baynetworks.com> on 30 Aug 1999 18:16:25 -
0400, Paul L. Lussier <plussier@baynetworks.com> says...
> I'm trying sort a lists of ip addresses in a script, and thought there
> must be a perl way of doing it.  I'm can get exactly what I want from
> the command line using this:
> 
> 	sort -n -t. -k 1,1 -k 2,2 -k 3,3 -k 4,4
 ...
> ...  I've tried various ugly and cpu intensive 
> ideas with hashes and for loops that seem to just take forever.

I can see why!

 ...

> sub sorthosts {
> 
>   # Sort hosts based on IP address
 ...

> I either:
> 
> 	a) don't know enough about sorting in perl
> 	b) have run out of creative ideas
> 	c) am making more of the problem than I should, and am missing 
> 	   a quite obvious and simple solution
> 	d) all of the above
> 
> Does anyone else have any more elegent, more efficient ways of doing this?

How would a paper whose primary example is sorting a list of strings 
acccording to an embedded IP address suit you?  If you absorb all of it, 
I guarantee that item 'a' in your list will be taken care of.  Item 'c' 
won't be far behind.  And if you come up with anything under item 'b', 
please let us know.

<URL:http://www.hpl.hp.com/personal/Larry_Rosler/sort/>

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 30 Aug 1999 15:41:32 -0400
From: <ICEMOUNTAIN@prodigy.net>
Subject: Searching with 2 input fields
Message-Id: <7qen01$38j4$1@newssvr04-int.news.prodigy.com>

I am new to perl and am making a script to search a gallery of pictures that
I have on my website. I have a text file with the information of the
pictures and I want to search that with 2 input fields (model and year), I
cant get it to work though. It works if I search with only one field. You
can see the script at http://www.3gc.net/gallerysearch.txt




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

Date: Mon, 30 Aug 1999 21:09:57 GMT
From: Justin Centanni <centja1@nich-academic.nich.edu>
Subject: sending mail through perl on IIS 4.0
Message-Id: <7qerus$b46$1@nnrp1.deja.com>

hi,

my team is in the middle of converting a website from a Unix box to an
NT machine running Internet Information Server 4.0.  My problem is that
although i have perl running the scripts correctly and the SMTP service
on IIS setup and working, i can't get the two to talk to each other on
a script that needs to send email from a form.

i've looked at matt wright's documentation on formmail as well as other
documentation, but that all is geared to Unix and not towards running
ActivePerl on Win32.

At any rate, if anyone can shed the light on the situation, as i am
totally inexperienced when it comes to perl, i would greatly appreciate
it and sleep a little better tonight

Thanks,
Justin


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Mon, 30 Aug 1999 15:05:52 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Subst text in file with variable contents
Message-Id: <37CB0040.92950048@cisco.com>

[ bigtrain23@my-deja.com wrote:

> i'm trying to open a file for writing (file
> contains info i want to keep), search for the
> string 'defaultgateway=' (no quotes) and subtitute
> a variable's value for whatever comes after the
> equal sign. how do i do this?

Assuming the value is in the variable $defaultgateway --

open(TEMPLATE, "your_file") or die "...saying something" ;
{
 local($/) = undef;
 my $template = <TEMPLATE>;  # read entire contents of the file..
 $template =~ s/(defaultgateway=)/$1$defaultgateway/g;
 #Now seek to the beginning of the file and write $template to it.
}
If the file is too large then read it line by line and make
substitutions
on each line and then write them to a new file. Delete the older
file when you are done. Rename the newer file as the older one.

If you are trying to use templates in your programs then
I would recommend you read this tutorial on using Perl/CGI/Templates
on webmonkey.com --
http://www.hotwired.com/webmonkey/code/97/21/index2a.html?tw=backend
--



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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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 V9 Issue 682
*************************************


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