[23068] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5289 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 29 18:06:04 2003

Date: Tue, 29 Jul 2003 15:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 29 Jul 2003     Volume: 10 Number: 5289

Today's topics:
    Re: Calculate directorysize from a list? <usenet@dwall.fastmail.fm>
    Re: Calculate directorysize from a list? (Math55)
    Re: Calculate directorysize from a list? <usenet@dwall.fastmail.fm>
        Can't load DBI module <raymond.chui@noaa.gov>
        Driving me mad.  Can't see the error in this code... <Ed+nospam@ewildgoose.demon.co.uk@>
    Re: Driving me mad.  Can't see the error in this code.. <jwillmore@cyberia.com>
        embedding a module in a script <tim_dietrich@agilent.com>
    Re: Gnuplot module <slaven@rezic.de>
    Re: Help with parsing text file (Tad McClellan)
    Re: How do you Call a Perl subroutine with a variable n <grazz@pobox.com>
    Re: How do you Call a Perl subroutine with a variable n <nobull@mail.com>
    Re: How do you Call a Perl subroutine with a variable n <nobull@mail.com>
    Re: How do you Call a Perl subroutine with a variable n <uri@stemsystems.com>
    Re: How do you Call a Perl subroutine with a variable n <noreply@gunnar.cc>
    Re: How do you Call a Perl subroutine with a variable n <grazz@pobox.com>
        How to print out the value of a Cookie? <marmot101@yahoo.com>
        HTML / text parsing - best module(s) to use? (Unknown Poster)
    Re: Is there a clean way to export all constants from a <stevea@wrq.com>
    Re: perl problem on windows <rpl-erroroneous@goldengate.net>
    Re: Perl training resources? <Bill_Fields@azb.uscourts.gov>
    Re: Perl training resources? (Tad McClellan)
    Re: porting perl scripts from NT to UNIX <potnuru@students.uiuc.edu>
    Re: Sorting out sort (James E Keenan)
        zero but true? <bill_knight2@yahoo.com>
    Re: zero but true? <asu1@c-o-r-n-e-l-l.edu>
    Re: zero but true? (Tad McClellan)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 29 Jul 2003 18:55:53 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Calculate directorysize from a list?
Message-Id: <Xns93C797E47CC47dkwwashere@216.168.3.30>

Tad McClellan <tadmc@augustmail.com> wrote:

>>   my ($size, $dir) = split;
> 
> That will fail for pathes that contain spaces.
> 
>>   my @f = split /\//, $dir;
> 
> That will fail on systems that use some other directory separator.
> 
>    use File::Basename;
> 
> will fail in neither case.


How about this little demo program?  It still depends on '/' being 
the root directory, though.

I think it does what the OP wants, but more eyeballs might see 
something I missed.



use strict;
use warnings;
use File::Basename;

my %dir_total;
while (<DATA>) {
    chomp;
    next unless /^(\S+)\s+(\S+.*)$/;  # skip invalid input
    my ($size, $filename) = ($1, $2);
    my $bytes = toBytes($size);
    my $path = dirname $filename;
    while ($path) {
        $dir_total{$path} += $bytes;
        last if $path eq '/';   # stop when we reach the root
        $path = dirname $path;
    }
}

use Data::Dumper;
print Dumper \%dir_total; # I didn't want to write an output routine

sub toBytes {
    my $size = shift;
    if ( $size =~ /^(\d+)(.?)$/ ) {
        return $1                if $2 eq '';
        return $1*1024           if $2 eq 'k';
        return $1*1024*1024      if $2 eq 'M';
        return $1*1024*1024*1024 if $2 eq 'G';
    }
    warn "Unexpected input to toBytes: '$size'";
    return 0;   # may not be what you want
}

__DATA__
528k	/tmp/icons/4599-OS-X-GamePak.tar.gz
244k	/tmp/icons/4780-OS-Logos.tar.gz
744k	/tmp/icons/5042-XP-iCandy2.zip
123k    /tmp/icons/test/hallo.txt
456k    /tmp/icons/test/hallo1.doc


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

Date: 29 Jul 2003 13:52:15 -0700
From: magelord@t-online.de (Math55)
Subject: Re: Calculate directorysize from a list?
Message-Id: <a2b8188a.0307291252.f8c24c5@posting.google.com>

"David K. Wall" <usenet@dwall.fastmail.fm> wrote in message news:<Xns93C797E47CC47dkwwashere@216.168.3.30>...
> Tad McClellan <tadmc@augustmail.com> wrote:
> 
> >>   my ($size, $dir) = split;
> > 
> > That will fail for pathes that contain spaces.
> > 
> >>   my @f = split /\//, $dir;
> > 
> > That will fail on systems that use some other directory separator.
> > 
> >    use File::Basename;
> > 
> > will fail in neither case.
> 
> 
> How about this little demo program?  It still depends on '/' being 
> the root directory, though.
> 
> I think it does what the OP wants, but more eyeballs might see 
> something I missed.
> 
> 
> 
> use strict;
> use warnings;
> use File::Basename;
> 
> my %dir_total;
> while (<DATA>) {
>     chomp;
>     next unless /^(\S+)\s+(\S+.*)$/;  # skip invalid input
>     my ($size, $filename) = ($1, $2);
>     my $bytes = toBytes($size);
>     my $path = dirname $filename;
>     while ($path) {
>         $dir_total{$path} += $bytes;
>         last if $path eq '/';   # stop when we reach the root
>         $path = dirname $path;
>     }
> }
> 
> use Data::Dumper;
> print Dumper \%dir_total; # I didn't want to write an output routine
> 
> sub toBytes {
>     my $size = shift;
>     if ( $size =~ /^(\d+)(.?)$/ ) {
>         return $1                if $2 eq '';
>         return $1*1024           if $2 eq 'k';
>         return $1*1024*1024      if $2 eq 'M';
>         return $1*1024*1024*1024 if $2 eq 'G';
>     }
>     warn "Unexpected input to toBytes: '$size'";
>     return 0;   # may not be what you want
> }
> 
> __DATA__
> 528k	/tmp/icons/4599-OS-X-GamePak.tar.gz
> 244k	/tmp/icons/4780-OS-Logos.tar.gz
> 744k	/tmp/icons/5042-XP-iCandy2.zip
> 123k    /tmp/icons/test/hallo.txt
> 456k    /tmp/icons/test/hallo1.doc



hi, i will try that tomorrow. here is a program that uses the 3
methods. justopen a new filehandle to a file that looks like i said!

---
#! /usr/local/bin/perl

    use strict;
    use warnings;

    use File::Basename;

    sub to_bytes {
        my $size = shift;

        if ($size =~ s/k$//) {
            $size *= 1024;
        }
        elsif ($size =~ s/M$//) {
            $size *= 1024 * 1024;
        }

        $size;
    }

    sub to_unit {
        my $size = shift;

        if ($size > 1024 * 1024) {
            $size = sprintf "%.1fM", $size / (1024*1024);
        }
        elsif ($size > 1024) {
            $size = sprintf "%.1fk", $size / 1024;
        }

        $size;
    }

    ## main
    my %size;
    my @files = <DATA>;

    for (@files) {
        chomp;
        my($size,$path) = split;

        my $bytes = to_bytes $size;
        my $dir = dirname $path;
        $size{$dir} += $bytes;
    }

    # pass two: zap subdirs from parents' totals
    for (@files) {
        chomp;
        my($size,$path) = split;

        next unless exists $size{$path};

        my $dir = dirname $path;
        my $bytes = to_bytes $size;
        $size{$dir} -= $bytes;
    }

    for (sort { $a cmp $b } keys %size) {
        print "$_ - ", to_unit($size{$_}), "\n";
    }

    __DATA__
    32k     /var/log/XFree86.0.log
    76k     /var/log/auth.log
    116k    /var/log/auth.log.0
    8.0k    /var/log/auth.log.1.gz
    228k    /var/log/kdm.log
    20k     /var/log/kern.log
    1.2M    /var/log/kern.log.0
    12k     /var/log/kern.log.1.gz
    2.8M    /var/log/ksymoops
    228k    /var/log/ksymoops/20030628062520.ksyms
    4.0k    /var/log/ksymoops/20030628062520.modules
    228k    /var/log/ksymoops/20030629062502.ksyms
    4.0k    /var/log/ksymoops/20030629062502.modules
    12k     /var/log/ksymoops/20030630.log
    228k    /var/log/ksymoops/20030630062525.ksyms
    4.0k    /var/log/ksymoops/20030630062525.modules
    12k     /var/log/ksymoops/20030701.log
    228k    /var/log/ksymoops/20030701062504.ksyms

---

how must i change the code so it works with this implementation?
thanks :)


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

Date: Tue, 29 Jul 2003 22:00:11 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Calculate directorysize from a list?
Message-Id: <Xns93C7B723587DAdkwwashere@216.168.3.30>

Math55 <magelord@t-online.de> wrote:

> how must i change the code so it works with this implementation?
> thanks :)

Pay me lots of money and I'll do it for you.  Otherwise, spend a few 
minutes reading the code.  It's not exactly complicated, and besides it 
may not even do what you want.  If you understand Greg Bacon's code[1] 
then what I posted should present no problem.

(I didn't notice the thread from several weeks ago about this problem 
until after I had posted.)

[1] Message-ID: <vg8iancknatk3c@corp.supernews.com>


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

Date: Tue, 29 Jul 2003 16:00:52 -0400
From: RC <raymond.chui@noaa.gov>
Subject: Can't load DBI module
Message-Id: <bg6ljd$1n1$1@news.nems.noaa.gov>

I used REdhat Linux 7.2 for PostgreSQL 7.1.3
database

I installed DBI and DBD modules without problem.
But when I test it by

PER_DL_DEBUG=255
perl -e 'use DBI;'

I got

Can't locate loadable object for module DBI in @INC (@INC contains: 
/usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5
/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 
/usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 /us
r/lib/perl5/site_perl .) at 
/usr/lib/perl5/site_perl/5.6.1/i386-linux/DBI.pm line 255
BEGIN failed--compilation aborted at 
/usr/lib/perl5/site_perl/5.6.1/i386-linux/DBI.pm line 255.

But when I run these two lines as root (super user), I don't
got above error messages.

The correct output should be look like

DynaLoader.pm loaded (/usr/lib/perl5/5.6.1/i386-linux 
/usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux 
/usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux 
/usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl ., 
/usr/local/lib /lib /usr/lib)
DynaLoader::bootstrap for DBI (auto/DBI/DBI.so)

I run these two lines in a different REdhat Linux 7.2 machine.

I checked the DynaLoader.pm, DBI.pm and DBI.so files,
they are all inatalled there.
Do you think something missing with the perl dynamic loader?
Or I have missing something?

If you know how to set up this, please let me know.
I can't access USENET news groups all the time.
So, can you also Cc to me when you follow up this?



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

Date: Tue, 29 Jul 2003 18:21:31 GMT
From: "Edward Wildgoose" <Ed+nospam@ewildgoose.demon.co.uk@>
Subject: Driving me mad.  Can't see the error in this code...
Message-Id: <LWyVa.1203890$ZC.175922@news.easynews.com>

I'm trying to track down a problem with my TWiki installation on windows
which is driving me nuts.  I have traced it to the rcs command which is run,
but which does nothing via perl, but runs fine from the windows command
prompt.

I have a skeleton piece of code here which demonstrates the problem

>>>>>>>
use strict;

    my $cmd =
'z:/twikiUnixSupportFiles/ci -x,v -q -l -m"none" -t-none -w"edward"
z:/twiki/data/Sandbox/TestTopic4.txt 2>&1';
    my $rcsOutput = `$cmd`; # capture stderr  (S.Knutson)
    print $rcsOutput;
>>>>>>>>>

I suspected a shell quoting issue, so I changed the command to be 'echo
z:/twiki/etc etc' and then look at the output variable, but this still
executes fine if I copy and paste it into a windows command prompt...

If I create a deliberate error, eg mis-spell the file name then I do get
back an error from the command (so I am capturing stdout), however, when
running the correct command above I get no output back, but equally no rcs
checkin file is actually created....

Is this a "ci" problem?  If so, why might it execute correctly from the cmd
prompt, but not from perl?  Am I doing something strange in the code above?

This is all running on Perl 5.8 under Windows 2K

Thanks for any insight, getting bored of looking at this now...

Ed




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

Date: Tue, 29 Jul 2003 19:54:32 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Driving me mad.  Can't see the error in this code...
Message-Id: <20030729155609.56f3c995.jwillmore@cyberia.com>

> I'm trying to track down a problem with my TWiki installation on
> windows which is driving me nuts.  I have traced it to the rcs
> command which is run, but which does nothing via perl, but runs fine
> from the windows command prompt.
> 
> I have a skeleton piece of code here which demonstrates the problem
> 
> >>>>>>>
> use strict;
> 
>     my $cmd =
> 'z:/twikiUnixSupportFiles/ci -x,v -q -l -m"none" -t-none -w"edward"
> z:/twiki/data/Sandbox/TestTopic4.txt 2>&1';
>     my $rcsOutput = `$cmd`; # capture stderr  (S.Knutson)
>     print $rcsOutput;
> >>>>>>>>>

This is just a guess, but is the code example EXACTLY as it is in the
script?  Complete with the command on separate lines (same scalar
variable, but on separate lines for readability)?  If so, I'm guessing
that the command, since you're using single quotes, may be interpreted
as as:

 'z:/twikiUnixSupportFiles/ci -x,v -q -l -m"none" -t-none -w"edward"
<CR> <= a carriage return, aka return key
 z:/twiki/data/Sandbox/TestTopic4.txt 2>&1';

Try:

my $cmd = 'z:/twikiUnixSupportFiles/ci -x,v -q -l -m"none" -t-none
-w"edward" ';
$cmd .=  'z:/twiki/data/Sandbox/TestTopic4.txt 2>&1';

This way, the command is all on one line (which is probably the way
you're running it at the command line).  In the Unix world, when you
want to type a long command and want it on two separate lines, you put
a '\' at the end of each line - so the shell knows you're continuing
the line.  I'm not sure if there's an equivalent in Windows.

Again, this is just a guess.

HTH

Jim


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

Date: Tue, 29 Jul 2003 15:01:36 -0700
From: Timothy Dietrich <tim_dietrich@agilent.com>
Subject: embedding a module in a script
Message-Id: <3F26EEC0.94C076ED@agilent.com>

I have a need to embed a module in a perl script. Basically, I want to
cut and paste the contents of the module directly into my script, but
otherwise have the script and module interact in the same way as if the
module and script were in different files.

The script in question is used to set up installs and deinstalls of my
application, which consists of a suite of perl scripts and some custom
modules. The setup script needs to leverage some of the custom modules
in my application, but the setup script needs to be completely self
contained so that it can be distributed as a single file. Tarballs and
the like are not an option. I also want to avoid having to fully specify
which package a variable of subroutine resides in when I call it i.e.
I want to import any of the modules exported symbols into my scripts
name space, just like it would if the module was in a separate file and
I was loading it with a "use" statement.

From the Perl documentation, I thought the following code would work,
but it just aborts with undefined subroutine errors for &main::a and
&main::b in the main body of the script. Does anyone have any solutions
that will enable me to do what I want?

-Tim-

#!/usr/bin/perl

# First module
package ModuleA;
use strict;
require Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA         = qw(Exporter);
@EXPORT      = qw(&a);

sub a
{
  print "This is function a.\n";
}

1;

#-------------------------------

# Second module
package ModuleB;
use strict;
require Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA         = qw(Exporter);
@EXPORT      = qw(&b);

sub b
{
  print "This is function b.\n";
}

1;

#-------------------------------

# Main body of script
package main;
use strict;
BEGIN
{
  import ModuleA;
  import ModuleB;
}

&a();

&b();




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

Date: 28 Jul 2003 21:31:03 +0200
From: Slaven Rezic <slaven@rezic.de>
Subject: Re: Gnuplot module
Message-Id: <87ispm1ma0.fsf@vran.herceg.de>

yuchung@mail.com (Yuchung Cheng) writes:

> alythh@netscape.net (Alythh) wrote in message news:<6a25ba72.0307230050.57da7475@posting.google.com>...
> > I just installed  Chart::Graph::Gnuplot, and I'm fairly satisfied.
> > But...
> > 
> > My wish is to be able to make a  gnuplot() call, make it display the
> > graph, and stay there while other data becomes available... while
> > replotting the updated data.
> > 
> > Is there a way to communicate between the two processes in this way?
> > Or is this module just to output to a file?
> > 
> AFAIK, gnuplot only parse static data and generate the graph, even with
> "gnuplot -persist" command. The simplist way to do above is to call 
> gnuplot every once while and re-plot to the same file. 

No, it's perfectly possible to open a communication channel via
IO::Pipe and to send multiple commands to gnuplot. Example code on
demand.

Regards,
	Slaven

-- 
Slaven Rezic - slaven@rezic.de

    tknotes - A knotes clone, written in Perl/Tk.
    http://ptktools.sourceforge.net/#tknotes


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

Date: Tue, 29 Jul 2003 15:46:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help with parsing text file
Message-Id: <slrnbidn8p.4fa.tadmc@magna.augustmail.com>

Kent <kstairley@coppernospam.com> wrote:

> can I pass $ARGV[1] instead of myfile.txt as
> the file to open?


What happened when you tried it?





[ snip TOFU. Please do not do that anymore. ]


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


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

Date: Tue, 29 Jul 2003 18:09:46 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <KLyVa.16040$AO6.7313@nwrdny02.gnilink.net>

Tad McClellan <tadmc@augustmail.com> wrote:
> Fred <fred.illig@lmco.com> wrote:
> 
>> I want to call this subroutine
>> (x) via an array element - @array = (a,b,c,x,y,z);
>> ($outvar1, $outvar2) = &$array[3]($invar1,$invar2,$invar3);
> 
> Use a "dispatch table".
> 
>> How do I make a call to a subroutine where the name of the
>> subroutine to be called is being derived from an element in
>> an array?  
> 
> By using "symbolic references".
> 
> But *don't do that*!

Is this guilt-by-association or is there a problem here that
I can't see?

    @soft = qw(a b c);
    @hard = (\&a, \&b, \&c);

    $soft[1]->();
    $hard[1]->();

What's the difference?

If b() doesn't exist they both die with the same (runtime)
error.  If b() does exist they both succeed.  If b() wasn't
what you thought it would be, they both quietly do something
unexpected.

Now:

If @soft comes from user input, then sure, it's stupid.
But the OP hasn't done that.

If he needed to pass the code reference to another package,
then the unqualified symrefs just won't work.

And of course, if somebody reads this and thinks that *all*
symrefs must therefore be safe, then I screwed up.

But what else is there?

-- 
Steve (actually curious)



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

Date: 29 Jul 2003 19:15:59 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <u9znixgpwg.fsf@wcl-l.bham.ac.uk>

Uri Guttman <uri@stemsystems.com> writes:

> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
> 
>   BM> Even Uri has fallen into this trap in the past:
>   BM>   Message-ID: <u91ypd62ze.fsf@wcl-l.bham.ac.uk>
>   BM>   http://groups.google.com/groups?selm=u91ypd62ze.fsf%40wcl-l.bham.ac.uk
> 
> heh!
> 
> symbolic lookups of methods are not the same as with plain subs.

Actually thay are in Perl (ignoring @INC and UNIVERSAL::).

> in fact that is called late binding and is used by polymophism.
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Renaming somthing doesn't make it something different.           

This is a pointless semantic argument.

It is also irrelvant.

If you look at the aforementioned thread you'll see it is nothing to
do with actually performing method lookups.  You proposed fooling Perl
into thinking that you were doing a method lookup in order to suppress
strict refs.  I somehow doubt that's something you'd really intend to
propose - I'd guess you were having a bad day.

>   >> If you have several subroutines that you want to call that way, you
>   >> should really consider a dispatch table as Tad illustrated. But if you
>   >> only have one, the above is a convenient solution IMO.
> 
>   BM> But the OP _is_ using a dispatch table.  @array is a dispatch table.
>   BM> It's just a dispatch table using symrefs.
> 
> then amend that to a dispatch table using hard refs.

Er, I think that was my point.  Since there is a dispatch table anyhow
whatever arguments could possbily have been put forward for "symrefs
are simpler than using a dispatch table" are moot. 

> in general when people say dispatch tables here they mean
> with code refs and not symbolic.
 
Yes verily.  (Unless, of course, when they are methods, which as we've
already said are always symbolic in Perl).

But when a proponent of symrefs says "If you have several subroutines
that you want to call that way, you should really consider a dispatch
table as Tad illustrated. But if you only have one, the above is a
convenient solution" I think it is pertenant to point out that "the
above" was infact a dispatch table but using symrefs.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 29 Jul 2003 19:20:27 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <u9u195gpp0.fsf@wcl-l.bham.ac.uk>

fred.illig@lmco.com (Fred) spits TOFU in Tad's face:

> Thanks

Please express your thanks by learning how to quote properly.

Failure to do not only makes you appear rude and arrogant but may even
cause you get "killfiled" (your posts are automatically ignored) by
many of the most knowledgable people here.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 29 Jul 2003 18:36:03 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <x7brvdp4do.fsf@mail.sysarch.com>

>>>>> "SG" == Steve Grazzini <grazz@pobox.com> writes:

  >> By using "symbolic references".
  >> 
  >> But *don't do that*!

  SG> Is this guilt-by-association or is there a problem here that
  SG> I can't see?

  SG>     @soft = qw(a b c);
  SG>     @hard = (\&a, \&b, \&c);

  SG>     $soft[1]->();
  SG>     $hard[1]->();

  SG> What's the difference?

  SG> If b() doesn't exist they both die with the same (runtime)
  SG> error.  If b() does exist they both succeed.  If b() wasn't
  SG> what you thought it would be, they both quietly do something
  SG> unexpected.

  SG> If @soft comes from user input, then sure, it's stupid.
  SG> But the OP hasn't done that.

that is the big pitfall. why convert a string to a string and then call
the sub? so some will just bypass the dispatch table and call the sub
passed in from outside. boom!

and allowing that (even conceptually) can lead to symrefs for vars and
data structures where they are truly bad.

so the hard ref dispatch table converts strings to code refs which is a
full transformation and safer both in theory and practice (to drag in
another thread :).

  SG> And of course, if somebody reads this and thinks that *all*
  SG> symrefs must therefore be safe, then I screwed up.

that is a major point to consider. but as i said, a symref dispatch
table does little more than string to string conversion. you might as
well just add a suffix to the name and call that sub symbolicly and skip
the table. that is not a good idea. the table is there to prevent
calling any random sub by name. it is a user level restriction on what
subs are allowed. all calls though a dispatch table should check if the
sub exists (a boolean check on the resulting code ref is fine) and die
or call a default code ref.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 29 Jul 2003 21:42:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <bg6irh$lfs54$1@ID-184292.news.uni-berlin.de>

Brian McCauley wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>>It should be noted that I'm not using a symbolic reference (in that
>>case Perl would have complained, since I run it under "strict
>>refs"),
> 
> As is says in perldoc strict..
> 
>       ""strict refs""
>              This generates a runtime error if you use symbolic
>              references (see the perlref manpage).
>                [snip]
>              There is one exception to this rule:
> 
>                  $bar = \&{'foo'};
>                  &$bar;
> 
> You _are_ using a symbolic reference but you are doing so in a way
> that is explicitly exempted from "strict refs".

Hmm.. Obviously I am. Thanks for pointing it out. Seems as if I need 
to read more about it.

However, in the meantime, can somebody explain why (or rather _how_) 
the following code works:

     sub x { print "'sub x' was called via \$coderef->().\n" }
     my $function = 'x';
     my $coderef = \&$function;
     $function = "The value of \$function is no longer 'x'.\n";
     print $function;
     $coderef->();

As far as I can see, $coderef behaves like a real reference.

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



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

Date: Tue, 29 Jul 2003 20:27:25 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <NMAVa.3$cI2.1@nwrdny01.gnilink.net>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>      sub x { ... }
>      my $function = 'x';
>      my $coderef = \&$function;
> 
> As far as I can see, $coderef behaves like a real reference.

That's because it *is* a real ("hard") reference.

Maybe an analogy will help:

    $$soft       => smoking in bed
    $$hard       => smoking in a bar
    ${ \$$soft } => smoking in bed, in a bar

HTH!
-- 
Steve


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

Date: Tue, 29 Jul 2003 15:28:42 -0400
From: "marmot101" <marmot101@yahoo.com>
Subject: How to print out the value of a Cookie?
Message-Id: <BVzVa.78$xq3.40414@news.uswest.net>

Hi, All,

Using CGI, I get a response from server which plant a Cookie in client
machine. Now I can get this Cookie, but I don't know how to print out the
value of this Cookie? I checked online manual, but seems none method works.
Can anyone help me?

Many thanks!

marmot101

############## My Source Code ####################
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Cookies;
use HTTP::Request::Common qw(POST);

my $agent = LWP::UserAgent->new();

my $url = 'http://***';
my $content = [ 'UserName' => '***', 'Password' => '***' ];
my $request = POST $url, $content;

my $response = $agent->request($request);

if ($response->is_success) {
 print "Yes, it is success\n";
 print $response->content;

 $cookie_jar = new HTTP::Cookies->new;
 $cookie_jar->extract_cookies($response);

# How to print out value of Cookie here?
# print "Cookie = ", $cookie_jar{'Stamp'}->value;   # doesn't work
}




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

Date: 29 Jul 2003 14:16:00 -0700
From: use63net@yahoo.com (Unknown Poster)
Subject: HTML / text parsing - best module(s) to use?
Message-Id: <c62e93ec.0307291316.4ac76339@posting.google.com>

Assuming I have used LWP to get an HTML document into a response
object, I'd like to know what module(s) to use for the following task.
I would like to disregard the content of HTML tags (that is, everything
in angled brackets) and then break the "real" text into words so that
I can do a frequency count, etc.

   Would someone experienced in this sort of task recommend
a combination of the following (or others I may have missed) ?

   Text::WordParse
   HTML::Parse
   HTML::Parser
   HTML::PullParser
   HTML::TokeParser


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

Date: Tue, 29 Jul 2003 19:08:07 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Is there a clean way to export all constants from a module?
Message-Id: <u7k61kv6x.fsf@wrq.com>

Bart,

Bart Lateur <bart.lateur@pandora.be> writes:

>Steve Allan wrote:
>
>>I'm creating a module for the sole purpose of defining constants to be
>>shared among several Perl scripts.  I'm looking for a way to simplify
>>getting all the constant names into the @EXPORT_OK array, so I don't
>>end up with this:
>>
>>@EXPORT_OK = qw(CURRENTCHANGE BLDNUM STAGEROOTDIR ...);
>>
>>because I can envision that list becoming large, and everytime I
>>define a new constant I have to remember to add it to the list.
>
>That's not your only problem. Every script using this module will also
>have to be changed to include this constant in it's use statement. Or is
>that not a problem? If you don't use a constant, you don't need to
>import it...
>
>But anyway: there's a way to group these names into a tag, for example
>":constants", and all you have to do to import them all, is call
>
>	use Foo qw(:constants);

This works very nicely!  By combining your suggestion with Jay's I have
exactly what I was after.

Thanks.

-- 
-- Steve


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

Date: Tue, 29 Jul 2003 13:51:43 -0500
From: "Bob" <rpl-erroroneous@goldengate.net>
Subject: Re: perl problem on windows
Message-Id: <3f26c214$0$104$8f4e7992@newsreader.goldengate.net>

"Fong Tsui" <f.tsui@f5.com> wrote in message
news:e7ffa9a7.0307290901.3619360c@posting.google.com...
> "dw" <me@verizon.invalid> wrote in message
news:<opnVa.21285$FP5.19256@nwrddc02.gnilink.net>...
> > "mgarrish" <mgarrish@rogers.com> wrote in message
> > news:dNlVa.110419$zwL.58270@news04.bloor.is.net.cable.rogers.com...
> > >
> > > "dw" <me@verizon.invalid> wrote in message
> > > news:L4kVa.19523$FP5.5834@nwrddc02.gnilink.net...
> > > >
[snip a lot ]

> Thanks for all inputs.
> I've tried what suggested. If there is space within an arg, it doesn't
work.

I am using w2k perl 5.6.1.633, and I can not get it to work with a space in
it, also.
It works without the space for me.

so I thought I would upgrade to perl 5.8  and that started another whole set
of problems with the install.





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

Date: Tue, 29 Jul 2003 11:39:07 -0700
From: "William Fields" <Bill_Fields@azb.uscourts.gov>
Subject: Re: Perl training resources?
Message-Id: <bg6f0e$ih7$1@apollo.nyed.circ2.dcn>

> Ultimately, you're only going to learn the language by playing with it,
and
> Perl lets you jump right into the deep end (whether that's a good thing or
a
> bad thing depends on how much common sense you have and how often you back
> up your files).

Yeah, I figured as much. What I'm looking for though is a way to reduce the
trial/error cycle and learn from other's experiences in a concise manner
(you know, best-practices and all that). I'm sure I could glean everything
from google, but I seem to ramp-up on a new language more quickly with a
little structure.

Are there monthly hardcopy publications for Perl (how to/tips/tricks etc..)?

-- 
William Fields
MCSD - Microsoft Visual FoxPro
MCP - Win2k Pro
US Bankruptcy Court
Phoenix, AZ

The secret to creativity is knowing how to hide your sources.

        - Albert Einstein


"mgarrish" <mgarrish@rogers.com> wrote in message
news:QLjVa.109431$zwL.56076@news04.bloor.is.net.cable.rogers.com...
>
> "William Fields" <Bill_Fields@azb.uscourts.gov> wrote in message
> news:bg4dvr$s06$1@apollo.nyed.circ2.dcn...
> >
> > If there are no local Perl training resources in the Phoenix, Arizona
> area,
> > could someone suggest alternate training methods (CBT, videos, hands on
> > books etc...)
> >
>
> Perl is a remarkably simple language to learn, and unlike some other
> languages, the documentation tends to be very good (although sorely
lacking
> in practical examples at times, groups.google.com usually makes up for
this
> deficiency). A copy of Programming Perl is all you really need to get
going
> (plus the docs, see www.perldoc.com if you don't know where they are on
your
> computer). You probably won't get a whole lot more out of the O'Reilly
books
> (www.oreilly.com) that you can't get for free online, but if you prefer
> reading from a book they're usually very good (I can't vouch for some of
the
> newer ones though, as the Tk book, in particular, is a bit of a rag). If
you
> want hands-on, just read the newsgroups, try solving the problems people
> post and see how close your answers come to those that get posted.
>
> Ultimately, you're only going to learn the language by playing with it,
and
> Perl lets you jump right into the deep end (whether that's a good thing or
a
> bad thing depends on how much common sense you have and how often you back
> up your files).
>
> Matt
>
>




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

Date: Tue, 29 Jul 2003 15:42:28 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl training resources?
Message-Id: <slrnbidn1k.4fa.tadmc@magna.augustmail.com>

William Fields <Bill_Fields@azb.uscourts.gov> wrote:

> Are there monthly hardcopy publications for Perl (how to/tips/tricks etc..)?


   http://www.tpj.com/

Not hardcopy.

Wildly useful nonetheless.

Why impose such arbitrary restrictions?


   http://www.stonehenge.com/merlyn/columns.html

Also not hardcopy.

Not monthly.

Also chock full of useful tips and code.


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


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

Date: Tue, 29 Jul 2003 13:26:12 -0500
From: mani srinivas potnuru <potnuru@students.uiuc.edu>
Subject: Re: porting perl scripts from NT to UNIX
Message-Id: <Pine.GSO.4.31.0307291308060.25837-100000@ux13.cso.uiuc.edu>

>
> "mani srinivas potnuru" <potnuru@students.uiuc.edu> wrote in message
> news:Pine.GSO.4.31.0307282029080.9550-100000@ux13.cso.uiuc.edu...
> >
> > Hi,
> > I am newbie to Perl in general. But i need to port a perl script which
> > uses WIN32 API to unix. I am wondering if anybody has some pointers about
> > how to go about this task.
> >
>
> You can't port Win32::API to Unix ..... so for a start you have to write the
> script so that it doesn't 'use Win32::API;' (or any other Win32 module).
>
> Beyond that, I don't think there are any *general* pointers - it depends
> upon what the script actually does.
>
> Cheers,
> Rob

Thanks for the reply Rob.
One of the primary things it does is to create a process with some
executable and waits for sometime period before it kills it. For this
simple thing, I guess i can just use a combination of fork,exex,pipe along
with some SIGALRM handler.

But my problem is a different guy works on the win32 version of the script
and it continously evolving and he refuses to do anything with UNIX. So i
am trying to figure out a good way (less nightmarish) of being in sync
with his script.

Creating a new module (something like UWIN32), with exact API for whatever
routines the script uses in win32 module is one idea. But is it worth the
trouble? and more importantly will it avoid my trouble? One potentiall
problem is that, if the other guy decides to use some arcane win32api
call, i will have to figure out a way of porting that call again. I may
endup with a much bigger task than the problem at hand. I have to get this
done in 2 weeks. Is this possible is another question..

I would greatly appreciate your input on this.

Thanks!
Mani




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

Date: 29 Jul 2003 11:38:05 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: Sorting out sort
Message-Id: <b955da04.0307291038.431fb8cf@posting.google.com>

peterstokes@operamail.com (Peter Stokes) wrote in message news:<10876b94.0307290655.50e56394@posting.google.com>...
> I'm trying to extract a column from a flatfile database and print it
> alphabetically. I can get the data out, but I can't get it to sort.
> 
> The database is pipe-separated in a plain text file and looks like
> this:
> 
> Ref_no|Title|County|Another_field|And_another|And_another
> 1234|A Name|Devon|Data here|More data here|And more data
> 1234|A Name|Somerset|Data here|More data here|And more data
> 1234|A Name|Nottinghamshire|Data here|More data here|And more data
> 1234|A Name|Essex|Data here|More data here|And more data
> ... and so on
> 
> My routine is as follows:
> [snip]
> while (<INFILE>) {
> #split the array at the separator
> 	@out = split /\|/;
> #select the field with the county names	
> 	@out = $out[2];

Here's your problem (or, at least, "a" problem).  You're using @out
for 2 contradictory purposes.  OT1H, you're using it to temporarily
hold the fields for each record in turn.  OTOH, you're using it to
collect the data you *really* want:  the counties.

Suggestion:  before entering the 'while' loop, define a hash which can
function as a "seen-hash":

    my %counties;

Then, for each line/data record:

    my @temp = split /\|/;
    $counties{$temp[2]}++ unless exists $counties{$temp[2]};

Then, when you've worked thru every line/record, you can get a sorted
list:

    my @out = sort keys %counties;

and you can print it out as you wish.  HTH.

Jim Keenan


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

Date: Tue, 29 Jul 2003 19:32:44 +0000 (UTC)
From: bill <bill_knight2@yahoo.com>
Subject: zero but true?
Message-Id: <bg6i4s$p8m$1@reader1.panix.com>



$ perl -e 'print "$]: ", 0E0 ? "OK\n" : "not OK\n"'
5.008: not OK

Isn't 0E0 supposed to evaluate to true?

TIA,

bill



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

Date: 29 Jul 2003 19:44:06 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: zero but true?
Message-Id: <Xns93C7A011DD633asu1cornelledu@132.236.56.8>

bill <bill_knight2@yahoo.com> wrote in news:bg6i4s$p8m$1@reader1.panix.com:

> 
> 
> $ perl -e 'print "$]: ", 0E0 ? "OK\n" : "not OK\n"'
> 5.008: not OK
> 
> Isn't 0E0 supposed to evaluate to true?

No, "0E0" is though.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Tue, 29 Jul 2003 15:37:02 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: zero but true?
Message-Id: <slrnbidmne.4fa.tadmc@magna.augustmail.com>

bill <bill_knight2@yahoo.com> wrote:
> 
> 
> $ perl -e 'print "$]: ", 0E0 ? "OK\n" : "not OK\n"'
> 5.008: not OK
> 
> Isn't 0E0 supposed to evaluate to true?


No. There are four false values in Perl:

   numerically zero
   undef
   empty string
   1-char string where the 1 char is the zero char


There are an infinite number of ways of writing that first one,
the way you have written it is but one of them.


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


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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