[20033] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2228 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 28 11:06:27 2001

Date: Wed, 28 Nov 2001 08:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006963508-v10-i2228@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 28 Nov 2001     Volume: 10 Number: 2228

Today's topics:
    Re: 2D Array from Text File <MichaelRunningWolf@att.net>
    Re: 2D Array from Text File <MichaelRunningWolf@att.net>
    Re: A Perl Bug? <jake@chaogic.com>
    Re: A Perl Bug? (Helgi Briem)
        Arbitrary Precision Perl Scripts for Subtraction, Multi <SSEA@SSEAweb.com>
    Re: Change file extensions in specific subfolders. (Helgi Briem)
    Re: File::Copy - Which Perl Versions Include It? <mkruse@netexpress.net>
    Re: File::Copy - Which Perl Versions Include It? (Helgi Briem)
    Re: How do you pronounce "Perl"? (Randal L. Schwartz)
    Re: How to implement "peres unbiasing" in perl. (John J. Trammell)
    Re: How to implement "peres unbiasing" in perl. (John J. Trammell)
    Re: Internal Server Error (Helgi Briem)
    Re: Internal Server Error <username@this.is.a.trap.graffl.net>
    Re: Internal Server Error <admin@asarian-host.net>
    Re: Internal Server Error (Helgi Briem)
    Re: Internal Server Error <username@this.is.a.trap.graffl.net>
    Re: Internal Server Error <username@this.is.a.trap.graffl.net>
    Re: is rename atomic? (Randal L. Schwartz)
    Re: Must be a better way.. (HoboSong)
    Re: Must be a better way.. <bart.lateur@pandora.be>
    Re: newline problem with messy output - v simple proble (Helgi Briem)
    Re: Perl for WinNT <dbohl@sgi.com>
    Re: Perl for WinNT <edgue@web.de>
    Re: Perl for WinNT (Helgi Briem)
    Re: Problems while Installing modules from Source on w2 (Helgi Briem)
    Re: System call return value 256 - Bad file descriptor (Bryce Pursley)
    Re: Win32::ODBC => generating a list of hashes from the <simon.oliver@umist.ac.uk>
    Re: Win32::ODBC => generating a list of hashes from the <simon.oliver@umist.ac.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 28 Nov 2001 14:19:25 GMT
From: Michael Running Wolf <MichaelRunningWolf@att.net>
Subject: Re: 2D Array from Text File
Message-Id: <wkpu633rma.fsf@att.net>

Laocoon <Laocoon@eudoramail.com> writes:

> my @codes = <INPUT> =~ /\d+/g;
> my @desc  = <INPUT> =~ /[^,]+/g;    	
> for (@codes) {
>     	$hash{$_} = $desc[$i++]
> }	

Or, eliminating the 'for' loop and using a hash slice:

 @hash{@codes} = @desc;

BTW - I don't like naming a variable for its type.  I'd rather name it
for the contents.  Some folks don't like that there's a hash and an
array both named 'desc' in the following code.  I can hear that as a
valid argument.  I kinda' like having the hash and array name be the
same -- it "says" something to me.  It's documentation to me.  If it's
confusion to you, choose a different.  Style.

my @codes = <INPUT> =~ /\d+/g;
my @desc  = <INPUT> =~ /[^,]+/g;
# The hash 'desc' is initialized from the array 'desc'.
my @desc{@codes} = @desc;       


-- 
All mammals learn by playing.
   MichaelRunningWolf@att.net


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

Date: Wed, 28 Nov 2001 14:33:13 GMT
From: Michael Running Wolf <MichaelRunningWolf@att.net>
Subject: Re: 2D Array from Text File
Message-Id: <wkk7wb3qza.fsf@att.net>

"Paul Wasilkoff" <paul_wasilkoff@ucg.org> writes:

> AA,Alpha Description
> BB,Beta Description

Much better file structure.  Much better to maintain.  Yeah!!!!

Just for kicks, you could implement "comments" in the file to help
future maintainers.  I often write loops that throw out comment and
blank lines.  The following snippet throws out "shell-style" comments
(i.e. sharp as the first non-whitespace character on a line) and blank
lines.  I then put a comment at the beginning of the file that looks
like a table header line.  I can then 'group' my data into
'paragraphs', and even introduce each separate paragraph.  I can even
"disable" a line temporarily by "commenting" it out, and let the file
remember what the data is for re-enabling it.

This is one of my favorite perl code frags:

while (<DATA>) {
  next if /^\s*#/ || /^\s*$/;
  # continue with real data
}

Alternatively - 

while (<DATA>) {
  next if /^\s*#/;      # skip comments
  next if /^\s*$/;      # skip blank lines
  # continue with real data
}

__DATA__
# Blah-blah data file:
# The rules for this data file are quite strange!
#/----- Blah-blah code (must be 2 digit prime number)
#|  /-- Blah-blah desc (must not contain vowels or the letter 'M')
#|  |
#V  V

# ================
# From North America
AA,Alpha Description
BB,Beta Description

# ================
# From Central America
CC,asdf
DD,asdf

# ================
# From South America
XY,asdf

# ================
# From Oz
zz,asfd

-- 
All mammals learn by playing.
   MichaelRunningWolf@att.net


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

Date: Wed, 28 Nov 2001 09:10:17 -0600
From: "Jake Fan" <jake@chaogic.com>
Subject: Re: A Perl Bug?
Message-Id: <9u2upp$j72$1@Masala.CC.UH.EDU>

[/lurking mode off]

Helgi Briem <helgi@decode.is> wrote:

> There is plenty of danger.  Using "working" scripts
> from Matt's script archive or Godzilla or countless
> other sources of crap code can open your system to
> all manner of exploit  and data corruption even
> though the scripts "work" when tested.
>
> Many of the people you have been arguing with
> "are" super gurus.

That danger has always existed, and will always exist.  It is not because of
anything else, it is because Matt, Godzilla etc. are humans (although
Godzilla's nick does make one wonder from time to time).  Have you heard of
a major bug in one of the latest Linux kernel releases?  (A quick summary
for those who haven't followed the Linux news lately or those who don't care
about Linux: One of the latest Linux kernel releases has a bug which could
corrupt an entire file system.  It has affected many users, but a fix has
also been quickly released.)

The real danger arises when some people start to develop "Individual
Worship", or when some individuals start to develop "God Complex".

[/lurking mode on]





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

Date: Wed, 28 Nov 2001 15:56:14 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: A Perl Bug?
Message-Id: <3c050860.3566065211@News.CIS.DFN.DE>

On Wed, 28 Nov 2001 09:10:17 -0600, "Jake Fan"
<jake@chaogic.com> wrote:

>The real danger arises <SNIP> when some 
>individuals start to develop "God Complex".

What you mistakenly think of as a "God Complex" is
simply the regulars trying to maintain a semblance
of common courtesy in the face of rude, clueless
boors who try to get ahead of the line at the
pot-luck.  People who have no manners invariably
think that being asked to show etiquette is a sign 
of a "God Complex".

Regards,
Helgi Briem



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

Date: Wed, 28 Nov 2001 15:53:10 GMT
From: "Basil Skordinski" <SSEA@SSEAweb.com>
Subject: Arbitrary Precision Perl Scripts for Subtraction, Multiplication, and Division Needed
Message-Id: <GL7N7.11234$WC1.1412116@newsread2.prod.itd.earthlink.net>

Is there anyone out there who is willing to share their Perl scripts for
subtraction, multiplication, and division?  I'm looking for Perl scripts
that will perform these operations accurately on numbers with 30 digits to
the right or left of the decimal point.  (The Perl module Math::BigFloat
gives me all sorts of warnings when I try to use it -- needless to say, I
don't have too much confidence in its ability to do things correctly.)  Help
would be greatly appreciated.  Thanks.




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

Date: Wed, 28 Nov 2001 14:41:10 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Change file extensions in specific subfolders.
Message-Id: <3c04f65e.3561455312@News.CIS.DFN.DE>

On Wed, 28 Nov 2001 13:59:41 +0100, starflyer <adr@not.av>
wrote:
>I need to change html files to shtml in
>folders with the same name (all within
>a complex folder tree).

perldoc -f rename
perldoc -X File::Find

If the contents of shtml files are
different from html files you will
also need to read the perldoc for
the following functions:
open, die, print, while, close and s///

>Someone help me out?
>Or maybe a good perl site for starters?

www.perldoc.com
web.stonehenge.com/merlyn
www.perl.com
theoryx5.uwinnipeg.ca/CPAN/cpan-search.html

Regards,
Helgi Briem



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

Date: Wed, 28 Nov 2001 09:34:55 -0600
From: "Matt Kruse" <mkruse@netexpress.net>
Subject: Re: File::Copy - Which Perl Versions Include It?
Message-Id: <3c050377$0$19472$724ebb72@reader2.ash.ops.us.uu.net>

Jeff 'japhy' Pinyan <jeffp@crusoe.net> wrote:
> Grr.  I could not find such a statement in Changes5.002.  That's
> upsetting.

Interesting. It's difficult to track down the truth :)

> Well, you COULD always do:
>   use 5.005;
> to require the user have at least 5.005 installed.  These days, people
> should have at least 5.005.

Well, that's true, but when writing something for the mass audience, it's
best to not assume anything.
An average Joe web developer who wants a CGI script doesn't necessarily know
much about Perl, much less have control over which version of perl his web
host uses. When something doesn't work because his site doesn't have a
recent version, he gives up and assumes that the script sucks because it
doesn't work.
It's best, IMO, to write portable scripts which don't make many demands
about the environment of the user, so that almost anyone can pick it up and
use it. That's my goal, at least. For the most part, it works well for me :)

Thanks,

Matt Kruse
http://www.mattkruse.com/





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

Date: Wed, 28 Nov 2001 15:59:12 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: File::Copy - Which Perl Versions Include It?
Message-Id: <3c05093f.3566288732@News.CIS.DFN.DE>

On Wed, 28 Nov 2001 09:34:55 -0600, "Matt Kruse"
<mkruse@netexpress.net> wrote:

>An average Joe web developer who wants a CGI script doesn't 
>necessarily know much about Perl, 

Since when is ignorance an excuse for incompetence?

>much less have control over which version of perl his web
>host uses. 

He should ask the web host to install a newer version,
install it himself or find a new hosting company.

In this age of daily security breaches, there is no
excuse for an ISP to provide outdated and obsolete
tools.

Regards,
Helgi Briem



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

Date: 28 Nov 2001 06:54:38 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How do you pronounce "Perl"?
Message-Id: <m17ksb9c9d.fsf@halfdome.holdit.com>

>>>>> "Jan" == Jan Pieter Kunst <devnull@cauce.org> writes:

Jan> Hello all,
Jan> This is probably a stupid question, but my native language is not
Jan> English, so please bear with me.

Jan> How do you pronounce "Perl"? Does it sound like "pearl" , or is the "e"
Jan> the same as the "e" in "help"?

Larry says it like "pearl".  The other one would sound to me like
"peril", which amazingly is what FrameMaker always wants to
spell-correct it as until I tell it "no". :)

print "Just another Perl hacker,"
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 28 Nov 2001 08:38:36 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: How to implement "peres unbiasing" in perl.
Message-Id: <slrna09tt1.tc8.trammell@haqq.el-swifto.com>

On Wed, 28 Nov 2001 02:30:35 -0500, Benjamin Goldberg wrote:
> John J. Trammell wrote:
> > 
> > On Tue, 27 Nov 2001 19:06:28 -0500, Benjamin Goldberg wrote:
> > > I'm trying to implement a really funky algorithm known as "Peres
> > > unbiasing."
> > [snip]
> > 
> > sub advanced_multi_level
> > {
> >     my @bits = ( [ @_ ] );
> >     my @out;
> >     my $max = 0;
> [snip]
> 
> Hmm.  Verry interesting.  However, I'm sorta looking for something which
> will process bits in an incremental fashion, and not require that I grab
> my entire input and process it all at once... especially since my input
> is potentially gargantuan.

Yep.  It's not too hard to tweak my code to accept a code reference
(for getting biased flips) and a count, and generate $count unbiased
bits though.

Then you set $count to 1e6 and watch it suck.  :-)

> If the size of the input is in the vicinity of 2**32 items, the code *I*
> gave would work with a relatively tiny amount of memory, and yours might
> not even fit within the computer's addressable space!  Now, if only my
> code worked right :)

I understand the Peres algorithm, but how your code implements it
is a bit opaque to me.  How do you represent the two children of
the j'th flip sequence?  I use a heap structure (in case the 2j+1,
2j+2 in the code didn't give it away).

> Not that I don't appreciate it... it's just not suitable for my
> purposes.

Yeah, it's only practical on my machine for n ~ 1e5 or less.  I'm
interested in making this work more efficiently.



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

Date: Wed, 28 Nov 2001 08:49:51 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: How to implement "peres unbiasing" in perl.
Message-Id: <slrna09ui4.tc8.trammell@haqq.el-swifto.com>

On Wed, 28 Nov 2001 03:18:13 -0500, Benjamin Goldberg wrote:
> Benjamin Goldberg wrote:
> > 
> > I'm trying to implement a really funky algorithm known as "Peres
> > unbiasing."
> > 
> > I couldn't find the original paper online, but did find it described
> > in the paper "Tossing a Biased Coin" by Michael Mitzenmacher, [which
> > is available at http://www.fas.harvard.edu/~libcs124/CS/coinflip3.pdf
> > and at http://www.fas.harvard.edu/~libcs124/CS/coinflip3.ps ], as
> > something called the "Advanced Multi-Level Strategy."
> > 
> > I understand the basic "Multi-Level Strategy," [also described in that
> > paper] but the "Advanced" one is hurting my brane.
> 
> Hmm, I *think* I've found my problem, or part of it.
> 
> With the advanced strategy, each level recieves exactly half as many
> input bits as the prior level.  At each level, the basic multi-level
> strategy is applied to those input bits to get output bits.

No, I'd say each level receives at most half as many, because some
bits get Neumanned out.  Fig. 2 in the Mitzenmacher paper shows this.

> Obviously, if the basic multi-level strategy averages X bits/flip then
> the advanced strategy will get X * ( 1 + 1/2 + 1/4 + 1/8 + ... ) bits
> per flip... that is, twice as many bits per flip, or half as many flips
> per bit.
> 
> Considering that with my implementation of mls, I average about 3 flips
> per bit... 1.5 does seem to make some sense.
> 
> But the paper implies that I should be able to get ONE flip per bit...
> 
> The problem, then, is that to get 1 flip per bit with amls, I need to
> get 2 flips per bit with mls...  here's mls:
> 
> my ($heads, $tails) = (0,0);
> sub get_bit {
>     my ($coin,$mask);
>     do {
>         ($coin = coinflip()) ? ++$heads : ++$tails;
>         $mask = $heads & $tails;
>     } until($mask);
>     $heads &= ~$mask; $tails &= ~$mask;
>     $coin;
> }
> 
> Experimentation shows that this requires 3 coinflips per returned bit.
> 
> Logic *seems* to indicate that it should consume 1 / (1/4+1/8+1/16+...)
> flips per output bit, or 2 flips per bit.  This is the expectation, but
> reality seems to differ.
> 
> Either my code's wrong, or my logic's wrong, or reality's wrong.
> 
> Waah!  Somebody help me before I spontaneously combust!  :)
> 

Here's my stats:

[ ~ ] perl bias.pl 0.5 10000
using bias=0.5, n=10000
H(0.5) = 1
algorithm  mean       n'         eff. (%)   dev. (%)  
---------- ---------- ---------- ---------- ----------
neumann    0.50110    40136      24.9153    75.0847   
twolevel   0.49620    34274      29.1766    70.8234   
multilevel 0.51020    30154      33.1631    66.8369   
aml        0.50380    10752      93.0060    6.9940    
[ ~ ] 

Arguments are bias and number of unbiased bits to generate.
Mean is a check on the output.
n' is the number of biased flips used to generate the unbiased data.
Efficiency is the ratio of unbiased to biased flips.
Deviation is the percentage of bits "wasted"; this changes with H.

This looks right to me but has not been rigorously checked.
Cranking up "n" ups the efficiency; I'm thinking it approaches 1
for advanced multilevel.

Maybe an interesting statistic would be the number of bits each
level contributes, to compare to the sum 1 + 1/2 + 1/4 + ...

-- 
[8 PM] Xena: Modestly dressed Housewife - Xena stays home and does some cooking.


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

Date: Wed, 28 Nov 2001 14:29:48 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Internal Server Error
Message-Id: <3c04f44a.3560923137@News.CIS.DFN.DE>

On Wed, 28 Nov 2001 10:15:46 -0000, "Andy Laurence"
<username@this.is.a.trap.graffl.net> wrote:

>
>I feel such an idiot!  I looked at the scripts from the console and at the
>end of each line there is a ^M.  This I expect is a newline character
>created my the MS software I'm using to write it on.  There seems to be a ^M
>at the end of each line, so a simple s/^m//g; should see me through!

No, it won't, but s/\r//g will or even better
because it also fixes Mac files: s/\r\n*/\n/g

Regards,
Helgi Briem



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

Date: Wed, 28 Nov 2001 14:51:17 -0000
From: "Andy Laurence" <username@this.is.a.trap.graffl.net>
Subject: Re: Internal Server Error
Message-Id: <9u2tl7$5thqv$1@ID-109625.news.dfncis.de>

> >I feel such an idiot!  I looked at the scripts from the console and at
the
> >end of each line there is a ^M.  This I expect is a newline character
> >created my the MS software I'm using to write it on.  There seems to be a
^M
> >at the end of each line, so a simple s/^m//g; should see me through!
>
> No, it won't, but s/\r//g will or even better
> because it also fixes Mac files: s/\r\n*/\n/g

why should s/\r//g work?  Is this a shortcut to a DOS newline character?
All I need to do is remove the newline character, so I would run s/^M//g on
the linux box.  I'm manually deleting the characters at the moment, as it's
only one character per script (I've left them on the end of the other
lines).  Luckily, I don't have macs to contend with as well.

Andy
--
PC-Based Multimedia System
http://www.andylaurence.pwp.blueyonder.co.uk/pcbmms
NB: Spamtrap - my name @yahoo.co.uk




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

Date: Wed, 28 Nov 2001 15:34:05 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: Internal Server Error
Message-Id: <Nt7N7.18$ox2.39057@bin4.nnrp.aus1.giganews.com>

"Andy Laurence" <username@this.is.a.trap.graffl.net> wrote in message
news:9u2tl7$5thqv$1@ID-109625.news.dfncis.de...

> why should s/\r//g work?  Is this a shortcut to a DOS newline
> character?

\r represents the ASCII character 13 (0DH), the "return" (hence \r) -- the
yea-old Carrriage Return, to be precise. In the old days, a CR would return
the "carriage" (as in a typewriter) to the start of the line, and the LF
(linefeed, 0AH) would avance the "cursor" one line down. Here endeth the
short peek into why DOS files (among others) use the ODH 0AH pair. :)

Hence, s/\r\n?/\n/g should do what you want.

P.S. I use a rather useful small prog, called "fixcrlf", that you can drag
and drop your scripts on to convert LF to CR-LF, and vice versa. I will
email it to your privately, as this is not a binary group.

- Mark




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

Date: Wed, 28 Nov 2001 15:50:38 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Internal Server Error
Message-Id: <3c05047f.3565071942@News.CIS.DFN.DE>

On Wed, 28 Nov 2001 14:51:17 -0000, "Andy Laurence"
<username@this.is.a.trap.graffl.net> wrote:

>> >I feel such an idiot!  I looked at the scripts from the console and 
>>> at the  end of each line there is a ^M.  This I expect is a newline 
>> > character
>> >created my the MS software I'm using to write it on.  There seems to be a
>>>^M at the end of each line, so a simple s/^m//g; should see me 
>>>through!

>> No, it won't, but s/\r//g will or even better
>> because it also fixes Mac files: s/\r\n*/\n/g
>
>why should s/\r//g work?  Is this a shortcut to a DOS newline character?

\r is half of the DOS newline character or <CR>.
\n is the other half (<LF>).

>All I need to do is remove the newline character, 
>so I would run s/^M//g on the linux box. 

Does that actually work for you?  It doesn't for me.  I 
don't think perl understands ^M as a <CR> character.
I may be wrong but my little test:
 perl -e 'my $cr = "\r"; if ($cr =~ /^M/) { print "SAME";}
else { print "NOT SAME";}'
prints NOT SAME indicating that you are wrong.

^M is simply how some text editors display the \r 
character, not the character itself.

> I'm manually deleting the characters at the moment, as it's
>only one character per script (I've left them on the end of the other
>lines).  

Don't do that.  It can cause lots of other problems
as well.  FTP from PC to Unix using ASCII mode
or incorporate my regex into a dos2unix utility.

>Luckily, I don't have macs to contend with as well.

That is a piece of luck indeed.

Regards,
Helgi Briem




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

Date: Wed, 28 Nov 2001 15:55:48 -0000
From: "Andy Laurence" <username@this.is.a.trap.graffl.net>
Subject: Re: Internal Server Error
Message-Id: <9u31e5$5mbnf$1@ID-109625.news.dfncis.de>

> > why should s/\r//g work?  Is this a shortcut to a DOS newline
> > character?
>
> \r represents the ASCII character 13 (0DH), the "return" (hence \r) -- the
> yea-old Carrriage Return, to be precise. In the old days, a CR would
return
> the "carriage" (as in a typewriter) to the start of the line, and the LF
> (linefeed, 0AH) would avance the "cursor" one line down. Here endeth the
> short peek into why DOS files (among others) use the ODH 0AH pair. :)
>
> Hence, s/\r\n?/\n/g should do what you want.

I see.  thanks for that.

> P.S. I use a rather useful small prog, called "fixcrlf", that you can drag
> and drop your scripts on to convert LF to CR-LF, and vice versa. I will
> email it to your privately, as this is not a binary group.

That would be much appreciated.  To clarify, it's
<myfirstname><mylastname>@yahoo.co.uk

Cheers,
Andy
--
PC-Based Multimedia System
http://www.andylaurence.pwp.blueyonder.co.uk/pcbmms
NB: Spamtrap - my name @yahoo.co.uk




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

Date: Wed, 28 Nov 2001 15:58:45 -0000
From: "Andy Laurence" <username@this.is.a.trap.graffl.net>
Subject: Re: Internal Server Error
Message-Id: <9u31jo$6120d$1@ID-109625.news.dfncis.de>

> >All I need to do is remove the newline character,
> >so I would run s/^M//g on the linux box.
>
> Does that actually work for you?  It doesn't for me.  I
> don't think perl understands ^M as a <CR> character.
> I may be wrong but my little test:
>  perl -e 'my $cr = "\r"; if ($cr =~ /^M/) { print "SAME";}
> else { print "NOT SAME";}'
> prints NOT SAME indicating that you are wrong.
>
> ^M is simply how some text editors display the \r
> character, not the character itself.

OK, well, I've yet to try it.

> > I'm manually deleting the characters at the moment, as it's
> >only one character per script (I've left them on the end of the other
> >lines).
>
> Don't do that.  It can cause lots of other problems
> as well.  FTP from PC to Unix using ASCII mode
> or incorporate my regex into a dos2unix utility.

It's a quick fix until I sort something more permanent out.  I'm using Samba
on the linux box and saving files directly to the network drive, which is
where my problem comes from.  This program Mark speaks of looks to be the
perfect solution though.

> >Luckily, I don't have macs to contend with as well.
>
> That is a piece of luck indeed.

;-)

Andy
--
PC-Based Multimedia System
http://www.andylaurence.pwp.blueyonder.co.uk/pcbmms
NB: Spamtrap - my name @yahoo.co.uk




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

Date: 28 Nov 2001 06:48:06 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: is rename atomic?
Message-Id: <m1elmj9ck9.fsf@halfdome.holdit.com>

>>>>> "Anno" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

Anno> According to Joachim Ziegler <ziegler@algorilla.de>:
Anno> [...]

>> is 'rename' atomic in the sense that it is either carried out
>> completely or not all all?

Anno> Yes.

"yes" ... provided that you have rename(2).  If rename(2) is absent,
and being emulated using link(2) and unlink(2), there's a crash point
that would leave the file hardlinked under both the old and new names.

But (nearly?) all modern Unix flavors (since 2.8BSD and SysV and all
derivatives and copycats) have rename(2).

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 28 Nov 2001 07:20:33 -0800
From: chrisvano@yahoo.com (HoboSong)
Subject: Re: Must be a better way..
Message-Id: <4fbb9396.0111280720.42b994a3@posting.google.com>

Uri Guttman <uri@stemsystems.com> wrote in message news:<x77ksb8qmp.fsf@home.sysarch.com>...
> >>>>> "JWK" == John W Krahn <krahnj@acm.org> writes:
> 
>   JWK> my %lookup = ( qr/SETTLEMENT SECTION/,     \&parse_settlement,
>   JWK>                qr/DIVIDENDS REPORT/,       \&parse_divs,
>   JWK>                qr/RISK MANAGEMENT REPORT/, \&parse_risk,
>   JWK>               );
> 
>   JWK> while ( <TEXTFILE> ) {
>   JWK>     for my $regex ( keys %lookup ) {
>   JWK>         /$regex/ and $lookup{ $regex }->( $_ );
>   JWK>         last;
> 
> hmm, will that ever try the 2nd and third regexes if the first fails?
> 
> i think you meant:
> 
> 		$lookup{ $regex }->( $_ ), last if /$regex/ ;
> 
>   JWK>         }
>   JWK>     }
> 
> uri

 When I go to http://www.perldoc.com/perl5.6/pod/func/qr.html#top to
look for documentation on "qr/ /" , I get a blank page, Im assuming it
is "quote regex"?
 Then, If I am reding your code correctly, it looks like the values to
the %lookup hash are pointers? to the subroutines...so I ask,

  This would only process lines that match the regex?


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

Date: Wed, 28 Nov 2001 15:44:12 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Must be a better way..
Message-Id: <ke1a0ugbqnsn8baritr2uav4tbvbo9pvfj@4ax.com>

HoboSong wrote:

>When I go to http://www.perldoc.com/perl5.6/pod/func/qr.html#top to
>look for documentation on "qr/ /" , I get a blank page, Im assuming it
>is "quote regex"?

That looks like an error. Anyway, here you can find out more:

<http://www.perldoc.com/perl5.6/pod/perlop.html#Regexp-Quote-Like-Operators>

although you'll have to scroll a little to find it, or use your
browser's search, look for "qr/STRING/".

-- 
	Bart.


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

Date: Wed, 28 Nov 2001 14:34:50 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: newline problem with messy output - v simple problem
Message-Id: <3c04f599.3561258118@News.CIS.DFN.DE>

On 28 Nov 2001 03:12:10 -0800, eguttridge@buildonline.com
(bigpig) wrote:

> I cannot work out how to format the output so it contains 
>line ends etc. where it should do.

Replace the following line:
>print "$output\n";
with this one:
print "<pre>$output</pre>\n";
to tell the browser to use the linebreaks in the
original data.

Regards,
Helgi Briem




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

Date: Wed, 28 Nov 2001 08:56:00 -0600
From: Dale Bohl <dbohl@sgi.com>
Subject: Re: Perl for WinNT
Message-Id: <3C04FB00.79F071A9@sgi.com>

"G.Doucet" wrote:
> 
> Here's the scoop!
> 
> The last PERL script I wrote was more than a year ago and ran on the Novell
> Enterprise Server.
> 
> Now I need to program a PERL script to run on a UNIX server.
> 
> The problem however is that I must create, test and debug it at home.
> 
> Unfortunately, at home, I only found a copy of WinNT4, and I also have a
> copy of Novell Netware 4. - And I have unfortunately never touched UNIX.
> 
> I was hoping to develop my script with NT4 or Novell 4 and then make a few
> changes when it came time to transfer it to UNIX. Invoking PERL is different
> for all these OS but I'm hoping that since my script will be relatively
> simple it will transfer smoothly to UNIX.
> 
> At first I installed Novell at home but I think I may be too rusty in
> finding and installing the Enterprise Web Server - if that's even still in
> use.
> 
> So then I removed Novell and installed WindowsNT4. The problem however, is
> that I have never seen a PERL script for windows. PERL scripts for UNIX
> usually begin with:   #!/usr/local/bin/perl   , for Novell it was:
> require("cgilib.pl");   but what about NT4?
> 
> I am wondering if someone could reply to the newsgroup here with a
> relatively short PERL script written for winNT4, if that even still exists!
> Or perhaps there is a web site with lots of WinNT PERL examples or whatever!
> 
> Thank you for all and any information.
> Please don't reply to email.
> 
> G.Doucet

#!c:/apps/perl5/bin/perl -w

print "\nHello World!\n";
<STDIN>

-----



Thanks,
Dale

Dale Bohl
SGI Worldwide Systems Administration
dbohl@sgi.com
(715)-726-8406
http://wwwcf.americas.sgi.com/~dbohl/


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

Date: Wed, 28 Nov 2001 15:57:06 +0100
From: Edwin =?iso-8859-1?Q?G=FCnthner?= <edgue@web.de>
Subject: Re: Perl for WinNT
Message-Id: <3C04FB42.7A974203@web.de>

Hi G.

"G.Doucet" wrote:
 ...

You might start with downloading ActivePerl from ActiveState.com.
It comes with all the Perl docu (for example about using Perl
on Windows).


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

Date: Wed, 28 Nov 2001 15:01:55 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Perl for WinNT
Message-Id: <3c04f865.3561973707@News.CIS.DFN.DE>

On Wed, 28 Nov 2001 13:55:15 GMT, "G.Doucet"
<gldoucette@nbnet.nb.ca> wrote:

>Now I need to program a PERL script to run on a UNIX server.

They can be exactly the same most of the time.
Perl (not PERL) is as platform independent as Java 
once aspired to be and failed.

>The problem however is that I must create, test and debug it at home.

No problem.  Get perl from www.activestate.com or
www.indigostar.com.  The latter includes an apache
webserver which is handy for CGI purposes.
> PERL scripts for UNIX
>usually begin with:   #!/usr/local/bin/perl   ,    but what about NT4?

The name of a Perl program on PC should end with .pl or .plx
if you want Windows to associate them with the perl 
interpreter and execute automatically.
#!/usr/local/bin/perl  (called the shebang or hashbag
line) in Unix tells the shell what
program to use to execte and thus has the same
function as the extension in Windows.
Windows does not need it, but it is a good place to
stick command line switches like -w and -T.

>for Novell it was: require("cgilib.pl");

That is however, something completely different.
cgilib.pl was an old library for running CGI programs,
(any platform) that is now obsolete.  Nowadays
people use CGI.pm which comes standard with all
decent Perl installations.

>I am wondering if someone could reply to the newsgroup here with a
>relatively short PERL script written for winNT4, if that even still exists!

What exists?  Perl? Yes.  WinNT4?  Yes.  
Both are going strong.

Here's one:

print "Hello World\n";

Here's another:

#!perl -wT
use CGI;
use strict;
my $form = new CGI;
my $name = $form->param('NAME');
print $form->header;
print "Your name is $name<br>\n";

Save it as test.cgi in the cgi-bin directory of your
webserver, give it 755 permissions and run it in a browser
with http://yourwebserver/cgi-bin/test.cgi?NAME=foo

It should print "Your name is foo" if you have set
up your webserver correctly.

>Or perhaps there is a web site with lots of WinNT PERL examples or whatever!

They are the same for all platforms, so try these:

www.perldoc.com
web.stonehenge.com/merlyn
www.perl.com
theoryx5.uwinnipeg.ca/CPAN/cpan-search.html

Regards,
Helgi Briem



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

Date: Wed, 28 Nov 2001 14:42:02 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Problems while Installing modules from Source on w2k.
Message-Id: <3c04f7a2.3561778847@News.CIS.DFN.DE>

On 28 Nov 2001 05:07:37 -0800, sreelathas@yahoo.com
(Sreelatha) wrote:

>Hi,
>   I installed perl from source (not the active state perl). 

Why??

Regards,
Helgi Briem



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

Date: Wed, 28 Nov 2001 15:54:08 GMT
From: hbpursle@duke-energy.com (Bryce Pursley)
Subject: Re: System call return value 256 - Bad file descriptor
Message-Id: <3c0a0561.177200671@news.infoave.net>

For anyone unfortunate enough to have followed this thread I thought
I'd at least post the solution (hopefully) that I have found.

The "bad file descriptor" error message returned to me from the OS (I
assume) I believe was due to the file in question still being open
from another process.  In the few lines preceding my "system" call I
had opened the file to extract a piece of data.  The loop ended and
then I made the system call.  My guess (I am still somewhat of a
beginner at this.) is that, for whatever reason, the closing of the
loop and then the system call happened too fast for the file close
process to be completed.  I added a "close FILEHANDLE;" command and I
also added a "sleep 1;" command after the close of the loop and
everything works again.  Now I may or may not need the sleep code and
I'll probably play around with that just to see but that is what I
changed and it now works.  That was the bottom line for me.

Hopefully the next post by me will be better thought out and less
painful but "ya gotta start somewhere."

Bryce


On Mon, 26 Nov 2001 16:15:52 GMT, hbpursle@duke-energy.com (Bryce
Pursley) wrote:

>A line of code that has worked for over a month has all of a sudden
>gone "intermittent."  One day it won't work at all and the next day it
>will work on every other file passed to it.  If it wasn't for the
>"every other file" thing, I would have guessed I had a path or
>permission problem but when it works on every other file it doesn't
>make any sense to me.  I can't find any detailed help for this error
>message either.  It seems to be a fairly generic error msg from what I
>read.  I have included the key line of code, a portion of the
>subroutine it lives in and some output from my logfile below.  Thanks
>for any help on this.
>
>Bryce
>
>
>This is the line of code that is generating the error:
>
>$rtn_val = system ("$dirapps\\batch2raw.exe -t -n $file >>
>$dircdrpro\\$cdname.pol");
>
>
>This is "a portion" of the subroutine that contains the line just in
>case it is helpful to see how I get to this point.
>
>sub cdrprocess
>{
>  my $file;
>  chdir ($dircdrpro) or die "can't change to . . . $dircdrpro : $!";
>  opendir THISDIR, "." or die "can't open current directory: $!";
>  @allfiles = grep !/^\.\.?$/, readdir THISDIR;
>  closedir THISDIR;
>  foreach $file (@allfiles) 
>  {
>   if (-d $file)
>   { 
>    #print2both ("\tDIR - $file\n");
>   }
>   else # continue process if file is not a directory
>   {
>    open (CDRFILE, $file) or die "can't open CDRFILE = $file: $!";
>    while (<CDRFILE>) 
>    {
>     if (/^CD:(.*)/)
>     {
>      $cdname = $1;
>      last;
>     }
>    } #end while
>   $rtn_val = system ("$dirapps\\batch2raw.exe -t -n $file >>
>$dircdrpro\\$cdname.pol");
>   if ($rtn_val)
>   {
>    print2both ("\tSystem call failed. Return value is $rtn_val. Error
>is $!\n");
>   }
>   else
>   {
>    print2both ("\tSystem call succeeded.\n");
>   } #end else for system call
>  } #end else to process files
> } #end foreach
>
>
>
>This is some output from my logfile:
>
>ALLENSTM - CDR FILE -> 1006660839-8.dat
>System call succeeded.
>
>BADCREEK - CDR FILE -> 1006660913-9.dat
>System call failed. Return value is 256. Error is Bad file descriptor
>
>BELWSCRK - CDR FILE -> 1006660977-9.dat
>System call succeeded.
>
>BUCKSTEM - CDR FILE -> 1006660989-8.dat
>System call failed. Return value is 256. Error is Bad file descriptor
>
>BUZZROST - CDR FILE -> 1006661008-7.dat
>System call succeeded.
>
>CATAWBA - CDR FILE -> 1006661133-8.dat
>System call failed. Return value is 256. Error is Bad file descriptor
>
>CHESTER - CDR FILE -> 1006661152-7.dat
>System call succeeded.
>
>CHAPHILL - CDR FILE -> 1006661153-9.dat
>System call failed. Return value is 256. Error is Bad file descriptor
>
>CLEMSCMC - CDR FILE -> 1006661216-7.dat
>System call succeeded.
>
>CLEMSON - CDR FILE -> 1006661253-8.dat
>System call failed. Return value is 256. Error is Bad file descriptor
>
>CLIFSIDE - CDR FILE -> 1006661315-7.dat
>System call succeeded.
>



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

Date: Wed, 28 Nov 2001 15:43:00 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Zoltan Kandi <zoltan.kandi@tellabs.com>
Subject: Re: Win32::ODBC => generating a list of hashes from the query result set
Message-Id: <3C050604.FA8ED9A0@umist.ac.uk>

> I can't help you with that since I don't know how %a is filled.
> I see it used only in the FetchRow method so that must be the place,
> but I've never used DBI and don't know anything about it. Hold tight,
> though, I'm sure you'll get more help in a little while from someone
> else.

It's not DBI - it's Win32::ODBC.  I use DBI where possible - if you are
going to learn a database module you might as well learn a one that is
cross-platform, unless you need a specific Win32::ODBC function of
course.

Anyway....

Problem is in sub insert:

>              while( $db->FetchRow( \%a ) ) {
>                     push @adat,%a;

Should read:

             while( $db->FetchRow ) {
                    my %a = $db->DataHash;
                    push @adat,\%a;

Also, personally I would not return an array from sub insert, but a
reference to the array.

Your code is really quite inefficient - why loop though the data-set,
store it in an array and then loop through it again when it can be done
in one loop.  Also, you are storing the column names multiple times.  If
you really need to keep a store of the query and want to work with
column names you could try creating a hash of lists instead od a list of
hashes.  The hash of lists would have column names as the keys and
column values as the list elements:

%data = {
        text_id  => [1, 2, 400],
        text_val => ['a', 'b', 'oj'],
}

Of course DBI does all this much better. As soon as you have executed
your query you can retrieve the column names via the $sth->{NAME}
attribute and get the complete recordset as a list of lists via the
$sth->fetchall_arrayref method.  Here's a complete rewrite using DBI:

use strict;
use warnings;
use diagnostics;
use DBI;

my $data = insert();

my $columns = shift @$data;

for my $row (0..@$data-1) {
        print "Row $row \t";
    for my $col (0..@$columns-1) {
        print "$columns->[$col] => $data->[$row][$col]\t";
    }
    print "\n";
}
exit;

sub insert {
        my $dsn = "dsn";
        my $login = "uid";
        my $password = "pwd";
        my $query = "select text_id from table where text_id<11";
        my $dbh = DBI->connect("dbi:ODBC:$dsn", $login, $password,
{RaiseError
=> 1});
        my $sth = $dbh->prepare($query);
        $sth->execute();
        my $rows = $sth->fetchall_arrayref;
        unshift @$rows, $sth->{NAME};
        $sth->finish;
        $dbh->disconnect;
        return $rows;
} 

Personally, I wouldn't call it 'insert' (it suggests data will be
inserted into the table), perhaps 'get_data' is better.  And I would
make it take arguments:

sub get_data {
        my ($query, $dsn, $login, $password) = @_;
        $dsn ||= 'my_default_dsn';

--
  Simon Oliver


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

Date: Wed, 28 Nov 2001 15:43:36 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Zoltan Kandi <zoltan.kandi@tellabs.com>
Subject: Re: Win32::ODBC => generating a list of hashes from the query result set
Message-Id: <3C050628.EB920AA6@umist.ac.uk>

>                                        push @adat, { %a };

That is a solution, but not very efficient because it creates an
unnecessary copy of the hash.

The solution is to create a new hash with every iteration of the loop
via 'my %a'.  You then store a reference to each new hash:

	while( $db->FetchRow ) {
		my %a = $db->DataHash;
		push @adat, \%a;

--
  Simon Oliver


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 2228
***************************************


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