[16831] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4243 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 6 21:10:28 2000

Date: Wed, 6 Sep 2000 18:10:14 -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: <968289014-v9-i4243@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 6 Sep 2000     Volume: 9 Number: 4243

Today's topics:
        Newbie - windows directory location scottfreez@my-deja.com
        newbie module install problem [have read faq8] <jeseem@unity.ncsu.edu>
    Re: newbie: redirect problem <suchalm@americasm01.nt.com>
        Perl 5.6.0 on BSDI 4.0... build problem. <elf@halcyon.com>
    Re: Q. relating to  perlfaq(4) / sort <ren.maddox@tivoli.com>
    Re: Stable sorting <lr@hpl.hp.com>
    Re: UDP Broadcast does not work <kiwi@kiwinet.de>
    Re: unpack and Solaris acct struct <tim@ipac.caltech.edu>
        VBA conversion to Perl <dhedtke@birch.com>
    Re: why does foreach iterate on an undef variable? (Martien Verbruggen)
    Re: why does foreach iterate on an undef variable? (Martien Verbruggen)
    Re: why does foreach iterate on an undef variable? (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 06 Sep 2000 23:56:46 GMT
From: scottfreez@my-deja.com
Subject: Newbie - windows directory location
Message-Id: <8p6ljm$rue$1@nnrp1.deja.com>

I'm writing a program that loads some stuff from a config file:

open(DAT, "g-file.txt") or die("Couldn't open g-file.txt\n");

I want to have the config file in the same directory as the .pl file.
What's happening is that unless I give the full path from the root of
the web server (in this case, the root I assigned in IIS), it looks for
the filename in the root rather than the current location. The problem
is that I will be porting this program to different machines and have no
way of knowing the full path to the config file.

Is there a way to get the file's location into a variable, and then
simply append the filename onto that variable? Better yet, is there a
way to simply tell the program to get the file from the same directory
as the directory the program is in??

Thanks
scottfreez



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 06 Sep 2000 18:22:29 -0400
From: Jessica Elizabeth Seem <jeseem@unity.ncsu.edu>
Subject: newbie module install problem [have read faq8]
Message-Id: <39B6C3A5.8FB9C997@unity.ncsu.edu>

Im pretty new to perl, and having trouble each time I try to install a
module. I've read the faq8 to no avail.  I dont have root, so i do:

download .tar.gz
gunzip, tar, etc.
perl Makefile.PL PREFIX=/my/home/perl [for exampl]
make
make test
make install

All goes well until the install tries to write files all over the system
installation (for which I don't have root).  This seems to work for
everyone else, but not for me.  Im on SunOS...

any help is much appreciated,
-kev


%% make install
Warning: You do not have permissions to install into
/afs/.eos.ncsu.edu/contrib/perl5005/lib/site_perl/5.005/solaris26 at
/afs/eos.ncsu.edu/contrib/perl5005/lib/5.00503/ExtUtils/Install.pm line
61.
Installing
/afs/.eos.ncsu.edu/contrib/perl5005/lib/site_perl/5.005/solaris26/auto/HTML/Parser/Parser.so
Installing
/afs/.eos.ncsu.edu/contrib/perl5005/lib/site_perl/5.005/solaris26/auto/HTML/Parser/Parser.bs
Files found in blib/arch --> Installing files in blib/lib into
architecture dependend library tree!
mkdir
/afs/.eos.ncsu.edu/contrib/perl5005/lib/site_perl/5.005/solaris26/HTML:
Permission denied at
/afs/eos.ncsu.edu/contrib/perl5005/lib/5.00503/ExtUtils/Install.pm line
114
*** Error code 2


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

Date: Wed, 6 Sep 2000 20:09:10 -0400
From: "Chalmers, Susan [FITZ3:1123-S:EXCH]" <suchalm@americasm01.nt.com>
Subject: Re: newbie: redirect problem
Message-Id: <8p6mba$4pi$1@bcrkh13.ca.nortel.com>

i don't know about everyone else's ideas, but i use:

print "HTTP/1.1 302 Redirected\nLocation: <url goes here>\n\n"

and it works perfectly and quickly.  i have used it as a one-line script
quite effectively.


harry <hmacdonald@europarl.eu.int> wrote in message
news:39B5F77A.5BC53D45@europarl.eu.int...
> Can anyone please sort me out.
>
> I'm browsing a perl script which is served up by an IIS server.
> (http://site/my.pl)
> And from within the perl script I want to jump to another URL.





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

Date: Wed, 6 Sep 2000 16:34:45 -0700
From: Elf Sternberg <elf@halcyon.com>
Subject: Perl 5.6.0 on BSDI 4.0... build problem.
Message-Id: <Pine.GSO.4.21.0009061631520.14826-100000@king.halcyon.com>


Actually, two problems.  The first is that the NDBM module is dumping core
during the testing phase.  The DB module works fine, but BSDI 4.0 is a
strange hybrid of BSDI 3.1 and FreeBSD, and the incogruities are sometimes
annoying.

Another is that pragma/warnings #257 fails, and I can't figure out why.

Short question: has anyone else gotten perl 5.6.0 to build properly on
BSDI 4.0 such that it passes all tests?

		Elf

Elf M. Sternberg, rational romantic mystical cynical idealist
http://www.halcyon.com/elf/

   "The purpose of writing is to inflate weak ideas, obscure pure
reasoning, and inhibit clarity.  With a little pratice, writing can
be an intimidating and impenetrable fog!"  - Bill Watterson's Calvin.



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

Date: 06 Sep 2000 16:48:47 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Q. relating to  perlfaq(4) / sort
Message-Id: <m3k8cp2nuo.fsf@dhcp11-177.support.tivoli.com>

Larry Rosler <lr@hpl.hp.com> writes:

> I've been watching this thread evolve for about a week, and wondering 
> what problem you all are trying to solve.  Apparently you are trying to 
> sort by numerical value strings of arbitrary length that seem to 
> represent floating-point numbers, using the GRT.  While perhaps 
> interesting, this bears little relation to reality.  One can sort those 
> strings using double-precision floating-point representation.  That is 
> certainly adequate for most data sets, including the test case shown 
> above.

Agreed.  It was really an academic exercise.  A nearly pure one at
that seeing how it is hard to imagine a practical application.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 6 Sep 2000 15:25:28 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Stable sorting
Message-Id: <MPG.1420643549125f8598ad30@nntp.hpl.hp.com>

In article <x7hf7tjjng.fsf@home.sysarch.com> on Wed, 06 Sep 2000 
21:27:32 GMT, Uri Guttman <uri@sysarch.com> says...
> >>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:

 ...

>   BL> Too bad that the field I want to sort to, is a floating point number.
>   BL> I'm not sure what relation there is between numerical comparison and
>   BL> string comparision and the packed float, but it's signed (ugh), only
>   BL> available in native format (endianness? Ugh ugh) and I don't know what
>   BL> number of bytes it takes. Or: no can do.
> 
> well, you didn't state the field type before. larry has shown ways to
> sort floats as long as they are in ieee format which is true for almost
> all common cpus today. i have not played with that but he could help
> you. i think you would use the d format and that would work. ieee floats
> are designed to compare directly as byte strings.

I posted the following this morning.

Message-ID: <MPG.142027a0f2ec628198ad26@nntp.hpl.hp.com>

 ...

> > >#!/usr/bin/perl -w
> > >use strict;
> > >
> > >my @data = (
> > >    '123.342',
> > >    '-23234',
> > >    '2347872347878273878984527636598264368234',
> > >    '1234878234' x 100,
> > >    '-' . '23423423' x 50,
> > >);

 ...

Here is all it takes, copied verbatim from the paper:


BEGIN {
  my $big_endian = pack('N', 1) eq pack('L', 1);
  sub double_sort ($) {
    ($big_endian ? pack 'd', $_[0] :
      reverse pack 'd', $_[0]) ^
      ($_[0] < 0 ? "\xFF" x 8 : "\x80" . "\x00" x 7)
  }
}

my @orderd = map substr($_, 8) => sort
	map { double_sort($_) . $_ } @data;
	
print "$_\n\n" for @orderd;

__END__

Here is another way of coding it, which is more verbose but slightly 
more efficient, because the endian test isn't repeated for each 
comparison:

my $double_sort = pack(N => 1) eq pack(L => 1) ?
      sub { (pack d => $_[0]) ^
          ($_[0] < 0 ? "\xFF" x 8 : "\x80" . "\x00" x 7) } :
      sub { (reverse pack d => $_[0]) ^
          ($_[0] < 0 ? "\xFF" x 8 : "\x80" . "\x00" x 7) } ;

my @orderd = map substr($_, 8) => sort
	map { $double_sort->($_) . $_ } @data;

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


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

Date: Thu, 7 Sep 2000 01:11:03 +0100
From: "Michael Kiwaczinski" <kiwi@kiwinet.de>
Subject: Re: UDP Broadcast does not work
Message-Id: <8p6it6$d9f$17$1@news.t-online.com>

Ipchains, yes. I hate this ;)

Mfg kwi

--
"It's not easy being green" (Kermit the frog)
Mulzergraben12, 87700 Memmingen
Telefon: +49 8331 490275





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

Date: Wed, 06 Sep 2000 15:32:30 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: unpack and Solaris acct struct
Message-Id: <39B6C5FE.43057D92@ipac.caltech.edu>

Matt Knecht wrote:
> 
> I'm trying to upack a pacct file generated by Solaris' accounting
> tools.  According to <sys/acct.h>, a struct of acct has the following
> format:
> 
> #     struct  acct
> #     {
> #             char    ac_flag;
> #             char    ac_stat;
> #             uid_t   ac_uid;
> #             gid_t   ac_gid;
> #             dev_t   ac_tty;
> #             time_t  ac_btime;
> #             comp_t  ac_utime;
> #             comp_t  ac_stime;
> #             comp_t  ac_etime;
> #             comp_t  ac_mem;
> #             comp_t  ac_io;
> #             comp_t  ac_rw;
> #             char    ac_comm[8];
> #     };
> 
> Where according to <sys/types.h> :
> 
> uid_t  == long
> gid_t  == long
> dev_t  == unsigned long
> time_t == int
> comp_t == unsigned short
> 
> I'm using the following format to unpack:
> 
> my $unpack_fmt = "ccllLiSSSSSSA*";
> sysread F, $buf, 40;

I only count 38 bytes in that template. See also below.

> my @s = unpack $unpack_fmt, $buf;
> 
> unpacking yields two extra bytes (Usually NULL, but not always)
> prepended to ac_comm.  The acct structs are coming from Solaris 2.6,
> and I'm crunching the data on a Linux box.  I've "duplicated" the acct
> struct in C on Linux, and I don't see these extra two bytes.
> 
> Any thoughts about what I'm doing wrong with unpack here?

I'd bet it's a word-alignment issue. After ac_flag and ac_stat the compiler may
or may not add 2 bytes to word align what follows, depending on the cpu
architecture. Add pad to the unpack on Solaris and see what happens:

my $unpack_fmt = "ccxxllLiSSSSSSA*";

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 6 Sep 2000 17:36:08 -0500
From: "David Hedtke" <dhedtke@birch.com>
Subject: VBA conversion to Perl
Message-Id: <srdhsrm7ljn62@corp.supernews.com>

I am unable to find any additional references to assist me in converting
this VBA macro for Excel in to Perl code.  Can anyone give me a hand with
this or at least point me in the right direction?  Yes, I have read through
the perlwin32faq.

This is basically what I have instantiated as my objects:

=============== perl code ======================
  # use existing instance if Excel is already running
  eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel
not installed" if $@;
  unless ( defined $ex )


    $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die
"Oops, cannot start Excel";
  }

  # get a new workbook
  $book = $ex->Workbooks->Add;

  $sheet = $book->Worksheets( 1 );

============= VBA MACRO ================

Sub TSDFormat()
'
' TSDFormat Macro
' Macro recorded 9/6/00
'

'
    Cells.Select
    Cells.EntireColumn.AutoFit
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlTop
        .WrapText = True
        .Orientation = 0
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Columns("F:F").Select
    Selection.ColumnWidth = 52
    Columns("H:H").Select
    Selection.ColumnWidth = 52
    ActiveWindow.LargeScroll ToRight:=-1
    Rows("1:1").Select
    Selection.Font.Bold = True
    Range("A1:H1").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlDouble
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$1"
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = ""
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.75)
        .RightMargin = Application.InchesToPoints(0.75)
        .TopMargin = Application.InchesToPoints(1)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .PrintHeadings = False
        .PrintGridlines = True
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 10
    End With
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$1"
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = ""
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "Network Systems Development Tivoli Tickets"
        .RightHeader = ""
        .LeftFooter = "&BBirch Telecom Confidential&B"
        .CenterFooter = "&D"
        .RightFooter = "Page &P"
        .LeftMargin = Application.InchesToPoints(0.75)
        .RightMargin = Application.InchesToPoints(0.75)
        .TopMargin = Application.InchesToPoints(1)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .PrintHeadings = False
        .PrintGridlines = True
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 10
    End With
End Sub





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

Date: Wed, 06 Sep 2000 23:36:12 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: why does foreach iterate on an undef variable?
Message-Id: <slrn8rdl6s.2cp.mgjv@verbruggen.comdyn.com.au>

On 06 Sep 2000 10:46:28 EDT,
	Abigail <abigail@foad.org> wrote:
> Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMDLXIII September
> MCMXCIII in <URL:news:slrn8rc8g3.ucf.mgjv@martien.heliotrope.home>:
> %% 
> %% That's correct. I'm glad you figured it out. My post is mainly as an
> %% asddition to that. If you now next time test these sorts of things with
> %% _all_ the help Perl gives you (-w flag, the strict pragma), you will
> %% probably figure it out before you need to post :)
> 
> No. Perl doesn't think anything strange is going on.
> 
>     $ perl -Mstrict -wle 'my @a = undef; foreach my $s (@a) {print "foo"}'
>     foo
>     $

Oops. You're right. I read badly, and assumed, falsely, that the OP
was printing out the values of the array elements. Probably because
that is how I would have written the loop.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Wed, 06 Sep 2000 23:40:03 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: why does foreach iterate on an undef variable?
Message-Id: <slrn8rdle3.2cp.mgjv@verbruggen.comdyn.com.au>

On 6 Sep 2000 17:45:43 GMT,
	Tina Mueller <tina@streetmail.com> wrote:
> hi,
> In comp.lang.perl.misc Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> > [reordered post to respect the natural flow of time, which makes it a
> > bit easier to follow]
> 
> > On Wed, 06 Sep 2000 09:10:44 GMT,
> > 	Paul Johnston <johnston.p@worldnet.att.net> wrote:
> >> Paul Johnston wrote in message ...
> >> >I'm confused as to the logic of why a foreach loop block *is* entered when
> >> >the LIST is undef (NOT expected), but *is not* when the LIST is an empty
> >> >array (expected behavior):
> 
> > I think this is where the confusion starts. A list cannot be undefined,
> 
> no? well, it doesn't work with
> @array = undef;
> but with
> undef @array;

A list is not an array, as I stated as well. But even undefining an
array is not recommendable. Mainly because it's meaningless, and
partly because it doesn't do what you mean. It works, but that's not
the same thing.

> of course in the most cases people want to prefer my();

Indeed, but that still leaves the question: How do I empty an array.
And the answer to that should simply be: Assign an empty list to it.

And using lexically scoped variables doesn't always preclude the
(perceived) need to empty arrays:

my @foo = (1, 2, 3);
print for (@foo);
@foo = ();
$foo[$_] = $_ for (3 .. 6);

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd.   | spot.
NSW, Australia                  | 


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

Date: Wed, 06 Sep 2000 23:51:09 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: why does foreach iterate on an undef variable?
Message-Id: <slrn8rdm2u.2cp.mgjv@verbruggen.comdyn.com.au>

On Wed, 6 Sep 2000 13:44:45 +0100,
	Louise Davis <louise.davis@breathemail.net> wrote:
> 
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message
> news:slrn8rc90h.ucf.mgjv@martien.heliotrope.home...
> > [please, in the future, put your followup text AFTER the text you
> > respond to. Also, don't respond twice to your own message.
> 
> I'll remember that but I don't think I will be posting again - not after
> this !

You can post, but please, do try to conform to the generally accepted
posting style. If everyone quotes posts whichever way suits them, then
a post with multiple levels of quoting soon becomes unreadable. In
this group we prefer to have quotes _before_ the original
contribution. Other groups prefer the other way around.

> > Rather: think
> > the problem through a bit better before posting, so you don't have to
> > post as much. One followup to yourself is acceptable, two is a bit much]
> 
> Sorry - I don't understand this - I only posted once and this is my only
> follow up.

Mea culpa. I misread the headers, thinking that you were the same
person as the original poster.

> > On Wed, 6 Sep 2000 11:36:54 +0100,
> > Louise Davis <louise.davis@breathemail.net> wrote:
> > [Also see my other reply]
> > >
> > > use     undef @array;      instead.
> >
> > No, no, no, no!
> >
> > Use
> >
> > @array = ();
> >
> > instead. Don't 'undefine' an array, whatever that should mean. Do what
> > you mean.
> 
> That is the terminology used in "Programming Perl 2nd Edition chapter 3.2"
> on the use of undef which, according to the book, can be used as a unary
> operator on an array. Is there is any reason I shouldn't be using undef in
> this way?

The documentation also states this, and I have complained about it in
the past. It's mainly a matter of style, as well as other reasons. If
you use something like www.deja.com, you probably will be able to find
other threads in this group on that subject. 

Perl is a language that allows you to do things in many ways, yes, but
it's also a language that is meant to allow you to express things in
the most natural way available. If you want to say

undef @array;

you are free to do so, but semantically it doesn't mean much, or is at
least ambiguous[1]. You should just say what you mean, and make your code
clearer. Also, It's not the same as

@array = ();

The latter form is clear, and does exactly what is wanted.

Martien

[1] People might think you mean to assign undef to all elements of
your array.
-- 
Martien Verbruggen              | 
Interactive Media Division      | You can't have everything, where
Commercial Dynamics Pty. Ltd.   | would you put it?
NSW, Australia                  | 


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

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


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