[26159] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8349 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 23 11:05:44 2005

Date: Tue, 23 Aug 2005 08:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 23 Aug 2005     Volume: 10 Number: 8349

Today's topics:
    Re: Dereferencing array/hash element with @{ } instead  (Anno Siegel)
    Re: FAQ 2.3 I don't have a C compiler. How can I build  <tintin@invalid.invalid>
    Re: how to read file from sub-directories and do an ave (Anno Siegel)
    Re: how to read file from sub-directories and do an ave (Anno Siegel)
    Re: Net::SFTP from memory instead of file? (Anno Siegel)
    Re: Obtaining verbose info for http transfers. <kuujinbo@hotmail.com>
        perl and ai/neural networks <"h.v.niekerk at hccnet.nl">
    Re: Symbol tables <josef.moellers@fujitsu-siemens.com>
    Re: Symbol tables (Anno Siegel)
    Re: Text display like table (Anno Siegel)
    Re: Use of uninitialized value Error (Anno Siegel)
    Re: Use of uninitialized value Error <nospam@nospam.com>
    Re: Use of uninitialized value in substitution (s///) <hlawson@triad.rr.com>
    Re: Use of uninitialized value in substitution (s///) (Anno Siegel)
    Re: Use of uninitialized value in substitution (s///) <hlawson@triad.rr.com>
    Re: Use of uninitialized value in substitution (s///) (Anno Siegel)
    Re: Use of uninitialized value in substitution (s///) <hlawson@triad.rr.com>
    Re: Use of uninitialized value in substitution (s///) (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Aug 2005 10:48:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Dereferencing array/hash element with @{ } instead of ${ }
Message-Id: <deeut1$b0n$1@mamenchi.zrz.TU-Berlin.DE>

David Serrano (Hue-Bond) <responder_solo_en_el_grupo@yahoo.es> wrote in comp.lang.perl.misc:
> I'm learning to use references and complex data structures. No problem at
> all until I discovered a typo in a program that was working perfectly. I've
> investigated that (reading perlref, perldsc, perldata and perlobj) but found
> nothing similar except pseudo-hashes, but I think this is not the case since
> I'm under strict and I'm not setting up a special first field.
> 
> This is the (conveniently shortened) code:
> 
> use strict;
> use warnings;
> my $lines = [
>   {
>     stations => [
>       {
>         name => "baz"
>       }
>     ]
>   }
> ];
> # same as $lines->[0]{stations}[0]{name}
> print ${ ${ ${ $lines->[0] }{stations} }[0] }{name},"\n";
> print    ${ ${ $lines->[0] }{stations} }[0]        ,"\n";
> print    @{ ${ $lines->[0] }{stations} }[0]        ,"\n";
> print       ${ $lines->[0] }{stations}             ,"\n";
> print       @{ $lines->[0] }{stations}             ,"\n";
> 
> 
> And the output:
> 
> 
> baz
> HASH(0x8071fbc)
> HASH(0x8071fbc)
> ARRAY(0x8071fec)
> ARRAY(0x8071fec)
> 
> 
> I expect to see some error instead of the second HASH(0x8071fbc) and the
> second ARRAY(0x8071fec). Why not?

These are perfectly legitimate slices, an array slice in the first case
and a hash slice in the second.  Slices behave list-like (not array-like),
so in scalar context they return the last element of the slice, not the
number of elements in the slice.

> [ ... ] Could it be a slice of just one element?

Exactly!

> use strict;
> use warnings;
> my $a=[4,6,8];
> print $$a[1], "\n";   ## normal usage, prints 6 without warnings
> print @$a[1], "\n";   ## what I'm doing, also prints 6 without warnings
> 
> Using an array instead of a reference yields "Scalar value @a[1] better
> written as $a[1] at - line 4.", why doesn't that happen with references?

I don't know, I never noticed before.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 23 Aug 2005 22:18:29 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: FAQ 2.3 I don't have a C compiler. How can I build my own Perl interpreter?
Message-Id: <SJCOe.5012$iM2.502784@news.xtra.co.nz>


"PerlFAQ Server" <comdog@panix.com> wrote in message 
news:dees8k$pbj$1@reader2.panix.com...

> --------------------------------------------------------------------
>
> 2.3: I don't have a C compiler. How can I build my own Perl interpreter?
>
>    Since you don't have a C compiler, you're doomed and your vendor should
>    be sacrificed to the Sun gods. But that doesn't help you.
>
>    What you need to do is get a binary version of gcc for your system
>    first. Consult the Usenet FAQs for your operating system for 
> information
>    on where to get such a binary version.
>
>
>
> --------------------------------------------------------------------

I know there's a separate FAQ entry for where to obtain Perl binaries, but I 
think this entry should
reference it, otherwise there may be some people who think you *need* a 
compiler to install Perl. 




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

Date: 23 Aug 2005 12:06:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to read file from sub-directories and do an average?
Message-Id: <def3gl$c4n$3@mamenchi.zrz.TU-Berlin.DE>

Brian McCauley  <nobull@mail.com> wrote in comp.lang.perl.misc:
> 
> 
> Tad McClellan wrote:
> 
> > Ross <a@cuhk.edu.hk> wrote:
> >>        chdir ($ARGV[0]);
> > 
> > 
> > You should probably ensure that it is an existing directory
> > before you try to open it:
> > 
> >    die "'$inputdirname' is not a directory" unless -d $inputdirname;
> 
> I disagree.  It's better to just try the chdir() and die if it fails. 
> There are numerous reasons why this is better to do with race conditions 
> and permissions.

Apart from that, $inputdirname is coming directly out of a readdir().
The possibility that chdir($inputdirname) fails because $inputdirname
isn't a directory is remote.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: 23 Aug 2005 12:19:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to read file from sub-directories and do an average?
Message-Id: <def48i$c4n$4@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Ross <a@cuhk.edu.hk> wrote:
> 
> > Is there any built-in function/parameters in Perl not to take . and .. into 
> > account when opening all the subdirectories?
> 
> 
> No, but there _is_ a way to avoid processing them.  :-)
> 
>    while ( my $item = readdir DIR ) {
> 
>       next if $item eq '.' or $item eq '..';
>       # next if $item /^\./;    # skip ALL items that start with dot
> 
>       # process non-dot files here
>    }

File::Spec can even do that portably (untested):

    use File::Spec qw( no_upwards);
    for my $item ( no_upwards readdir DIR ) {
        # no "." and ".." here
    }

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: 23 Aug 2005 10:25:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Net::SFTP from memory instead of file?
Message-Id: <deetjk$9ei$3@mamenchi.zrz.TU-Berlin.DE>

Fearless Fosdick  <BLOCKSPAMFearlessFosdick@your-mailbox.com> wrote in comp.lang.perl.misc:
> I have to sftp some data, but it's not allowed to live on the 
> filesystem. Short of implementing an sftp client, is there any other 
> solution I can use?

From the documentation of Net::SFTP I gather that the method ->do_write
accepts the data to be written from a string.  Where's the problem?

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 23 Aug 2005 22:38:13 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Obtaining verbose info for http transfers.
Message-Id: <def8sb$4l9$1@pin3.tky.plala.or.jp>

Eric Schwartz wrote:
> ko <kuujinbo@hotmail.com> writes:
> 
>>sub verbose_http {
>>   push my @urls, shift;
>>   while (my $url = shift @urls) {
> 
> 
> What's the point of this?  Why not just
> sub verbose_http {
>      my $url = shift;
> 
> <snip rest of code>
> 
> -=Eric

Yes, could've use recursion:

sub verbose_http {
   my $url = shift;
   my $r = $ua->get($url);
   if ($r->is_redirect) {
     print $r->headers->as_string . "\n\n";
     my $redirect = $r->header('Location');
     verbose_http($redirect);
   } elsif ($r->is_success) {
     print $r->content . "\n";
   }
}

Just a personal preference not to :)

<offtopic>
If the OP uses Firefox, have a look here:
http://livehttpheaders.mozdev.org/

If I remember correctly, it was a ~60KB or so download. Very nice.
</offtopic>

keith


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

Date: Tue, 23 Aug 2005 13:03:03 +0200
From: Huub <"h.v.niekerk at hccnet.nl">
Subject: perl and ai/neural networks
Message-Id: <430b01ca$0$145$3a628fcd@reader2.nntp.hccnet.nl>

Hi,

Where in the docs or faq can I find thorough info on perl with AI and 
neural networks? I can't find a link except a few by google.


Thanks,

Huub


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

Date: Tue, 23 Aug 2005 15:25:53 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Symbol tables
Message-Id: <def7te$t1m$1@nntp.fujitsu-siemens.com>

Anno Siegel wrote:
> Josef Moellers  <josef.moellers@fujitsu-siemens.com> wrote in comp.lang=
=2Eperl.misc:
>=20
>>Hi,
>>
>>I want to define a large set of almost identical functions:
>>
>>sub name {
>>     return $_[0]->{name};
>>}
>>with varying "name"s.
>>
>>I thought I'd be clever and do
>>foreach my $f ("name") {
>>     $PACK::{$f} =3D sub { return $_[0]->{$f}; }
>>}
>>
>>As long as I do it in one source file, it works:
>>
>>-8<-8<-8<-8<-8<-8<-8<-8<-8<-8<-8<-8<-
>>#! /usr/bin/perl
>>
>>use warnings;
>>use strict;
>># use FAT;
>>
>>package FAT32;
>>
>>use warnings;
>>use strict;
>>
>>sub func1() {
>>     print "Here is FAT32::func1\n";
>>}
>>
>>$FAT32::{func2} =3D sub { print "Here is FAT32::func2\n"; };
>>
>>1;
>>
>>package main;
>>
>>FAT32::func1();
>>FAT32::func2();
>>
>>exit 0;
>>-8<-8<-8<-8<-8<-8<-8<-8<-8<-8<-8<-8<-
>>Output:
>>Here is FAT32::func1
>>Here is FAT32::func2
>>
>>But when I put the package FAT32 into a separate file ("FAT.pm"), I get=

>>Here is FAT32::func1
>>Undefined subroutine &FAT32::func2 called at test.pl line 23.
>>
>>Is there any camel-dung I can put onto my hash assignment to make it=20
>>work cross-file?
>=20
>=20
> To answer the last question first, if you use
>=20
>     *FAT32::func2 =3D sub { print "Here is FAT32::func2\n"; };
>=20
> or just "*func2 =3D ........." in package FAT32, it works as expected
> either way.  I think that is also the more common way to assign to
> a glob.

That does work, but I need to define some 10 functions that way and I'd=20
likie to put that into a loop and using the typeglob thing doesn't allow =

me to put a variable where func2 is.

> Otherwise I would also have expected your code to work.  Something fish=
y
> is going on here.  Even the one-file version fails if you put the stash=

> assignment in a BEGIN block.  On the other hand, the two-file version
[ ... ]

It appears that it doesn't work with "use" but it does work with=20
"require"! Putting a BEGIN block around the require also doesn't work,=20
so it seems to be the BEGIN block that causes me headaches.
I can live with require-ing the module rather than use-ing it.

If anyone has more ideas, I'd be gratefull.

As the example suggests, I'm trying to handle FAT partitions (FAT32 for=20
the beginning).

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: 23 Aug 2005 14:06:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Symbol tables
Message-Id: <defahb$ia4$1@mamenchi.zrz.TU-Berlin.DE>

Josef Moellers  <josef.moellers@fujitsu-siemens.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Josef Moellers  <josef.moellers@fujitsu-siemens.com> wrote in
> comp.lang.perl.misc:

[...]

> >>$FAT32::{func2} = sub { print "Here is FAT32::func2\n"; };

[...]

> >>Is there any camel-dung I can put onto my hash assignment to make it 
> >>work cross-file?
> > 
> > 
> > To answer the last question first, if you use
> > 
> >     *FAT32::func2 = sub { print "Here is FAT32::func2\n"; };
> > 
> > or just "*func2 = ........." in package FAT32, it works as expected
> > either way.  I think that is also the more common way to assign to
> > a glob.
> 
> That does work, but I need to define some 10 functions that way and I'd 
> likie to put that into a loop and using the typeglob thing doesn't allow 
> me to put a variable where func2 is.

Without strict refs you can:

    for my $x ( qw( gaga blub huhu) ) {
        no strict 'refs';
        *{ $x} = sub { print "I'm $x\n" };
    }

> > Otherwise I would also have expected your code to work.  Something fishy
> > is going on here.  Even the one-file version fails if you put the stash
> > assignment in a BEGIN block.  On the other hand, the two-file version
> [ ... ]
> 
> It appears that it doesn't work with "use" but it does work with 
> "require"! Putting a BEGIN block around the require also doesn't work, 
> so it seems to be the BEGIN block that causes me headaches.

Yes, I pointed that out.  Doing it at compile time seems to be the
problem.

> I can live with require-ing the module rather than use-ing it.
> 
> If anyone has more ideas, I'd be gratefull.

A bunch of similar function is an invitation to consider a dispatch table
(a hash of coderefs).  No problems defining these, but of course the
calls look different.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: 23 Aug 2005 10:14:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Text display like table
Message-Id: <deestq$9ei$2@mamenchi.zrz.TU-Berlin.DE>

ngoc  <ngoc@yahoo.com> wrote in comp.lang.perl.misc:
> Hi
> I want to make
> 
> column1    column2    column3
> ------     -------    -------
> value1     value2     value3
> value1     value2     value3
> 
> I evaluate Text::Table, Text::ASCIITable, Text::TabularDisplay
> 1. Text::Table does not have set_width() function between columns and it 
> uses {title => ' ' x 5, is_sep => 1}. I do not like this way.

You can also specify column separators as string refs in Text::Table:

    my $sep = \ '   ';
    my $tb = Text::Table->>new( 'column1', $sep, 'column2' $sep, 'column3');

would also describe your layout.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: 23 Aug 2005 11:35:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Use of uninitialized value Error
Message-Id: <def1l5$c4n$1@mamenchi.zrz.TU-Berlin.DE>

daniel kaplan <nospam@nospam.com> wrote in comp.lang.perl.misc:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrndgkeni.m06.tadmc@magna.augustmail.com...
> 
> > Your answer is not in keeping with "one of the rudest people i have
> > ever encountered on a newsgroup".
> >
> > You're going to blow your reputation!  :-)
> 
> 
> ah but don't worry, i fought back a little ...
> 
> in reply to:
> 
> >>    my $came_from = 'I must learn proper CGI programming first';
> 
> i responded with:
> 
> But even after changing:  my $came_from   = xxxxxxxxx
> to:  my $came_from = 'You need to learn to be nicer to others';

Yes.  We've read it the first time.

> so if you want, we can do this dance....but am so tired, we don't have to,
> do we? ;-)

After having gratuitously repeated your riposte this remark looks
more than disingenuous.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 23 Aug 2005 10:49:21 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: Use of uninitialized value Error
Message-Id: <1124808497.853899@nntp.acecape.com>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:def1l5$c4n$1@mamenchi.zrz.TU-Berlin.DE...

> After having gratuitously repeated your riposte this remark looks
> more than disingenuous.

just reposting the joke in response to someone's post...sincerly did it in
jest.

let's just leave it all as it is, shall we?  much easier, friendly, etc, and
we can just go back to our own lives.  which i am sure is stressful enough
for all us, that we would all prefer not to add to it here.  ey?

daniel
p.s. i know i for one would prefer it that way.





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

Date: Tue, 23 Aug 2005 12:05:38 GMT
From: Hugh Lawson <hlawson@triad.rr.com>
Subject: Re: Use of uninitialized value in substitution (s///)
Message-Id: <87ll2soo37.fsf@desktop.xx.yy>

"John W. Krahn" <someone@example.com> writes:

> Hugh Lawson wrote:
> > This error occurs in this program.  What is uninitialized in the substitution?
> > 
> > I've spent quite a while searching for clues.
> 
> See the example code for 'filter_fetch_value' in the perldbmfilter man page.
> 
> perldoc perldbmfilter
Hi John,

Did you mean this line?

$db->filter_fetch_value(sub{no warnings 'uninitialized'; s/\0$//} ) ; 


That stops the warning, but why is 'no warnings' needed? Why can't the
substitution be written to evade the warning?  Is it "just one of
those things"?

And thanks for the reply.

-- 
Hugh Lawson
hlawson@triad.rr.com


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

Date: 23 Aug 2005 12:26:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Use of uninitialized value in substitution (s///)
Message-Id: <def4m3$c4n$5@mamenchi.zrz.TU-Berlin.DE>

Hugh Lawson  <hlawson@triad.rr.com> wrote in comp.lang.perl.misc:
> "John W. Krahn" <someone@example.com> writes:
> 
> > Hugh Lawson wrote:
> > > This error occurs in this program.  What is uninitialized in the
> substitution?
> > > 
> > > I've spent quite a while searching for clues.
> > 
> > See the example code for 'filter_fetch_value' in the perldbmfilter man page.
> > 
> > perldoc perldbmfilter
> Hi John,
> 
> Did you mean this line?
> 
> $db->filter_fetch_value(sub{no warnings 'uninitialized'; s/\0$//} ) ; 
> 
> 
> That stops the warning, but why is 'no warnings' needed? Why can't the
> substitution be written to evade the warning?  Is it "just one of
> those things"?

The substitution can do nothing to stop the warning.  The warning happens
whenever you try to apply *any* substitution to an undefined value.

There is, of course, more than one way to silence the warning.

    sub { s/\0$// if defined }

should work as well.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 23 Aug 2005 12:55:49 GMT
From: Hugh Lawson <hlawson@triad.rr.com>
Subject: Re: Use of uninitialized value in substitution (s///)
Message-Id: <87fyt0olrf.fsf@desktop.xx.yy>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

> > $db->filter_fetch_value(sub{no warnings 'uninitialized'; s/\0$//} ) ; 
> > 
> > 
> > That stops the warning, but why is 'no warnings' needed? Why can't the
> > substitution be written to evade the warning?  Is it "just one of
> > those things"?
> 
> The substitution can do nothing to stop the warning.  The warning happens
> whenever you try to apply *any* substitution to an undefined value.
> 
> There is, of course, more than one way to silence the warning.
> 
>     sub { s/\0$// if defined }
> 
> should work as well.

Hello Anno,

Why is the substitution undefined?  What in Perl is undefined about

        s/\0$//

That's what I'm wondering about.  From my earlier document-reading I
learned how to stifle the warning, but what evoked it?

To me 's/\0$//' says 

        take the variable $_, and if there is a \0 at the end,
        remove it, leaving everything else in $_

How can the code work right if $_ is undefined?

Thanks for the reply.
-- 
Hugh Lawson
hlawson@triad.rr.com


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

Date: 23 Aug 2005 13:07:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Use of uninitialized value in substitution (s///)
Message-Id: <def735$c4n$6@mamenchi.zrz.TU-Berlin.DE>

Hugh Lawson  <hlawson@triad.rr.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> 
> > > $db->filter_fetch_value(sub{no warnings 'uninitialized'; s/\0$//} ) ; 
> > > 
> > > 
> > > That stops the warning, but why is 'no warnings' needed? Why can't the
> > > substitution be written to evade the warning?  Is it "just one of
> > > those things"?
> > 
> > The substitution can do nothing to stop the warning.  The warning happens
> > whenever you try to apply *any* substitution to an undefined value.
> > 
> > There is, of course, more than one way to silence the warning.
> > 
> >     sub { s/\0$// if defined }
> > 
> > should work as well.
> 
> Hello Anno,
> 
> Why is the substitution undefined?  What in Perl is undefined about
> 
>         s/\0$//

Nothing is undefined about it, it's an operator.

> That's what I'm wondering about.  From my earlier document-reading I
> learned how to stifle the warning, but what evoked it?

The warning happens when Perl tries to apply the perfectly legal s///
operator to the undefined variable $_ (*if* it is undefined).

> To me 's/\0$//' says 
> 
>         take the variable $_, and if there is a \0 at the end,
>         remove it, leaving everything else in $_
> 
> How can the code work right if $_ is undefined?

Perl converts the undefined value to an empty string, if forced.  It
does that here, finds that the empty string doesn't end with a "0" and
returns the empty string unchanged.  That works perfectly well, but it
may not be what the programmer intended, hence the warning.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 23 Aug 2005 13:44:39 GMT
From: Hugh Lawson <hlawson@triad.rr.com>
Subject: Re: Use of uninitialized value in substitution (s///)
Message-Id: <87acj8oji6.fsf@desktop.xx.yy>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:


> > Hello Anno,
> > 
> > Why is the substitution undefined?  What in Perl is undefined about
> > 
> >         s/\0$//
> 
> Nothing is undefined about it, it's an operator.
> 
> > That's what I'm wondering about.  From my earlier document-reading I
> > learned how to stifle the warning, but what evoked it?
> 
> The warning happens when Perl tries to apply the perfectly legal s///
> operator to the undefined variable $_ (*if* it is undefined).
> 
> > To me 's/\0$//' says 
> > 
> >         take the variable $_, and if there is a \0 at the end,
> >         remove it, leaving everything else in $_
> > 
> > How can the code work right if $_ is undefined?
> 
> Perl converts the undefined value to an empty string, if forced.  It
> does that here, finds that the empty string doesn't end with a "0" and
> returns the empty string unchanged.  That works perfectly well, but it
> may not be what the programmer intended, hence the warning.


Hello Anno,

Thank you for the reply.  Perhaps we are communicating at cross
purposes.  My point is that warning or not, the substitution seems to
work as expected.

To see what I'm talking about, search for this line

 $db->filter_fetch_value(
               sub { no warnings 'uninitialized' ;s/\0$// } ) ;

in perldoc perldbmfilter.

This is one of several recommended filters for use when perl accesses
and changes strings in db files that must also be available for C
programs.

-- 
Hugh Lawson
hlawson@triad.rr.com


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

Date: 23 Aug 2005 14:17:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Use of uninitialized value in substitution (s///)
Message-Id: <defb5a$ia4$2@mamenchi.zrz.TU-Berlin.DE>

Hugh Lawson  <hlawson@triad.rr.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

[...]

> > > How can the code work right if $_ is undefined?
> > 
> > Perl converts the undefined value to an empty string, if forced.  It
> > does that here, finds that the empty string doesn't end with a "0" and
> > returns the empty string unchanged.  That works perfectly well, but it
> > may not be what the programmer intended, hence the warning.
> 
> 
> Hello Anno,
> 
> Thank you for the reply.  Perhaps we are communicating at cross
> purposes.  My point is that warning or not, the substitution seems to
> work as expected.

How is that surprising?  The purpose of the substitution is to get rid
of a trailing null byte in C strings.  If $_ is undefined, the
substitution returns an empty string. That doesn't have a trailing null
byte, so the purpose of the substitution is attained.

> To see what I'm talking about, search for this line
> 
>  $db->filter_fetch_value(
>                sub { no warnings 'uninitialized' ;s/\0$// } ) ;
> 
> in perldoc perldbmfilter.

I don't have perldbmfilter around (is it really spelled that way?).
The code is the same as earlier in the thread.  What's to discover?

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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