[25085] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7335 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 28 21:05:43 2004

Date: Thu, 28 Oct 2004 18:05:09 -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           Thu, 28 Oct 2004     Volume: 10 Number: 7335

Today's topics:
    Re: browser output <segraves_f13@mindspring.com>
    Re: Common file operations <usenet@morrow.me.uk>
    Re: Common file operations <usenet@morrow.me.uk>
    Re: cpan <tim@vegeta.ath.cx>
    Re: Detecting a Process using Perl Win32 <1usa@llenroc.ude.invalid>
    Re: How can I change a Perl floating-point value to a b <none@nowhere.invalid>
    Re: How can I change a Perl floating-point value to a b ctcgag@hotmail.com
    Re: Little question on regex. <lwt0301@bellsouth.net>
    Re: Little question on regex. <uguttman@athenahealth.com>
    Re: modifying hash key (dispatch table) <jeff@spamalanadingong.com>
    Re: print FILE function() <1usa@llenroc.ude.invalid>
    Re: print FILE function() <mritty@gmail.com>
    Re: print FILE function() <ebohlman@omsdev.com>
    Re: print FILE function() <usa1@llenroc.ude.invalid>
    Re: print FILE function() <mritty@gmail.com>
    Re: print FILE function() <noreply@gunnar.cc>
    Re: print FILE function() <usa1@llenroc.ude.invalid>
    Re: print FILE function() <ebohlman@omsdev.com>
    Re: print FILE function() <usa1@llenroc.ude.invalid>
    Re: Should I use BEGIN, CHECK, or INIT? <usenet@morrow.me.uk>
    Re: What are these extra spaces in my registry? <usa1@llenroc.ude.invalid>
    Re: What are these extra spaces in my registry? <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Oct 2004 23:23:43 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: browser output
Message-Id: <3cfgd.10946$5i5.6092@newsread2.news.atl.earthlink.net>

"Daniel R. Tobias" <dan@tobias.name> wrote in message
news:aab17256.0410281339.6ea7a8b3@posting.google.com...
> "Bill Segraves" <segraves_f13@mindspring.com> wrote in message
news:<KEWfd.9845$5i5.4791@newsread2.news.atl.earthlink.net>...
> > Also, it appears the OP is interested in preventing the browser from
> > interpreting HTML that is embedded in what is returned to the browser.
>
> The best solution to that problem is to use a more standards-compliant
> browser... Mozilla or Firefox will display plain text as plain text
> regardless of the URL "extension", presence of stuff that looks like
> "tags", and so on.

Agreed. At the very least, the OP should try them to see if they help with
the problems he has.

OTOH, there's no way to ensure that solution will be employed by by the
users of his web pages or mail with embedded HTML.

From the bits and pieces that the OP has posted, the OP's objectives are not
clearly stated.

Cheers.
--
Bill Segraves




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

Date: Thu, 28 Oct 2004 22:02:11 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Common file operations
Message-Id: <jb3852-uch.ln1@osiris.mauzo.dyndns.org>


Quoth "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>:
> There doesn't seem to be a single service that will handle recursion.
> File::Find as documented doesn't do the matching. What I'm looking for
> is a directory tree-walking function that applies matching criteria
> and only returns the files meeting those criteria.

File::Find::Rule.

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk                                    The Levellers, 'Believers'


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

Date: Thu, 28 Oct 2004 22:07:54 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Common file operations
Message-Id: <am3852-uch.ln1@osiris.mauzo.dyndns.org>


Quoth "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>:
> In <31bvn0pnelmb5sgm3k5ds5ffcjavv4lfjn@4ax.com>, on 10/27/2004
>    at 04:34 PM, Michele Dondi <bik.mido@tiscalinet.it> said:
> 
> >BTW: do you really need -T?
> 
> Probably not; I just assumed that it was prudent to make a habit of
> it.

Well, it certainly won't do any harm :).

> >Also, with modern perls it's better to
> >  use warnings;
> 
> Do you mean instead of the taint flag?

No, instead of -w. warnings is a replacement, that allows fine-grained
lexically-scoped control of warnings.

> >> my ($dir,$file)=@ARGV;
> 
> >Hmmm, then I'd rather do (somthing like):
> >  @ARGV == 2 or die "Usage: $0 <wildcard> <file>\n";
> 
> ITYM in additon to the existing code.

Yup, he does.

> >Hey, and you said you had never heard about regexen...
> 
> Correct. Check the spelling ;-)

regex is the usual spelling in this group, and regexen the usual plural.

> >However... you're just removing possible C<'>s from at ^ or $,
> >right?
> 
> Yes. I need to be able to pass command arguments containing * without
> the shell interpreting the * as a wildcard. The only other technique
> that I came up with was keying the argument with \* instead of *,
> which I would have found to be more of a nuisance than the
> apostrophes.

 ...and your shell doesn't do proper quoting and remove the 's for you,
right?

> >Then I suggest you do something like
> >  s/^'//, s/'$// for $dir;
> 
> Thanks. In this case efficiency is irelevant, but if I need to do
> something similar inside a loop, is the clear version as fast as the
> other?

Which are you calling the clear version? I (and most Perl programmers)
would call Michele's clearer than yours.

> >Also, still if you really *do* want to print all those info, then
> >for clarity resons you may consider an HERE doc instead.
> 
> EXPN?

See <<EOF under 'Regexp Quote-like Operators' in perlop.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Thu, 28 Oct 2004 22:14:16 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: cpan
Message-Id: <slrnco2rl0.ugn.tim@vegeta.saiyix>

Stuart Carrison <stuart--nospam--@carrison.co.uk.nospam> wrote:
>  I'm running Mandrake 7.2 on Sparc with Perl 5.6.0.
>  
>  I need at least 5.6.1 to use razor and spamassassin, but I'm having
>  problems with RPMs - there just doesn't seem to be a precompiled
>  version of 5.6.1 for Sparc anymore (well, one that works anyway) and
>  compiling isn't going well either.

Your Mandrake version seems somewhat old.

Try running OpenBSD ( http://openbsd.org ) instead.  OpenBSD has had
Perl 5.8 since version 3.4 (over a year), has perl pre-installed, and
even has packages for SpamAssassin.

>  However, I've heard of this thing called CPAN, which I'm led to
>  beleive can be used to up-grade PERL.
>  
>  Can someone confirm this and perhaps provide some _simple_
>  instructions for me?

Yes, CPAN can be used to upgrade your perl version (and occasionally
decides to upgrade it without being told).  Unfortunately in your case,
it does so by compiling a the new version of perl from source, which
would likely run into the same problem you're already having compiling
perl.

HTH,
Tim Hammerquist


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

Date: 28 Oct 2004 22:10:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Detecting a Process using Perl Win32
Message-Id: <Xns9590B8E0A853Casu1cornelledu@132.236.56.8>

bitbucketz2002@yahoo.com (Bryan Williams) wrote in
news:38a10436.0410252151.6f7094a3@posting.google.com: 

> Tom Tingdale <tom.tingdale@sbcglobal.net> wrote in message
> news:<cntqn0ljli76jgit7sel1hjk9om7e6co4m@4ax.com>... 
>> I have a perl program that launchs every minutes using a Windows Task
>> Scheduler to process some files. If the Perl program is still
>> running, I don't want to run it again until the previous Perl
>> application has finished. It is possible to detect whether or not my
>> Perl application is already running?
> 
> sub runUpdate{
>  my $pi = Win32::Process::Info->new();
>  my $Updates = 0;
> 
>  foreach $proc ($pi->GetProcInfo())
>     {
>        foreach ($proc)
>           {
>              if ($proc->{Name} eq "update.exe")
>                 {
>                    #Count the number of running instances
>                    $Updates++
>                 }
>           }
>     }


Huh? In Perl, one would do:

my $instances = grep { /^update.exe$/ } @{[ $pi->GetProcInfo()};

>  # if no running update.exe found start it otherwise exit
>  if ($Updates <= 1)
>     {
>        doit();
>     }

Ahem, the criterion was to not start an update if update.exe was already 
running. So, there should be no instances of 'update.exe' running.

However, this is neither here nor there. Since the operation of counting 
the number of instances of update.exe in the process table is not atomic, 
this code will not prevent two or more instances of update.exe from 
running.

That is, an update process might be launched between searching the 
process table for 'update.exe' entries, and the check on the number of 
instances.

Sinan.


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

Date: Thu, 28 Oct 2004 22:09:41 GMT
From: none <none@nowhere.invalid>
Subject: Re: How can I change a Perl floating-point value to a bit vector?
Message-Id: <F6egd.2387$eU2.2368@trndny05>

> my @x = unpack "b*", pack "d", 1/3;

This worked perfectly! Thanks! I tried chaining pack and unpack before, 
but I was assigning the result to a scalar and so didn't get the right 
answer.

Thanks,
-Mike


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

Date: 28 Oct 2004 23:32:21 GMT
From: ctcgag@hotmail.com
Subject: Re: How can I change a Perl floating-point value to a bit vector?
Message-Id: <20041028193221.494$XB@newsreader.com>

none <none@nowhere.invalid> wrote:
> > my @x = unpack "b*", pack "d", 1/3;
>
> This worked perfectly! Thanks!

Hold on, not so fast!

> I tried chaining pack and unpack before,
> but I was assigning the result to a scalar and so didn't get the right
> answer.

But that is right!  I was only loading the first element of @x, and that
one element is a string of ones and zeros.  So I should have used a scalar
instead.

my @x=split //, unpack "b*", pack "d", 1/3;

Is what I really meant.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 28 Oct 2004 18:12:42 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: Little question on regex.
Message-Id: <10o2rsuo2bs4g31@news.supernews.com>

NeoAsimov wrote:

> Hello,
> 
>     I want to select specific lines of C++ source codes.
> 
> 
> There is the pattern that I want to match:
> 
>     I want a line that have a "..." string in but not any "//" characters.
> 
> Exemple:
> 
>     public void Foo("test")                 [This one match]
> //  public void Foo("test")                 [This one doesn't match]
> 
> 
> 
> I tested many things but none works....
> 
> there are some of my tests:
> 
> ^([^//])*("[^"]*")$
> ^([^//]|[^"])* "[^"]*"
> ^([^//]*|[^"]*)*"[^"]*"
> ^([^//]*|[^"]*|$)("[^"]*")
> ^[ \t]*[^//]*("[^"]*")*$
> 
> Is this really possible to do what i want?
> 
> 
> 
> 
> Thank alot for your help/hints,
> 
> 
> Salutations,

Try this:

#! /usr/bin/perl

$string = $ARGV[0];
if (!($string =~ m/\/\//))
{print "match!\n";}
else
{print "no match.\n";}



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

Date: Thu, 28 Oct 2004 18:46:06 -0400
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: Little question on regex.
Message-Id: <m3is8uwjf5.fsf@linux.local>

>>>>> "L" == Laura  <lwt0301@bellsouth.net> writes:

  >> There is the pattern that I want to match:
  >> 
  >> I want a line that have a "..." string in but not any "//" characters.
  >> 
  >> Exemple:
  >> 
  >> public void Foo("test")                 [This one match]
  >> //  public void Foo("test")                 [This one doesn't match]
  >> 

  L> $string = $ARGV[0];
  L> if (!($string =~ m/\/\//))
  L> {print "match!\n";}
  L> else
  L> {print "no match.\n";}

huh? that doesn't even come close to what the OP asked for. where is the
match for '...' (i assume the OP means some arbitrary string
there). then your logic is backwards with print "match" when the match
fails. finally you should use alternate delimiters when you need to
match / chars. 3 strikes and yer out! (just like the cardinals).

so when will you decide to actually learn perl? you seem to have the
interest but haven't mastered even the basics. i recommend you read a
few decent perl books and more of the docs before you embarrass yourself
again here.

uri


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

Date: Thu, 28 Oct 2004 22:25:38 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: Re: modifying hash key (dispatch table)
Message-Id: <Clegd.10916$5i5.4869@newsread2.news.atl.earthlink.net>


>>   I'm calling a dispatch table:
>>
>>my $hashref=\%SOME_HASH;
>>
>>if(exists $DISPATCH{modify_hash_key}){
>>my $sub_ref=$DISPATCH{modify_hash_key};
>>&$sub_ref($hashref);
>>}
>>
<snip>
> 
>>### In some external config file
>>
>>$DISPATCH{modify_hash_key}=sub{
>>my $hashref=shift;
>>
>>????
>>
>>};
> 
> 
> 
> That code is not attempting to add/modify a hash key, it is
> modifying a hash *value*.
> 
> 
> What happened when you tried it?
> 
> 
Well I always take that as I've missed something obvious.

And when I do this:

$hashref->{new_key}='some_value';

It does work!

I think I was doing this:

my %hash=%$hashref;
$hash{new_key}='some_value';

And that doesn't.

I've got a pretty good 50-50 grip on why that is!

   Cheers,
Jeff


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

Date: 28 Oct 2004 22:19:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: print FILE function()
Message-Id: <Xns9590BA7D8D3F3asu1cornelledu@132.236.56.8>

Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com> wrote in news:10o2qp5sbg6u284
@corp.supernews.com:

> I've looked all over the 'net for an answer but can't find it.

Apparently, looking all over the net is not the right way of solving 
problems. Instead, you might want to look at your own code.

> print FILE hdump($loc);

 ...

The hdump sub below does not return anything. Instead, it just prints to 
STDOUT. 

> sub hdump {
>      my $offset = 0;
>      my(@array,$format);
>      foreach my $data (unpack("a16"x(length($_[0])/16)."a*",$_[0])) {
>          my($len)=length($data);
>          if ($len == 16) {
>              @array = unpack('N4', $data);
>              $format="0x%08x (%05d)   %08x %08x %08x %08x   %s\n";
>          } else {
>              @array = unpack('C*', $data);
>              $_ = sprintf "%2.2x", $_ for @array;
>              push(@array, '  ') while $len++ < 16;
>              $format="0x%08x (%05d)" .
>                 "   %s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s   %s\n";
>          }
>          $data =~ tr/\0-\37\177-\377/./;
>          printf $format,$offset,$offset,@array,$data;

You are printing to STDOUT here.

>          $offset += 16;
>      }

You don't return anything from this sub. Since you are calling the sub in 
list context, print is called with an empty list.

> };

This is where it becomes useful to write the shortest possible script 
that exhibits the problem you are experiencing. The posting guidelines 
for this group has many other good rules to follow before posting here.

In this case, you could test if there was a problem with Perl's print or 
your code by writing the following script:

use strict;
use warnings;

my $path = "/home/atc/scripts/test.txt";
open my $file, '>', $path
    or die "Cannot open $path: $!";

print $file function();

sub function {
    "Hi there\n";
}

__END__

The script above ought to do what you expect. Then, you start adding 
things until you encounter the problem. This process will help you solve 
your own problems.

Sinan.


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

Date: Thu, 28 Oct 2004 18:23:00 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: print FILE function()
Message-Id: <clrrgk$18n$1@misc-cct.server.rpi.edu>

Spin wrote:
> Why is that I can't print a function's output to file?

A function doesn't have 'output'.  It has a return value.  Your function 
doesn't return anything.

> my $path = "/home/atc/scripts/test.txt";
> open (FILE, ">$path") or die "Unable to open file $!";
> print FILE "PC: Status Inquiry ",curr_time(),"\n";
> print FILE hdump($loc);

This print would print the return value of hdump($loc) to the FILE.

> close (FILE) or die "Can't close file";
> 
> 
> The first print line prints to file and not to screen (including the 
> curr_time() func).
> The second prints to screen and not to the file.
> 
> Here's the subroutines:
> sub hdump {
>     my $offset = 0;
>     my(@array,$format);
>     foreach my $data (unpack("a16"x(length($_[0])/16)."a*",$_[0])) {
>         my($len)=length($data);
>         if ($len == 16) {
>             @array = unpack('N4', $data);
>             $format="0x%08x (%05d)   %08x %08x %08x %08x   %s\n";
>         } else {
>             @array = unpack('C*', $data);
>             $_ = sprintf "%2.2x", $_ for @array;
>             push(@array, '  ') while $len++ < 16;
>             $format="0x%08x (%05d)" .
>                "   %s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s   %s\n";
>         }
>         $data =~ tr/\0-\37\177-\377/./;
>         printf $format,$offset,$offset,@array,$data;

This printf prints its arguments to the screen, because you haven't told 
it to print anywhere else.


>         $offset += 16;
>     }

Here your function ends, without returning anything for the original 
print to print.
> };
> 
> sub curr_time {
>     my $curr_time = localtime();

This function, on the other hand, returns the value of $curr_time (by 
virtue of Perl's standard "return the last value evaluated" feature).

> }

If you want your function to print to a file, you have to tell the 
prints within that function to print to the file.  This could be done 
either with a global Filehandle (generally not perferred), or with a 
lexical filehandle that you pass to the function.

open my $file, '>', 'output.txt' or die "Could not open file: $!";

hdump ($file, $loc);

#...
sub hdump {
    my ($handle, $arg) = @_;
    print $handle "Argument was: $arg\n";
}


Paul Lalli


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

Date: 28 Oct 2004 22:27:41 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: print FILE function()
Message-Id: <Xns9590B2A013B01ebohlmanomsdevcom@130.133.1.4>

Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com> wrote in 
news:10o2qp5sbg6u284@corp.supernews.com:

> I've looked all over the 'net for an answer but can't find it.
> 
> Why is that I can't print a function's output to file?
> 
> my $path = "/home/atc/scripts/test.txt";
> open (FILE, ">$path") or die "Unable to open file $!";
> print FILE "PC: Status Inquiry ",curr_time(),"\n";

This prints whatever value curr_time() returns,

> print FILE hdump($loc);

This prints whatever value hdump() returns.

> close (FILE) or die "Can't close file";
> 
> 
> The first print line prints to file and not to screen (including the 
> curr_time() func).

So it's plain that curr_time() is returning something reasonable.

> The second prints to screen and not to the file.

So maybe we should see what it returns...
> 
> Here's the subroutines:
> sub hdump {
>      my $offset = 0;
>      my(@array,$format);
>      foreach my $data (unpack("a16"x(length($_[0])/16)."a*",$_[0])) {
>          my($len)=length($data);
>          if ($len == 16) {
>              @array = unpack('N4', $data);
>              $format="0x%08x (%05d)   %08x %08x %08x %08x   %s\n";
>          } else {
>              @array = unpack('C*', $data);
>              $_ = sprintf "%2.2x", $_ for @array;
>              push(@array, '  ') while $len++ < 16;
>              $format="0x%08x (%05d)" .
>                 "   %s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s   %s\n";
>          }
>          $data =~ tr/\0-\37\177-\377/./;
>          printf $format,$offset,$offset,@array,$data;

This, of course, will print to STDOUT, which will go to the screen unless 
you've redirected it, so I think we now know why there's output going to 
the screen.

>          $offset += 16;
>      }
> };

Since there's no explicit return statement, hdump() will return the value 
of the last expression evaluated, which looks to me like it will be the 
final value of $offset.

It looks like you need to either:

1) Change that printf to a sprintf and buffer up the results in a string 
and return that or
2) Pass the filehandle as an argument to the hdump() and have the printf 
print to it rather than STDOUT.  That will be easier to do if you use a 
lexical filehandle created by the three-argument form of open, which is now 
recommended practice.  (you *could*, of course, just change that printf to 
"printf FILE ..." but that's *not* recommended practice; subs shouldn't 
rely on intimate knowledge of how their callers are implemented.) 
 
> 
> sub curr_time {
>      my $curr_time = localtime();
> }

This returns the value of $curr_time, and so works as expected.


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

Date: 28 Oct 2004 23:38:37 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: print FILE function()
Message-Id: <Xns9590C7D3A8347asu1cornelledu@132.236.56.8>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns9590BA7D8D3F3asu1cornelledu@132.236.56.8: 

>>          $offset += 16;
>>      }
> 
> You don't return anything from this sub. Since you are calling the sub
> in list context, print is called with an empty list.
> 

OOOOOPS!!!! Clearly, the last value of $offset will be returned from this 
subroutine.

Sorry about that.

Sinan.


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

Date: Thu, 28 Oct 2004 19:48:46 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: print FILE function()
Message-Id: <cls0he$1k8$1@misc-cct.server.rpi.edu>

A. Sinan Unur wrote:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
> news:Xns9590BA7D8D3F3asu1cornelledu@132.236.56.8: 
> 
> 
>>>         $offset += 16;
>>>     }
>>
>>You don't return anything from this sub. Since you are calling the sub
>>in list context, print is called with an empty list.
> 
> OOOOOPS!!!! Clearly, the last value of $offset will be returned from this 
> subroutine.
> 
> Sorry about that.
> 
> Sinan.

I'm pretty sure you were right the first time...

#!/usr/bin/perl
use strict;
use warnings;
sub fctn{
   my $bar;
   for my $i (1..10){
     $bar += $i;
   }
}

my $foo = fctn();
print "Foo: $foo\n";
__END__
Foo:

Am I missing something?

Paul Lalli


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

Date: Fri, 29 Oct 2004 01:45:32 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: print FILE function()
Message-Id: <2udf5jF28qlhoU1@uni-berlin.de>

A. Sinan Unur wrote:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
> news:Xns9590BA7D8D3F3asu1cornelledu@132.236.56.8: 
> 
>>>         $offset += 16;
>>>     }
>>
>>You don't return anything from this sub. Since you are calling the sub
>>in list context, print is called with an empty list.
> 
> OOOOOPS!!!! Clearly, the last value of $offset will be returned from this 
> subroutine.

Nope.

     sub hdump {
         my $offset;
         for (1..3) {
             $offset += 5;
         }
     };

     print '[', hdump(), "]\n";

Outputs:
[]

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 28 Oct 2004 23:58:08 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: print FILE function()
Message-Id: <Xns9590CB22D5FAasu1cornelledu@132.236.56.8>

Paul Lalli <mritty@gmail.com> wrote in
news:cls0he$1k8$1@misc-cct.server.rpi.edu: 

> A. Sinan Unur wrote:
>> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
>> news:Xns9590BA7D8D3F3asu1cornelledu@132.236.56.8: 
>> 
>> 
>>>>         $offset += 16;
>>>>     }
>>>
>>>You don't return anything from this sub. Since you are calling the
>>>sub in list context, print is called with an empty list.
>> 
>> OOOOOPS!!!! Clearly, the last value of $offset will be returned from
>> this subroutine.
>> 
>> Sorry about that.
>> 
>> Sinan.
> 
> I'm pretty sure you were right the first time...


 ... snipped code that shows the sub did not return anything ...

> Am I missing something?

The fact that I am so out of it right before the second midterm exams that 
yesterday, I posted my micro economics class notes on my stats class web 
site and stats notes on my micro economics web site. You should have seen 
the confusion that created among my students :)

 Hence, when I saw Eric Bohlman's message 
(news:Xns9590B2A013B01ebohlmanomsdevcom@130.133.1.4), I immediately assumed 
I had made an error.

One more apology ... I'll try to stop now :)

Sinan.


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

Date: 29 Oct 2004 00:24:45 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: print FILE function()
Message-Id: <Xns9590C6790E25ebohlmanomsdevcom@130.133.1.4>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news:2udf5jF28qlhoU1@uni-berlin.de: 

> A. Sinan Unur wrote:
>> OOOOOPS!!!! Clearly, the last value of $offset will be returned from
>> this subroutine.
> 
> Nope.
> 
>      sub hdump {
>          my $offset;
>          for (1..3) {
>              $offset += 5;
>          }
>      };
> 
>      print '[', hdump(), "]\n";
> 
> Outputs:
> []

Hmmm.  *Why* this behavior?  It doesn't strike me as consistent with the 
documentation in perlsub:

The return value of a subroutine is the value of the last expression 
evaluated by that sub, or the empty list in the case of an empty sub. More 
explicitly, a return statement may be used to exit the subroutine, 
optionally specifying the returned value, which will be evaluated in the 
appropriate context (list, scalar, or void) depending on the context of the 
subroutine call. If you specify no return value, the subroutine returns an 
empty list in list context, the undefined value in scalar context, or 
nothing in void context. If you return one or more aggregates (arrays and 
hashes), these will be flattened together into one large indistinguishable 
list.

Experimentation makes it *look* like expressions enclosed in a for(), 
while(), or do() loop are "lost" as far as return values are concerned.  
Expressions enclosed in a bare block after the loop are "kept," as well as 
expressions in statements governed by modifiers.  Expressions evaluated 
before a loop are "lost."  A loop loses the last expression even if it 
doesn't execute (while(0)).

Am I missing some place where this behavior is documented?


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

Date: 29 Oct 2004 00:41:03 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: print FILE function()
Message-Id: <Xns9590D2692FA57asu1cornelledu@132.236.56.8>

Eric Bohlman <ebohlman@omsdev.com> wrote in
news:Xns9590C6790E25ebohlmanomsdevcom@130.133.1.4: 

> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
> news:2udf5jF28qlhoU1@uni-berlin.de: 
> 
>> A. Sinan Unur wrote:
>>> OOOOOPS!!!! Clearly, the last value of $offset will be returned from
>>> this subroutine.
>> 
>> Nope.
>> 
>>      sub hdump {
>>          my $offset;
>>          for (1..3) {
>>              $offset += 5;
>>          }
>>      };
>> 
>>      print '[', hdump(), "]\n";
>> 
>> Outputs:
>> []
> 
> Hmmm.  *Why* this behavior?  It doesn't strike me as consistent with
> the documentation in perlsub:

 ...

> Experimentation makes it *look* like expressions enclosed in a for(), 
> while(), or do() loop are "lost" as far as return values are
> concerned.  Expressions enclosed in a bare block after the loop are
> "kept," as well as expressions in statements governed by modifiers. 
> Expressions evaluated before a loop are "lost."  A loop loses the last
> expression even if it doesn't execute (while(0)).
> 
> Am I missing some place where this behavior is documented?

I don't know if it is documented anywhere, but the reason it seemed 
intuitively obvious to me (and therefore, the reason I posted my original 
response) was that the last statement that is executed in the sub is the 
condition of the loop. When that condition evaluates to false, the loop 
terminates. In list context, in which the subroutine itself was being 
evaluated, that would naturally yield an empty list.

However, I tend to be consistently wrong when I find something "intuitively 
obvious", so take this with a grain of salt.

Sinan.


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

Date: Thu, 28 Oct 2004 22:14:50 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Should I use BEGIN, CHECK, or INIT?
Message-Id: <a34852-uch.ln1@osiris.mauzo.dyndns.org>


Quoth abigail@abigail.nl:
> It's not entirely clear to me when (or if) an INIT in a module is run.
> Is that just before runtime of the main program, or just before runtime
> of the module?

All INIT blocks parsed during the main script's compile time (the call
to perl_parse) are queued, and are run in FIFO order at the beginning of
perl_run. INIT blocks parsed after perl_run has started are never run.
Thus, if a used module defines an init block, it will be run at the
beginning of the execution of the main script (well after the use
statement has finished); if a required one defines one it will never be
run.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: 28 Oct 2004 23:39:58 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: What are these extra spaces in my registry?
Message-Id: <Xns9590C80DCF98Fasu1cornelledu@132.236.56.8>

Brian McCauley <nobull@mail.com> wrote in
news:clr99f$ia4$1@sun3.bham.ac.uk: 

> A. Sinan Unur wrote:

>> the native character set of Win2K is 16 bits wide (I do not 
>> think it is UTF-16, if such a thing exists).
> 
> Er, no.  On recent Windows the native character set is Unicode (which
> is wider than 16 bits) and the native encoding is UTF-16.  UTF-16
> exists is two flavours BE or LE and I can't recall which Win32 uses 
> but it  doesn't matter because Perl will autodetect.

Ah! Thank you for the correction.

Sinan.


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

Date: Thu, 28 Oct 2004 22:19:38 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: What are these extra spaces in my registry?
Message-Id: <ac4852-uch.ln1@osiris.mauzo.dyndns.org>


Quoth Brian McCauley <nobull@mail.com>:
>
> Er, no.  On recent Windows the native character set is Unicode (which is 
> wider than 16 bits) and the native encoding is UTF-16.  UTF-16 exists is 
>   two flavours BE or LE and I can't recall which Win32 uses but it 
> doesn't matter because Perl will autodetect.

LE with BOM, as Intel processors are LE. This means you should use
utf16, not utf16le, as utf16le will return the BOM as a character.

Perl can only autodetect if the text has a BOM, BTW, so in general (say,
some text in the middle of a file) it can't.

Ben

-- 
        I must not fear. Fear is the mind-killer. I will face my fear and
        I will let it pass through me. When the fear is gone there will be 
        nothing. Only I will remain.
ben@morrow.me.uk                                          Frank Herbert, 'Dune'


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

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


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