[8651] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2268 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 7 17:07:34 1998

Date: Tue, 7 Apr 98 14:00:33 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 7 Apr 1998     Volume: 8 Number: 2268

Today's topics:
        "Continuations" in Perl <scribble@pobox.com>
    Re: -comparing the values of 2 arrays- <ludlow@us.ibm.com>
    Re: 5.004.004 won't configure on RH5 gatman@gate.DIESPAM.net
        [Perl] How to find the Perl FAQ <rootbeer&pfaq*finding@redcat.com>
    Re: Database sorting problem (Andre L.)
    Re: DB_File and multiple processes (RonaldWS)
    Re: dup2 of main::STDERR (RonaldWS)
    Re: foreach loop & current element index (Mark-Jason Dominus)
        Getting the subroutine name from within a sub <Scott.L.Erickson@HealthPartners.com>
    Re: Getting the subroutine name from within a sub (Mark-Jason Dominus)
        How do I sort without having a space before the record? <poohba@io.com>
    Re: How do I sort without having a space before the rec (Andrew M. Langmead)
    Re: How do I strip newlines from a var (Ken Fox)
    Re: How would _you_ do this? <rootbeer@teleport.com>
        Is it just me?  (error/bug? with "my") <cortez@tfn.com>
    Re: Let it flow .. let it flow! <jdporter@min.net>
    Re: MKDIR problem (Martin Vorlaender)
    Re: MKDIR problem (Gabor)
        need help with references problem <vic.parekh@aig.com>
    Re: need help with references problem <lr@hpl.hp.com>
    Re: need help with references problem <kapur@cbl.ncsu.edu>
    Re: need help with references problem <jdf@pobox.com>
        Need help with simple for loop <pem@U.Arizona.EDU>
        need perl script to convert unix/dos text files dan@analogy.com
    Re: need perl script to convert unix/dos text files <lr@hpl.hp.com>
    Re: Packing? (Jeffrey R. Drumm)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 7 Apr 1998 15:39:02 -0500
From: Tushar Samant <scribble@pobox.com>
Subject: "Continuations" in Perl
Message-Id: <6ge2t6$7oh@tekka.wwa.com>

Somebody once asked about continuations in Perl. Well, one limited way
in which a subroutine knows the current "context" is via wantarray, one
way in which it knows its own "name" is via AUTOLOAD, and one way in
which it can call code "later" is via closures.  

Putting these together:


    sub AUTOLOAD {
      my $code = shift;
      my $name = $AUTOLOAD;
      $name =~ s!.*::!!;
      $name .= " ";

      wantarray?
        sub {
          my $cont = shift;
          $cont .= $name;
          $code?&{$code}($cont):print($cont);
        }
      :
      &{$code}($name);
    }


    Oh( No( Not( Another( Perl( Hacker())))))



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

Date: Tue, 07 Apr 1998 12:53:00 -0500
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: -comparing the values of 2 arrays-
Message-Id: <352A67FC.66531EC0@us.ibm.com>

Ronald J Kimball wrote:
> 
> [posted but not mailed - munged addresses are annoying]
> 
> James wrote:
> >
> > I am trying to compare the values of two arrays, and combining them in
> > another array, ensure that no duplicates are entered.
> >
> > For example:
> >
> > @array1 = ("12 ","13 ","14 ","15 ");
> > @array2 = ("14 ","15 ","16 ","17 ");
> >
> > The end result should look like this:
> >
> > @newarray = ("12 ","13 ","14 ","15 ","16 ","17 ");
> 
> # sort is optional
> @_{@array1, @array2} = 0;
> @newarray = keys sort %_;
              ^^^^^^^^^
@newarray = sort keys %_;    # obviously just a typo.

Okay, let me see if I understand what's going on here.  I'd appreciate
some input if I get this screwed up.

@_ threw me at first, because I'd only ever used it in a subroutine. 
But, apparently "_" is just the name of the hash that is being created. 
It could have been written as @a or @whatever.   

Inside the {} the values of @array1 and @array2 act as though they were
written like ("12 ","13 ","14 ",15 ","14 ","15 ","16 ","17 ").  

So then for each value in the list inside the {}, the hash, %_, gets the
next value from the list on the right side of the equals sign.  In this
case the list consists of one number, "0", so only the first key will
have a value, and the rest will be undef.  It could have been written
@_{@array1,@array2} = (0,,,,,,,); (Not that you would want to do it that
way of course).

But, these undef values don't matter, because all we're interested in is
the keys.  
Then the "keys" function simply gives us a list of the keys, which just
happens to be a list of unique values from the arrays.

Wow.  I realize that the code itself is straight out of the FAQ, but
until now I never bothered to try to figure out why it worked.  I never
thought about using a hash with the @ sign.  I'd only used %hash, or the
$hash{} in a loop.  It's yet another instance where Perl just continues
to amaze me. 

-- 
James Ludlow (ludlow@us.ibm.com)
This isn't tech support, and all opinions are my own.


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

Date: Tue, 07 Apr 1998 17:50:51 GMT
From: gatman@gate.DIESPAM.net
Subject: Re: 5.004.004 won't configure on RH5
Message-Id: <352a66d8.273089@news.gate.net>

Now it comes up with an error during make

DB_File.0 (.text+0xb36): undefined reference to 'dbopen' make:
***[perl] ERROR1


This is not making my day.....


>I had this exact problem myself.  The fix was to add another directory to
>the path for libraries.
>
>I think the path I added was /usr/local/include or /usr/local/lib or
>something.
>
>You can have my log file if you want.
>
>~TK
>
>
>



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

Date: 7 Apr 1998 19:24:05 GMT
From: Tom Phoenix <rootbeer&pfaq*finding@redcat.com>
Subject: [Perl] How to find the Perl FAQ
Message-Id: <6gdugl$k3e$1@news1.teleport.com>

Archive-name: perl-faq/finding-perl-faq
Posting-Frequency: weekly
Last-modified: 7 April 1998

For most people, this URL should be all you need in order to find Perl's
Frequently Asked Questions (and answers).

    http://cpan.perl.org/doc/FAQs/

Please look over (but never overlook!) the FAQ and related docs before
posting anything to the comp.lang.perl.* family of newsgroups.

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

Beginning with Perl version 5.004, the Perl distribution itself includes
the Perl FAQ. If everything is pro-Perl-y installed on your system, the
FAQ will be stored alongside the rest of Perl's documentation, and one
of these commands (or your local equivalents) should let you read the FAQ.

    perldoc perlfaq
    man perlfaq

If a recent version of Perl is not properly installed on your system,
you should ask your system administrator or local expert to help. If you
find that a recent Perl distribution is lacking the FAQ or other important
documentation, be sure to complain to that distribution's author.

If you have a web connection, the first and foremost source for all things
Perl, including the FAQ, is the Comprehensive Perl Archive Network (CPAN).
CPAN also includes the Perl source code, pre-compiled binaries for many
platforms, and a large collection of freely usable modules, among its
403_662_481 bytes (give or take a little) of super-cool (give or take
a little) Perl resources.

    http://cpan.perl.org/
    http://www.perl.com/CPAN/
    http://cpan.perl.org/doc/FAQs/FAQ/html/perlfaq.html
    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/perlfaq.html

You may wish or need to access CPAN via anonymous FTP. (Within CPAN,
you will find the FAQ in the /doc/FAQs/FAQ directory. If none of these
selected FTP sites is especially good for you, a full list of CPAN sites
is in the SITES file within CPAN.)

    California     ftp://ftp.cdrom.com/pub/perl/CPAN/
    Texas          ftp://ftp.metronet.com/pub/perl/
    South Africa   ftp://ftp.is.co.za/programming/perl/CPAN/
    Japan          ftp://ftp.dti.ad.jp/pub/lang/CPAN/
    Australia      ftp://cpan.topend.com.au/pub/CPAN/
    Netherlands    ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
    Switzerland    ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
    Chile          ftp://ftp.ing.puc.cl/pub/unix/perl/CPAN/

If you have no connection to the Internet at all (so sad!) you may wish
to purchase one of the commercial Perl distributions on CD-Rom or other
media. Your local bookstore should be able to help you to find one.

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

Comments and suggestions on the contents of this document
are always welcome. Please send them to the author at
<pfaq&finding*comments@redcat.com>. Of course, comments on
the docs and FAQs mentioned here should go to their respective
maintainers.

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/


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

Date: Tue, 07 Apr 1998 15:24:49 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Database sorting problem
Message-Id: <alecler-0704981524490001@dialup-639.hip.cam.org>

In article <352A646B.3D1D2C21@hpl.hp.com>, Larry Rosler <lr@hpl.hp.com> wrote:

> Undoubtedly correct, but would run much slower than necessary on large
> data sets, because of all the computation occurring repeatedly in the
> sort sub.  The FAQ and other sources [snip] would recommend using something 
> like this:
> 
> @result = map $_->[0], sort { $a->[1] <=> $b->[1] }
>         map { [ $_, (split /\|/)[3] ] } @rawData;
> 
> To "sort" that out, read it right-to-left:  create -- *once* per datum
> -- an auxiliary element which is the sort key;  sort by that key;  then
> recover the original datum.  Note how much less computation occurs in
> the sort sub (which is invoked approximately N log N times).
> 
> This idiom should become part of every serious Perl programmer's 
> vocabulary.

===============

Larry,

I read your post with great interest, but for the life of me I can't see
what could be wrong with the suggestion I made earlier in that thread.
Here it is:

#############
@stuff = ( 
   '9|04-02-98|today|364604|today|NULL',
   '10|04-01-98|yesterday|364603|yesterday|NULL',
   '11|04-03-98|tomorrow|364605|tomorrow|NULL'
);

# Put the data in a LoL:

for (0..$#stuff) {
   @fields = split(/\|/,$stuff[$_]);

   for $i (0..$#fields) {
      $data[$_][$i] = $fields[$i];
   }
}

@sorted = sort { $a->[3] <=> $b->[3] } @data;
##############

Seems to me that this code extracts the sort field for each datum and
sorts by this criterium, without the need for a Schwartzian construct, nor
any splitting. (Of course this assumes that the data has already been
stored in a LoL (or a LoH), which would usually be the case anyway,
right?)

One advantage I see is that the whole dataset doesn't get copied in memory
in the sort, as only an array of references is returned. And the sort loop
couldn't be simpler, no?

So, is there anything wrong with that code, speed-wise or otherwise? Why
should I use Schwartz's algorithm instead? I really would like to know,
because this is the kind of code I use for real life projects, and I might
as well change my way of doing things if proven wrong or unefficient. I
consider myself but a learner at this point.

Thank you in advance for any feedback.

A.L.


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

Date: 7 Apr 1998 18:54:05 GMT
From: ronaldws@aol.com (RonaldWS)
Subject: Re: DB_File and multiple processes
Message-Id: <1998040718540501.OAA28363@ladder01.news.aol.com>

In article <6g3ser$vu$1@nnrp1.dejanews.com>, otis@POPULUS.net writes:

>Subject:	DB_File and multiple processes
>From:	otis@POPULUS.net
>Date:	Fri, 03 Apr 1998 17:47:39 -0600
>
>Hello,
>
>I would like to do this, but I'm not sure if it is possible:
>
>script A uses DB_File and generates a DBM (by using DB_File).
>
>I want to have scripts B and C that can read that DBM file and also delete
>hash elements of that DBM that script A generates.
>
>Can that be done?
>Can scripts B and C read and modify (delete) elements of that hash at the
>same
>time that script A is generating the file?
>
>Does DB_File provide some kind of internal locking/serialization mechanism
>that will allow me to have multiple processes modify the same DBM without
>having to handle those acecsses myself?
>
>Thanks
>
>Otis
>P.S.
>If I use DB_File and HAVE Berkeley DB installed oon my machine, will DB_File
>use Berkeley DB or something else? Thanks!
>
>

Use of DB_File by multiple processes is covered, with an example, in the camel
book "Programming Perl" by Wall, Christiansen & Schwartz in Chapter 7 (Library
Modules) of the second edition.  It is discussed in the section of that chapter
covering DB_File.  I have emailed an example more specific to the question at
hand to the poster and will do likewise to any requests emailed to
RonaldWS@aol.com.

Ronald Schmidt


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

Date: 7 Apr 1998 18:54:06 GMT
From: ronaldws@aol.com (RonaldWS)
Subject: Re: dup2 of main::STDERR
Message-Id: <1998040718540601.OAA01583@ladder03.news.aol.com>

In article <6g3emq$gnk$1@nnrp1.dejanews.com>, indhiraa@hotmail.com writes:

>Hi,
>
>I am writing a Perl program in which I want all the error messages
>to go to a file. So I tried to use dup2. Here is the code
>
>#!/usr/local/bin/perl -w
>use strict;
>
>use FileHandle;
>use POSIX;
>
>my $errfd = POSIX::open($errFile, O_CREAT|O_APPEND, 0644);
>(defined $errfd) or die "Can't open $errFile.. : $!\n";

Probably should check for ($errfd >= 0) or die ...

>
>## Get the filedescriptor for STDERR
>
>my $std_err = FileHandle::fileno (main::STDERR);
>
>dup2 ($errfd, $std_err);
>
>### Testing stderr
>
>print STDERR "stderr working..\n";
>die "Error testing dup..\n";
>
>It doesn't print on screen or in file.
>
>What am I doing wrong..

Not too much I think.

>
>Thanks,
>
>

I tried this under Perl 5.003 and Caldera Linux and was surprised to see that
it did not work - it may be some kind of bug.  There is, however, an easy way,
see below, to get the results you desire.

HTH,
Ronald Schmidt

#!/usr/local/bin/perl -w

use FileHandle;
use POSIX;

$errFile = "errf.txt";

# create file with correct permissions if it does not yet exist
unless (-w $errFile) {
	my $errfd = POSIX::open($errFile, O_CREAT|O_APPEND, 0644);
	die "could not create error file reason: $!" unless ($errfd >= 0);
	POSIX::close($errfd);
}

open STDERR, ">>$errFile";

### Testing stderr

print STDERR "stderr working..\n";
die "Error testing dup..\n";




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

Date: 7 Apr 1998 16:31:42 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: foreach loop & current element index
Message-Id: <6ge2fe$l11$1@monet.op.net>

In article <Pine.SGI.3.95.980402102433.27534A-100000@vangogh.bergen.org>,
Jeff Pinyan  <jefpin@bergen.org> wrote:
>This question simultaneously came up in the #perl channel on EFnet.

Chip and I also discussed the same thing there a few weeks ago.

>Currently, there are _no more_ puncuation variables left... they've all
>been used up (from $` to $?).  So currently, it can't be done.  

My suggestion was to use a non-punctuation variable, like $LOOP_INDEX,
and then provide a trivial index.pm pragma that simply did

	*# = \$LOOP_INDEX;

and then if you had `use index' in your program, you could use $# as
asn abbreviation for $LOOP_INDEX.  $# seems nice and mnemonic to me,
and it is presently not very useful.  

Anyway, I put it on my to-do list, but I haven't done it yet.



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

Date: Tue, 07 Apr 1998 14:50:39 -0500
From: "Scott L. Erickson" <Scott.L.Erickson@HealthPartners.com>
Subject: Getting the subroutine name from within a sub
Message-Id: <352A838F.AEABD242@HealthPartners.com>

Hello,

Is it possible for a subroutine to get its name? If so, how is this
done? I looked through the Camel book, but I did not find any reference
to such an activity. If I missed it somewhere, please let me know where
to look.

The reason I want to do this is laziness. I have calls to a logging
subroutine in nearly every subroutine I write. I would like to plunk
down into the subroutine some code like this:

&Log("Begin: $subroutine_name") if ($DEBUG == 2);

Instead, I must write individualized code for every subroutine. Being
able to type one or two generic &Log calls and then cut and paste them
into my subroutines would save me a bit of effort. Also, as I develop a
program, I occasionally rename a subroutine to more accurately reflect
the nature of its function, which means I must remember to update my
&Log call.

On a related note, can a subroutine determine it's caller and if so, how
do I get at that information?

If this information is in the Camel book, I must have missed it, so
please just give me a page reference. Or if this is addressed somewhere
on the Web, I would appreciate a pointer to that. BTW, I have the 2nd
ed. of the Camel book.

I appreciate your help.

Sincerely,
Scott Erickson
Scott.L.Erickson@HealthPartners.com


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

Date: 7 Apr 1998 16:11:50 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Getting the subroutine name from within a sub
Message-Id: <6ge1a6$kli$1@monet.op.net>
Keywords: canvass Clapeyron patio scandium

In article <352A838F.AEABD242@HealthPartners.com>,
Scott L. Erickson <Scott.L.Erickson@HealthPartners.com> wrote:
>Is it possible for a subroutine to get its name? 

use 
	@stuff = caller(0);

The subroutine name is in $stuff[3]; see the perlfunc man page for
more complete details.

>The reason I want to do this is laziness. I have calls to a logging
>subroutine in nearly every subroutine I write. I would like to plunk
>down into the subroutine some code like this:
>
>&Log("Begin: $subroutine_name") if ($DEBUG == 2);

You can do a lot better than that.  
Don't have every function figure out its own name and pass it to the
logger; instead, have the *logging* subrountine figure out where it
was called from and include that automatically:

	sub Log {
	  my $caller = (caller(1))[3];
	  print @_, ': ', $caller, "\n";
	}

Then the call just looks like this:

	Log("Begin") if $DEBUG == 2;



>On a related note, can a subroutine determine it's caller and if so, how
>do I get at that information?

Would I be rude to suggest that you try the index next time?  There is
an entry for `caller function'. 



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

Date: Tue, 7 Apr 1998 13:37:53 -0500
From: Chocolate <poohba@io.com>
Subject: How do I sort without having a space before the record?
Message-Id: <Pine.BSI.3.96.980407133602.5175A-100000@bermuda.io.com>

This is what I have:

#!/usr/local/bin/perl -w

$file = "music.txt";
$tmp = "music.tmp";

open (FILE,"$file")  || die "Can't open $file:   $!\n";
@lines=<FILE>;
close(FILE);

@newlines = sort {$b cmp $a} @lines;

open (FILE,">$tmp")  || die "Can't open $tmp:   $!\n";
print FILE "@newlines\n";
close(FILE);

open (FILE, $tmp) || die "Can't open $tmp:    \n\n";
while (<FILE>) {
	s/\s//g;
}
close(FILE);

When I run this it sorts but it puts a space in front of every record
except the first one.  How do I stop that?




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

Date: Tue, 7 Apr 1998 19:39:42 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: How do I sort without having a space before the record?
Message-Id: <Er26M6.86p@world.std.com>

Chocolate <poohba@io.com> writes:

>Subject: Re: How do I sort without having a space before the record?

The problem isn't with your sort(), but with the quotes you use 
with our print().

>print FILE "@newlines\n";

When you interpolate an array inside double quotes, it puts the
contents of the $" variable between each array element. Since your
elements end in a newline, that puts a space after each newline.

Take a look at what these do:

@array = ('foo', 'bar',  'baz');
print "@array\n";
print @array;

in your code change the print to:

print FILE @newlines;

-- 
Andrew Langmead


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

Date: 7 Apr 1998 18:37:03 GMT
From: kfox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: How do I strip newlines from a var
Message-Id: <6gdrof$cne4@eccws1.dearborn.ford.com>

lassehp@imv.aau.dk (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen) writes:
> As for its creativity, I think it's on par with graffiti: considered
> creative in its own subculture, but ugly and destructive by most other
> people.

I've always thought the real shame with graffiti is that somebody
is destroying the opportunity to look at the original work the way
the author intended.  Last time I checked, a news posting didn't
destroy anything.  The worst they can be is subversive. ;)

> You RRRRR i TTTTTTTTTT  FFFFFFFF  MM  b MM range, so I have to ask you in
> wha RR  RR  TTTTTTTTTT  FFFFFFFF  MMM  MMM s informative? As for its
> cre RR RRR, I t TT  it' FF   ar w MMMMM MM ti: considered creative in its
> own RRRRR ture, TT  ugl FFFFF est MM M  MM  most other people. And what
> you RR  RR musi TT ade  FF eel a  MM si MM nd quite depressed, so your
> sen RR f RR or  TT  be  FF nge to MM    MM

Hmm.  Yes, IMHO that does look a little bit more like graffiti than
Abigail's posting.  (Well, extraordinarily bad graffiti anyway...) ;)

- Ken

-- 
Ken Fox (kfox@ford.com)                  | My opinions or statements do
                                         | not represent those of, nor are
Ford Motor Company, Powertrain           | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section             | "Is this some sort of trick
                                         |  question or what?" -- Calvin


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

Date: Tue, 7 Apr 1998 11:42:48 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Peter Serwe <serwep01@med.nyu.edu>
Subject: Re: How would _you_ do this?
Message-Id: <Pine.GSO.3.96.980407113656.1034J-100000@user2.teleport.com>

On Tue, 7 Apr 1998, Peter Serwe wrote:

> Being extremely new to perl, I did this, for the purpose of checking
> through a list of dns servers, since a 15-30 second response on dns
> queries is unacceptable, if it finds the first one down, it switches out
> the resolv.conf file.  

Doesn't your resolver "remember" where it's gotten an answer from, so it
can ask the same server the next time?

> $res = pingecho("$nsrv[0]",10);
>         if ($res >= '1') { $srv = '1' }
> 
> $res = pingecho("$nsrv[1]",10);
>         if ($res >= '1') { $srv = '2' }
> 
> $res = pingecho("$nsrv[2]",10);
>         if ($res >= '1') { $srv = '3' }

How about this? (This code makes it easier to add or delete servers. But
haven't checked it.)

    undef $srv;
    for $server (0..$#nsrv) {
	my $res = pingecho($nsrv[$server]);
	unless ($res >= 1) {
	    $srv = $server;
	    last;
	}
    }
    die "No server found!" unless defined $srv;

> system('cp /etc/resolv.conf /etc/resolv.bk');

You should probably use a module (or rename) for this. Or a symlink?

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 07 Apr 1998 14:37:45 -0400
From: Frank Cortez <cortez@tfn.com>
Subject: Is it just me?  (error/bug? with "my")
Message-Id: <352A7279.4642@tfn.com>

I've only recently started reading up on/using object-oriented
programming in Perl.  I've been using it for at least two years
now.

Anyway, I seem to have a problem with "my"-- whenever I use it,
the variables it creates simply DON'T EXIST!  I first noticed
the problem when I started using canned code other folks have
sent or that I've gleaned from books.  Any code that uses
variables created using "my" will act as if these variables
are undefined.  I've even tried resetting them myself within
subroutines to what they're supposed to be, only to discover
that my explicit declarations are *ignored*.  Here's a
sample scenario:

#> $Loc and $SessId are set before this point (I checked
#> at this line before calling the routine!)

ShowLoc($SessId, $Loc);

# (intermediate code omitted)

#> routine definition
sub ShowLoc  {

    my ($ID, $URL) = @_;
    my %SessionValues, @matches;

#> my $ID and $URL are undefined!  Here I set the values by
#> hand, and *still* they're ignored!

    # Open the requested file for reading:

    open(RETURNFILE, $URL) ||
	&HTMLError("Unable to open file \"", $URL, "\" for reading.");

# which inevitably gives my error...

Has anyone else seen this?  Perchance, is there something I'm
doing wrong?

Any and all responses appreciated; I'm running the Gurusamy-
Sarathy port of Perl, version 5.004_02, on Win NT 4.0.

-Frank


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

Date: Tue, 07 Apr 1998 18:51:00 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Let it flow .. let it flow!
Message-Id: <352A76F8.181D@min.net>

Eugene Melamud wrote:
> 
> purl (purl) intr.verb

Knit one, perl two...

John Porter


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

Date: Tue, 07 Apr 1998 18:17:15 +0200
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: MKDIR problem
Message-Id: <352a518b.524144494f47414741@radiogaga.harz.de>

bjf (ben@wallroyds.demon.co.uk) wrote:
: Greetings :-)

: I'm having a problem ... I need to create a new directory in a script ... Ie
: ....

: mkdir($dir, 777);

: This won't work ... But when I tried ...

: mkdir($dir, 766);

: It worked OK ... But, I need to make the permission set to 777 ... Not 766,
: can anyone tell me what I'll have to do to make the permission set to 777?
: (Via script, not UNIX, FTP, whatever)

You need to prefix the number with a '0' to get perl to recognize it as
an octal number. What you are doing is set the permission mask to 01411
(decimal 777) and 01376 (decimal 766), respectively.

cu,
  Martin
--
                          | Martin Vorlaender | VMS & WNT programmer
 Ceterum censeo           | work: mv@pdv-systeme.de
 Redmondem delendam esse. |       http://www.pdv-systeme.de/users/martinv/
                          | home: martin@radiogaga.harz.de


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

Date: 7 Apr 1998 20:26:33 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: MKDIR problem
Message-Id: <slrn6il36e.5h1.gabor@vnode.vmunix.com>

In comp.lang.perl.misc, bjf <ben@wallroyds.demon.co.uk> wrote :
# Greetings :-)
# 
# I'm having a problem ... I need to create a new directory in a script ... Ie
# ...
# 
# mkdir($dir, 777);

change it to 
mkdir $dir, 511;

# This won't work ... But when I tried ...
# 
# mkdir($dir, 766);
# 
# It worked OK ... But, I need to make the permission set to 777 ... Not 766,
# can anyone tell me what I'll have to do to make the permission set to 777?
# (Via script, not UNIX, FTP, whatever)
# 
# Sorry about my English by the way (Not my first language)
# 
# Thanks for reading this ...
# 
# BJF
# 
# 


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

Date: Tue, 07 Apr 1998 15:51:42 -0400
From: Vic Parekh <vic.parekh@aig.com>
Subject: need help with references problem
Message-Id: <352A83CE.1A8BD45D@aig.com>

I can do this:

$entry->{'blahblah'}[0]
$entry->{'blahblah'}[1]
and get valid entries for both

I need to figure out how to loop through 'blahblah' to pull out all of
them, meaning $entry{'blahblah'}[n] A foreach type loop, if you will.

Can someone please provide some guidance? I have gone through the blue
camel book, and the websites.






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

Date: Tue, 07 Apr 1998 13:00:36 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: Vic Parekh <vic.parekh@aig.com>
Subject: Re: need help with references problem
Message-Id: <352A85E4.7F75A260@hpl.hp.com>

Vic Parekh wrote:
> 
> I can do this:
> 
> $entry->{'blahblah'}[0]
> $entry->{'blahblah'}[1]
> and get valid entries for both
> 
> I need to figure out how to loop through 'blahblah' to pull out all of
> them, meaning $entry{'blahblah'}[n] A foreach type loop, if you will.
> 
> Can someone please provide some guidance? I have gone through the blue
> camel book, and the websites.

my $entry;
$entry->{blahblah}[0] = 'foo';
$entry->{blahblah}[1] = 'bar';
$entry->{blahblah}[2] = 'baz';

foreach (@{$entry->{blahblah}}) { print "$_\n" }
__END__

prints:

foo
bar
baz

HTH.

Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: 07 Apr 1998 16:21:49 -0400
From: Nevin Kapur <kapur@cbl.ncsu.edu>
Subject: Re: need help with references problem
Message-Id: <tyn2dxmlgi.fsf@cbl.ncsu.edu>

[posted and mailed]

Vic Parekh <vic.parekh@aig.com> writes:

> I can do this:
> 
> $entry->{'blahblah'}[0]
> $entry->{'blahblah'}[1]
> and get valid entries for both
> 
> I need to figure out how to loop through 'blahblah' to pull out all of
> them, meaning $entry{'blahblah'}[n] A foreach type loop, if you will.

What you want is a way to dereference. Here is a way to do that:

for (@{$entry->{'blahblah'}}){
   ## Each element of @{$entry->{'blahblah'}}
   ## is sequentially assigned to $_
}

@$arrayref (or more explicitly @{$arrayref}) behaves exactly like an
array, so you can do perform any kind of array operation on it:


> Can someone please provide some guidance? I have gone through the blue
> camel book, and the websites.

>From perldoc perlref

     That's it for creating references.  By now you're probably
     dying to know how to use references to get back to your
     long-lost data.  There are several basic methods.
 
     1.  Anywhere you'd put an identifier (or chain of
         identifiers) as part of a variable or subroutine name,
         you can replace the identifier with a simple scalar
         variable containing a reference of the correct type:
 
             $bar = $$scalarref;
             push(@$arrayref, $filename);
             $$arrayref[0] = "January";
             $$hashref{"KEY"} = "VALUE";
             &$coderef(1,2,3);
             print $globref "output\n";
-- 
Nevin


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

Date: 07 Apr 1998 16:36:21 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: need help with references problem
Message-Id: <7m5148mi.fsf@mailhost.panix.com>

Vic Parekh <vic.parekh@aig.com> writes:

> I need to figure out how to loop through 'blahblah' to pull out all of
> them, meaning $entry{'blahblah'}[n] A foreach type loop, if you will.

Sure, just refer to the array @{$entry{'blahblah'}}.

> Can someone please provide some guidance? I have gone through the blue
> camel book, and the websites.

Before you go to the camel (or perhaps, at the same time?) you should
check the documentation.  In this case, you should check out perlref,
perllol, perldsc, and perldata.  Hope this helps.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: Tue, 7 Apr 1998 13:30:59 -0700
From: Patrick E Mcknight <pem@U.Arizona.EDU>
Subject: Need help with simple for loop
Message-Id: <Pine.A41.3.96.980407132808.82508A-100000@aruba.u.arizona.edu>

Greetings,

I've tried to get this simple text output program to work but it seems to
only get through the second iteration and then it stops.  Could someone
out there show me the errors in my code.  Thanks in advance.  

Here is the code...very simple:



#!/usr/bin/perl

# PERL script to create bigsteps programs for golf data

for ($i = 1, $i < 46, $i++) {
  for ($j = 1, $j < 5, $j++) {

   $out = "irt$i$j.con";

   open(OUTFILE, ">$out");

   print OUTFILE "\; PGA IRT data anslysis batch\n";
   print OUTFILE "&INST\n";
   print OUTFILE "TITLE=\"PGA IRT data analysis for tournament $i and round $j\n";
   print OUTFILE "ASCII=Y\n";
   print OUTFILE "DATA=IRT$i$j.DAT\n";
   print OUTFILE "NAME=1\n";
   print OUTFILE "ITEM=16\n";
   print OUTFILE "NI=18\n";
   print OUTFILE "CODES=0123456789\n";
   print OUTFILE "PFILE=PGA$i$j.pf\n";
   print OUTFILE "IFILE=PGA$i$j.if\n";
   print OUTFILE "&END\n";
   print OUTFILE "HOLE1\n";
   print OUTFILE "HOLE2\n";
   print OUTFILE "HOLE3\n";
   print OUTFILE "HOLE4\n";
   print OUTFILE "HOLE5\n";
   print OUTFILE "HOLE6\n";
   print OUTFILE "HOLE7\n";
   print OUTFILE "HOLE8\n";
   print OUTFILE "HOLE9\n";
   print OUTFILE "HOLE10\n";
   print OUTFILE "HOLE11\n";
   print OUTFILE "HOLE12\n";
   print OUTFILE "HOLE13\n";
   print OUTFILE "HOLE14\n";
   print OUTFILE "HOLE15\n";
   print OUTFILE "HOLE16\n";
   print OUTFILE "HOLE17\n";
   print OUTFILE "HOLE18\n";
   print OUTFILE "END NAMES\n";

                    }
            }
		
#end of script

Any help would be greatly appreciated.



Cheers,
Patrick
_____________________________________________________________________




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

Date: Tue, 07 Apr 1998 13:02:40 -0600
From: dan@analogy.com
Subject: need perl script to convert unix/dos text files
Message-Id: <6gdpo6$n2e$1@nnrp1.dejanews.com>

I am looking for two simple perl scripts that convert between unix and
dos text files. I would like the script to be as short as possible
but I don't know all the differences between unix and dos text file
formats. In you have such a script available or if you know difinitive
answers to the following questions, I would appreciate your post:

1) Does the CR+LF seperate or terminate each line of a DOS text file?
2) Does the LF seperate or terminate each line of a DOS text file?
3) Do dos text files have a terminal Control-Z for an end of file?
4) Are there any general rules about when text files are implicitly
   converted from one format to another when using ftp, email, or
   zip programs. It seems like you are at the mercy of how individual
   applications behave.

Thanks in advance.


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 07 Apr 1998 13:17:30 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: dan@analogy.com
Subject: Re: need perl script to convert unix/dos text files
Message-Id: <352A89DA.4750A5FC@hpl.hp.com>

dan@analogy.com wrote:
> 
> I am looking for two simple perl scripts that convert between unix and
> dos text files. I would like the script to be as short as possible
> but I don't know all the differences between unix and dos text file
> formats. In you have such a script available or if you know difinitive
> answers to the following questions, I would appreciate your post:
> 
> 1) Does the CR+LF seperate or terminate each line of a DOS text file?
> 2) Does the LF seperate or terminate each line of a DOS text file?
> 3) Do dos text files have a terminal Control-Z for an end of file?
> 4) Are there any general rules about when text files are implicitly
>    converted from one format to another when using ftp, email, or
>    zip programs. It seems like you are at the mercy of how individual
>    applications behave.
> 
> Thanks in advance.
> 
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/   Now offering spam-free web-based newsreading

ux2dos:   perl -we 's/$/\r/' ... (other options and args)

dos2ux:   perl -we 's/\r$//' ... (other options and args)

Can't be much shorter than that :-).

To answer your questions as best I can:

1)  Terminate.
2)  I don't understand.  See 1).
3)  No.
4)  Don't know.

HTH.

Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Tue, 07 Apr 1998 19:45:56 GMT
From: drummj@mail.mmc.org (Jeffrey R. Drumm)
Subject: Re: Packing?
Message-Id: <352a7d67.527895263@news.mmc.org>

On Tue, 7 Apr 1998 18:44:34 +0100, "bjf" <ben@wallroyds.demon.co.uk> wrote:

>Wish I have the same brain as your!

Aw, shucks . . . :-)

>
>The people around here are so clever, I must say :-)
>
>However, what I want to do is ...
>
>The user choose what s/he want (choices) then the file will be generated
>.... Then, it wil be saved on the server ... Then, the user can download it
>for their use ...

I'm assuming you're talking about HTTP and/or FTP here, and CGI scripting.

There's no guarantee that a given user will maintain the same IP address even
between connections during the same "session", since many of the larger ISPs do
load balancing across their internet gateways. Add to that the fact that proxy
servers and the above-mentioned address-translating gateways can make it look
as though multiple users are coming from the same address.

You'll need some other method for generating a unique, user-specific (as
opposed to browser or host IP-specific) key to maintain state. For example, it
might be based on some combination of date, time, and process ID; you could
pass this information from form to form via the URL or a hidden field.

The methods are not language specific, however, and are probably better
addressed in another news group such as comp.infosystems.www.authoring.cgi
(again, assuming you're talking about web development). There's a VERY good
chance that they've been discussed before, so you might wish to check out
www.dejanews.com before posting there, or look around for some CGI FAQs. When
you've made an attempt to do what you want in Perl, come back and ask again.
Just remember that we're pretty hard on folks that don't check their
documentation (including the FAQs) and other on-line resources first.

>How come that you all are SO, SO, SO, SO, clever! Hehe .... Are you all ...
>professor in univerities?

I dont even got me no kollij ejukayshin . . .

:-)

>
>And, apologise my English - Not my first language :-(
>
>Thanks again for the answers, thoughts, points, advices, much more!
>
>Best Regards
>
>BJF

-- 
                               Jeffrey R. Drumm, Systems Integration Specialist
                       Maine Medical Center - Medical Information Systems Group
                                                            drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented!" - me


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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 2268
**************************************

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