[18980] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1175 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 22 06:06:15 2001

Date: Fri, 22 Jun 2001 03:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993204311-v10-i1175@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 22 Jun 2001     Volume: 10 Number: 1175

Today's topics:
        [PAM] validating users using PAM <robin@aly.de>
    Re: adding newline in binary files (Martien Verbruggen)
        BCD Binary Coded Decimal Problem!! (Harry Yau)
    Re: command line news posting tools (Alexis Huxley)
    Re: connectivity problem using ADO (Peter Heweston)
    Re: deleting a file: permission denied nobull@mail.com
    Re: Executing UNIX shell commands in PERL <tp601553@cia.gov>
        Grabbing a web page? (cmavroudis)
    Re: Grabbing a web page? (Rafael Garcia-Suarez)
    Re: Install Perl on HP (Ralph)
    Re: Install Perl on HP (Ralph)
    Re: Is There Any Other Routine Like CHOP(); <michael_w@pacific.net.au>
    Re: Making a bundle of Perl modules <randy@theory.uwinnipeg.ca>
    Re: Mod_perl problem <ubl@schaffhausen.de>
    Re: Opening a Netscape Window using a Perl script (Tim Hammerquist)
    Re: Passing a DBM name to a program. <amittai@amittai.com>
        Perl description <ccespede@anakena.dcc.uchile.cl>
        Perl to Oracle connectivity <brian@jankoNOnet.SPAMcom.INVALID>
    Re: Reference-problem <bwalton@rochester.rr.com>
    Re: Reference-problem <sserena@freesurf.ch>
    Re: Reference-problem <sserena@freesurf.ch>
        Searchin for .sh (Naru Mangalath)
    Re: Searchin for .sh <krahnj@acm.org>
    Re: Searchin for .sh (Abigail)
    Re: Searchin for .sh (Abigail)
    Re: setting priority from perl on linux <troyr@vicnet.net.au>
    Re: Sorting array on multiple keys <goldbb2@earthlink.net>
    Re: splice/Join and split!! (Philip Lees)
    Re: splice/Join and split!! <krahnj@acm.org>
        Suggestion: fallback for Tie::Handle <johnlin@chttl.com.tw>
        Unix filepath completion within perl? <george.stevens@baesystems.com>
    Re: Unix filepath completion within perl? (Anno Siegel)
    Re: Which C compiler to use for modules? (Martin Vorlaender)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 22 Jun 2001 09:59:58 +0200
From: "Robin Aly" <robin@aly.de>
Subject: [PAM] validating users using PAM
Message-Id: <9gutqo$tdd$07$1@news.t-online.com>

Hello,
how can I validate user/password pairs with PAM (linux). Do I need a module?
Any Help?

Robin




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

Date: Fri, 22 Jun 2001 03:06:38 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: adding newline in binary files
Message-Id: <slrn9j5dhu.1sd.mgjv@verbruggen.comdyn.com.au>

On 20 Jun 2001 13:01:43 GMT,
	Bard Selbekk <bard.selbekk@edbteamco.NO_SPAMcom> wrote:
> Philip Newton <pne-news-20010620@newton.digitalspace.net> wrote in 
> news:6331jtsuj4o2khvlfeaccr0tkueir3u641@4ax.com:
>> 
>> Use read() in a loop? That lets you specify how many characters you
>> want.
>> 
> 
> Thank you very much, sir. That really did the trick!
> 
>   $input_file = "BCD";
>   open(UTFIL, ">UTFIL.txt");
>   open(F_FILE, $input_file);

You said these were binary files, right? As long as you're on an OS
that doesn't care about the difference between text and binary files,
this code will work fine. However, if you're on an OS that does care,
your code will suddenly, irregularly, and mysteriously start breaking.

It is always a good idea to use binmode() on file handles that need to
read or write binary data, even if you're on a platform that doesn't
care, just for the sake of portability, and code documentation.

binmode(UTFIL);
binmode(F_FILE);

Martien
-- 
Martien Verbruggen                      |
Interactive Media Division              | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 22 Jun 2001 02:17:22 -0700
From: harry.yau@regaltronic.com (Harry Yau)
Subject: BCD Binary Coded Decimal Problem!!
Message-Id: <afe2a6a8.0106220117.38389594@posting.google.com>

Hi Folk: 
    I am working on a project to calculate the average cost of
products which is made of a lot of small parts. In order to find out
the cost of a product, I have to find out the cost of all its parts.
However, I am facing some problem with the the decimal
pleace. The range of the parts values is about $0.00001 - $3.00. When
I multiple these price with the quantity something
around 0.001 -10, the result returned by the script will be
inaccurated. Let say, I doing something like:
    $0.05126 * 2  =  $0.10252 
supposingly, but the result will become something like 
    0.102519999999997986. 
    I think this is the problem of my CPU or the complier that they
can't represent the decimal number precisely in binary mode
underneath. Althougth I can round off the result to get a pretty good
answer for each part, the cost of the final product
becomes unacceptable after summing up the price of all litte parts. 
    I, then, wrote a small script to tried out this problem with
simple calculation. I did:
    3.03313 - 3.03312 
obviously, the answer should be 
    0.00001 
but the result of the script becomes: 
    9.99999999997669e-06 
    These several day, I've tried to find something like BCD (Binary
Coded Decimal) for Perl, but nothing had been found.
Therefore, I'm wondering may anybody out there could help me with this
problem. I wanna know is there any third party
module that can do the calculation in BCD mode for perl. Actually,
I've tried the Math::BigFloat, and
Math::FixedPrecision, but I find that they mainly limit the number
decimal pleaces to be calculated or the round off problem.
This is not something I am really looking for. 
Please, find me some method. 

Thank You very Much. 

Harry Yau


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

Date: Fri, 22 Jun 2001 07:07:29 +0000 (UTC)
From: ahuxley@eso.org (Alexis Huxley)
Subject: Re: command line news posting tools
Message-Id: <9guqrg$he8$1@nntp.hq.eso.org>

In <sa8n172wnck.fsf@suntong.personal.users.sourceforge.net> * Tong * <sun_tong@users.sourceforge.net> writes:

> Please suggest a news posting tool that can be used from command
> line, which has the function that like 'sendmail -t' (scanned
> message for headers) TIA

Try nnpost, which is part of the 'nn', still the king of NUA's?: 

te35$  nnpost -s "test alexis" -k "" -y "" -d world -f /dev/null -p de.test
Connecting to NNTP server news.hq.eso.org ...
Connecting to NNTP server news.hq.eso.org ... ok (posting is allowed)
Be patient! Your new article will not show up immediately.
Article posted
te35$ 

Alexis
--
------------------------------------------------------------------------------
Alexis Huxley                                                  ahuxley@eso.org
Rilke,SW,me                                       http://www.eso.org/~ahuxley/
------------------------------------------------------------------------------


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

Date: 21 Jun 2001 22:45:03 -0700
From: p.heweston@att.net (Peter Heweston)
Subject: Re: connectivity problem using ADO
Message-Id: <a973e59.0106212145.7b820b8a@posting.google.com>

We've had considerable success using ADO and Access, with a very
simple connection string. See the attached code for some examples of
ADO connecting to Access, Oracle, and Foxpro:
use Win32;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';


      # Foxpro table connection
$Connect = "Driver={Microsoft Visual FoxPro
Driver};UID=;PWD=;SourceType=DBF;SourceDb=g:\\hyd\\dat\\dbf;";
#$Connect = "Driver={Microsoft Visual FoxPro
Driver};UID=;PWD=;SourceType=DBF;SourceDb=c:\\temp;";
      # Oracle Connection
#$Connect = "Provider=OraOLEDB.Oracle.1;Persist Security
Info=False;User ID=xxx;Password=yyy;Data
Source=HYDDEV.cbr.hydsys.com";
     # Jet table connection
#$Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\temp\SITE.mdb;"



    # Create a record set of the site table
my $RS = Win32::OLE->new('ADODB.Recordset');    # creates a recordset
object
$RS->open("SELECT * FROM SITE",$Connect);  
#,adOpenDynamic,adLockOptimistic);
      $source = $RS->Source;                    #View some record set
information
      $Cursorlocation = $RS->CursorLocation;
      $PropertyCount = $RS->Properties->Count;
      print "$source  $Cursorlocation   $PropertyCount\n";


      
      
  # View the record set properties
while ($count < $PropertyCount-1) {    
	$count++;
  $PropName = $RS->Properties->item($count)->Name;
  $PropValue = $RS->Properties->item($count)->Value;
  $PropAttrib = $RS->Properties->item($count)->Attributes;
  $PropType= $RS->Properties->item($count)->Type;
  print "$count  $PropName     $PropValue      $PropAttrib\n";
}  



  # Browse All records in the site database
$RetValue =  Win32::MsgBox('Do you wish to VIEW the Database
contents?',4,'Perl ADO access');  # yes=6 no=7
if ($RetValue == 6) {
  while ( !$RS->EOF ) {   
  $RecCount++;
	  my($Station,$StnName,$ShortName) = (
		  $RS->Fields('STATION')->Value,
		  $RS->Fields('STNAME')->Value,
		  $RS->Fields('SHORTNAME')->Value );
	  print "$RecCount   $Station   $ShortName          $StnName    \n";
	  $RS->MoveNext;
  }
}




  # Add a new Record to the site database
$RetValue =  Win32::MsgBox('Do you wish to ADD a new record?
SQL',4,'Perl ADO access');  # yes=6 no=7
if ($RetValue == 6) {
	$Station = "PERLADO";
  $ShortName= "Record from PERL ADO";
  $StnName = "Record inserted by PERL using ADO";
	print "$Station   $ShortName          $StnName    \n";
  my $WRITERS = Win32::OLE->new('ADODB.Recordset');    # creates a
recordset object
                      # have found that field names need to be in
upper case even it that are lower case in the Data Table
  $WRITERS->open("INSERT INTO SITE (STATION,SHORTNAME,STNAME) VALUES
('$Station','$ShortName','$StnName');",$Connect);
  $WRITERS->Close; 
}


$RS->Close;


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

Date: 22 Jun 2001 08:37:21 +0100
From: nobull@mail.com
Subject: Re: deleting a file: permission denied
Message-Id: <u966do7vaa.fsf@wcl-l.bham.ac.uk>

Barry White <barry@white.com> writes:

> I have written a small perl script,

But your question is not related to Perl.

> So questions are: Why if the permissions are set at 777 during
> creation, why am i not able to delete created files with a normal
> user login.

This is really a feature of Unix and is explained in every Unix FAQ
I've seem.  But it's so common that it's also explained in
the Perl FAQ: "Why does Perl let me delete read-only files?"

The problem you are experiencing is, of course, the flip side ("Why
doesn't Perl let me delete writable files?") but the reason is the
same.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 22 Jun 2001 09:02:07 GMT
From: Tweetie Pooh <tp601553@cia.gov>
Subject: Re: Executing UNIX shell commands in PERL
Message-Id: <Xns90C86617064F5TweetiePooh@62.253.162.108>

moser@ivk.uni-stuttgart.de (Rainer Moser) honoured comp.lang.perl.misc on
Thu 21 Jun 2001 02:06:29p with
news:3b31eee2.20333818@news.uni-stuttgart.de: 

> Hi everyone,
> 
> I am trying to execute shell commands from a PERL script. The shell
> script uses aliases. If I execute a system command in the way      
> 
> system("my_alias") 
> 
<snip> 
> Thanks

Why use the alias at all.  They are there to make things easy for users
running at the command prompt.  Code in the command the alias points to. 


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

Date: 22 Jun 2001 02:04:53 -0700
From: costas@othermedia.com (cmavroudis)
Subject: Grabbing a web page?
Message-Id: <48dc5908.0106220104.656193f7@posting.google.com>

What is the best way for me to grab the source of a web page and put
it into a single variable?

Thanks


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

Date: 22 Jun 2001 09:13:36 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Grabbing a web page?
Message-Id: <slrn9j633k.cbf.rgarciasuarez@rafael.kazibao.net>

cmavroudis wrote in comp.lang.perl.misc:
} What is the best way for me to grab the source of a web page and put
} it into a single variable?

Probably the LWP::Simple module. Grab libwww from CPAN to install it (if
you don't have it already).

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 21 Jun 2001 20:11:13 -0700
From: ralphwang@hotmail.com (Ralph)
Subject: Re: Install Perl on HP
Message-Id: <57999a2f.0106211911.37b12d30@posting.google.com>

"H. Merijn Brand" <h.m.brand@hccnet.nl> wrote in message news:<Xns90C78CA57930Merijn@192.0.1.90>...
> Philip Newton <pne-news-20010620@newton.digitalspace.net> wrote in 
> news:csg1jt00moe7q2s2jq2l3u4nkk9s9afe7q@4ax.com:
> 
> > [Posted and CC'ed to ralphwang@hotmail.com]
> > 
> > Are you the same Ralph Wang who just sent me email asking essentially
> > the same question as you just posted in the newsgroup?
> > 
> > I got this when I tried to respond:
> > 
> >   wang_yifu@yahoo.com.tw:
> >     SMTP error from remote mailer after end of data:
> >     host mx1.mail.tw.yahoo.com [202.1.238.35]:
> >     554 delivery error:
> >     dd This user doesn't have a yahoo.com.tw account
> > (wang_yifu@yahoo.com.tw) - mta103.mail.tpe.yahoo.com
> > 
> > I can't reply if you use an address that doesn't exist.
> 
> He did the same with me. Same result. He just ended up in my Killfile, for I 
> don't think this is the right way to deal with newsgroup replies.

I am really sorry about the trouble I cause.  The new yahoo e-mail account
, I set up a couple weeks ago, I can login and send e-mail but I don't know
there is problem to receive until Philip told me.  I already check with
yahoo about my mail account and I really apologized for the trouble I 
caused.


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

Date: 22 Jun 2001 02:15:42 -0700
From: ralphwang@hotmail.com (Ralph)
Subject: Re: Install Perl on HP
Message-Id: <57999a2f.0106220115.48cd0ab8@posting.google.com>

garnerjr@ci.richmond.va.us (Jim Garner) wrote in message news:<9gtklh$qn4$1@bob.news.rcn.net>...
> I can compile perl 5.6.1 on 11.0 (ANSI/C or gcc), but it dumps core on the 
> pwent test.  From what I can gather, calling getpwent() at end of file blows up 
> every time.  The problem doesn't happen when compiled on 10.20.  I've tried 
> +DAportable.  I've tried the source code from the HP porting library.  I've 
> tried numerous combinations of flags, static libs, dynamic loading, nothing 
> gets rid of the problem.  I'm a pretty good programmer, but the source code has 
> so many layers of abstraction and ifdefs that I haven't been able to pin down 
> where the error occurs.  Any suggestions would be appreciated.  My one 
> remaining 10.20 system won't be around much longer.
> 
> -Jim Garner
> garnerjr@ci.richmond.va.us
> 
> 
> In article <Xns90C474C841F36Merijn@192.0.1.90>, h.m.brand@hccnet.nl says...
> >
> >Philip Newton <pne-news-20010617@newton.digitalspace.net> wrote in 
> >news:1q4pit4so3hcel3lrlqgkhcvm3grej7uo1@4ax.com:
> >>> *  I have previous verion perl install on my system,
> >> 
> >> Which one? The 4.036 that comes with HP-UX?
> >
No, mine is 4.0.1.8 ( i saw there is perls under /opt/local/bin and
/opt/local/lib/perl ), is this version ok ? 

> >Should be no problem /if/ you did not choose "/usr/contrib/bin" as 
> >installation path for the binaries (not very likely though)
> >
> >>>    so before I install, should I clean up previous version ?
> >> 
> >> With 4.036, that shouldn't be necessary.
> >
> >Would be very bad for the system too, cause HP uses this for their updates.
> >(HP has plans to upgrade to perl5 for internal use ;-)
> >
> >-- 
> >H.Merijn Brand    Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
> >using perl-5.6.1, 5.7.1 & 626 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
> >     WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
> >ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/


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

Date: Fri, 22 Jun 2001 11:29:20 +1000
From: Michael Walmsley <michael_w@pacific.net.au>
Subject: Re: Is There Any Other Routine Like CHOP();
Message-Id: <3B329F70.3030900@pacific.net.au>

Why not use a regex to delete the \r\n chars at the end of the line ?

Windows line terminator is \r\n whereas unix is \n.

You can either pre-process the file with dos2nuix which will convert the 
line termination chars for you or use a regex of the form :

while(<>) {
	s/\r\n$/\n/;
		print;
}

This loop will iterate over the file and replace occurences of \r\n with 
just a \n.

to get rid of spaces, etc again use a regex :


my $string = "  \r\n   \r\r   This is a test!  \n\r ";

$string =~ s/^[\s\r\n]*(.*?)[\r\n\s]*$/$1/m;

print "[$frank]\n";

The above regex will strip \r\n\s chars from the beginning and end of 
the tring as long as that is all there is.  It will also match lines 
ending in that only and also starting in tht only.  perldoc perlre will 
give you all the gory details on perl regular expresions which are far 
more powerful than delphi trim functions.  The reason perl doesn't have 
these kinds of functions is because of it's regular expression power.

Michael.



Line termination differences is always a pain between unix and windows.

Lars wrote:

> I hava a list of items written to a file in windows.
> when I open this file on unix systems, there seem to be 2 wrappings
> (\n\n) at the end.
> I use the chop routine which deletes one of them, that should be for
> the line brake, but now there seem to be another char!? when I output
> the chopped string I can see an space char (#32) at the end!
> 
> So now my question: is there any practical function to cut all special
> characters (line brakes, spaces and so on) at the beginning and at the
> end of my string?
> Borland Delphi has such a routine, it's name is:
> "function trim(s: string): string;"
> 
> is there a similar function in perl available?
> if not, how can I realize that!? 2xchop is not the result, because
> some strings do not have strange characters at the and, and in this
> case importent chars would be cut!
> 
> thx in advance
> Lars
> 



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

Date: Thu, 21 Jun 2001 21:35:18 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: Making a bundle of Perl modules
Message-Id: <9gubcr$nqi$1@canopus.cc.umanitoba.ca>

"sdf" <sdfsd@com.com> wrote in
   message news:9gtpp6$1koab147@news1s.iddeo2.es...

> I need to make a bundle of several modules in order to distribute a
> software.
> I've seen in Perl Cookbook 12.8. Preparing a Module for Distribution, how
to
> prepare a single module for distribution. It's also explained in Simon
> Cozens's page (perlnewmod - preparing a new module for distribution -
> http://www.enstimac.fr/Perl/perl5.6.1/5.6.1/pod/perlnewmod.html).
>
> However none of these two references explain how to make a distribution
> based in more than one module.
>
> I'll really appreciate any hint

You could place all the modules you want installed in a directory
"lib" in the top-level directory of your distribution. eg
      lib
      lib/Math
      lib/Math/Integrate.pm                     # package Math::Integrate
      lib/Math/Integrate
      lib/Math/Integrate/Simpson.pm   # package Math::Integrate::Simpson
and so on - these will automatically be recognized by
MakeMaker. For finer control, take a look at the DIR attribute
in 'perldoc ExtUtils::MakeMaker'.

best regards,
randy kobes





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

Date: Fri, 22 Jun 2001 09:12:39 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Mod_perl problem
Message-Id: <3B32FDF7.4C79F5E8@schaffhausen.de>

"irl.com" schrieb:
> 
> Hi,
>    I'm a newbie to mod_perl programming.  I have written a script to aloow
> users of my website to log in and check there email.  This script runs on
> every page of my site.  When each page is loaded the script opens a socket
> to our mail server and checks the number of new messages the user has.
>    The script works fine under normal CGI put under mod_perl it isn't
> opening the socket at all.

There are tons of materials available on the topic why something wouldnt work
under mod_perl which worked under CGI. Its even distributed with the mod_perl
distributions. You probably encountered a problem which is described in those
papers.

->malte


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

Date: Fri, 22 Jun 2001 04:48:28 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Opening a Netscape Window using a Perl script
Message-Id: <slrn9j5k5h.2oh.tim@vegeta.ath.cx>

Scott Vetter <svetter@dsli.com> wrote:
> Hello all:
> 
>     In know in some other language, which I won't mention, can open
> another Netscape Window both with and without certain attributes.  Can
> this also be done in Perl?  And if so how?

Assuming you mean Javascript, which is a client-side scripting language,
then you can accomplish this with any language available as a browser
scripting language. (ie, JavaScript on Netscape; JScript, VBScript,
PerlScript, Python in MSIE)

In order to do this in PerlScript, you have be reasonably sure that
ActivePerl is installed on every single client who might be viewing your
web page and that they've installed the PerlScript ActiveX engine.  The
same goes for Python; they need ActivePython installed.  And this only
applies to Win32 platforms, as only Win32 platforms have ActiveX
(AFAIK).

If you want this to work on Netscape, or on any non-Win32 platform, use
JavaScript.

So the simple answer is, yes, but it's probably not worth it.

-- 
-Tim Hammerquist <timmy@cpan.org>
Once you know the truth you can hide it on a shelf,
But unless you bring it down you can't live with yourself.
	-- Steve Taylor, "Jenny"


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

Date: Fri, 22 Jun 2001 11:46:19 +0200
From: "Amittai Aviram" <amittai@amittai.com>
Subject: Re: Passing a DBM name to a program.
Message-Id: <9gv4f8$a4j$1@rznews2.rrze.uni-erlangen.de>

(See below. -- AA)

"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:9gtlel$hcq$2@bob.news.rcn.net...

> Did you wonder *why* the colon started on a new line?  Could it have been
> that $datafile has a trailing newline, but you don't have a database file
> whose name ends in a newline?

Sorry!  Realized this immediately as soon as I walked away from the
computer.  Sorry for the wasted bandwidth!

Amittai





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

Date: 22 Jun 2001 06:52:59 GMT
From: Cristian Cespedes V <ccespede@anakena.dcc.uchile.cl>
Subject: Perl description
Message-Id: <9guq0b$ig7$1@sunsite.dcc.uchile.cl>

Hi!
	i need some help, does any body know the answer of this questions?

1. is perl strong typing? what kind of typing it has?

2. perl has lazy or active evaluation?

3. how is the variable binding (linking) in Perl?

well, i hope you wil help me... please helpme!!!

Thanx.



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

Date: Fri, 22 Jun 2001 06:26:22 GMT
From: "Brian Janko" <brian@jankoNOnet.SPAMcom.INVALID>
Subject: Perl to Oracle connectivity
Message-Id: <iyBY6.39736$0e3.35611247@news1.rsm1.occa.home.com>

Does anyone know about Perl to Oracle connectivity?  Is it difficult to set
 up?  Where might I find information about this topic?

Thanks,
Brian






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

Date: Fri, 22 Jun 2001 03:44:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Reference-problem
Message-Id: <3B32BEC3.DDFA95F8@rochester.rr.com>

Stefan Serena wrote:
> 
> Thx! I've written that I _could_ use a hash, because Rafael Garcia-Suarez
> recommended to rather use hashes than symbolic references.
> Everybody sais that using symbolic references is a bad idea. But, lets say I
> have 20 variables: $apple, $orange, $lemon, $banana and so on. They have to
> remain like that (no hash or array). Then, I have to perform 5 tasks with

You say they *have* to remain simple variables.  Why?  All you have to
do is substitute for each simple variable like $var an expression like
$hash{var} everywhere it appears (except in my's, which can be removed
or replaced with my %hash; if desired).  Every operation you can do with
$var you can do with $hash{var}.  I will grant you that if you totally
control the names of the symbolic references, you will be OK using
symbolic references.  It is a bad habit to get into, though, because
eventually you will be tempted to do
$$varname_from_someone_elses_data=1; and you will clobber a variable you
really didn't want to clobber, and you'll have a debugging nightmare
(that's called symbol table pollution).  Whereas using
$hash{$varname_from_someone_elses_data}=1; will never clobber anything
other than a hash value.  When you use a hash, you have a whole brand
new symbol table all to yourself in the hash keys, and you don't have to
worry that some of the keys might be used for other purposes.  It's just
a matter of good safe programming habits versus the potential nightmares
which can happen with unsafe habits such as symbolic references.  And if
you like keeping the hash keys in an array, that's no problem:  use
$hash{$array[$n]}, instead of ${$array[$n]}.  Trust me, the benefits if
using hashes like this instead of symbolic references vastly outweigh
the extra couple of keystrokes.  Symbolic references are so dangerous
and so easily replaced with hashes that there is debate about removing
symbolic references from Perl.  HTH.
-- 
Bob Walton

> each of these variables. I could write 100 lines or use a procedure, but
> wouldn't it be better to put the names of the variables into an array and
> work with symbolic references?
> 
> Stefan
 ...


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

Date: Fri, 22 Jun 2001 11:11:34 +0200
From: "Stefan Serena" <sserena@freesurf.ch>
Subject: Re: Reference-problem
Message-Id: <9gv24b$l86$1@news1.sunrise.ch>

"Chris Stith" <mischief@velma.motion.net> schrieb im Newsbeitrag
> BTW, when you quote someone, please show some sort of attribution
> for that person.

It's fascinating how much I can learn by asking a simple
reference-question... ;-)
Am I allowed to write 'schrieb im Newsbeitrag' (german) or does it have to
be english...?

Stefan




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

Date: Fri, 22 Jun 2001 11:26:49 +0200
From: "Stefan Serena" <sserena@freesurf.ch>
Subject: Re: Reference-problem
Message-Id: <9gv30u$s0n$1@news1.sunrise.ch>

"Bob Walton" <bwalton@rochester.rr.com> schrieb im Newsbeitrag
> You say they *have* to remain simple variables.  Why?

Concerning the opening-question they don't have to remain, that's true. But
it happens quite often that I have to work with existing scripts which have
not been written by myself. And there it happens from time to time that they
_have_ to remain simple variabels because it would be too much work to go
over the whole script to change them. I mean, I could blindly replace them
but I'm not sure about the safety of this idea...

> I will grant you that if you totally
> control the names of the symbolic references, you will be OK using
> symbolic references.  It is a bad habit to get into, though, because
> eventually you will be tempted to do
> $$varname_from_someone_elses_data=1; and you will clobber a variable you
> really didn't want to clobber, and you'll have a debugging nightmare
> (that's called symbol table pollution).  Whereas using
> $hash{$varname_from_someone_elses_data}=1; will never clobber anything
> other than a hash value.  When you use a hash, you have a whole brand
> new symbol table all to yourself in the hash keys, and you don't have to
> worry that some of the keys might be used for other purposes.  It's just
> a matter of good safe programming habits versus the potential nightmares
> which can happen with unsafe habits such as symbolic references.  And if
> you like keeping the hash keys in an array, that's no problem:  use
> $hash{$array[$n]}, instead of ${$array[$n]}.  Trust me, the benefits if
> using hashes like this instead of symbolic references vastly outweigh
> the extra couple of keystrokes.  Symbolic references are so dangerous
> and so easily replaced with hashes that there is debate about removing
> symbolic references from Perl.  HTH.

Ok, you convinced me! Thx!
At first sight they seemed really useful...

Stefan




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

Date: 21 Jun 2001 21:54:15 -0700
From: nmangalath@amcon.com.au (Naru Mangalath)
Subject: Searchin for .sh
Message-Id: <2feaabca.0106212054.38eafe2b@posting.google.com>

I am not an expert in Unix, least of all Perl and regular expressions.
I have this probelm. I have a bin directory containing Bourne shell
scripts. I want to search each of the scripts to search for other
scripts (.sh) that it is calling. Finally I want to create a file like
this:
script       calls
======       =====    
script1.sh   script5.sh
             script4.sh
script2.sh   script4.sh
             script1.sh
scrpit3.sh

etc.

Can some one provide mw with a code sample?

Thanks in advance!

Naru Mangalath
UDB DBA (not a unix administrator)


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

Date: Fri, 22 Jun 2001 07:26:05 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Searchin for .sh
Message-Id: <3B32F340.AF89D1CF@acm.org>

Naru Mangalath wrote:
> 
> I am not an expert in Unix, least of all Perl and regular expressions.
> I have this probelm. I have a bin directory containing Bourne shell
> scripts. I want to search each of the scripts to search for other
> scripts (.sh) that it is calling. Finally I want to create a file like
> this:
> script       calls
> ======       =====
> script1.sh   script5.sh
>              script4.sh
> script2.sh   script4.sh
>              script1.sh
> scrpit3.sh
> 
> etc.
> 
> Can some one provide mw with a code sample?

This should get you started.


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

my $dir = shift || '.';

chdir $dir or die "Cannot find $dir directory: $!";

opendir DIR, '.' or die "Cannot open $dir: $!";
my @files = grep { -T $_ } readdir DIR;
closedir DIR;

my $regex = join '|', map { quotemeta } @files;

my %lookup;
foreach my $file ( @files ) {
    my $data;
    open IN, "< $file" or warn "Cannot read from $file: $!";
    binmode IN;
    read IN, $data, -s $file;
    my @temp = $data =~ /($regex)/g;
    my %saw;
    @temp = grep { $_ ne $file and !$saw{ $_ }++ } @temp;
    $lookup{ $file } = [ @temp ];
    }

print "$_: @{$lookup{$_}}\n" for sort keys %lookup;

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: 22 Jun 2001 08:02:55 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Searchin for .sh
Message-Id: <slrn9j5v55.idp.abigail@alexandra.xs4all.nl>

Naru Mangalath (nmangalath@amcon.com.au) wrote on MMDCCCLII September
MCMXCIII in <URL:news:2feaabca.0106212054.38eafe2b@posting.google.com>:
// I am not an expert in Unix, least of all Perl and regular expressions.
// I have this probelm. I have a bin directory containing Bourne shell
// scripts. I want to search each of the scripts to search for other
// scripts (.sh) that it is calling. Finally I want to create a file like
// this:
// script       calls
// ======       =====    
// script1.sh   script5.sh
//              script4.sh
// script2.sh   script4.sh
//              script1.sh
// scrpit3.sh
// 
// etc.
// 
// Can some one provide mw with a code sample?


The problem as stated is at least as difficult as solving the halting
problem. The halting problem had been proven to be uncomptable.

You must lower your requirements.


Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


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

Date: 22 Jun 2001 08:06:08 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Searchin for .sh
Message-Id: <slrn9j5vb5.idp.abigail@alexandra.xs4all.nl>

John W. Krahn (krahnj@acm.org) wrote on MMDCCCLII September MCMXCIII in
<URL:news:3B32F340.AF89D1CF@acm.org>:
!! Naru Mangalath wrote:
!! > 
!! > I am not an expert in Unix, least of all Perl and regular expressions.
!! > I have this probelm. I have a bin directory containing Bourne shell
!! > scripts. I want to search each of the scripts to search for other
!! > scripts (.sh) that it is calling. Finally I want to create a file like
!! > this:
!! > script       calls
!! > ======       =====
!! > script1.sh   script5.sh
!! >              script4.sh
!! > script2.sh   script4.sh
!! >              script1.sh
!! > scrpit3.sh
!! > 
!! > etc.
!! > 
!! > Can some one provide mw with a code sample?
!! 
!! This should get you started.
!! 
!! 
!! #!/usr/bin/perl -w
!! use strict;
!! 
!! my $dir = shift || '.';
!! 
!! chdir $dir or die "Cannot find $dir directory: $!";
!! 
!! opendir DIR, '.' or die "Cannot open $dir: $!";
!! my @files = grep { -T $_ } readdir DIR;
!! closedir DIR;
!! 
!! my $regex = join '|', map { quotemeta } @files;
!! 
!! my %lookup;
!! foreach my $file ( @files ) {
!!     my $data;
!!     open IN, "< $file" or warn "Cannot read from $file: $!";
!!     binmode IN;
!!     read IN, $data, -s $file;
!!     my @temp = $data =~ /($regex)/g;
!!     my %saw;
!!     @temp = grep { $_ ne $file and !$saw{ $_ }++ } @temp;
!!     $lookup{ $file } = [ @temp ];
!!     }
!! 
!! print "$_: @{$lookup{$_}}\n" for sort keys %lookup;
!! 
!! __END__


Hmmm, that would mean that if the program does "cp script1.sh script2.sh"
it falsely reports script1.sh and script2.sh are called, and if it does
"for i in *.sh ; do ./$i ; done" it doesn't report the scripts that are
being called.



Abigail
-- 
BEGIN {print "Just "   }  #  The Ninja laughing
INIT  {print "Perl "   }  #  near the forest. A spider watches.
CHECK {print "another "}  #  Ceasar. A fly crawls.
END   {print "Hacker\n"}


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

Date: Fri, 22 Jun 2001 11:54:59 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: Re: setting priority from perl on linux
Message-Id: <BBxY6.9323$qJ4.375608@ozemail.com.au>


> Do you know of any scripts that will build an index of html pages
> and then search it from a CGI ?

Not sure about the building of HTML pages

But Searching of html pages can be done with htdig




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

Date: Fri, 22 Jun 2001 05:11:55 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting array on multiple keys
Message-Id: <3B330BDB.46D62FCE@earthlink.net>

Ren Maddox wrote:
> 
> On Wed, 20 Jun 2001, ps@siteindia.com wrote:
> 
> > Hi Experts,
> >
> > I want to sort my array on multiple keys, right now it is sorted on
> > one key date and it has another field description
> >
> > i want to sort first on date and then under date on description.
> > Any help or pointer is greatly appreciated.
> >
> >  my(@itemList) = sort {
> >     return 0 if !defined($$a{date}) and !defined($$b{date});
> >     return -1 if !defined($$a{date});
> >     return 1 if !defined($$b{date});
> >     $$a{date} <=> $$b{date}
> >       } ( @Fees);
> 
> Starting from your existing comparison, you could use:
> (Note: I prefer $a->{date} over $$a{date}.)
> 
> my(@itemList) = sort {
>   return $a->{desc} cmp $b->{desc}
>     if !defined $a->{date} and !defined $b->{date};
>   return -1 if !defined $a->{date};
>   return  1 if !defined $b->{date};
>   $a->{date} <=> $b->{date} or $a->{desc} cmp $b->{desc}
> } @Fees;

How about:
my @itemList = sort {
  defined $a->{date} && defined $b->{date} ?
    $a->{date} <=> $b->{date} :
    defined $a->{date} <=> defined $b->{date}
  or $a->{desc} cmp $b->{desc};
} @Fees;

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Fri, 22 Jun 2001 07:33:40 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: splice/Join and split!!
Message-Id: <3b32f489.64475881@news.grnet.gr>

On Thu, 21 Jun 2001 22:59:29 GMT, "John W. Krahn" <krahnj@acm.org>
wrote:

>Michael Carman wrote:
>> 
>> while (<IN>) {
>>     if ($. == 6 .. $. == 9) {
>          ^^^^^      ^^^^^^
>The "$. ==" part is superfluous.
>
>    if ( 6 .. 9 ) {
>

Surely not - it should be checking $. not $_

 ... or am I missing something?

Phil
-- 
Philip Lees
ICS-FORTH, Heraklion, Crete, Greece
Ignore coming events if you wish to send me e-mail
'The aim of high technology should be to simplify, not complicate' - Hans Christian von Baeyer


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

Date: Fri, 22 Jun 2001 08:39:47 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: splice/Join and split!!
Message-Id: <3B33044E.D6DDA3B8@acm.org>

Philip Lees wrote:
> 
> On Thu, 21 Jun 2001 22:59:29 GMT, "John W. Krahn" <krahnj@acm.org>
> wrote:
> 
> >Michael Carman wrote:
> >>
> >> while (<IN>) {
> >>     if ($. == 6 .. $. == 9) {
> >          ^^^^^      ^^^^^^
> >The "$. ==" part is superfluous.
> >
> >    if ( 6 .. 9 ) {
> >
> 
> Surely not - it should be checking $. not $_
> 
> ... or am I missing something?

From perlop:

                        If either operand of scalar ".." is a
       constant expression, that operand is implicitly compared
       to the $. variable, the current line number.  Examples:

       As a scalar operator:

           if (101 .. 200) { print; }  # print 2nd hundred lines



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 22 Jun 2001 11:41:50 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Suggestion: fallback for Tie::Handle
Message-Id: <9guekp$hlq@netnews.hinet.net>

Dear all,

In many cases when I use Tie::Handle I encounter this situation:

package Tee;
sub TIEHANDLE { shift; bless [@_] }
sub PRINT { my $self = shift; print $_ @_ for @$self }

package main;
tie *F,'Tee',*STDERR,*STDOUT;
print F "hello\n";

Wow, this 'Tee' package is so tidy!!!  But wait, when using 'printf'

printf F "hello\n";  # it would cause an error

Can't locate object method "PRINTF" via package "Tee" at line 7.

Sorry, you can't just implement the DWIM parts.  You have to
take care all the PRINT, PRINTF and WRITE... methods.

IMHO, PRINTF can be 'fallback'ed to "print + sprintf",
and WRITE can be fallbacked to "print + substr".

I suggest Perl to take care those fallbacks and don't require
Tie::Handle users to take care of everything.  Then we can just
focus on what we want to do (just TIEHANDLE and PRINT would work).
That would be very nice.  What do you think about it?

Thank you very much.

John Lin





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

Date: Fri, 22 Jun 2001 09:52:05 +0100
From: George Stevens <george.stevens@baesystems.com>
Subject: Unix filepath completion within perl?
Message-Id: <3B330735.8E51B196@baesystems.com>

Does anyone know a way of getting unix command line filepath completion
to work within a perl script?  I've tried inserting a
system ("set filec");
in the script, but it doesn't want to play!  The .cshrc has set filec in
as standard, but running the perl script somehow over-rides this.
The perl is being used in a install script, where the user enters the
filepath where they wish the software to be installed.


cheers,
George

PS I'm not a unix or  perl  guru, so answers in simple English, not
hieroglyphics please!




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

Date: 22 Jun 2001 09:52:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Unix filepath completion within perl?
Message-Id: <9gv4h6$d68$1@mamenchi.zrz.TU-Berlin.DE>

According to George Stevens  <george.stevens@baesystems.com>:
> Does anyone know a way of getting unix command line filepath completion
> to work within a perl script?  I've tried inserting a
> system ("set filec");
> in the script, but it doesn't want to play!  The .cshrc has set filec in
> as standard, but running the perl script somehow over-rides this.

There is nothing to override.  Perl's IO is completely independent
from what your shell does.

> The perl is being used in a install script, where the user enters the
> filepath where they wish the software to be installed.

The Text::Complete module (which you might have found via a CPAN
search) does what you want:

    use Term::Complete;

    my @filenames = do {
        opendir my $d, '.' or die "Can't read current dir: $!\n";
        readdir $d;
    };
    my $input = Complete( 'Enter file name > ', @filenames);

> cheers,
> George
> 
> PS I'm not a unix or  perl  guru, so answers in simple English, not
> hieroglyphics please!

Do you realize how arrogant that sounds?  "You people have this
habit of using funny terms for no good reason.  Don't do that when
you're talking to *me*"

Anno


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

Date: Fri, 22 Jun 2001 06:04:57 +0200
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: Which C compiler to use for modules?
Message-Id: <3b32c3e9.524144494f47414741@radiogaga.harz.de>

isterin (isterin@hotmail.com) wrote:
> "John Imrie" <john.imrie@pa.press.net> wrote...
> > Godzilla! <godzilla@stomp.stomp.tokyo> wrote...
> > > isterin wrote:
> > >
> > > (topic is compiling modules for Win 32)
> > >
> > > > On Windows you should have ActiveState and install binary packages
> > > > through ppm utility that comes with it.  [...]
> > 
> > If you are going to get the free compiler talked about in this thread then
> > the first thing you need to do is get the Perl source code and compile it
> > with your program.
> > 
> > The source will compile for unix and windose
>
> Any module that does not use XS for extensions can just be copied and
> pasted in your site/perl directory.

Not quite. Makefile.PL may contain configuration procedures that won't
be executed in that case (e.g. libnet).

cu,
  Martin
-- 
                        | Martin Vorlaender  |  VMS & WNT programmer
 VMS is today what      | work: mv@pdv-systeme.de
 Microsoft wants        |    http://www.pdv-systeme.de/users/martinv/
 Windows NT 8.0 to be!  | home: martin@radiogaga.harz.de


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.

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 V10 Issue 1175
***************************************


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