[24768] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6921 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 27 11:06:46 2004

Date: Fri, 27 Aug 2004 08: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           Fri, 27 Aug 2004     Volume: 10 Number: 6921

Today's topics:
    Re: -s vs du - different results <Joe.Smith@inwap.com>
    Re: get variables from another file <PerlGuRu2b@bobotheclown.org>
    Re: How to randomize foreach <bart.lateur@pandora.be>
    Re: How to randomize foreach (Anno Siegel)
    Re: How to unzip backup files of RaQ4 server? <Joe.Smith@inwap.com>
    Re: HTML::Parser <bart.lateur@pandora.be>
    Re: HTML::Parser <wfsp@removeyahoo.com>
    Re: Larry Wall & Cults <peter@engcorp.com>
    Re: Larry Wall & Cults <dietz@dls.net>
    Re: Larry Wall & Cults <john.thingstad@chello.no>
    Re: Larry Wall & Cults (Dr. Richard E. Hawkins)
    Re: Net::Ping::External doesn't honor timeout or count (Stuart Kendrick)
    Re: Parsing FileName for upload <Joe.Smith@inwap.com>
    Re: Parsing FileName for upload <Joe.Smith@inwap.com>
    Re: Parsing FileName for upload (Tony McGuire)
    Re: performance surprise -- why? <uri@stemsystems.com>
    Re: Problem on Debian Linux Installing DBD-mysql <footnipple@indiatimes.com>
    Re: Reference to functions <mritty@gmail.com>
    Re: Reference to functions <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Resizing JPG images with Perl? <patrice.auffret@intranode.com>
    Re: Resizing JPG images with Perl? (Randal L. Schwartz)
        subroutines with XML (Sara)
    Re: using the result of a variable regular expression <nobull@mail.com>
    Re: using the result of a variable regular expression (Anno Siegel)
    Re: using the result of a variable regular expression (Sara)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 27 Aug 2004 10:41:01 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: -s vs du - different results
Message-Id: <1dEXc.76977$mD.45029@attbi_s02>

Zebee Johnstone wrote:

>         $total += -s $File::Find::name;
> produces: total = 695543582 
> Running du -sb on the directory given to that program gets me:
> 750284800

For file systems where you know for sure that disk allocation
is based on 1K blocks, I have used something like this:

    $bytes = -s $name;
    $blocks = ($bytes + 1023) >> 10;
    $total += $blocks << 10;

But that would not take into consideration the overhead for
large files (indirect blocks and double indirect blocks)
the way that (stat $name)[12]*512 does.

The overhead required for large files on the CD is something you
ought to include in your calculations.
	-Joe


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

Date: Fri, 27 Aug 2004 12:16:42 GMT
From: Rocky <PerlGuRu2b@bobotheclown.org>
Subject: Re: get variables from another file
Message-Id: <pan.2004.08.27.12.10.10.857916@bobotheclown.org>

On Thu, 26 Aug 2004 18:47:31 +0000, David K. Wall wrote:

> Rocky <PerlGuRu2b@bobotheclown.org> wrote in message
> <news:pan.2004.08.26.13.52.50.870402@bobotheclown.org>: 
> 
>> my $recipient1 = 'EMAIL1 HERE';
>> my $recipient2 = 'EMAIL2 HERE';
>> my $recipient3 = 'EMAIL3 HERE';
>> my $recipient4 = 'EMAIL4 HERE';
>> my $recipient5 = 'EMAIL5 HERE';
> 
> The original problem has been answered by other posters, so I'll ignore  
> it. 
> 
> The quoted code is a red flag: a sequence of numbered scalars like that 
> suggests you should be using an array instead. Consider how your code 
> might change if you wanted to add a 6th recipient, and how using an 
> array could make that easier.
> 
> Mark-Jason Dominus wrote a series of "Red Flag" articles that you may 
> find interesting.  Links to them are at http://perl.plover.com/.

Thank you sir.  That site is pretty cool.


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

Date: Fri, 27 Aug 2004 11:32:55 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How to randomize foreach
Message-Id: <rl6ui0hj28u6bdlml7d4tb0tomsuhsb0a7@4ax.com>

Matthew Braid wrote:

>Odd. I just tried the same thing (well, I added a third option - sort 
>{int(rand(3)) - 1} @arr - to double check:

I've always heard that using an inconsequent sorting function in perl,
like this one, is a recipe for a disaster.

You could just generate a random number per entry, and sort according to
that list. Like:

	@sort = map rand, 0 .. $#item;
	@shuffled = @item[sort { $sort[$a] <=> $sort[$b] } 0 .. $#item];

-- 
	Bart.


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

Date: 27 Aug 2004 12:53:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to randomize foreach
Message-Id: <cgnat6$cph$2@mamenchi.zrz.TU-Berlin.DE>

Bart Lateur  <bart.lateur@pandora.be> wrote in comp.lang.perl.misc:
> Matthew Braid wrote:
> 
> >Odd. I just tried the same thing (well, I added a third option - sort 
> >{int(rand(3)) - 1} @arr - to double check:
> 
> I've always heard that using an inconsequent sorting function in perl,
> like this one, is a recipe for a disaster.
> 
> You could just generate a random number per entry, and sort according to
> that list. Like:
> 
> 	@sort = map rand, 0 .. $#item;
> 	@shuffled = @item[sort { $sort[$a] <=> $sort[$b] } 0 .. $#item];

It may still be hard to prove that this generates an unbiased sequence.
There will usually be a few duplicates among the generated numbers.
For these, the sequence is determined by the sort algorithm, not by
the random generator.

Anno


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

Date: Fri, 27 Aug 2004 10:08:29 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: How to unzip backup files of RaQ4 server?
Message-Id: <xKDXc.53991$9d6.45573@attbi_s54>

Andy Signer wrote:

> my $infile;
> my $outfile = "out.tar.gz";
> my $header_start ="\%\%BACKUP_HEADER";
> my $header_end = "\%\%END_XML";
> 
> if (@ARGV) {
>         $infile = $ARGV[0];
> } else {
>         print "usage: stripheader.pl <file name>\n";
>         exit 1;
> }
> 
> open (INFILE, $infile) or die "Can't open: $!\n";
> open (OUTFILE, ">$outfile") or die "Can't open $!\n";
> 
> while (<INFILE>) {
>         if ( /^$header_start/ ... /^$header_end/ ) {
>                 next;
>         }
>         print OUTFILE $_;
> }
> 
> close(INFILE);
> close(OUTFILE);
> exit 0;

That can be made a lot shorter.
	-Joe

use constant OUTFILENAME => 'out.tar.gz';
my $header_start = '%%BACKUP_HEADER';
my $header_end   = '%%END_XML';
die "Usage: $0 inputfile\n" unless @ARGV;
open OUT,'>',OUTFILENAME or die "Cannot create ",OUTFILENAME,": $!\n";
while (<>) {
   print OUT unless /^$header_start/ ... /$header_end/;
}
close OUT or warn "Possible truncation on output file: $!\n";


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

Date: Fri, 27 Aug 2004 11:48:57 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: HTML::Parser
Message-Id: <n17ui0dbvgn23f5eb5toim7d986jq1l0rs@4ax.com>

Zebee Johnstone wrote:

>Are there any tutorials or explanations of HTML::Parser?  
>
>I've read the perldoc and I don't understand it.  It's gibberish to me.

The best intro on the subject, IMO, is gellyfish's old tutorial.

	<http://www.gellyfish.com/htexamples/>

Now, if after going through this, you decide that callback-oriented
programming isn't your cup of tea, you might also want to take a look at
the alternative approach, token stream oriented: using HTML::TokeParser,
or a bit more high-level: HTML::TokeParser::Simple. There, you read
tokens (a tag, a piece of plain text) from a HML source one at a time,
like lines from a file.

-- 
	Bart.


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

Date: Fri, 27 Aug 2004 13:58:43 +0000 (UTC)
From: "wfsp" <wfsp@removeyahoo.com>
Subject: Re: HTML::Parser
Message-Id: <cgnemj$7gn$1@hercules.btinternet.com>


"Bart Lateur" <bart.lateur@pandora.be> wrote in message
news:n17ui0dbvgn23f5eb5toim7d986jq1l0rs@4ax.com...
> Zebee Johnstone wrote:
>
> >Are there any tutorials or explanations of HTML::Parser?
> >
> >I've read the perldoc and I don't understand it.  It's gibberish to me.
>
> The best intro on the subject, IMO, is gellyfish's old tutorial.
>
> <http://www.gellyfish.com/htexamples/>
>
> Now, if after going through this, you decide that callback-oriented
> programming isn't your cup of tea, you might also want to take a look at
> the alternative approach, token stream oriented: using HTML::TokeParser,
> or a bit more high-level: HTML::TokeParser::Simple. There, you read
> tokens (a tag, a piece of plain text) from a HML source one at a time,
> like lines from a file.
>
> -- 
> Bart.

HTML::TokeParser doc has an example:
"This example extracts all links from a document. It will print one line for
each link, containing the URL and the textual description between the
<A>...</A> tags:

  use HTML::TokeParser;
  $p = HTML::TokeParser->new(shift||"index.html");  while (my $token =
$p->get_tag("a")) {
      my $url = $token->[1]{href} || "-";
      my $text = $p->get_trimmed_text("/a");
      print "$url\t$text\n";
  }"




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

Date: Fri, 27 Aug 2004 07:51:54 -0400
From: Peter Hansen <peter@engcorp.com>
Subject: Re: Larry Wall & Cults
Message-Id: <IP-dne7gas7GvbLcRVn-gw@powergate.ca>

norman werner wrote:

> Peter Hansen <peter@engcorp.com> wrote:
>>Robert wrote:
>>>Isn't "Xah Lee" chinese for "Moron"?
>>No, it's Esperanto (universal language) for "troll"...
> 
> Bonvolu ne s:ercu pri nekonatoj aferoj. "Xah Lee" certe - pro manko de
> Ikso - ne estas esperanto. Kaj via s:erco nur s:tulta estas.
> 
> Norman
> tradukita:
> You certainly have not the slightest idea about esperanto. So please 
> dont't emberass yourself. And back to topic(?): "Xah lee" is not
> esperanto.

Well, let's see how your clear your mind was today.

Either it's a joke, in which case it is clear to all
that it doesn't really mean troll, or it's not a joke
in which case I obviously don't know Esperanto.

Here are the facts:

1. It's a joke, as you surmised.

2. I know Esperanto.

Now can you perhaps see that your first comment in the poor
translation of your own Esperanto is invalid and offensive?

By the way, to those not fluent in both languages, what this
fellow really wrote was more along the lines of "Please do not
joke about things you don't know about.  Xah Lee certainly --
because Esperanto has no "x" -- is not Esperanto.  And your
joke is merely stupid."

If you're going to accuse me of stupidity, please at least
get your own translation and logic skills in working order
first.

-Peter


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

Date: Fri, 27 Aug 2004 07:30:53 -0500
From: "Paul F. Dietz" <dietz@dls.net>
Subject: Re: Larry Wall & Cults
Message-Id: <jvydnS3JlcWttLLcRVn-vQ@dls.net>

Rich Teer wrote:
> On Fri, 27 Aug 2004, Reynir Stefánsson wrote:
> 
> 
>>And then there's this crazy little thing called love...
> 
> 
> Nah - that was Queen!

When I was seventeen
I drank some very good beer.
I drank some very good beer
I purchased with a fake ID.
My name was Brian McGee.
I stayed up listening to Queen.
When I was seventeen.

	Paul (channeling Homer)


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

Date: Fri, 27 Aug 2004 14:30:25 +0200
From: "John Thingstad" <john.thingstad@chello.no>
Subject: Re: Larry Wall & Cults
Message-Id: <opsdd40znlpqzri1@mjolner.upc.no>

I think I just hit the 'wall'.
rlol

On 25 Aug 2004 14:56:06 -0700, Xah Lee <xah@xahlee.org> wrote:

> Larry Wall and Cults
> (Lazyness, Impatience and Hubris)
> 200012
>
> Dear readers,
>
> Did you know that throughout history there's this thing called cult?
> It is a very interesting phenomenon. I don't have time to expound and
> teach, but will try to brief you.
>
> These cults, are often lead by a single person. They form a group as
> small as a dozen to multinational octopuses (such as
> Scientology). Their creed varies from the mild in appearance
> (Dianetics) to appalling (flat earth, extraordinary life-after-death,
> impinging apocalypse scenarios, militant anti-government conspiracy,
> diabolism with human sacrifices ...). Don't think that i'm citing from
> some arcane books buried in libraries. These are real, and not
> difficult to find in real life. Some of these cult leaders, are so
> able to totally wash their member's brain, as to have them
> autonomously swear and volunteer to die for the cause of the cult.
> Occasionally, you'll even see mass suicide.
>
> You know, the world is not made completely of rubes. Somebody
> somewhere, will observe this phenomenon and study or report it as
> is. Big brother organizations, such as the FBI, is keen on these and
> very interested in benefiting from social psychology themselves. They
> are recorded in books too. Ever wonder why the library houses so many
> cold volumes of paper? This is one contributing reason. You might be
> interested to verify that sometimes.
>
> These brain-washing phenomenon, are not limited to fanatical
> life-and-death or otherwise dire beliefs. You see it work in all
> manners of human thought in the general sense. From culture formation
> to fashion to commercialism.  Surely you have heard of Adolf Hitler
> and his atrocities of genocide? I must alert you, that a single person
> couldn't commit such a crime. You see, even if you are superman, you
> can only kill few at a time. You see, it is the people, people like
> you and me, who commit the killings willingly, by Hitler's
> teaching. You may say: "no, i won't ever do such stupid thing", well
> because you are very ignorant about social psychology. It is precisely
> innocent people like you and (not) me, who were lead by the radical
> leaders of supreme brain-washing abilities. The innocent mob were
> fervent in their leader's vision and beliefs to commit anything. You
> know the concept of war, right? We have two massive body of people
> committed to cut off other people's head or otherwise stick a knife in
> their bodies or bomb off an arm or leg. How did that happen? Well, it
> starts with patriotism for people like you and (not) me.
>
> Now, back to topic. In the computing world, there're also bad seeds
> with colorful creed taking innocent mobs forming cults. The three
> principal virtues of a programmer are Laziness, Impatience, and
> Hubris. Yes?
>
> How can we prevent heinous cults then? Stop bending truths. Education
> and rationalism. I'm starting my own cult to exterminate morons on
> this earth.  Two things are on the top of my agenda: Unixism and Perl.
>
> --------
> This post is archived at
>  http://xahlee.org/UnixResource_dir/writ/larry_wall_n_cults.html
>
> Copyright 2000-2004 Xah Lee. Verbatim Reproduction for non-commercial
> purposes is hereby granted provided proper credit is given.
>
>  Xah
>  xah@xahlee.org
>  http://xahlee.org/PageTwo_dir/more.html



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


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

Date: Fri, 27 Aug 2004 14:45:20 +0000 (UTC)
From: hawk@slytherin.ds.psu.edu (Dr. Richard E. Hawkins)
Subject: Re: Larry Wall & Cults
Message-Id: <cgnhe0$o8o$3@f04n12.cac.psu.edu>

In article <412dfc1c$0$65599$a1866201@newsreader.visi.com>,
Grant Edwards  <grante@visi.com> wrote:
>On 2004-08-26, Sara <genericax@hotmail.com> wrote:

>> Hey this ain't no CULT! Our creedo is simply:

>>    "Larry said it, I believe it, THAT settles it!"

>> If you don't believe it just look at the reaction if any questions any
>> element of Perl design!

>Over here in c.l.python, it's more like

>   "Guido said it, that settles it, but we're going to discuss
>    it endlessly and and vote on it using six or seven
>    different voting algorithms anyway.  Then we'll argue about
>    the voting algorithms."

Now I understand what happenend in the 2000 election:  Al Gore, after
inventing the internet, became a python programmer :)

hawk
-- 
Richard E. Hawkins, Asst. Prof. of Economics    /"\   ASCII ribbon campaign
dochawk@psu.edu  111 Hiller (814) 375-4846      \ /   against HTML mail
These opinions will not be those of              X    and postings. 
Penn State until it pays my retainer.           / \   


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

Date: 27 Aug 2004 05:38:48 -0700
From: skendric@fhcrc.org (Stuart Kendrick)
Subject: Re: Net::Ping::External doesn't honor timeout or count
Message-Id: <62dbf7f1.0408270438.515a4ba5@posting.google.com>

ahhh, RTFM ... or RTFC ...

i've modified my copy of Net::Ping::External to accept the "-W"
argument ... thanx bill,

--sk

Bill <wherrera@lynxview.com> wrote in message news:<1MednWQL--Y9IbPcRVn-tg@adelphia.com>...
> Stuart Kendrick wrote:
> 
> > hi,
> > 
> > i'm using Net::Ping::External to do my pings.  i would like to fiddle
[...]

> 
> Yes, with Mandrake. But:
> 
>  From the docs:
> -----------------------
> Linux
> 
> Tested OK on Debian 2.2 and Redhat 6.2. It appears that different 
> versions of Linux use different versions of ping, which support 
> different options. Not sure how I'm going to resolve this yet; for now, 
> all the options but count are disabled.


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

Date: Fri, 27 Aug 2004 10:17:01 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Parsing FileName for upload
Message-Id: <xSDXc.242540$eM2.154052@attbi_s51>

Tore Aursand wrote:

> On Tue, 24 Aug 2004 14:49:59 -0700, Tony McGuire wrote:
> 
>>I've been going batty trying to figure out a routine that will detect
>>when there is a full path sent and parse the file name from that path,
>>and when there is only a file name sent.
> 
> BTW: Why do you need to know _if_ there is a full path present?

In case it is not obvious, let me re-state Tore's question.

   Why do you need to know _if_ there is a full path present?
   Why not call the parse routine always?

A properly written parse routine will return the correct
results even when "only a file name was sent".
	-Joe


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

Date: Fri, 27 Aug 2004 10:26:47 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Parsing FileName for upload
Message-Id: <H%DXc.242566$eM2.202925@attbi_s51>

Tore Aursand wrote:

> OS'es and their path separators?
> I'm only familiar with '/', '\' and ':'.

TOPS-20   PS:<DECUS.LIB.TAPE01>FOOBAR.TXT.1
TOPS-10   DSKB:[13,10,MYSTUF,DECUS,LIB,TAPE10]FOOBAR.TXT
VAX/VMS and IBM/MVS are not like Posix.
	-Joe


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

Date: 27 Aug 2004 06:30:21 -0700
From: tony@paradoxcommunity.com (Tony McGuire)
Subject: Re: Parsing FileName for upload
Message-Id: <f896a829.0408270530.29e7e154@posting.google.com>

Joe Smith <Joe.Smith@inwap.com> wrote 
> 
>    Why do you need to know _if_ there is a full path present?
>    Why not call the parse routine always?
> 
> A properly written parse routine will return the correct
> results even when "only a file name was sent".
> 	-Joe

Joe,

I don't need to know.

I just want the file name reliably.

Tore pointed me to fileparse(), which appears to work.  At least for
Linux and Windows, it gives the file name reliably regardless of path
or not.


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

Date: Fri, 27 Aug 2004 13:50:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: performance surprise -- why?
Message-Id: <x7k6vklmhm.fsf@mail.sysarch.com>

>>>>> "A" == Abigail  <abigail@abigail.nl> writes:

  A> Uri Guttman (uri@stemsystems.com) wrote on MMMMXIII September MCMXCIII in
  A> <URL:news:x7sma9qx11.fsf@mail.sysarch.com>:
  A> "" >>>>> "A" == Abigail  <abigail@abigail.nl> writes:
  A> ""  
  A> ""   A> Or one could just read the manual page. From 'man English':
  A> ""  
  A> ""   A>     PERFORMANCE
  A> ""   A>            This module can provoke sizeable inefficiencies for regu­
  A> ""   A>            lar expressions, due to unfortunate implementation
  A> ""   A>            details.  If performance matters in your application and
  A> ""   A>            you don't need $PREMATCH, $MATCH, or $POSTMATCH, try doing
  A> ""  
  A> ""   A>               use English qw( -no_match_vars ) ;
  A> ""  
  A> ""  and as damian conway says (and i agree) they chose the wrong default for
  A> ""  that option. it should have been -use_match_vars and the default for
  A> ""  english should be to not alias them.


  A> Well, yes, but Perl is full of things that are there because of
  A> wrong decisions made in the past, and won't be changed for the sake
  A> of backwards compatability.

but that was a fairly recent decision. the slowness of $& was known for
a long time and also that english triggered it. adding the ability to
not have english alias $& was a good idea. just no one seemed to think
it through and select the proper default. this is a good thing to learn
when designing apis. think carefully about which param values will be
the most common and make them defaults.

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: Fri, 27 Aug 2004 14:42:16 GMT
From: "Guy Smiley" <footnipple@indiatimes.com>
Subject: Re: Problem on Debian Linux Installing DBD-mysql
Message-Id: <cLHXc.1238$w_4.512095@twister.tampabay.rr.com>

"Hal Vaughan" <hal@thresholddigital.com> wrote in message
news:kYCdnV-PPICbTLPcRVn-gw@comcast.com...

> I'm not using the MySQL server on this computer, but I am using the
> client to connect to MySQL on another system.

AFAIK, you definately need the server onboard in order to install the
dbd-mysql. I run libranet also and use apt-get like I would if it was a
regular Debian install

apt-get mysql-server
apt-get libdbd-mysql-perl

For more information see:
http://packages.debian.org/cgi-bin/search_packages.pl?keywords=mysql&searcho
n=names&subword=1&version=all&release=all




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

Date: Fri, 27 Aug 2004 12:15:38 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Reference to functions
Message-Id: <KBFXc.12165$Nn2.1008@trndny05>

"Vito Corleone" <corleone@godfather.com> wrote in message
news:20040827161406.6c37d3e5.corleone@godfather.com...
> Hi,
>
> I tried to make a call a function by reference. Here is the code:
>
> #!/usr/bin/perl
> use strict;
>
> sub show_a {
>     my ($txt) = @_;
>     print "show_a: $txt\n\n";
> }
>
> sub show_b {
>     my ($txt) = @_;
>     print "show_b: $txt\n\n";
> }
>
> sub show {
>     my ($type) = @_;
>     my $f = "show_" . $type;
>     $f->($type);
> }
>
> show("a");
>
> But there was an error:
> Can't use string ("show_a") as a subroutine ref while "strict refs" in
> use at ./test.pl line 18.
>
> How do I make this kind of call to function with 'use strict' turned
on?

You don't.  That's specifically the kind of thing use strict; exists to
prevent.  What you are doing is using a variable as a variable name,
otherwise known as symbolic references.  (Although, I grant you, you're
doing it differently than most people who ask this question have
tried...).  Read
perldoc -q 'variable name'
for information on why this is A Bad Idea.

Instead, you should create your two subroutines as anonymous coderefs,
stored in a hash.  Then your show() routine simply picks the right
coderef to call from the hash:

#!/usr/bin/perl
use strict;
use warnings;
my %show = (
    a => sub {
        my $txt = shift;
        print "Show A: $txt\n";
    },
    b => sub {
        my $txt = shift;
        print "Show B: $txt\n";
    }
);

sub show {
    my $let = shift;
    $show{$let}->(shift);
}

print "A:\n";
show('a', 'foo');

print "B:\n";
show('b', 'bar');
__END__


Paul Lalli




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

Date: Fri, 27 Aug 2004 14:33:30 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Reference to functions
Message-Id: <Xns95529497BBB90elhber1lidotechnet@62.89.127.66>

"Paul Lalli" <mritty@gmail.com> wrote:

> "Vito Corleone" <corleone@godfather.com> wrote in message
> news:20040827161406.6c37d3e5.corleone@godfather.com...
>> Hi,
>>
>> I tried to make a call a function by reference. Here is the code:
>>
>> #!/usr/bin/perl
>> use strict;
>>
>> sub show_a {
>>     my ($txt) = @_;
>>     print "show_a: $txt\n\n";
>> }
>>
>> sub show_b {
>>     my ($txt) = @_;
>>     print "show_b: $txt\n\n";
>> }
>>
>> sub show {
>>     my ($type) = @_;
>>     my $f = "show_" . $type;
>>     $f->($type);
>> }
>>
>> show("a");
>>
>> But there was an error:
>> Can't use string ("show_a") as a subroutine ref while "strict
>> refs" in use at ./test.pl line 18.
>>
>> How do I make this kind of call to function with 'use strict'
>> turned 
> on?
> 
> You don't.  That's specifically the kind of thing use strict;
> exists to prevent. [...]


It's *one of several* kinds of things use strict exists to prevent. 
Not a nitpick. That kind of statement would have confused me to no 
end back when I was starting out with Perl. :)


-- 
Cheers,
Bernard


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

Date: Fri, 27 Aug 2004 15:14:42 +0200
From: Patrice Auffret <patrice.auffret@intranode.com>
Subject: Re: Resizing JPG images with Perl?
Message-Id: <20040827151442.004b92e1.patrice.auffret@intranode.com>

On 26 Aug 2004 09:04:11 -0700
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
[..]
>   So, after invoking convert some 200 to 300 times, slowly varying the
>   parameters, and trying new things, and then trying to figure out how
>   to convert that to the Perl bindings, again invoking it some 200
>   times or so (I'm not joking about these numbers, and I wish I was),
>   I've come up with [listing one, below].


  And what about Gimp::* hierarchy ? Have someone in this group 
  ever tested it ? (I'm curious about it, maybe I'll have to use 
  it one day).


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

Date: 27 Aug 2004 07:07:26 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Resizing JPG images with Perl?
Message-Id: <863c28n081.fsf@blue.stonehenge.com>

*** post for FREE via your newsreader at post.newsfeed.com ***

>>>>> "Patrice" == Patrice Auffret <patrice.auffret@intranode.com> writes:

Patrice>   And what about Gimp::* hierarchy ? Have someone in this group 
Patrice>   ever tested it ? (I'm curious about it, maybe I'll have to use 
Patrice>   it one day).

I've had all of like an hour with the Gimp on my screen.  With the
Gimp being fairly underdocumented, always in motion, and still lagging
about 4 years behind Photoshop, there's no reason for me to not use
"the real thing".

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


 -----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
                  


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

Date: 27 Aug 2004 06:37:07 -0700
From: sa_ravenone@yahoo.com (Sara)
Subject: subroutines with XML
Message-Id: <8e3b2dfa.0408270537.5805f4b0@posting.google.com>

Hi all,
Thanks to the guidance provided for an earlier query I am progressing
into references and objects.

Now I want to associate every element of an XML file with a
subroutine. I searched CPAN and also read Perl-XML FAQ; XML::Dumper is
excellent and almost exactly what I wanted but it doesn't support
references to Perl subroutines. I'm new to using Perl with XML, though
I have used Perl and XML separately for quite some time. Is there any
easy way to associate XML elements with specific subroutines. I
thought of using symbolic references in haste then didn't do so
because I was reminded of the advice given by many in this community.
Is it necessary to have elements of XML declared as part of a data
structure in the program to make this association work?
Every bit of help is welcome.


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

Date: Fri, 27 Aug 2004 13:05:48 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: using the result of a variable regular expression
Message-Id: <cgn7r0$jtl$2@sun3.bham.ac.uk>

Anno Siegel wrote:

> Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
>>You can do:
>>
>>     if ( my @capt = $data =~ /$regexp/ ) {
>>         print $capt[$numb-1];
>>     }
> 
> 
> Or, without an auxiliary variable:
> 
>     defined and print for ( $data =~ /$regex/ )[ $numb - 1];

In this particular case it is probably safe to assume that we want to 
treat the case where the ${numb}th capture didn't capture to be 
equivalent to the case where /$regex/ didn't match.

However it is important to be aware that you are making such an assumption.	



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

Date: 27 Aug 2004 12:44:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: using the result of a variable regular expression
Message-Id: <cgnaak$cph$1@mamenchi.zrz.TU-Berlin.DE>

Brian McCauley  <nobull@mail.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> 
> > Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> >>You can do:
> >>
> >>     if ( my @capt = $data =~ /$regexp/ ) {
> >>         print $capt[$numb-1];
> >>     }
> > 
> > 
> > Or, without an auxiliary variable:
> > 
> >     defined and print for ( $data =~ /$regex/ )[ $numb - 1];
> 
> In this particular case it is probably safe to assume that we want to 
> treat the case where the ${numb}th capture didn't capture to be 
> equivalent to the case where /$regex/ didn't match.
> 
> However it is important to be aware that you are making such an assumption.	

You are right.  I thought about explaining how it is okay (under this
assumption) to use the regex without explicitly checking if it matched,
but decided to let it slip.  Thanks for pointing it out.

Anno


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

Date: 27 Aug 2004 07:44:00 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: using the result of a variable regular expression
Message-Id: <776e0325.0408270644.935dd5d@posting.google.com>

leifwessman@hotmail.com wrote in message news:<cgl2im$tru@odak26.prod.google.com>...
> Hi!
> 
> I need to extract a certain value from a text. But the result isn't
> always in the variable $1 - it might be in $2, $3, $4 or some other
> predefined variable.
> 
> Some code to illustrate my problem:
> 
> $regexp = "(\d)(\w)(\d)";
> $numb   = 3;                # Means the result I'm looking for is in $3
> # I don't know this number, it's submitted
> by user
> # and may differ
> 
> if ($data =~ /$regexp/) {
> 
> print $numb; # does not work, prints "3"
> 
> # alternative solution that works
> # but it's UGLY
> if ($numb == 1) {
> print $1;
> } elsif ($numb == 2) {
>  print $2;
> } elsif ($numb == 3) {
>  print $3;
> }
> 
>    # is there another way?
> }
> 
> Thanks for any input!
> 
> Leif

Hi there Leif:

Interesting question. As pointed out, $$numb will work nicely for you.
The odd thing being that this LOOKS like a scalar dereference, which
it really isn't since 2 isn't the memory location of the value. Seems
like there is an ambiguity in there somewhere but I can't pinpoint it.

Thanks for posting.

G


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

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


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