[18978] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1173 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 21 18:05:37 2001

Date: Thu, 21 Jun 2001 15:05:10 -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: <993161110-v10-i1173@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 21 Jun 2001     Volume: 10 Number: 1173

Today's topics:
    Re: CGI.pm, cookies and redirect PLS HELP! (Zur Aougav)
    Re: CGI::CARP (carpout) or (fatalsToBrowser) ? <bart.lateur@skynet.be>
    Re: Difficulty exporting from modules <bart.lateur@skynet.be>
    Re: don't know if this can be done.to do with splitting (Tony L. Svanstrom)
    Re: Exception handling ? <bart.lateur@skynet.be>
    Re: having trouble with system <me@grimblefritz.com>
    Re: how does one go about assigning the ip address from <krahnj@acm.org>
    Re: how does one go about assigning the ip address from (Zur Aougav)
    Re: how does one go about assigning the ip address from <bart.lateur@skynet.be>
    Re: how does one go about assigning the ip address from <bart.lateur@skynet.be>
    Re: How i Install module in NT platform <bart.lateur@skynet.be>
    Re: Install Perl on HP (Jim Garner)
    Re: int sub - strange behaviour <ren@tivoli.com>
        Making a bundle of Perl modules <sdfsd@com.com>
    Re: memory-leaks (in mod_perl) <newspost@coppit.org>
        Mod_perl problem <irl.com@ntlworld.com>
        Opening a Netscape Window using a Perl script <svetter@dsli.com>
    Re: Opening and Reading Named Pipes <narendra@spiff.hr.att.com>
    Re: Passing a DBM name to a program. (Eric Bohlman)
    Re: Perl Test Problem - show-shebang <krahnj@acm.org>
    Re: Reference-problem <sserena@freesurf.ch>
    Re: Reference-problem (Eric Bohlman)
    Re: Reference-problem <sserena@freesurf.ch>
    Re: Salary for teaching intro to perl (Randal L. Schwartz)
        RE: splice/Join and split!! <19wlr@globalnet.co.uk>
    Re: splice/Join and split!! <ren@tivoli.com>
    Re: splice/Join and split!! <mjcarman@home.com>
    Re: Why does this split not work? <nospam@cfl.rr.com>
    Re: Why does this split not work? <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 21 Jun 2001 12:21:19 -0700
From: aougav@hotmail.com (Zur Aougav)
Subject: Re: CGI.pm, cookies and redirect PLS HELP!
Message-Id: <bccc87cc.0106211121.5b864469@posting.google.com>

cperl520335@aol.com (CPERL520335) wrote in message news:<20010619135922.08314.00000038@ng-cm1.aol.com>...
> I have a script that sets a cookie, then re-directs the browser.
> 
> It's all been working great with the code:-
>  ...
>   $cookietime = "+" . $cookietime . "h";
>   $query = new CGI; 
>   $my_cookie = $query->cookie(-name=>'AFFILIATE', -value=>$userhandle,
> -expires=>$cookietime, -path=>'/');
>   print $query->header(-cookie=>$my_cookie);
> ...

Yes, Michael is right. Code what/as he wrote.

You use
         $cookietime = "+" . $cookietime . "h";
*Before* this statement, please check if $cookietime is a number. It
must be.

Also, try to check if your cookie is there by using about:* etc. It
may be set, but other things had change... It happens.

[BTW, don't use "302 FOUND", use "302 MOVED"... Why Standards are made
for?]

Zur


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

Date: Thu, 21 Jun 2001 20:27:47 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: CGI::CARP (carpout) or (fatalsToBrowser) ?
Message-Id: <l2m4jt071appnitb4sl2bnbjmki6vkos3v@4ax.com>

David Soming wrote:

>So.. qw()= quotes?

qw() = Quote Words. It quotes a string, literally, and splits on
whitespace. There's no interpolation, but you'll get a warning if there
is a comma in there.

So,

	qw(foo $bar @baz quux)

is the same as

	('foo', '$bar', '@baz', 'quux')

Documentation is in... perlop. Yeah, it may seem a bit strange, but
apparently this is considered an operator.

See also q(), qq(), qx() and qr().

-- 
	Bart.


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

Date: Thu, 21 Jun 2001 20:45:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Difficulty exporting from modules
Message-Id: <f7n4jts8aohe0bju0q0vglqmhhafa54jqj@4ax.com>

Matthew Miller wrote:

>I'm working on my first module/OO based program. So far it has been
>interesting ;) The main package name is CWidget. I try to export some
>subroutines from that package but, it doesn't work. It is still necessary
>to call the subroutine like this: CWidget::cwidget_init(); in my test
>program, I want to be able to leave off the CWidget:: part.

It's uncommon for OO modules to export anything. Usually, you provide a
contructor method, eg called "new", and you get a new CWidget object by
calling

	my $obj = new CWidget(optional parameters here);

Without the parameters, you may even drop the parens.

-- 
	Bart.


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

Date: Thu, 21 Jun 2001 19:29:52 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: don't know if this can be done.to do with splitting up file names
Message-Id: <1evdfml.1qm7kb31bbf6bkN%tony@svanstrom.com>

lying_happy_eyes <lying_happy_eyes@hotmail.com> wrote:

> I've got a load of files named
> my_file.txt
> my_other_text_file.txt
> another_small_file.txt
> 
> etc etc
> 
> And i wanted to know if i could show them in a perl script as
> 
> my file
> my other text file
> another small file

What do you mean by "show them in a perl script"?

Do you want to print the filenames so that the user see them as above?!
If that's the case then have a look at s/replacethis/withthis/ and
tr/removethesecharacters/.


        /Tony
-- 
########################################################################
            I'm sorry, I'm sorry; actually, what I said was:
                  HOW WOULD YOU LIKE TO SUCK MY BALLS?
                             - South Park -


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

Date: Thu, 21 Jun 2001 20:42:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Exception handling ?
Message-Id: <23n4jtkf0frv9d5jvg9h7g84kojltlv0n3@4ax.com>

BeyondContol Inc. wrote:

>Is there an equivalent to the try/catch c++ directives?

eval { ... code here };
if($@) { print "An error occurred: $@" }

There are modules on CPAN that elaborate on the syntax, but this still
the principle behind them.

-- 
	Bart.


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

Date: Thu, 21 Jun 2001 21:26:01 GMT
From: "grimblefritz" <me@grimblefritz.com>
Subject: Re: having trouble with system
Message-Id: <JDtY6.896$7Y2.454380568@newssvr17.news.prodigy.com>

[I wrote]
>
> Thanks all -- stay tuned.

Well, quite by accident I stumbled on the concept of tainted data. Seems
that was most of the problem all along. Since the command string I was
passing to system() was pulled into a hash from a file, perl considers it
tainted. And system() will not execute tainted strings.

So...

if ( $action =~ /^(.*)$/ ) {
     $action = $1;
} else {
     $action = "echo 'error processing action'";
}

system $action;

works perfectly.

Learn something new everyday!

grim




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

Date: Thu, 21 Jun 2001 20:44:07 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how does one go about assigning the ip address from gethostbyname to  variable...
Message-Id: <3B325CCB.2E81E316@acm.org>

Bart Lateur wrote:
> 
> Demitri Borg wrote:
> 
> >Does anyone happen to have a place where i could read up on how to
> >assign the output from gethostbyname() to a variable ?
> 
> Lincoln L Steins[sic] book is really goo. "Network Programming with Perl".
                                       ^^^^
Is that anything like slime?  :-)



John
-- 
use Perl;
program
fulfillment


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

Date: 21 Jun 2001 11:32:11 -0700
From: aougav@hotmail.com (Zur Aougav)
Subject: Re: how does one go about assigning the ip address from gethostbyname to variable...
Message-Id: <bccc87cc.0106211032.626d8ef9@posting.google.com>

demitri-borg@home.com (Demitri Borg) wrote in message news:<3b31c8d1.221794914@news.grlnd1.tx.home.com>...
> Does anyone happen to have a place where i could read up on how to
> assign the output from gethostbyname() to a variable ?
> ...

Well, with Win95 we have a problem. The gethostbyname returns
127.0.0.1. One short (and ugly, sorry) solution can be:

        my $ip;
        system("netstat -r > temp.tmp");
        my $page = read_file("temp.tmp");    # read all file sub
        while ($page =~ m/\s(\d+\.\d+\.\d+\.\d+)\s/gis) {
                $ip = $1;
                next if ($ip eq "0.0.0.0");
                next if ($ip eq "127.0.0.1");
                next if ($ip eq "255.0.0.0"); # want one line? /^255/
etc.
                next if ($ip eq "255.255.0.0");
                next if ($ip eq "255.255.255.0");
                next if ($ip eq "255.255.255.255");
                print "Found ip: ".$ip."\n";
                last;
        }
        unlink("temp.tmp"); # etc...

This code does the work.

Zur


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

Date: Thu, 21 Jun 2001 20:37:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how does one go about assigning the ip address from gethostbyname to variable...
Message-Id: <0bm4jt87lmq4v7l9b4malik7hkjc7se2g6@4ax.com>

Demitri Borg wrote:

>Does anyone happen to have a place where i could read up on how to
>assign the output from gethostbyname() to a variable ?

Lincoln L Steins book is really goo. "Network Programming with Perl".
You can find the code samples (and a few chapters) on the web, on
<http://www.modperl.com/perl_networking/>. gethostbyname() and related
functions are demonstrated in chapter 3, code samples 3.5 to 3.7.

-- 
	Bart.


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

Date: Thu, 21 Jun 2001 20:48:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how does one go about assigning the ip address from gethostbyname to variable...
Message-Id: <kdn4jtosoun68trdv759hsoiocj7lutn8m@4ax.com>

Bart Lateur wrote:

>Lincoln L Steins book is really goo. "Network Programming with Perl".

A book for 5 year olds! Slime, yeah!

Of course, it's a "good" book. No goo involved. Not that I know of,
anyway.

-- 
	Bart.


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

Date: Thu, 21 Jun 2001 18:26:46 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How i Install module in NT platform
Message-Id: <aue4jt0v0ele9afrb9tg2shh8p1s45l0nv@4ax.com>

isterin wrote:

>dmake is the Borland make utility.  Which can't be used with compiling
>the modules anyways since ActivePerl was compiled with VC++.

Bollocks. The make utility ghas nothing to do with a C compiler. "make"
is a utility that *happens* to be mostly used in combination with a C
compiler, but it was designed and developed independently.

What matters, for what kind of "make" you use, is that what Makefile.PL
(with the help of ExtUtils::MakeMaker.pm) generates, is compatible with
the syntax the "make" utlility understands.

-- 
	Bart.


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

Date: 21 Jun 2001 20:15:45 GMT
From: garnerjr@ci.richmond.va.us (Jim Garner)
Subject: Re: Install Perl on HP
Message-Id: <9gtklh$qn4$1@bob.news.rcn.net>

I can compile perl 5.6.1 on 11.0 (ANSI/C or gcc), but it dumps core on the 
pwent test.  From what I can gather, calling getpwent() at end of file blows up 
every time.  The problem doesn't happen when compiled on 10.20.  I've tried 
+DAportable.  I've tried the source code from the HP porting library.  I've 
tried numerous combinations of flags, static libs, dynamic loading, nothing 
gets rid of the problem.  I'm a pretty good programmer, but the source code has 
so many layers of abstraction and ifdefs that I haven't been able to pin down 
where the error occurs.  Any suggestions would be appreciated.  My one 
remaining 10.20 system won't be around much longer.

-Jim Garner
garnerjr@ci.richmond.va.us


In article <Xns90C474C841F36Merijn@192.0.1.90>, h.m.brand@hccnet.nl says...
>
>Philip Newton <pne-news-20010617@newton.digitalspace.net> wrote in 
>news:1q4pit4so3hcel3lrlqgkhcvm3grej7uo1@4ax.com:
>>> *  I have previous verion perl install on my system,
>> 
>> Which one? The 4.036 that comes with HP-UX?
>
>Should be no problem /if/ you did not choose "/usr/contrib/bin" as 
>installation path for the binaries (not very likely though)
>
>>>    so before I install, should I clean up previous version ?
>> 
>> With 4.036, that shouldn't be necessary.
>
>Would be very bad for the system too, cause HP uses this for their updates.
>(HP has plans to upgrade to perl5 for internal use ;-)
>
>-- 
>H.Merijn Brand    Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
>using perl-5.6.1, 5.7.1 & 626 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
>     WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
>ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/



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

Date: 21 Jun 2001 15:08:26 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: int sub - strange behaviour
Message-Id: <m3sngtbnph.fsf@dhcp9-173.support.tivoli.com>

On 21 Jun 2001, anno4000@lublin.zrz.tu-berlin.de wrote:

> According to Ron Savage <ron@savage.net.au>:
> 
>> Hmmm. And despite Greg's reponse, I don't see sprintf
>> rounding-to-even.  Math::Currency does. Try (tested code):
>> 
>> -----><8-----
>> #!/perl/lib/perl
>> 
>> use strict;
>> use warnings;
>> 
>> # ---------------------------------------------------------------
>> 
>> print sprintf("Perl V %vd. \n", $^V);
>> 
>> for my $i (0.555, 1.555, 0.565, 1.565, 0.575, 1.575)
>> {
>>  print "$i => ", sprintf("%.2f. \n", $i);

Change to:
    print "$i => ", sprintf("%.20f => $.2f\n", $i, $i);

>> }
>> -----><8-----
>> 
>> My output:
[replaced by new output]
Perl V 5.6.0. 
0.555 => 0.55500000000000004885 => 0.56
1.555 => 1.55499999999999993783 => 1.55
0.565 => 0.56499999999999994671 => 0.56
1.565 => 1.56499999999999994671 => 1.56
0.575 => 0.57499999999999995559 => 0.57
1.575 => 1.57499999999999995559 => 1.57

[snip Anno's underlying implementation dependency discussion]

> However, your tests don't show whether or not your machine rounds to
> even.  On a binary machine, rounding to even can only occur when
> you round to integer values.  That is because the last digit (in
> decimal) of the number in question must be exactly 5.  On a binary
> computer the only numbers with that property are numbers n + 1/2
> for integer n.  In other words, the numbers you are rounding are
> internally only approximations of 1.555 (or whatever) and rounding
> to even doesn't apply.

As demonstrated by the change above.  Except that {n+1/2 | integer n}
is not the complete set of decimals ending in 5 that can be exactly
represented in binary.  To wit, the following does exhibit
round-to-even:

0.125 => 0.12500000000000000000 => 0.12
0.375 => 0.37500000000000000000 => 0.38
1.625 => 1.62500000000000000000 => 1.62
0.875 => 0.87500000000000000000 => 0.88

I believe the set is actually {n/m | odd n,m=2**k | pos integer k }

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 21 Jun 2001 22:47:50 +0200
From: "sdf" <sdfsd@com.com>
Subject: Making a bundle of Perl modules
Message-Id: <9gtpp6$1koab147@news1s.iddeo2.es>

Hi,

I need to make a bundle of several modules in order to distribute a
software.
I've seen in Perl Cookbook 12.8. Preparing a Module for Distribution, how to
prepare a single module for distribution. It's also explained in Simon
Cozens's page (perlnewmod - preparing a new module for distribution -
http://www.enstimac.fr/Perl/perl5.6.1/5.6.1/pod/perlnewmod.html).

However none of these two references explain how to make a distribution
based in more than one module.

I'll really appreciate any hint
Santiago




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

Date: Thu, 21 Jun 2001 16:28:02 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: memory-leaks (in mod_perl)
Message-Id: <Pine.SUN.4.33.0106211612330.26339-100000@mamba.cs.Virginia.EDU>

On Tue, 19 Jun 2001, peter pilsl wrote:

> I've a strange memleak (like all memleaks are) and want to know if there is
> a way to tell how many references (and which) point to a certain construct
> (anymous hashes and arrays in my case) ?

You may be able to use Data::Dumper to help debug it:

------
$foo = 2;
$bar = [ \$foo, \$foo];

use Data::Dumper;
print Dumper $bar;
------

prints:

  $VAR1 = [
            \2,
            $VAR1->[0]
          ];

Obviously you lose some information, but at least you can track some
references.

> Second I'd like to know, if there is way to manually delete a anonymous
> construct or 'free' the mem allocated by it ?

AFAIK, Perl cleans up when you no longer have any references to the
data. The gurus here can help you find any references that may be
laying around. To be safe, you may want to declare variables with "my"
whenever possible. (And you're using strict and -w, right?)

The other thing that most languages with garbage collection have to
deal with is circular references. If you have a data structure that
refers to itself, you should "break the circle" so that the garbage
collector can determine that the structure is not being refered to,
and then clean it up.

> However there is another strange thing: when I manually delete the hash_ptr
> to the bigarray the leaking is reduced by its big size. Shouldnt it be
> deleted anyway when leaving the script ?

But if you're running in a mod_perl context, you never really "leave
the script", right?

> Or : If any other reference points to bigarray, deleting the hash-entry
> shouldnt free the allocated mem at all ?

This is true.

> sub main
> {
>    my $ptr=module::init();
>    my $x=sub1($ptr);
>    my $y=sub2($ptr,x);
>
>    # uncommenting the next line will reduce leaking by amount of bigarray !
>    # delete($ptr->{bigarray});
>
> }

No surprise that delete frees the memory, right?

> sub1
> {
>   my $ptr=shift;
>   $ptr->{val2}=example($ptr);
> }
> sub2
> {
>   my $ptr=shift;
>   print $ptr->{val1},"\n";
> }

Does example return a pointer into $ptr? If so, you may be creating
circular references.

David



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

Date: Thu, 21 Jun 2001 19:51:46 +0100
From: "irl.com" <irl.com@ntlworld.com>
Subject: Mod_perl problem
Message-Id: <HnrY6.2439$Yx1.267979@news6-win.server.ntlworld.com>

Hi,
   I'm a newbie to mod_perl programming.  I have written a script to aloow
users of my website to log in and check there email.  This script runs on
every page of my site.  When each page is loaded the script opens a socket
to our mail server and checks the number of new messages the user has.
   The script works fine under normal CGI put under mod_perl it isn't
opening the socket at all.

G Cubitt
mailto:gary@irl.com





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

Date: Thu, 21 Jun 2001 17:00:25 -0400
From: Scott Vetter <svetter@dsli.com>
Subject: Opening a Netscape Window using a Perl script
Message-Id: <3B326069.F3FA5D1E@dsli.com>

Hello all:

    In know in some other language, which I won't mention, can open
another Netscape Window both with and without certain attributes.  Can
this also be done in Perl?  And if so how?

Thanks,

Scott




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

Date: Thu, 21 Jun 2001 14:23:22 -0400
From: Narendra Ravi <narendra@spiff.hr.att.com>
To: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: Opening and Reading Named Pipes
Message-Id: <3B323B9A.7A55D917@spiff.hr.att.com>

Philip Newton wrote:
> 
> On Thu, 21 Jun 2001 11:03:30 -0400, Narendra Ravi
> <narendra@spiff.hr.att.com> wrote:
> 
> > The program just hangs at
> >
> >   sysopen (FIFO, $pipename, O_RDONLY) ...
> 
> It's probably waiting for someone to write the pipe. Is there a process
> writing to it before you try to read it?
> 
> > Looks like the call blocks.
> 
> That's probably what's happening.

I just found that if I use

  $pfh = new IO::File, "$pipename", O_RDONLY|O_NONBLOCK ;

the code works. Advanced Programming in UNIX, W. Richard Stevens
discusses these issues in great detail.

Thank you Philip, for the dialog.

-- 

 -- Narendra Ra[a]vi     Email : narendra@spiff.hr.att.com
    MT  A4-4B27       Phone : 732-420-7792


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

Date: 21 Jun 2001 20:29:09 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Passing a DBM name to a program.
Message-Id: <9gtlel$hcq$2@bob.news.rcn.net>

Amittai Aviram <amittai@amittai.com> wrote:
> I would like to write a simple diagnostic tool that opens any DBM and reads
> out the respective keys and values.  But how to pass the name of the DBM as
> a variable?  I have tried the code below and get the error message that
> there is "no such file."  Of course, a DBM name is _not_ the name of the

> #!/usr/local/bin/perl


Get in the habit of enabling warnings and using strict.

> print "Enter the DBM name you wish to open:";

> $datafile = <STDIN>;

> dbmopen(%DATA, $datafile, 0666) || die "Cannot open $datafile: $!";

Did you notice something odd about the error message you got here?  That 
it looked something like

"Cannot open foo.dat
: no such file..."?

Did you wonder *why* the colon started on a new line?  Could it have been 
that $datafile has a trailing newline, but you don't have a database file 
whose name ends in a newline?



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

Date: Thu, 21 Jun 2001 19:50:30 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl Test Problem - show-shebang
Message-Id: <3B32503B.90E4040B@acm.org>

Brian Seppanen wrote:
> 
> I've had an ongoing issue with a solaris 7 host that won't run a simple
> perl script that will work on other solaris 7 boxes without modification
> and without problem.
> 
> Basically it appears as if the box does not interpret the file as a perl
> script and gives me shell
> errors when I try to execute it.

The perlrun man page gives some options that may be applicable to your
situation.



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 21 Jun 2001 20:23:51 +0200
From: "Stefan Serena" <sserena@freesurf.ch>
Subject: Re: Reference-problem
Message-Id: <9gte3v$b9q$1@news1.sunrise.ch>

thx! I think there are still more things I haven't understood than I
thought...

<nobull@mail.com> schrieb im Newsbeitrag
news:u9y9qn6poo.fsf@wcl-l.bham.ac.uk...
> "Stefan Serena" <sserena@freesurf.ch> writes:
>
> > What's wrong?
>
> Presedence.
>
> > It doesn't cause an error, but I want it to print "Hello
> > World!"...
> >
> > @foo = ('bar', 'anything');
> > $$foo[0] = "Hello World!";
> > print $bar;
>
> You are actually setting the first element of an anonymous array to
> "Hello World!" and storing a reference to that anonymous array in the
> scalar variable $foo.
>
> Change your code to:
>
> use strict;
> use warnings;
> my ($bar, $anything);
> my @foo = \ ($bar, $anything);
> ${$foo[0]} = "Hello World!";
> print $bar;
>
> Note: I've also changed the symbolic references to real refererences
> and the package variables to lexicals because >99% of the time using
> package variables and/or symbolic refererences is a bad idea.
>
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\




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

Date: 21 Jun 2001 20:18:31 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Reference-problem
Message-Id: <9gtkqn$hcq$1@bob.news.rcn.net>

Stefan Serena <sserena@freesurf.ch> wrote:
>> First off: Please trim the quoted text and place your reply below
>> the part(s) you are replying to.  Don't slap it on top and let
>> your readers sort it out.

> Ok. Sorry!

Thanks for fixing your posting style.  It makes it a *lot* easier to carry 
on a conversation.

>>     foreach ( $apple, $orange, $lemon, $banana ) {
>>         # do something with $_ here.
>>     }
>>
>> Note that foreach makes $_ an alias to each variable in turn, so
>> everything you do to $_ really happens to $apple, $orange, etc.

> Didn't know that. I thought it makes a copy to $_
> That means, the following code changes every entry of the array?

> foreach $entry (@allentries) {
>     $entry = $entry x 2;    # can be anything...
> }

Yep, and in fact many programs make good use of this behavior; it allows 
you to step through an array and make changes to all or some of the 
elements without having to manually index the array with a counter 
variable.



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

Date: Thu, 21 Jun 2001 22:45:20 +0200
From: "Stefan Serena" <sserena@freesurf.ch>
Subject: Re: Reference-problem
Message-Id: <9gtmd6$pgr$1@news1.sunrise.ch>

> > Didn't know that. I thought it makes a copy to $_
> > That means, the following code changes every entry of the array?
>
> > foreach $entry (@allentries) {
> >     $entry = $entry x 2;    # can be anything...
> > }
>
> Yep, and in fact many programs make good use of this behavior; it allows
> you to step through an array and make changes to all or some of the
> elements without having to manually index the array with a counter
> variable.

I see... I'm one of the programmers who always worked with a counter
variable. But this changes for sure now! ;-)




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

Date: 21 Jun 2001 12:41:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Salary for teaching intro to perl
Message-Id: <m13d8tips9.fsf@halfdome.holdit.com>

>>>>> "James" == James Richardson <time4tea@monmouth.com> writes:

James> "Allan Peda" <tl082@yahoo.com> wrote in message
James> news:20010620.103148.480298490.1213@yahoo.com...
>> I am interested in teaching a basic perl class, say 20
>> hours, which I expect will cover references and possibly
>> some object oriented programming (just how to create an object).
James> [...]
>> What are reasonable salary numbers?

James> Depends if you are teaching one of those shite classes with
James> loads of flashy handouts, but no content, or a real course.

And how many magazine columns you've written... I'm up to 133 at last
count. :) Last I recall, Stonehenge is billing me out at $4000/day,
although a *lot* of that is sucked down in overhead, and the lawyers
and IRS seem to grab the rest. :)

"Just another Perl hacker," # and columnist, and book author, and ...

p.s.  most of these are online at:

        http://www.stonehenge.com/merlyn/WebTechniques/
        http://www.stonehenge.com/merlyn/UnixReview/
        http://www.stonehenge.com/merlyn/LinuxMag/

-- 
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: Thu, 21 Jun 2001 20:57:06 +0100
From: "John Plaxton" <19wlr@globalnet.co.uk>
Subject: RE: splice/Join and split!!
Message-Id: <tj4kgtgc0j6b71@xo.supernews.co.uk>

Hi there All. As usual My problem is probably easy to solve but I have come
to a grinding halt in the search for an answer

I am reading a text file into an array.I am then changing some of the rows
before writing back to text file.This is the bit of code that should alter
the array:

  for($x=6;$x<10;$x++){
    my $oldrow = $filedata[$x];
    my ($autold,$dold,$avold,$yold,$pold,$paold) = split(/\|/, $oldrow);
    my $newrow = join '|',$aut,$dold,$avail,$yold,$p,$pa;
    splice(@filedata,$x,1,$newrow);
} # end for loop

I hoped this would change records 6 .. etc substituting $newrow for $oldrow,
which it does except that the line feed has been lost so that row 6 and 7
etc are all joined.

How do I add back the \n or whatever it is at the end of $newrow? I suppose
I want the oposite of Chomp. Could it be pmohC? $newrow .='\n'; doesn't
work!

Thanks in advance


John




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

Date: 21 Jun 2001 15:28:43 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: splice/Join and split!!
Message-Id: <m3ofrhbmro.fsf@dhcp9-173.support.tivoli.com>

On Thu, 21 Jun 2001, 19wlr@globalnet.co.uk wrote:

> I am reading a text file into an array.I am then changing some of
> the rows before writing back to text file.This is the bit of code
> that should alter the array:
> 
>   for($x=6;$x<10;$x++){
>     my $oldrow = $filedata[$x];
>     my ($autold,$dold,$avold,$yold,$pold,$paold) = split(/\|/, $oldrow);
>     my $newrow = join '|',$aut,$dold,$avail,$yold,$p,$pa;
>     splice(@filedata,$x,1,$newrow);

Using splice() here is probably overkill.  How about:

      $filedata[$x] = $newrow;

>} # end for loop
> 
> I hoped this would change records 6 .. etc substituting $newrow for
> $oldrow, which it does except that the line feed has been lost so
> that row 6 and 7 etc are all joined.

There are two possible reasons for the newline to be lost here.  One
is that there are more "|" in the row than you have variables split
out of it.  However, the second possibility would still apply and is
most likely the real problem.  That is that the newline was split into
$paold, which you are no longer using.  There are several solutions:

  1. Include "\n" in the value of $pa
  2. Use "$pa\n" in the call to join
  3. Use "$newrow\n" in the assignment to $filedata[$x]

> How do I add back the \n or whatever it is at the end of $newrow? I
> suppose I want the oposite of Chomp. Could it be pmohC? $newrow
> .='\n'; doesn't work!

'\n' doesn't work, but "\n" does.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 21 Jun 2001 16:01:25 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: splice/Join and split!!
Message-Id: <3B3260A5.9307289A@home.com>

John Plaxton wrote:
> 
> I am reading a text file into an array.I am then changing some
> of the rows before writing back to text file.

An operation that should almost certainly be done line-by-line:
slurping entire files doesn't scale well when the files get big.

> This is the bit of code that should alter the array:
> 
>   for($x=6;$x<10;$x++){
>     my $oldrow = $filedata[$x];
>     my ($autold,$dold,$avold,$yold,$pold,$paold) =
>             split(/\|/, $oldrow);
>     my $newrow = join '|',$aut,$dold,$avail,$yold,$p,$pa;
>     splice(@filedata,$x,1,$newrow);
> } # end for loop

As an example of more idiomatic Perl, I'd do it this way:
[Expanding your context a little]

while (<IN>) {
    if ($. == 6 .. $. == 9) {
        my (undef, $dold, undef, $yold) = split(/\|/, $_);
        $_  = join('|', $aut, $dold, $avail, $yold, $p, $pa);
        $_ .= "\n";
    }
    print;
}

> [T]he line feed has been lost so that row 6 and 7
> etc are all joined.
> 
> How do I add back the \n or whatever it is at the end of $newrow?
> I suppose I want the oposite of Chomp. Could it be pmohC?

Heh. Uh, no, but that's an interesting guess. :)

> $newrow .='\n'; doesn't work!

So close! But single quotes don't interpolate.

$newrow .= "\n";

-mjc


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

Date: Thu, 21 Jun 2001 21:26:48 GMT
From: tuxy <nospam@cfl.rr.com>
Subject: Re: Why does this split not work?
Message-Id: <3B326763.4146F83E@cfl.rr.com>

Mr Bug:

Your sophmoric response is demonstrative of a clear lack of
understanding. You have no idea of how many times I applied the "broken
5.6 split" in my application. Jumping to the conclusion that it's on 1
line- wow I'd hate to see what assumptions you make when you code!

As far as what I present, it would not be responsible on my part to post
a >1000 line proprietary file to a newsgroup for more than 1 reason. I
described what Perl did, and how it was broken. I presume that much less
thourough testing would reveal similar flaws.

Get over your wonderful self and look at the facts. The damn thing
doesn't work; I coded a legitimate solution and Perl choked. So kill me
that I'm not tickled to death with that.





Buggs wrote:
> 
> tuxy wrote:
> 
> > Hi Ren:
> >
> > I solved the problem. I went to a box with Perl 5.004 and botta-bing
> > botta-boom just as I suspected, my code is pristine, it's Perl 5.6
> > that's wacked. Apparently. Anyhow, now I either have to re-write this
> > algorithm in something 5.6-friendly, or  have to revert to 5.004 on this
> > other box. Neither prospect is overly appealing.
> >
> > A little surprizing too that in a forum this large, none of the guru's
> > would chime in with "oh split has some serious problems in 5.6".... That
> > message would have saved me many hours of study and experimentation. Oh
> > well what can I expect for free LOL..
> 
> Really sorry that you think you have to rewrite
> the whole ( w h o l e ) line of "algorithm",
> because you believe that 5.6 ships a broken split,
> which causes random errors throughout your programm.
> 
> Oh and 5.6 has some serious ( even serial )
> problems with you not presenting it a file
> which it can understand.
> 
> Indeed LOL.
> 
> Buggs


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

Date: Thu, 21 Jun 2001 21:33:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why does this split not work?
Message-Id: <f1q4jtk0t98m35ipiubbtc7r1kt8j6danr@4ax.com>

tuxy wrote:

>Get over your wonderful self and look at the facts. The damn thing
>doesn't work; I coded a legitimate solution and Perl choked. So kill me
>that I'm not tickled to death with that.

The damn thing works on my 5.6.0. So are you sure it chokes on THIS
particular line? Print out $buf just above this line, perhaps using
Data::Dumper. See if indeed $buf is not undef. That is what I would
think.

-- 
	Bart.


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

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


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