[10855] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4456 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 18 18:17:31 1998

Date: Fri, 18 Dec 98 15:01:32 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 18 Dec 1998     Volume: 8 Number: 4456

Today's topics:
        IPC + UNIX (uncommon platform) kkivi@chat.ru
    Re: log using CGI.pm <gellyfish@btinternet.com>
        Nested sorting (Bill Moseley)
    Re: Nested sorting (Larry Rosler)
    Re: numbers in base 36 ptimmins@netserv.unmc.edu
    Re: numbers in base 36 <jhi@alpha.hut.fi>
    Re: Parsing image tags <gellyfish@btinternet.com>
    Re: Passing hash to module written in C <Arved_37@chebucto.ns.ca>
        Script that faxes <erik@caid.com>
    Re: Search Not Working <r28629@email.sps.mot.com>
    Re: Searching through a 10MB file (Bart Lateur)
    Re: Security in Distributing Scripts. (Tad McClellan)
    Re: Unix / Nt Perl Modules ?? <gellyfish@btinternet.com>
    Re: Writing Perl with Notepad <shameluss plug> (Sean McKenna)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 18 Dec 1998 22:00:44 GMT
From: kkivi@chat.ru
Subject: IPC + UNIX (uncommon platform)
Message-Id: <75ejaa$lu7$1@nnrp1.dejanews.com>

Hello All!

Please help to understand the
problem with our perl script that makes backup
of our oracle database.

This script is used by our friendly
DBA to backup several oracle database
and work just fine. The unixes
are usual SCO, Solaris, ...

But on our machine it fails every
other time. The oracle part works
just fine. The problem begins
when we try to manipulate files.

The scripts uses the following
constructs

@OldArchiveLogs = split(/\s+/,`echo $ArchiveDest*.gz
$ArchiveDestDir/BEFORE-$ORACLE_SID*.ARC`);

 .........

@BackupDirectories =
   sort { (stat($b))[10] <=> (stat($a))[10]; } # reverse sort by creation date
   <$BackupRoot/root/$ORACLE_SID-*>;


 ............
    open (DELFILES,"find $from -type f ! -name $bih  -follow -print|")
        or Die_("Errors during DeleteTree.");
    @flist=(<DELFILES>);

all variables being interpreted are set correctly.

All of these command sometimes fails. The result is empty arrays.
Some of them was put in a loop and works correctly on the second run.
The next run of the failing programme  almost always is successful.
All variables being interpreted are set correctly.

I think that there is a problem with reading output from the child
process. But all constructs looks rather standard. I guess
if I can trust perl at our (Nile Pyramid, MIPS, DC/OSx)
rather unusual machine. Is this a known bug, or
such constructs are unreliable, or our computer is not
supported? What will you say?

PS this the output of perl -V
hope it will help

Summary of my perl5 (5.0 patchlevel 4 subversion 1) configuration:
  Platform:
    osname=svr4, osvers=, archname=NILE 150-svr4
    uname='smp_dc-osx nile150 1.1-95d087 dcosx nile 150 4256 r4400 '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=n useperlio= d_sfio=
  Compiler:
    cc='cc', optimize='-O -K Olimit:3064', gccversion=
    cppflags='-DLANGUAGE_C'
    ccflags ='-DLANGUAGE_C'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=n, randbits=15
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib /shlib /lib
    libs=-lsocket -lnsl -lmalloc -ldl -lm -lc -lcrypt
    libc=/usr/ccs/lib/libc.so, so=so
    useshrplib=true, libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags='-Blargedynsym'
    cccdlflags='-Kpic', lddlflags='-G -lc -L/usr/local/lib'


Characteristics of this binary (from libperl):
  Built under svr4
  Compiled at Oct 28 1997 17:20:57
  @INC:
    /ROOT/usr/local/lib/perl5/NILE
    /ROOT/usr/local/lib/perl5
    /ROOT/usr/local/lib/perl5/site_perl/NILE
    /ROOT/usr/local/lib/perl5/site_perl
    .

Sincerely yours, Konstantin Kivi

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 18 Dec 1998 22:28:59 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: log using CGI.pm
Message-Id: <75ekvb$e6$1@gellyfish.btinternet.com>

On 18 Dec 1998 05:05:08 GMT 6})lRD <youzi.bbs@MSIA.pine.ncu.edu.tw> wrote:
> 
>         I used remote_host() to read where the user came from,
>         but when remote user use proxy server to catch data,
>         I can only know the proxy server's IP, but not the real one,
>         what shall I do?  

Its basically tough.  Even if you *could* (and you almost certainly cant) 
in some way determine the actual IP address it would probably be a waste of 
time knowing it because very often a proxy will hide a bunch of bogus 
addresses that are meaningful only on that network and meaningless to the 
wider DNS or anything else for that matter...

/J\
-- 
Jonathan Stowe <jns@btinternet.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: 18 Dec 1998 21:08:02 GMT
From: moseley@best.com (Bill Moseley)
Subject: Nested sorting
Message-Id: <367ac432$0$214@nntp1.ba.best.com>

I'm looking for some suggestions on improving this nested sort routine.


I've got an array where each element points to another array, with the first
element being a reference to my actual data, and the second element points to
a list of sort keys extracted from the data in pre-processing.

So, an array element looks like [ $data_ref, \@sort_keys ];

I don't know the format of the sort keys (numeric vs. alpha), and if the first
character is a "!" then I do a reverse sort.


sub list_sort {

   my $compare;

   
   # Loop through all the sort keys
   
   for (0..$#{$a->[1]} )  {

       # create local copies of the data 

       my $aa = $a->[1][$_];
       my $bb = $b->[1][$_];


       
       # look for reverse sort flag

       if ( $aa =~ /^!/ ) {      # "!" is a reverse flag
          my $cc = $aa;          # Would index() be better than m//?
          $aa = $bb;
          $bb = $cc;
       }

       $compare =  (
                       $aa <=> $bb 
                            or
                    lc($aa) cmp lc($bb)
                   );


       # Return if they don't match

       return $compare if $compare;
   }

   0;  # return something if falls through
}




--------------
Bill Moseley
moseley@best.com



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

Date: Fri, 18 Dec 1998 14:20:29 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Nested sorting
Message-Id: <MPG.10e4750c33ead7bc9898db@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <367ac432$0$214@nntp1.ba.best.com> on 18 Dec 1998 21:08:02 
GMT, Bill Moseley <moseley@best.com> says...
> I'm looking for some suggestions on improving this nested sort routine.

You came to the right place!  You should look back in DejaNews for many 
recent discussions on this subject.

> I've got an array where each element points to another array, with the first
> element being a reference to my actual data, and the second element points to
> a list of sort keys extracted from the data in pre-processing.

You didn't do enough pre-processing.  The goal should be to reduce the 
sort subroutine to triviality, or -- even better -- to non-existence.  
All the processing you do in your current routine on a comparison-by-
comparison basis should be done once, before actually sorting.
  
> So, an array element looks like [ $data_ref, \@sort_keys ];
> 
> I don't know the format of the sort keys (numeric vs. alpha), and if the first
> character is a "!" then I do a reverse sort.

These characteristics can and should be resolved during the pre-
processing that computes a single key per datum.

I have made a couple of comments below about your code, but I don't 
endorse this approach.

> sub list_sort {
> 
>    my $compare;
>    
>    # Loop through all the sort keys
>    
>    for (0..$#{$a->[1]} )  {
> 
>        # create local copies of the data 
> 
>        my $aa = $a->[1][$_];
>        my $bb = $b->[1][$_];
>        
>        # look for reverse sort flag
> 
>        if ( $aa =~ /^!/ ) {      # "!" is a reverse flag
>           my $cc = $aa;          # Would index() be better than m//?

Yes, but considering how pokey the rest of the code is, you would 
*never* note the difference.

>           $aa = $bb;
>           $bb = $cc;

Perl supports a one-line swap:  ($aa, $bb) = ($bb, $aa);  But where do 
you get rid of the '!'?  What if it is one one of the values but not the 
other?

>        }
> 
>        $compare =  (
>                        $aa <=> $bb 

With '-w' on, this would be a very noisy way to disambiguate numbers 
from letters.  Convert the numbers to strings in the pre-processing, as 
discussed and demonstrated in the recent discussions in this group.

>                             or
>                     lc($aa) cmp lc($bb)

Similarly, do the case-smashing in the pre-processing.

>                    );
> 
> 
>        # Return if they don't match
> 
>        return $compare if $compare;
>    }
> 
>    0;  # return something if falls through
> }

There is also a FMTYEWTK about sorting, and a FAQ that you should 
absorb:  perlfaq4:  "How do I sort an array by (anything)?"

Good luck!

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


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

Date: Fri, 18 Dec 1998 20:55:58 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: numbers in base 36
Message-Id: <75efgt$ijv$1@nnrp1.dejanews.com>

In article <75d90c$h4f$1@nnrp1.dejanews.com>,
  deja@kiama.com wrote:

> Is there a way for perl to read numbers in bases other 8,10, and 16?
>
> There is a function in Java to format an integer in any base, I would like to
> create a base 36 number in java and pass it to a perl script. Can perl convert
> it back to decimal?

$digit = "3F2M";         # the base36 $digit you want to convert to decimal
$temp  = $digit;         # making a copy to work with
$temp =~ tr/A-Z/a-z/;    # allowing for uc or lc letters

%dec = map { $_ => $i++ } (0..9,'a'..'z'); # map the 36 base36 characters
                                           # to their corresponding base10
                                           # values

if ($temp =~ /^[0-9a-z]+$/) {
    print b36_to_d($temp) or die "$_\n";
} else {
    print "$digit is not a valid base36 number\n";
}

sub b36_to_d {
  my $temp = shift;
  my @holder = split //, $temp;
  my @rev_holder = reverse @holder;  # want to work from right to left
  my $new;
  my $i;
  foreach (@rev_holder) {
    $new += ( $dec{$_} * (36**$i++) );
  }
  return "base36 $digit equals base10 $new\n";
}

Going back the other way (base10 to base36) would be interesting ...
maybe later :)

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 18 Dec 1998 23:22:56 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: numbers in base 36
Message-Id: <oeesoedrvpr.fsf@alpha.hut.fi>


ptimmins@netserv.unmc.edu writes:

> In article <75d90c$h4f$1@nnrp1.dejanews.com>,
>   deja@kiama.com wrote:
> 
> > Is there a way for perl to read numbers in bases other 8,10, and 16?
> >
> > There is a function in Java to format an integer in any base, I would like to

Okay, give me 123**456 in base 789? 

-- 
$jhi++; # http://www.iki.fi/~jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: 18 Dec 1998 22:20:04 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Parsing image tags
Message-Id: <75ekek$e3$1@gellyfish.btinternet.com>

In comp.lang.perl.misc pedja@dds.nl wrote:
> Hi,
> 
> I am new in perl..
> I want to extract all image tags and his elements from html file.
> For example:
>  <img src="left.gif" alt="Go left" width=40 height=50>
> must return:
> -absolute path="http://www.dejanews.com/left.gif"
> -alt="Go left"
> -width=40
> -height=50
> 
> Can you give me example with use of HTML Parser or without.
> Sorry for bad english!
> 

What you mean something like this:

#!/usr/bin/perl

package GetIMG;

@ISA = qw(HTML::Parser);
require HTML::Parser;
use strict;

my $parser = new GetIMG;

$parser->parse_file($ARGV[0]);

sub start()
{
   my($self,$tag,$attr,$attrseq,$orig) = @_;
   if ( $tag eq 'img')
     {
       for (keys %{$attr} )
          {
            print "$_ = > $attr->{$_}\n";
          }
     }
}
__END__

You will pass this the name of an HTML file and it will print out the
attributes of all of the IMG tags.

Of course if you want to retrieve the file from another server you will need
to use LWP::UserAgent to retrieve the page into a variable and use the 
parse() method instead of parse_file().

/J\
-- 
Jonathan Stowe <jns@btinternet.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: Fri, 18 Dec 1998 17:44:15 -0400
From: Arved Sandstrom <Arved_37@chebucto.ns.ca>
Subject: Re: Passing hash to module written in C
Message-Id: <Pine.GSO.3.95.iB1.0.981218174109.19436B-100000@halifax.chebucto.ns.ca>


Excuse the massive snippage...

What bbecho is seeing is a RV *, not a HV *. So you need to declare it
that way, and then dereference.

Arved

On 15 Dec 1998, Bryan Beske wrote:

> bbtest( \%foo );
> ...
> void
> bbecho( host )
>         HV  * host
>         CODE:
> 
> When I build the module, All is fine. When I run the program, I get:
> "host is not of type HVPtr at test.pl line 10."



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

Date: Fri, 18 Dec 1998 14:45:05 -0800
From: Erik Boles <erik@caid.com>
Subject: Script that faxes
Message-Id: <367ADAF1.5DF5@caid.com>

I know there are scripts out there for CGI that will take info from a
web form and email it to someone, what I am looking to do is take the
information it would normally email and instead, fax it to a
predetermined fax number in the script...is this possible or would I
need another program to interprit the data and format it for faxing??

Any help is greatly appreciated....I am just getting into PERL and have
a lot of learning yet to do....

_E


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

Date: Fri, 18 Dec 1998 16:03:31 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Search Not Working
Message-Id: <367AD133.FB45D214@email.sps.mot.com>

Larry Rosler wrote:
> 
> In article <75c602$971$0@206.165.165.139> on 18 Dec 1998 00:01:06 GMT,
> Allan M. Due <due@murray.fordham.edu> says...
> > Tim Hicks wrote in message ...
> ...
> > |  @record = split(/|/,$_);
> >
> > Well, that | is a problem as it is the alternation metacharacter.  You need to
> > escape it
> >
> > @record = split(/\|/,$_);
> 
> Judging by the frequency of that bug in this newsgroup, it would make
> any "top 10" list of Frequent Perl Bugs, at least in the regex area.
> Such lists for C and C++ ended up in books, "C Traps And Pitfalls" by
> Andrew Koenig, ISBN 0201179288, and "Ruminations on C++" by Andrew
> Koenig and Barbara Moo, ISBN 0201423391.  Any similar lists for Perl?

perhaps someone should start a FAQ-like perltrap.

-TK


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

Date: Fri, 18 Dec 1998 21:04:01 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Searching through a 10MB file
Message-Id: <367dbe6a.2975122@news.skynet.be>

Christian M. Aranda wrote:

>Below, please find my modified version of the module.

I've messed with it a bit.

  sub get_ddts_record {
	local($id) = @_;	# $ddts_value{identifier}
	local($attached_record,$BugIdFound,$GetData) = "";
	open(DDTS_DATA, "$ddts_file") || 
	  &err_msg("fatal", "Unable to open data file", "open", undef );
	 while (<DDTS_DATA>) {
		if (/^Start: *(\w+)/ && $1 eq $id) {
			$BugIdFound = 1;
		} elsif ($BugIdFound) {
			last if /^End *(\w+)/ && $1 eq $id;	# done
			$GetData = 1 if /^History/;
			if ($GetData) {
				$attached_record .= $_; # no chop!
			}
		}
	}
	close(DDTS_DATA);
	@comments  = split("Related-file:",$attached_record);
	# works as a function as well...
  }

I hope it's fast, according to your requirements... (and I haven't
tested it. It does compile... on Perl 5 ;-)

   HTH,
   Bart.


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

Date: Fri, 18 Dec 1998 15:57:46 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Security in Distributing Scripts.
Message-Id: <q4je57.rpu.ln@magna.metronet.com>


[ How come you have a bunch of entries in your References:
  header, yet no Re: in your Subject: header?

  Followup when you are following up. Start a new thread when
  you are starting a new thread.
]

mjswart@my-dejanews.com wrote:
: When I write a c++ program, compile it, and distribute it, I am
: confident that noone can look at my source code since it is difficult
: to decompile an optimized executable.

: In a Perl program, since the scripts are interpreted, they must be
: distributed as is.


   Perl FAQ, part 3:

      "How can I hide the source for my Perl program?"


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 18 Dec 1998 21:48:38 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Unix / Nt Perl Modules ??
Message-Id: <75eijm$bp$1@gellyfish.btinternet.com>

On Fri, 18 Dec 1998 16:23:01 -0800 Kim Squires <kim@metanoia.demon.co.uk> wrote:
> I am running a pl script that uses the Date::Manip routines ... from an NT
> server.
> 
> I get an error message posted back :
> 
> ERROR: Date::Manip unable to determine TimeZone. Date::Manip::Date_TimeZone
> called at C:\perl\lib\site/Date/Manip.pm line 2332
> 
> What concerns me here is the change in the slashes from ' \ ' to  ' / ' in
> the middle of the path statement.
> 
> Which to me suggests I am running a unix version of the specified module, as
> opposed to the Nt version ?
> 
> And the string passed in being Nt is being added to a unix string ???
> 
> Or am I abit misguided here ...
> 

Yeah you're being a bit misguided here ;-}

> Any possiblities, thoughts, answers... would be greatly appreciated ... :)
> 

The actual slashes used make little difference to Perl (or the underlying
os for that matter) - on the whole you are better off using the forward 
slashes in your programs as path delimiters so you can avoid excessive
escaping of the backslashes.

The reason that the slashes change in the middle of the message there is
most probably because the path where the module is found is defined with
the backslashes whereas Perl works out the rest of the path using the more
platform independent forward slashes.

As for the actual message it is a bit strange - I assumed that the Timezone
was alaways available in NT - however you might try seting the TZ
environment variable to an appropriate value (I for instance would use
GMT0BST here and I guess from your mail address you could try it too).

/J\
-- 
Jonathan Stowe <jns@btinternet.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: Fri, 18 Dec 1998 14:19:35 -0800
From: seanmck@mckennaprod.com (Sean McKenna)
Subject: Re: Writing Perl with Notepad <shameluss plug>
Message-Id: <367bd311.22429105@nntp1.ba.best.com>

On Thu, 17 Dec 1998 23:55:54 +0100, Mark <admin@asarian-host.org>
wrote:

>
>I have recently discovered UltraEdit32; nothing compares to it;

Seconded.

Some features in UltraEdit32 which I find very useful are the Hex mode
and Column mode edit functions, the file compare and file format
conversion functions, and the built in FTP.


Sean McKenna   "All the world's a stage..."


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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