[19491] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1686 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 3 21:05:30 2001

Date: Mon, 3 Sep 2001 18:05:08 -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: <999565507-v10-i1686@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 3 Sep 2001     Volume: 10 Number: 1686

Today's topics:
    Re: ActivePerl says Out of Memory, but I'm not out of m <bwalton@rochester.rr.com>
    Re: array questions <dtweed@acm.org>
    Re: array questions <dtweed@acm.org>
    Re: Black Perl <elaine@chaos.wustl.edu>
    Re: ENV{'REMOTE_HOST'}; .... does not work ?! (Tad McClellan)
    Re: filetest (Abigail)
        from .pl to .exe on Win2K <tm@kernelconsult.com>
        from .pl to .exe on Win2K <tm@kernelconsult.com>
    Re: Godzilla DOS Environmental Variables Utility <news@simonflack.com>
    Re: Open 2 exes from Perl (Damian James)
        Perl and DBI <carrazola@home.com>
    Re: Perl for Psion - where? CPAN link broken <bwalton@rochester.rr.com>
        Problem reading an XML file (RoJo)
    Re: Problem reading an XML file <tony_curtis32@yahoo.com>
    Re: Problem reading an XML file (RoJo)
    Re: Problem reading an XML file (Tad McClellan)
        problem when execute query from windows to Unix (Valentin763)
    Re: Recommendations for a PERL editor (Tim Hammerquist)
    Re: Recommendations for a PERL editor <kevin@vaildc.net>
    Re: references, slices, voodoo (Abigail)
    Re: references, slices, voodoo (Tad McClellan)
    Re: RegEx? (Tad McClellan)
    Re: weird kind of eof <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 04 Sep 2001 00:38:01 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: ActivePerl says Out of Memory, but I'm not out of memory?  Is this a  limitation in the Perl build I have?
Message-Id: <3B942244.6DACE160@rochester.rr.com>

Jonadab the Unsightly One wrote:
> 
> I have a Perl script that, admittedly, uses a substantial amount
> of memory.  (It's using a recursive algorithm to solve a problem
> that, while finite, can involve some fairly deep recursion.)
> 
> I've come to the point now where Perl tells me it's
> "Out of memory!" and the script bails.  However, I'm
> not out of memory.  if I run mem *just* before the
 ...
> So Perl was using about 112024K of RAM, give or
> take a couple of megs.  Probably most of that is 
> the recursion in my script -- but there should be
> more available yet.  
 ...
> I can post my script if it will make any difference.
> It's just over 300 lines long, and I'm not at all
> sure I have it quite right yet.  (I've been in the
> process of debugging it, then this happened.)
 ...
> - jonadab

Please whittle your script down to the smallest number of lines that
will execute verbatim if copy/pasted and will also illustrate the
problem you have having, and repost. If you do that, I'm sure you'll get
responses from folks with various OS's, installed memory sizes, etc.
Your chances of getting a response with a 300-line script are almost as
slim as getting a response with no script :-).  I haven't run into the
problem you state you are having...but then again, 112 Mb worth of
recusion calls is an *awful* lot of recusion.  I'm sure I have never
gotten anywhere near that, except for infinite loops.
-- 
Bob Walton


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

Date: Mon, 03 Sep 2001 23:01:52 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: array questions
Message-Id: <3B940AC6.E7C39D13@acm.org>

"Randal L. Schwartz" wrote:
> Well, "deeper" copy, but not technically a "deep" copy. For the difference,
> see my article on deep copies ...

Yes, I made a copy of whatever scalars were in @child. If those were
themselves references, I didn't do anything about that.

I figured I explained it at an appropriate level of detail for arrays of
arrays, and if anyone had more complex structures, they would pick up on
the pattern.

In my experience, the required level of copying depth is going to be
highly dependent on the specific application. Consider:

   @a = ('scalar1', 'scalar2');
   @aa = (\@a, \@a);
   @bb = &deep_copy (\@aa);

@bb ends up with a very different structure than the one in @aa.

Ironically (?), this gets back to the same issues we were hashing out with
directory walkers like File::Find -- with general-purpose references, data
structures can't be assumed to be trees.

I remember exploring the topic rather thoroughly once when I built myself
a little in-core database module that maintained fully-inverted indices
(hashes) for all key fields.

-- Dave Tweed

P.S. Is there any particular reason your deep_copy() doesn't handle
simple indirection (refs to SCALARs or refs to REFs)? I think this
does it, but my test cases are giving Data::Dumper fits:

sub deep_copy {
    my $this = shift;
    if (not ref $this) {
        $this;
    } elsif (ref $this eq "SCALAR") {
        # make a copy of the scalar and return a reference to that
        my $temp = $$this;
        \$temp;
    } elsif (ref $this eq "REF") {
        # make a copy of whatever $this points to and then return a
        # new reference to that.
        my $temp = &deep_copy ($$this);
        \$temp;
    } elsif (ref $this eq "ARRAY") {
        [map deep_copy($_), @$this];
    } elsif (ref $this eq "HASH") {
        +{map { $_ => deep_copy($this->{$_}) } keys %$this};
    } else {
        die "what type is $_?";
    }
}


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

Date: Tue, 04 Sep 2001 00:59:46 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: array questions
Message-Id: <3B942667.AB3143A0@acm.org>

I wrote:
>    @a = ('scalar1', 'scalar2');
>    @aa = (\@a, \@a);
>    @bb = &deep_copy (\@aa);
> 
> @bb ends up with a very different structure than the one in @aa.

 ... which is true even if you do

   @bb = @{deep_copy (\@aa)};

to eliminate the extra level of indirection. Data::Dumper wasn't
showing this correctly. I finally wrote my own little dumper that
shows exactly what points where.

BTW, It's confusing that the value of ref \\1 is "REF", but the
string value of \\1 is "SCALAR(0x123456)" and not "REF(0x123456)".

> sub deep_copy {
>     my $this = shift;
>     if (not ref $this) {
>         $this;
>     } elsif (ref $this eq "SCALAR") {
>         # make a copy of the scalar and return a reference to that
>         my $temp = $$this;
>         \$temp;
>     } elsif (ref $this eq "REF") {
>         # make a copy of whatever $this points to and then return a
>         # new reference to that.
>         my $temp = &deep_copy ($$this);
>         \$temp;
>     } elsif (ref $this eq "ARRAY") {
>         [map deep_copy($_), @$this];
>     } elsif (ref $this eq "HASH") {
>         +{map { $_ => deep_copy($this->{$_}) } keys %$this};
>     } else {
>         die "what type is $_?";
>     }
> }

It looks like the $temp variable for the REF case is unnecessary; the
expression
   \deep_copy ($$this);
makes the necessary copy. I wasn't sure that it would. I can't find a way
to eliminate the $temp variable for SCALAR, other than to treat it exactly
the same as REF by doing another recursive call.

sub deep_copy {
    my $this = shift;
    if (not ref $this) {
        $this;
    } elsif (ref $this eq "SCALAR" or ref $this eq "REF") {
        \deep_copy ($$this);
    } elsif (ref $this eq "ARRAY") {
        [map deep_copy ($_), @$this];
    } elsif (ref $this eq "HASH") {
        +{map { $_ => deep_copy ($this->{$_}) } keys %$this};
    } else {
        die "what type is $_?";
    }
}

To be honest, I don't see why it's necessary to make a distinction
between a reference to a reference and a reference to any other scalar
in the first place.

-- Dave Tweed


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

Date: Tue, 04 Sep 2001 00:04:36 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: Black Perl
Message-Id: <B7B992E8.218A%elaine@chaos.wustl.edu>

On 9/2/01 6:16 AM, in article slrn9p41nr.3ga.mgjv@martien.heliotrope.home,
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote:

> On 2 Sep 2001 02:52:34 -0700,
> N01937 <N01937@hushmail.com> wrote:
>> Does anyone know the author of the Black Perl poem found in the Camel Book?
> 
> Larry Wall, of course.
> 
> Reread the first paragraph of the Perl Poetry section, and you'll notice
> that that is what it says. Of course, you could also just use Google.

No, it's written by 'anonymous'. It was an april fool's day forgery in 1990.

The Perl Timeline covers this but the box that hosts it will be down until
tomorrow at the earliest. http://history.perl.org/

e.



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

Date: Mon, 3 Sep 2001 19:29:27 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: ENV{'REMOTE_HOST'}; .... does not work ?!
Message-Id: <slrn9p84in.nim.tadmc@tadmc26.august.net>

Oliver Fietz <of@abakus-musik.de> wrote:

>Are some server maybe blocking the lookup command ?


There is no "server" with Perl.

I suggest asking in a newsgroup that discusses whatever protocol
your mysterious "server" is speaking. Perhaps one of the WWW groups?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 3 Sep 2001 23:19:26 GMT
From: abigail@foad.org (Abigail)
Subject: Re: filetest
Message-Id: <slrn9p83vq.dss.abigail@alexandra.xs4all.nl>

Newbie (youradmirer@onebox.com) wrote on MMCMXXIII September MCMXCIII in
<URL:news:582bc82b.0108311628.3187312@posting.google.com>:
][ does a filetest in Perl actually take up any io access? or does it

Yes.

][ just make a reference to an inode (in Unix) for infor? Thanks.

Yes.

(I think you are assuming referencing an inode doesn't mean you need to
 do I/O. But an inode is part of the filesystem on disk just as the 
 content of files is).


Abigail
-- 
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))


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

Date: Tue, 04 Sep 2001 00:08:38 +0200
From: TM <tm@kernelconsult.com>
Subject: from .pl to .exe on Win2K
Message-Id: <3B93FF66.7CBBB864@kernelconsult.com>

Hi,
I'm very confused about getting an compiled version of a perl script on
Win2K.

commands such
perl -MO=CC,-ohi.c hi.pl   or perlcc hi.pl abort.

Help welcomed!

TM



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

Date: Tue, 04 Sep 2001 00:17:38 +0200
From: TM <tm@kernelconsult.com>
Subject: from .pl to .exe on Win2K
Message-Id: <3B940182.30B71AB3@kernelconsult.com>

Hi,
I'm very confused about getting an compiled version of a perl script on
Win2K.

commands such
perl -MO=CC,-ohi.c hi.pl   or perlcc hi.pl abort.

Help welcomed!

TM



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

Date: Tue, 4 Sep 2001 00:58:22 +0100
From: "Simon Flack" <news@simonflack.com>
Subject: Re: Godzilla DOS Environmental Variables Utility
Message-Id: <9n15dm$4n1vn$1@ID-83895.news.dfncis.de>

Hello Godzilla.

Nice script.

> For years it has been said it is impossible to set
> parent DOS environmental variables via a Perl script.

I've never heard that.

> Extensive and exhaustive testing of various methods
> reveals his simple binary executable is the best
> choice for this task. His method is extremely fast.
> This applies to Win9.x and Win.me systems.

I don't know. I only did a few hours research into this, but I thought that
Win32::AdminMisc was pretty good for this task.

http://www.roth.net/perl/adminmisc/#SetEnvVar
http://www.roth.net/perl/adminmisc/#DelEnvVar

I haven't tested it on Win9x or WinMe so it might not work there, but it
works very well on WinNT and Win2K.

> Piece of cake. Shirley you Perl 5 Cargo Cultists can figure this.

I say "whatever works best for you".

Simon




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

Date: 4 Sep 2001 00:37:06 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Open 2 exes from Perl
Message-Id: <slrn9p88ee.7u8.damian@puma.qimr.edu.au>

Bart Lateur chose Mon, 03 Sep 2001 11:30:51 GMT to say this:
>George K wrote:
>
>>The closest I've come is 
>>system ('c:\winnt\notepad.exe');
>
>	system 'start', 'notepad';
>

That might work on 95/98/ME/etc and other dos-based systems (don't know,
haven't tried), but does nothing on NT -- where 'start' is a 'cmd.exe'
builtin command.

	system('cmd /c start your_program.exe');

But this is OT (and the system() call doesn't change that :-).

Cheers,
Damian
(who has also been bitten on some platforms by confusing shell builtins
with programs :-).
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: Tue, 04 Sep 2001 00:39:04 GMT
From: "christian" <carrazola@home.com>
Subject: Perl and DBI
Message-Id: <IoVk7.67396$f01.18381188@news3.rdc1.on.home.com>

Hello,

I'm looking for either a good Book or Documentation on all the mysql
functions that perl can use.


Thanks,




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

Date: Mon, 03 Sep 2001 22:54:32 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl for Psion - where? CPAN link broken
Message-Id: <3B940A0E.7DFC03DB@rochester.rr.com>

Stuart Moore wrote:
> 
> Hi, looking for the port of Perl to the Psion. The link in CPAN (on the page
> http://www.perl.com/CPAN-local/ports/) is
> http://www.science-computing.de/o.flebbe/perl/ but this seems to be broken.
> Anyone got another one?

The link you mention above seems to work fine.
-- 
Bob Walton


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

Date: Tue, 04 Sep 2001 00:11:35 GMT
From: rojo@mindspring.com (RoJo)
Subject: Problem reading an XML file
Message-Id: <3b94161c.33123649@news.mindspring.com>


I'm new to PERL.  I wrote a tiny script to read an XML file and
display its contents.  To my surprise, when the contents are sent to
the browser (as an HTML page), all the tags are stripped out !!

Is there a better way to read an XML file, or is there an option to
set that I don't know about?

If you prefer email to a followup usenet message, my email address is:
rojo@mindspring.com

The script is found at: (you can execute it)
http://www.rhjconsulting.com/cgi/read_xml_file.cgi

Below are the contents of the script, followed by the contents of the
XML file:

#!/usr/local/bin/perl -w
print "Content-type:text/html\n\n";
print "<html><head><title>Read Assets</title></head>";
print "<body><font face='Arial'>";

open(XMLFILE,"xml_file.xml") or dienice("Open failure: $!"); 
print "Open succeeded.<br>";
print "<br>Contents are:<font color=red>";
@data_array = <XMLFILE>;
foreach $data_line (@data_array) {
    chomp($data_line);
    print "<br>$data_line";
}
close(XMLFILE);
print "</font><br>";
print "</font></body></html>";

# The dienice subroutine, for handling errors.
sub dienice {
    my($errmsg) = @_;
    print "<h2>Error</h2>\n";
    print "$errmsg<p>\n";
    print "</body></html>\n";
    exit;
}

<asset_file>
<asset_item>	<asset_id>2</asset_id>	<asset_type>PC SW</asset_type>
<asset_descr>Quicken</asset_descr>	<asset_model>v
7.0</asset_model>
<asset_location>flr</asset_location>	<asset_owner>RHJ</asset_owner>
<asset_maker>Intuit</asset_maker>	</asset_item>
<asset_item>	<asset_id>3</asset_id>	<asset_type>Aud</asset_type>
<asset_descr>Cassette Deck</asset_descr>
<asset_model>GXC-730D</asset_model>
<asset_number>21215-02300</asset_number>
<asset_cost>400</asset_cost>
<asset_location>den</asset_location>	<asset_owner>RHJ</asset_owner>
<asset_maker>Akai</asset_maker>	</asset_item>
<asset_item>	<asset_id>4</asset_id>	<asset_type>PC HW</asset_type>
<asset_descr>486sx/25 PC</asset_descr>
<asset_model>PowerFlex</asset_model>
<asset_number>120650</asset_number>
<asset_date>1992-01-01</asset_date>
<asset_location>flr</asset_location>	<asset_owner>RHJ</asset_owner>
<asset_maker>ALR</asset_maker>	</asset_item>
<asset_item>	<asset_id>5</asset_id>	<asset_type>PC HW</asset_type>
<asset_descr>Video Card</asset_descr>	<asset_model>VGA
Wonder</asset_model>	<asset_number>V183764</asset_number>
<asset_location>flr</asset_location>	<asset_owner>RHJ</asset_owner>
<asset_maker>ATI</asset_maker>	</asset_item>
<asset_item>	<asset_id>6</asset_id>	<asset_type>Aud</asset_type>
<asset_descr>Loud Speakers</asset_descr>
<asset_model>301</asset_model>	<asset_number>386253 and
386268</asset_number>
<asset_location>mba</asset_location>	<asset_owner>RHJ</asset_owner>
<asset_maker>Bose</asset_maker>	</asset_item>
<asset_item>	<asset_id>7</asset_id>	<asset_type>Photg</asset_type>
<asset_descr>35mm SLR Camera</asset_descr>	<asset_model>AE-1
Program</asset_model>
<asset_location>scl</asset_location>	<asset_owner>RHJ</asset_owner>
<asset_maker>Canon</asset_maker>	</asset_item>
<asset_item>	<asset_id>8</asset_id>	<asset_type>Aud</asset_type>
<asset_descr>Loud Speakers</asset_descr>
<asset_model>DQM-5</asset_model>	<asset_number>05072 and
05073</asset_number>
<asset_location>den</asset_location>	<asset_owner>RHJ</asset_owner>
<asset_maker>Dahlquist</asset_maker>	</asset_item>
</asset_file>


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

Date: Mon, 03 Sep 2001 19:15:52 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Problem reading an XML file
Message-Id: <87elpnizev.fsf@limey.hpcc.uh.edu>

>> On Tue, 04 Sep 2001 00:11:35 GMT,
>> rojo@mindspring.com (RoJo) said:

> I'm new to PERL.  I wrote a tiny script to read an XML
> file and display its contents.  To my surprise, when the
> contents are sent to the browser (as an HTML page), all
> the tags are stripped out !!

> "Content-type:text/html\n\n";

XML != HTML

The browser is at liberty to ignore all the HTML tags it
does not recognise.

But that's got nothing to do with perl:

    comp.infosystems.www.authoring.html
and
    comp.infosystems.www.authoring.cgi

might be better places to inquire further.

hth
t
-- 
Yes way!  Mmmmkay?


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

Date: Tue, 04 Sep 2001 00:19:08 GMT
From: rojo@mindspring.com (RoJo)
Subject: Re: Problem reading an XML file
Message-Id: <3b941daf.35062527@news.mindspring.com>


Tony,

Well that makes sense!  If the browser is discarding the tags, then my
PERL script may be runnng just fine.  Thanks!


On Mon, 03 Sep 2001 19:15:52 -0500, Tony Curtis
<tony_curtis32@yahoo.com> wrote:

>>> On Tue, 04 Sep 2001 00:11:35 GMT,
>>> rojo@mindspring.com (RoJo) said:
>
>> I'm new to PERL.  I wrote a tiny script to read an XML
>> file and display its contents.  To my surprise, when the
>> contents are sent to the browser (as an HTML page), all
>> the tags are stripped out !!
>
>> "Content-type:text/html\n\n";
>
>XML != HTML
>
>The browser is at liberty to ignore all the HTML tags it
>does not recognise.
>
>But that's got nothing to do with perl:
>
>    comp.infosystems.www.authoring.html
>and
>    comp.infosystems.www.authoring.cgi
>
>might be better places to inquire further.
>
>hth
>t
>-- 
>Yes way!  Mmmmkay?



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

Date: Mon, 3 Sep 2001 19:38:24 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem reading an XML file
Message-Id: <slrn9p853g.nlg.tadmc@tadmc26.august.net>

RoJo <rojo@mindspring.com> wrote:
>
>I'm new to PERL.  


That's OK because Perl (not PERL) is not your problem, your
code is fine (within "baby talk" tolerances).


>I wrote a tiny script to read an XML file and
>display its contents.  To my surprise, when the contents are sent to
>the browser (as an HTML page), all the tags are stripped out !!


The browser does that, not Perl, so you should ask about it
in a newsgroup that has something to do with browsers.

This is not such a newsgroup.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 03 Sep 2001 22:25:17 GMT
From: valentin763@aol.com (Valentin763)
Subject: problem when execute query from windows to Unix
Message-Id: <20010903182517.13186.00005260@mb-ms.aol.com>

Hi,

I want to execute a script from windows on a Unix Machine.It works with a
script whithout parameters but not in the following script....

require "Telnet.pm";
$telnet = new Telnet (timeout=>10,Errmode=>'die');
$telnet->open('55.1.4.223');
$telnet->waitfor('/Connexion :$/i');
$telnet->print('pgexp0');
$telnet->waitfor('/Mot de passe de pgexp0 : $/i');
$telnet->print('pgexp0');
$telnet->waitfor('/\> $/i'); # > -> dernier char du prompt

#@lines = $telnet->cmd("/progres/appdir/cliexp"); #work
@lines = $telnet->cmd("/progres/appdir/cliexp -d 20010828 > jmfool");#doesn't
work
print @lines;

do u see what is wrong ?

Thanks for your Answers

Valentin






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

Date: Mon, 03 Sep 2001 22:50:14 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Recommendations for a PERL editor
Message-Id: <slrn9p8307.1cu.tim@vegeta.ath.cx>

Me parece que Yves Orton <demerphq@hotmail.com> dijo:
> "sabin" <sabin@cornhusker.net> wrote in message news:<3b928912_8@Usenet.com>...
> > > UltraEdit adds features like syntax highlighting (which IMO
> > > is a must-have feature for editing Perl code), but it is
> > > shareware.  It feels like a regular Windows app.  I don't
> > > remember how much the registration fee is.
> > 
> > Its $30.  I've used it.  Its 'ok' but seems to crash on me about every hour
> > or so.
> 
> Thats weird Ive never experienced that and I use it all the time.
> Maybe its just W9x thats the problem?  That does have a habit of
> BSODing you at the worst moment.

UltraEdit-32 never crashed my Win98SE system. It was possibly the most
stable application I installed.

I wish I could've said the same for MS Word...


-- 
Me? Lady, I'm your worst nightmare -- a pumpkin with a gun.
    -- Mervyn Pumpkinhead, The Sandman


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

Date: Mon, 03 Sep 2001 19:57:09 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Recommendations for a PERL editor
Message-Id: <030920011957090969%kevin@vaildc.net>

In article <slrn9p8307.1cu.tim@vegeta.ath.cx>, Tim Hammerquist
<tim@vegeta.ath.cx> wrote:

> UltraEdit-32 never crashed my Win98SE system. It was possibly the most
> stable application I installed.
> 
> I wish I could've said the same for MS Word...

I second both of these remarks.  UltraEdit32 did crash once, but I
don't think it was its fault...the system had been getting flaky for a
couple of hours before it happened.

-- 
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net   | blazing high above your head.
 . . . . . . . . .  | But _in_ you is the presence that
 . . . . . . . . . | will be, when all the stars are dead.  (Rainer Maria Rilke)


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

Date: 3 Sep 2001 23:29:16 GMT
From: abigail@foad.org (Abigail)
Subject: Re: references, slices, voodoo
Message-Id: <slrn9p84i8.dss.abigail@alexandra.xs4all.nl>

Tad McClellan (tadmc@augustmail.com) wrote on MMCMXXV September MCMXCIII
in <URL:news:slrn9p6uf4.m0m.tadmc@tadmc26.august.net>:
-: Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
-: >Walter Hafner wrote in comp.lang.perl.misc:
-: 
-: >}     @$array[$i,$j] = @$array[$j,$i] unless  $i == $j; # ???
-: 
-: >} Since i don't like to use code I don't understand, i really need to know 
-: >} WHY this code works.
-: 
-: 
-: >This lines swaps the values of the elements $i and $j in the array.
-: >It's equivalent to :
-: >
-: >    ($array[$i],$array[$j]) = ($array[$j],$array[$i]) unless $i == $j;
-:            ^^         ^^             ^^         ^^
-: 
-: $array is a reference, so those should all be deref'ing, eg:  
-: 
-:    $array->[$i]  (until we get to Perl 6)
-: 
-: It is unfortunate that the FAQ chose "@array" as a name for the (presumably)
-: global array used in the function call, as that makes the above appear
-: to "work" when it is not, in fact, acting on its args but on a global variabl


Eh? What global @array is being used by the FAQ? This is in the FAQ
(coming with 5.6.1):

           # fisher_yates_shuffle( \@array ) :
           # generate a random permutation of @array in place
           sub fisher_yates_shuffle {
               my $array = shift;
               my $i;
               for ($i = @$array; --$i; ) {
                   my $j = int rand ($i+1);
                   @$array[$i,$j] = @$array[$j,$i];
               }
           }

           fisher_yates_shuffle( \@array );    # permutes @array in place


There's no global @array in the subroutine - the only global @array I
see is in Rafael's code that's supposed to be "equivalent".

Note that the stupid 'unless $i == $j' no longer appears in modern
editions of the FAQ.



Abigail
-- 
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-
#    A bear fishes in the
#    pool. A pair of foxes beside
#    a dam. A fly flies.


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

Date: Mon, 3 Sep 2001 19:17:00 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: references, slices, voodoo
Message-Id: <slrn9p83rc.nim.tadmc@tadmc26.august.net>

Abigail <abigail@foad.org> wrote:
>Tad McClellan (tadmc@augustmail.com) wrote on MMCMXXV September MCMXCIII
>in <URL:news:slrn9p6uf4.m0m.tadmc@tadmc26.august.net>:
>-: Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>-: >Walter Hafner wrote in comp.lang.perl.misc:
>-: 
>-: >}     @$array[$i,$j] = @$array[$j,$i] unless  $i == $j; # ???
>-: 
>-: >} Since i don't like to use code I don't understand, i really need to know 
>-: >} WHY this code works.
>-: 
>-: 
>-: >This lines swaps the values of the elements $i and $j in the array.
>-: >It's equivalent to :
>-: >
>-: >    ($array[$i],$array[$j]) = ($array[$j],$array[$i]) unless $i == $j;
>-:            ^^         ^^             ^^         ^^
>-: 
>-: $array is a reference, so those should all be deref'ing, eg:  
>-: 
>-:    $array->[$i]  (until we get to Perl 6)
>-: 
>-: It is unfortunate that the FAQ chose "@array" as a name for the (presumably)
>-: global array used in the function call, as that makes the above appear
>-: to "work" when it is not, in fact, acting on its args but on a global variabl
>
>Eh? What global @array is being used by the FAQ? 


The one in the function call.


>This is in the FAQ
>(coming with 5.6.1):
>
>           # fisher_yates_shuffle( \@array ) :
>           # generate a random permutation of @array in place
>           sub fisher_yates_shuffle {
>               my $array = shift;
>               my $i;
>               for ($i = @$array; --$i; ) {
>                   my $j = int rand ($i+1);
>                   @$array[$i,$j] = @$array[$j,$i];
>               }
>           }
>
>           fisher_yates_shuffle( \@array );    # permutes @array in place
                                   ^^^^^^
                                   ^^^^^^ this one!


>There's no global @array in the subroutine - 


I did not say that there was. I said that I presume that the
array in the function _call_ is global.


>the only global @array I
>see is in Rafael's code that's supposed to be "equivalent".


We don't actually know what the scope of the @array in the function
call is.

I said it is unfortunate that @array was chosen as the array name,
as it makes Rafael's broken code appear to work.

s/\@ra/\@array/g  below, and it "looks like" it is working when
it isn't working correctly.

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

my @ra = qw/zero one two/;

           sub fisher_yates_shuffle {
               my $array = shift;
               my $i;
               for ($i = @$array; --$i; ) {
                   my $j = int rand ($i+1);
                   ($array[$i],$array[$j]) = ($array[$j],$array[$i]);
               }
           }

           fisher_yates_shuffle( \@ra );    # permutes @array in place

print "$_\n" for @ra;
-------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 3 Sep 2001 19:25:39 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: RegEx?
Message-Id: <slrn9p84bj.nim.tadmc@tadmc26.august.net>

[ First text moved to second. Second text moved to first. Now the
  first thing comes first and the second thing comes second instead
  of the second thing first and the first thing second.

  Please do not quote an entire article.

  Please do not quote .sigs.
]


Garry Short <garry_short@hotmail.com> wrote:
>"Jason Baker" <baker@Akira.cyborgworkshop.com> wrote in message
>news:tokodmm7552r95@news.supernews.com...

>> firstname lastname <email@wherever.com>
>>
>> All I want to do is capture the name, not email address, into a variable.

>Just out of interest, why a regex? How about using split instead?
>
>my ($firstname, $lastname, $email) = split /\s+/, $row->[1];


Either approach is bound to fail for:

   Billy Jean King <player@tennis.org>

Separating Given from Family names is not simply an exercise
in pattern matching...

You can separate the name from the email address easy enough
though:

   my($name, $address) = /(.*)\s+<([^>]+)/;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 03 Sep 2001 18:14:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: weird kind of eof
Message-Id: <3B9400DC.7EC1709C@earthlink.net>

Bart Van der Donck wrote:
> 
> Hello,
> 
> My string contains an eof that I cannot detect.

You mean eol [end of line], not eof [end of file].

> The purpose is to delete the eof from my string.
> 
> I tried about all to delete it:
> chop $a;

This removes the last character from your string.

> chomp $a;

This removes the last occurance of $/ from your string.

> $a=~s/\n\gi;

This removes \n, but keep in mind that \n is not neccessarily a LF
character.  Perl translates these in a system dependent way to try to
try to give a bit of DWIMish behavior.

> $a=~s/\\n\gi;

This removes backslash followed by newline.

> $a=~s/\^M//gi;

This removes caret followed by M

> and some others that I found in the docs.
> 
> In notepad the string appears as a little square. On a unix prompt it
> has the same effect as pressing the "Return"-key.
> 
> The question is:
> Is there a line that erases all kinds of eofs (DOS, Unix) from my
> string ?

$string =~ tr/\015\012//d;

However, this probably isn't really what you want, since there may be
occasions where you have a string like:
"foo
bar"

Where removing the newline characters will result in "foobar", when what
you probably want is to turn this into "foo bar".

$string =~ s/\s+/ /g;

Also, if you're reading in a file, line by line, and are trying to get
rid of newlines from the end... consider that on a mac, the eol is
different from either dos or unix.  You would in these cases be best off
doing the following:

my $slurp = do { local $/; <FILE> };
foreach my $line ( split /\015\012|\012\015?|\015/, $slurp, -1 ) {
	# process each line here.
}

This code will work ok regardless of whether the lines are delimited
with CRLF, LFCR, CR, or LF.  Dos uses CRLF, unix uses LF, mac uses CR,
and while I don't know of any OS which uses LFCR, it's possible that
some software exists which creates that.

-- 
"I think not," said Descartes, and promptly disappeared.


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

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


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