[16575] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3987 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 11 14:05:36 2000

Date: Fri, 11 Aug 2000 11:05:21 -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: <966017121-v9-i3987@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 11 Aug 2000     Volume: 9 Number: 3987

Today's topics:
    Re: 'require'd functions access main variables <tim@ipac.caltech.edu>
    Re: 'require'd functions access main variables <ab@cd.com>
    Re: -T and %ENV{'PATH'} <russ_jones@rac.ray.com>
    Re: [Q]s: sizeof in perl, ioctl.ph... <abe@ztreet.demon.nl>
    Re: Access html file from perl <care227@attglobal.net>
    Re: Access html file from perl <ab@cd.com>
        Best practices.... <lmoran@wtsg.com>
    Re: calculating with getting a formula out of a $string nobull@mail.com
        CGI, How to get back to cached dokument <Bulent@khio.no>
        chmod question <webmaster@cool-movie-trivia.com>
    Re: chmod question <tony_curtis32@yahoo.com>
    Re: CPAN.pm wants to install 5.6 (Anno Siegel)
        File Open <keithu@gte.net>
    Re: FileField Problem nobull@mail.com
    Re: FileField Problem <abe@ztreet.demon.nl>
    Re: GREP - type of script... <lr@hpl.hp.com>
    Re: Help - weird cgi-perl problem <Bulent@khio.no>
    Re: How to Access a hash value? <care227@attglobal.net>
        How to open a browsing window on  WINNT/Win98 <info@digitaltango.com>
    Re: How to open and append to a file <timewarp@shentel.net>
        How to pass a complex hashreference between two process (Konstantinos Agouros)
    Re: Illegal seek from backticks <tim@ipac.caltech.edu>
    Re: Intelligent "chomp" ? <et@telus.net>
    Re: Newbie: can't run my test script at my Web Host <guillaume.lahitette@cwusa.com>
    Re: Organizing and verifying a set of tree structures (Anno Siegel)
    Re: Organizing and verifying a set of tree structures <mjcarman@home.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 11 Aug 2000 10:01:26 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: 'require'd functions access main variables
Message-Id: <39943166.4273AB9D@ipac.caltech.edu>

Keith Calvert Ivey wrote:
> 
> Tim Conrow <tim@ipac.caltech.edu> wrote:
> >Blair Heuer wrote:
> >> In the main script:
> >>
> >>     &load( 'standard' );
> >>
> >> In a required 'parse.pl' file:
> >>
> >>     sub load() {
> >
> >Do you know what 'sub load() {...}' means? See perlsub. The '()' is a 
> >prototype
> >telling perl that load doesn't take any args. If you call it as you did you
> >should get an error message.
> 
> Not according to perlsub:
> 
> #   Not only does the ``&'' form make the argument list
> #   optional, but it also disables any prototype checking
> #   on the arguments you do provide.

Right. Sorry. Glossed over the '&'. I'll look for my glasses ...

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Fri, 11 Aug 2000 17:43:06 GMT
From: "Blair Heuer" <ab@cd.com>
Subject: Re: 'require'd functions access main variables
Message-Id: <KWWk5.940$IH.34897@newsread2.prod.itd.earthlink.net>

> Ugh.  Despite its name, $global, declared with my(), is a variable
> with lexical scope, meaning it is invisible outside the block is
> is declared in.  In this case the block, in absence of surrounding {},
> is the file.  So you have just made sure that $global is invisible
> to a subroutine that's defined in another file.

> This is another point.  Under "strict vars", you'd have to fully qualify
> the variable name: $main::global.

I just used "$global" for no reason, not thinking the name would make it
global. While using 'use strict' I have to declare variables with 'my' or
else I get an error. How do I declare the variable and still get it to be
accessable elsewhere?

-Blair






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

Date: Fri, 11 Aug 2000 10:54:59 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: -T and %ENV{'PATH'}
Message-Id: <399421D3.8843ACAA@rac.ray.com>

Johnny Amos wrote:
> 
> I am writing a script (my first) and i am using Taint mode.
> I forgot to set %ENV{'PATH'} initially and got the usual warning, but
> when I set %ENV{'PATH'} I got a 500 Server Error message instead.
> 
> Here's how I set %ENV{'PATH'}:
> 
> $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/lib';
> 
> What am I doing wrong?
> 

Check the permissions on the directories in your new path. The
directories need to be writable only by the directory's owner and
group.

Good luck!
-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Fri, 11 Aug 2000 18:35:05 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: [Q]s: sizeof in perl, ioctl.ph...
Message-Id: <7ha8pss6boi4u7b0ot09thotchj7ohepj5@4ax.com>

On 11 Aug 2000 10:57:39 -0400, kj0 <kj0@mailcity.com> wrote:

> In <hrd6ps0lecrrotflnj5jfbg0pg3413lulk@4ax.com> Abe Timmerman <abe@ztreet.demon.nl> writes:
> 
> >	L An unsigned long value.
> >		(This 'long' is _exactly_ 32 bits, which may differ from
> >		what a local C compiler calls 'long'.  If you want
> >		native-length longs, use the '!' suffix.)
> 
> My perlfunc (v. 5.0005_02) says nothing about the '!' suffix.  Is that
> a v. 5.6 addition?

Yep. From perldelta:

 pack() format modifier '!' supported

   The new format type modifier '!' is useful for packing and unpacking
   native shorts, ints, and longs. See the section on "pack" in the
   perlfunc manpage.

-- 
Good luck,
Abe


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

Date: Fri, 11 Aug 2000 11:15:34 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Access html file from perl
Message-Id: <39941896.2E3748BB@attglobal.net>

Gloff wrote:
> 
> Is it possible, on one or another way (copy with ftp?), to access, from a
> cgi application, an html file in another server than the one were the cgi
> script is working?
> I mean , for exemple, using the file access functions, (open / close etc...)
> to access an html file from its URL, like:
> open(MYFILE,"http://www.mydomain.com/myfile.htm");
> 

Check out the LWP module.  

http://search.cpan.org/search?mode=module&query=lwp


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

Date: Fri, 11 Aug 2000 17:51:50 GMT
From: "Blair Heuer" <ab@cd.com>
Subject: Re: Access html file from perl
Message-Id: <W2Xk5.993$IH.36312@newsread2.prod.itd.earthlink.net>

> Is it possible, on one or another way (copy with ftp?), to access, from a
> cgi application, an html file in another server than the one were the cgi
> script is working?
> I mean , for exemple, using the file access functions, (open / close
etc...)
> to access an html file from its URL, like:
> open(MYFILE,"http://www.mydomain.com/myfile.htm");

You can use the libwww-perl modules to do what you want to do. Look up
perldoc lwp.

I have not tested this part, but a book I have says it works. To get a web
document use this code:

use LWP::Simple;
$htmlfile = get( 'http://www.mydomain.com/myfile.html' );

[ or ]

use LWP::Simple;
getstore( 'http://www.mydomain.com/myfile.html',
'/my_files/where_i_want_to_store/myfile.html' );

Hope that helps.

-Blair




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

Date: Fri, 11 Aug 2000 12:42:37 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Best practices....
Message-Id: <6yqUOdNhqAAHDDxoguXX6WOM90lZ@4ax.com>

 ...I am not a programmer, though I sometimes program things.

 ...I read a fair amount of O'Reilly's but I used Elements of
Programming with Perl to really get things going.

Apparently my code is ugly.  I would like to know where I can get a
good best practices guide, lesson, clue, so that my code is less
offensive.

When I am in NT I use UltraEdit to write in, and Xemacs when I am in
Linux (although I just got Xemacs for NT so I might switch)

Here is an example:  (I didn't comment anything b/c even I can figure
out what it means) (this was a lesson from EoPwP)

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

my ($rate, $otrate, $regular, $overtime, $pay);

print "Enter your hourly rate: \n";
$rate = <STDIN>;
chomp ($rate);

print "Enter your regular hours: \n";
$regular = <STDIN>;
chomp ($regular);

print "Enter your overtime hours: \n"; 
$overtime = <STDIN>;
chomp ($overtime);

$otrate = $overtime * $rate * 1.5;
$regular = $regular * $rate;
$pay = $regular + $otrate;

print "Your gross pay for this period is $pay. \n";

 ...no Y2K was fine, it was W2K we had the problems with...
lmoran@wtsg.com


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

Date: 11 Aug 2000 17:13:55 +0100
From: nobull@mail.com
Subject: Re: calculating with getting a formula out of a $string
Message-Id: <u9n1ijvkqk.fsf@wcl-l.bham.ac.uk>

mgjv@martien.heliotrope.home (Martien Verbruggen) writes:

> On 11 Aug 2000 12:31:58 +0100,
> 	nobull@mail.com <nobull@mail.com> wrote:
> > 
> > # Do do this
> > $formula = sub { $_ * 1.16 };
> > do { local $_ = $int; &$formula };
> > 
> > Note: I'm using the $_ parameter convention here for passing a single
> > argument to a subroutine.  You can use the more conventional @_
> > convention if you prefer:
> 
> Running the chance that I offend:

> I think it is important to state here that $_ is not actually _passed_
> into the subroutine.

I think you'll find I said "convention here for passing a single
argument to a subroutine".  The argument _is_ passed by the mechanism
of a shared global variable.  This is the Perl equivalent of "asm
linkage" in C whereby paramters are passed in the CPU registers rather
than pushing them onto the stack.

> The subroutine just accesses the value of $_ that it can see when it
> executes. The do{} block has a local variable in there.

This is true.  Actually I usually advocate the use of "for" rather
than do{} and local() but decided in this case to spell it out for the
sake of making abundantly clear what you seem to feel needed to be
pointed out.

$var = &$formula for $int;

> To avoid interpretation errors there, it may be beter to use an
> explicitly named global variable,

I strongly disagree.  Once people have a sense that $_ means
"the current thing" I think they'll find this usage natural.  To use
any other global variable would take away this mnemonic value.

> or indeed, just use $_[0], as stated
> later:
> 
> > $formula = sub { $_[0] * 1.16 };
> > $formula->($int);
> 
> Many people have trouble distinguishing @var and $var, so I'd certainly
> avoid any code that could muddle the difference between @_ and $_.

So that would be an argument for writing it as:

$formula = sub { my ($thing) = @_; $thing * 1.16 };

> There hardly is any payoff in it, and a lot of possibilities for
> error and/or misinterpreation.

TMTOWTDT

I understand Martien's reasoning but I still disagree.  If you are
going to object to "implicit argument" in this context then you must
object to it completely.

Martien, do you object to:
  s/x/y/ for @a;

If not then what is wrong with:
  my $mutator = sub { s/x/y/ };
  &$mutator for @a;

Once you have accepted that then you should accept:
  my $mutator = sub { $_ .= 'x' };
  &$mutator for @a;

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


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

Date: Fri, 11 Aug 2000 18:22:16 +0200
From: Bulent Sarinc <Bulent@khio.no>
Subject: CGI, How to get back to cached dokument
Message-Id: <39942837.B6CAEC7A@khio.no>

Hi,

A trivial question for experienced CGI programmers


CGI, How to get back to cached already-filled-form from a CGIscript
without erasing the text in the fields.?

I use perl as programming language.

Thanx in advance

Bulent@khio.no



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

Date: Fri, 11 Aug 2000 16:55:52 GMT
From: "Cal Bond" <webmaster@cool-movie-trivia.com>
Subject: chmod question
Message-Id: <seWk5.143780$ef6.2038425@news1.rdc1.ab.home.com>

Hi,

Basic newbie question.  I've been trying to get the chmod command to work on
a  batch of files I want to write to.  I've been using

chmod (0777, $filename);

in the loop where the program is running through each filename, supposedly
to open the file and write to it.  This has not been working.  If I go
through an FTP program like CuteFTP and set the chmods of each file to 777
that way, everything works fine, so I know the filename path etc are
correct.  Could this be a server-related problem that they don't accept
chmod command from perl?  Any other ideas on what I can try?  Thanks very
much.

Cal




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

Date: 11 Aug 2000 11:58:35 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: chmod question
Message-Id: <87d7jfspj8.fsf@limey.hpcc.uh.edu>

>> On Fri, 11 Aug 2000 16:55:52 GMT,
>> "Cal Bond" <webmaster@cool-movie-trivia.com> said:

> in the loop where the program is running through each
> filename, supposedly to open the file and write to it.
> This has not been working.  If I go through an FTP
> program like CuteFTP and set the chmods of each file to
> 777 that way, everything works fine, so I know the
> filename path etc are correct.  Could this be a
> server-related problem that they don't accept chmod
> command from perl?  Any other ideas on what I can try?

Hmm, stealth CGI question?

    http://www.boutell.com/openfaq/cgi/8.html

hth
t
-- 
"With $10,000, we'd be millionaires!"
                                           Homer Simpson


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

Date: 11 Aug 2000 17:07:07 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: CPAN.pm wants to install 5.6
Message-Id: <8n1brr$95l$1@lublin.zrz.tu-berlin.de>

 <nobull@mail.com> wrote in comp.lang.perl.misc:
>Whenever I try to install a module from CPAN that is dependant on
>IO::Socket or some other path of the standard distribution CPAN.pm
>tries to install Perl-5.6 on my system.

Yes.  Edit .../CPAN/Config.pm and change the line

  'prerequisites_policy' => q[follow],

to read

  'prerequisites_policy' => q[ask],

You may have to do the same thing in a similar file under your .cpan/.
That should do it.

BTW, the ridiculous default of "follow" has been changed in the
newest version.  Unfortunately, this only helps when you install CPAN
for the first time.

Anno


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

Date: Fri, 11 Aug 2000 15:40:55 GMT
From: Keith Underwood <keithu@gte.net>
Subject: File Open
Message-Id: <39941DB1.5FD56BFF@gte.net>

Does Perl have a module, function to check and see if a file is open.
I need to make sure when I copy a file that is is complete and not being
copied to.
This is on NT.  In Unix I could use the command 'fuser' to see if there
was another process using the file.



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

Date: 11 Aug 2000 17:34:41 +0100
From: nobull@mail.com
Subject: Re: FileField Problem
Message-Id: <u9hf8rvjry.fsf@wcl-l.bham.ac.uk>

James Stephen Roberts <jsr@lucent.com> writes:

> I am writing a Perl/CGI code that should allow a user to input a filename and
> directory into a field and then the program should be able to retrieve this path
> and store it as a scalar value. When I use $path_name = $q->param('filefield')
> it returns a file handle. I just want the file path and name.

So just use a plain input field, not a file field.

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


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

Date: Fri, 11 Aug 2000 18:59:46 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: FileField Problem
Message-Id: <keb8ps8kcejr1gfc45o396b7q6gtfjs9lt@4ax.com>

On Fri, 11 Aug 2000 10:55:06 -0400, James Stephen Roberts
<jsr@lucent.com> wrote:
 ...
> I declare the filefield in the perl code and not the html. It is from the CGI
> library. 
> 
> $q = new CGI;
> $q->filefield(-name=>'bitmapname');
> $bitmapname = $q->param('bitmapname');
> 
> Once I have done this, the $bitmapname only contains the name of the file and
> not the entire path.
> 
> I need the entire path to send as an argument to another function.

Now why would you want the full path to a file on someone elses system?

If you want people to enter a string, just use a plain textfield().
If you want the contents of that file (using filefield()) you will get a
filehandle to a temp file that contains that content. 

Be sure to (re)read the section 'CREATING A FILE UPLOAD FIELD' in the
CGI.pm documentation.

-- 
Good luck,
Abe


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

Date: Fri, 11 Aug 2000 09:39:05 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: GREP - type of script...
Message-Id: <MPG.13fdcbff52bcce8298ac65@nntp.hpl.hp.com>

In article <ao48ps45qc1v46k4s8c79h0p0s9r808fnl@4ax.com> on Fri, 11 Aug 
2000 14:58:32 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> Larry Rosler wrote:
> 
> >>   Can't do inplace edit without backup.
> >> 
> >> this error is explained in perldiag
> >
> >The behavior (which is the same in 5.6.0) should be documented in 
> >perlrun, where I quoted from.  This is a documentation bug.
> 
> Is it? I would think it is an implementation bug. I can imagine what
> happens under Unix...

 ...

> This mechanism doesn't work in Win32, nor on DOS, nor on Mac. 
> 
> Conclusion: the port for those platforms should be rewritten so that the
> backup file is deleted once it's closed, *by perl*. So that's a "before"
> and an "after" task.

No doubt there is an implementation deficiency.  But as the behavior 
described in perlrun is known not to work using several implementations, 
that knowledge should be documented, both in perlrun and in perlport.  
There are plenty of other such anomalies that are correctly documented.

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


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

Date: Fri, 11 Aug 2000 18:30:30 +0200
From: Bulent Sarinc <Bulent@khio.no>
Subject: Re: Help - weird cgi-perl problem
Message-Id: <39942A26.DF8935DC@khio.no>

It may be the permission-problem on that directory
the first works because of /tmp is writeable for all users

i had a similar problem

praty@my-deja.com wrote:

> Am trying to write a perl script to be able to upload files without
> using ftp.
>
> I do a
> &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);
>
> to read all the data send by post.
>
> I want to read the destination from the form itself and I want to
> rename the file in the perl script to the name entered in the  form.
>
> Surprisingly
> rename($cgi_sfn{'upfile'},"/tmp/testfile")
> works
> but the following doesnt
> rename($cgi_sfn{'upfile'},$cgi_data{'completepath'})
>
> (Completepath is what I have the complete filename in the form, the
> value of $cgi_data{'completepath'} is "/tmp/testfile" as verified by
> printing)
>
> Whats going wrong ? I'm new to perl - is the language so weird ?
>
> Thanks in advance,
> Praty
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: Fri, 11 Aug 2000 11:10:03 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: How to Access a hash value?
Message-Id: <3994174B.66F7C9FE@attglobal.net>

"Frank L. Thomas" wrote:
> 
> The following code is intended to take input passed to this script. When I
> try to print the value in the hash table corresponding to $users{$userid},
> there is no value. I can print out the entire hash but cannot reference a
> value of the hash. Any thoughts?
> 
> #!/usr/local/bin/perl

Should be: #!/usr/local/bin/perl -Tw

> 
> use CGI qw(:standard);

use strict;

> 
> my $custnum = param("CustNum");
> my $userid = param("UserID");
> 
> if(open(MASTPASS, "filename")){

Why do it with an if(){}?

open MASTPASS, "<filename" or die $!;

> 
>  $key = <MASTPASS>;
> 
>  while($key ) {   #read in customer number and user name from file
>   chomp($key);
>   $value = <MASTPASS>;
>   chomp($value);
>   $users{$key} = $value;
>   $key = <MASTPASS>;}

I don't know why you are doing it this way, but I can't imagine
that its working.  Lets see a copy of some of the data you are 
working through, could we?

> 
>  close (MASTPASS);
>  print "Content-type: text/html\n\n";

You are use'ing CGI, so lets use it...

print header; etc...  If you are importing the standard functions,
why not use them?  Lots of HTML shortcuts for you.

>   print "<head>\n";
>   print "<title>On line ordering</title>\n";
>   print "</head>";
>   print "<body>";
>   print "<h1>Output Screen </h1>";
>   print "<h1>", $userid, $custnum, $value, $users{$userid}, "</h1>"; #this
> is the line I have a question about
>   print "</body>";


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

Date: Fri, 11 Aug 2000 15:43:04 GMT
From: "Etienne Laverdiere" <info@digitaltango.com>
Subject: How to open a browsing window on  WINNT/Win98
Message-Id: <caVk5.126595$1h3.2066282@news20.bellglobal.com>

Hi all,
Is it possible to open a browsing window using a perl cgi or libwin32
script?
We use a big network on NT and I would like, on a mouse clic in my HTML
Intranet, to make a share directory pop-up in an Explorer-Window for all of
us.
Is it a feature of Perl's libwin32?
Or should I use a third party software to share space disk like Samba on
linux?
I do not know where to begin...
Thanks,
Etienne Laverdiere






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

Date: Fri, 11 Aug 2000 13:14:04 -0400
From: Albert Dewey <timewarp@shentel.net>
Subject: Re: How to open and append to a file
Message-Id: <3994345C.33E71628@shentel.net>

Ala -

Thanks - always willing to learn new tricks even if I am an old dog.

Albert

Ala Qumsieh wrote:

> Albert Dewey <timewarp@shentel.net> writes:
>
> > This is a stripped down version of some code I have used to do precisely
> > the same thing. I wanted to prepend a file and not append it. This will
> > do exactly what you want.
> >
> > ## We need to prepend the data file and not append it, hence the two
> > step process used here
> >
> >  ## Step 1 - Load the current data file into a variable
> >  open(FILE,"<../data/inventory.dat") or print "ERROR 404: Cannot open
> > ../data/inventory.txt because $!<br>";
> >  while(<FILE>)
> >   {
> >   $OldData .= $_ if $. >= 0
>
> $. initially has the value 0, and increments with every line added. So,
> I don't see a reason why it would be negative. Hence, the if() statement
> is unnecessary.
>
> >   }
> >  close (FILE);
>
> The following is faster:
>
>         open FILE, "../data/..inventory.dat" or die $!;
>
>         my $OldData;
>         {
>                 local $/;
>                 $oldData = <FILE>;
>         }
>
> But, you should just check the FAQs before whipping up your own
> solution (hence saving time and energy).
> Checkout perlfaq5:
>
>         How do I change one line in a file/delete a line in a file/
>         insert a line in the middle of a file/append to the
>         beginning of a file?
>
> --Ala



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

Date: 11 Aug 2000 07:58:02 +0200
From: elwood@news.agouros.de (Konstantinos Agouros)
Subject: How to pass a complex hashreference between two processes?
Message-Id: <elwood.965973185@news.agouros.de>

Hi,

I need to get something like $a where $a is a hashref with arrays and other
hashreferences in it. From process a to process b. If this would be a C-program
I would use shared memory. I don't like the idea of constructing something 
parseable and reparse it. The other idea I have would be, to use Data::Dumper
write the result on a named pipe or socket and eval it on the other site.
So what's the best way to do this if both processes are on the same Unix-
Machine?

Konstantin

-- 
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not sustain the forming of the cosmos." B'Elana Torres


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

Date: Fri, 11 Aug 2000 10:08:21 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Illegal seek from backticks
Message-Id: <39943305.2CFF958C@ipac.caltech.edu>

Aaron Baugher wrote:
> 
> I must be staring too hard at this one.  Here's the chunk of
> code:
> 
>   my $res = `cat $base/cmyk$$.* | $base/cmyk $args`;
>   if( $res ){
>     print $res;
>   } else {
>     print "Problem doing cmyk analysis on $$: $!";
>     exit;
>   }

See perlvar. You want to check $? for the integer error code returned from a ``,
not $!. As Daivd said, you'll need to capture stderr as well to get more of a
clue about what's happening.

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Fri, 11 Aug 2000 09:48:15 -0700
From: Ed Toivanen <et@telus.net>
Subject: Re: Intelligent "chomp" ?
Message-Id: <39942E4F.851FD70C@telus.net>

Brendon Caligari wrote:

> i prefer to use regex substitution because it looks cryptic and takes more
> lines of code, hence making me look more productive.

> Brendon

Hehe...go get 'em tiger...:>




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

Date: Fri, 11 Aug 2000 15:29:52 GMT
From: Guillaume <guillaume.lahitette@cwusa.com>
Subject: Re: Newbie: can't run my test script at my Web Host
Message-Id: <sp86vgr1n4t154@corp.supernews.com>

Thanks Rajeev. I'll try to make sure I have the correct path on their box. 
Have a good week-end (;p

Rajeev wrote:
> 
> 
> Hi Guillaume
> 
> I tried your script in my Unix server by changing your first line to
> #!/usr/bin/perl -w and it works.
> 
> I suggest you check
> 
> a. is perl available in the path
> b. permissions on the script (755 in Unix)
> 
> Regards
> 
> Rajeev
> 
> 


--
Posted via CNET Help.com
http://www.help.com/


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

Date: 11 Aug 2000 16:04:49 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Organizing and verifying a set of tree structures
Message-Id: <8n1871$923$1@lublin.zrz.tu-berlin.de>

Bart Lateur  <bart.lateur@skynet.be> wrote in comp.lang.perl.misc:
>I have the subtask of modifiying data that should be ordered in a
>treelike structure. The user can modify the relationship between two
>items, so that if one is subordinate to the other, the reverse can't be
>true. No cycles. It's not just *verifying* that there are no cycles, but
>*removing* the inverse link, if this link did exist before. Also, not
>all items are indeed linked to each other. So it's a very loose tree. (a
>bush?)

A forest, perhaps.  There can be more than one tree in the structure.

>I'm looking for suggestions on what data structures and data
>organization I could use, to ease writing the program that maintains it
>in a state of integrity.

Interesting problem. In what follows, I'm assuming that the user
can reverse the relationship of a parent node and one of its immediate
kids.  If you want to swap any two nodes in general, I refuse to
think about it. :)

First off, I'd use the simplest representation of a forest I can
think of, just to keep the amount of updating small.  That would be
a structure where there is only a single link from each kid to its
parent.  Root nodes point to undef.  A leaf is only recognized
by the fact that nothing points to it.  This is readily implemented
as a hash whose keys and values are nodes.

Then, besides the usual repertoire of tree functions, you will have
to implement the somewhat unusual operation of swapping a kid
with its parent.

My tentative implementation below prints trees only as indented
lists (easily written, but not too clear for a human reader).
It builds a tree of four nodes, then swaps nodes A and B.  The
result is more clearly (but manually) depicted like this:

                 A               B
                / \             /|\
               B   C   =>      A D E
              / \              |
             D   E             C

Is that how you want the structure to behave?

Anno

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

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

my $forest = {};
add_node( $forest, 'A', undef); # this is a root (the only one)
add_node( $forest, 'B', 'A');
add_node( $forest, 'C', 'A');
add_node( $forest, 'D', 'B');
add_node( $forest, 'E', 'B');

print_forest( $forest);

swap_kid_parent( $forest, 'B'); # B is the kid, the parent is implicit

print_forest( $forest);

########################################################

sub add_node {
  my ( $forest, $node, $parent) = @_;
  $forest->{ $node} = $parent;
}

sub swap_kid_parent {
  my ( $forest, $kid) = @_;
  my $parent = $forest->{ $kid};
  $forest->{ $kid} = $forest->{ $parent};
  $forest->{ $parent} = $kid;
}

sub print_forest {
  my $forest = shift;
  my @roots = grep ! defined $forest->{ $_}, keys %$forest;
  foreach my $root ( @roots ) {
    print_tree( $forest, $root, 0);
    print "\n";
  }
}

sub print_tree {
  my ( $forest, $node, $indent) = @_;
  print '  ' x $indent, $node, "\n";
  my @kids = grep( ( defined $forest->{ $_} and $forest->{ $_} eq $node),
    keys %$forest);
  foreach my $kid ( @kids ) {
    print_tree( $forest, $kid, $indent + 1);
  }
}


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

Date: Fri, 11 Aug 2000 09:58:58 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Organizing and verifying a set of tree structures
Message-Id: <399414B2.CB5AFFD0@home.com>

Bart Lateur wrote:
> 
> I have the subtask of modifiying data that should be ordered in a
> treelike structure. The user can modify the relationship between two
> items, so that if one is subordinate to the other, the reverse can't be
> true. No cycles. It's not just *verifying* that there are no cycles,
> but *removing* the inverse link, if this link did exist before. Also,
> not all items are indeed linked to each other. So it's a very loose
> tree. (a bush?)
> 
> I'm looking for suggestions on what data structures and data
> organization I could use, to ease writing the program that maintains it
> in a state of integrity.
> 

Hrm. Do you want the data structure itself to (try to) prevent
circularity? What kind of access do you want? Do you want to start at
one end and work your way through, or can you jump in anywhere? Do you
need to be able to move both up and down the tree?

Here are the first couple of random ideas to wander through my head:

(Pseudo-Dumper illustration, not code!)
%tree1 = (
    obj1 => {
        val => 'value',
        children => ['obj2'],
    },
    obj2 => {
        val => 'value',
        children => ['obj3', 'obj4'],
    },
    obj3 => {
        val => 'value',
        children => [],
    },
    obj4 => {
        val => 'value',
        children => [],
    },
    obj5 => {
        val => 'value',
        children => [],
    },
);

(Or maybe use references instead of keys for children)

%tree2 = (
    obj1 => {
        val => 'value',
        children => [
            obj2 => {
                val => 'value',
                children => [
                    obj3 => {
                        val => 'value',
                        children => [],
                    },
                    obj4 => {
                        val => 'value',
                        children => [],
                    },
                ],
            },            
        ],
    },
    obj5 => {
        val => 'value',
        children => [],
    },
);

The first format would be more flexible for access and pruning, I would
think, but does nothing to prevent loops. The second is harder to
traverse, but a little more resilient to loops. Of course, in Perl you
can always stick in a reference anywhere, so I think you'll have to come
up with a way to check for cycles no matter what. And just what are you
supposed to do when you do find one?

-mjc


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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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