[9987] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3580 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 28 20:04:11 1998

Date: Fri, 28 Aug 98 17:00:22 -0700
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, 28 Aug 1998     Volume: 8 Number: 3580

Today's topics:
    Re: Another backslash question (Andre L.)
    Re: directories (Larry Rosler)
    Re: even or odd (Geoff Simmons)
    Re: even or odd <tchrist@mox.perl.com>
    Re: Hexdigit <crism@oreilly.com>
        Installed modules info? <ybelor1@uic.edu>
    Re: Misinterpreted => why no true/false keywords? <zenin@bawdycaste.org>
    Re: pattern matching (James Stout)
    Re: Perl Cookbook, does anyone have it? (Michael Rubenstein)
    Re: Problem with sending an array to a subrutine <egwong@netcom.com>
    Re: Repeating grouped substitutions (Bob Trieger)
    Re: Repeating grouped substitutions (Larry Rosler)
    Re: Repeating grouped substitutions <rick.delaney@shaw.wave.ca>
    Re: Repeating grouped substitutions (Larry Rosler)
    Re: Repeating grouped substitutions (Ilya Zakharevich)
    Re: Repeating grouped substitutions (Bob Trieger)
    Re: Repeating grouped substitutions (Larry Rosler)
    Re: Simple variable manipulation question <egwong@netcom.com>
    Re: Simple variable manipulation question (Bob Trieger)
    Re: Simple variable manipulation question <rick.delaney@shaw.wave.ca>
    Re: Simple variable manipulation question (Larry Rosler)
        re: simple variable manipulation <prw@evolving.com>
    Re: simple variable manipulation <prw@evolving.com>
    Re: simple variable manipulation (Bob Trieger)
    Re: simple variable manipulation <r28629@email.sps.mot.com>
    Re: SWF (Shockwave Flash) file format (Larry Rosler)
    Re: Uploading Binary files <joneil@cks.ssd.k12.wa.us>
        Using OLE to get Excel VBA using the clipboard <lynn@swcp.com>
        watching 'my' in debug mode <r28629@email.sps.mot.com>
    Re: watching 'my' in debug mode (Ilya Zakharevich)
        Win32 LWP Perl Module <jhr@best.com>
    Re: Windows95, Perl, PWS (IIS) (Angel Leyva)
        XS with win32 Perl <jeffk@synplicity.com>
    Re: {n} quantifier question <aqumsieh@tigre.matrox.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 28 Aug 1998 18:42:14 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Another backslash question
Message-Id: <alecler-2808981842140001@dialup-639.hip.cam.org>

In article <slrn6ue2a0.h53.dmr@doug.fc.hp.com>, dmr@doug.fc.hp.com (Doug) wrote:

> I get this error:
> 
>    /www.whatever.com\/: trailing \ in regexp at ./new.pl line 7.
> 
> With this code:
> 
>  5:   $fqdn="www.whatever.com\\";
>  6:   $machine_names[1]="www.whoever.com\\";
>  7:   if(grep(/$fqdn/, @machine_names))
>  8:   {
>  9:    ... ...
>  10:  } 
> 
> I can read the error message, but my attempts of working around
> it have failed. [...]

Quotemeta the pattern and the error will go away. (Note that using grep()
is not the most efficient solution if the array in large.)

   if (grep (/\Q$fqdn/, @machine_names))

Which leads me to a question: should (an eventual future version of) Perl
implicitely quotemeta the contents of any variable used in a regexp? I
don't see any instance where such a behavior would not make sense, but
maybe I'm not thinking hard enough.

Andre


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

Date: Fri, 28 Aug 1998 15:44:50 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: directories
Message-Id: <MPG.1050d2c01dfb9685989777@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <6s7743$676$1@news.monmouth.com> on Fri, 28 Aug 1998 17:16:40 
-0400, Matt <splinter@monmouth.com> says...
 ...
> chdir($certaindir);
> 
> It doesn't change the directory or doesn't do it fast enough because its
> writing all the files to the directory the perl script is in.
> 
> Any suggestions?

Indeed.

chdir($certaindir) or die "Couldn't change to $certaindir. $!\n";

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 29 Aug 1998 01:28:53 +0100
From: g.simmons@elmshorn.netsurf.de (Geoff Simmons)
Subject: Re: even or odd
Message-Id: <g.simmons-2908980128550001@e1-11.shlink.de>

In article <6s4thf$7nng$1@newssvr04-int.news.prodigy.com>, "Andy Lee"
<andylee@prodigy.net> wrote:

>     I don't know how to test the number for even or odd. Thanks..

   perl -nlw 'print $_ & 1 ? "odd" : "even"'



Best,
Geoff


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

Date: 28 Aug 1998 23:35:36 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: even or odd
Message-Id: <6s7es8$mcl$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    dmr@doug.fc.hp.com (Doug) writes:
:>You don't?  Really?  Can you tell us what an even or odd
:>number means to you?  If you can, you can test for it.
:>It's 4th-grade math stuff.  Just think it through.
:
:Great.  I'm sure that helps him and encourages him to program and
:continue to persue PERL.  Responses like that will just make him
:think you're an ass.  

I am trying to instill an algorithmic, problem-solving mentality.
Often if someone explains their problem thoroughly, they see
that the solution is just sitting there waiting for them.

What I was looking for was to provide a thought process, not an opaque
and instant answer.  The question ``Is a number even'' means ``Is a
number an even multiple of 2''.  In fact, once you do that, you can
extend it to ``Is it a multiple of N?''

BTW, I see that you managed to come up with a solution even though
you forgot about the modulus operator.  Aren't you glad there's
more than one way to do it? :-)

--tom
-- 
    X-Windows: The art of incompetence.
	--Jamie Zawinski


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

Date: 28 Aug 1998 15:38:09 -0400
From: Chris Maden <crism@oreilly.com>
Subject: Re: Hexdigit
Message-Id: <keu32wgan2.fsf@rosetta.ora.com>

"Jules" <julius@clara.net> writes:

> Dear all, I'm a complete newbie to perl and am reading this O'Reilly
> camel book of Programming Perl. It's got an example (page 48) which
> has a single line:
> 
> $hexdigit = ('a','b','c','d','e','f') [$digit-10];
> 
> and it claims that its a hex digit finder.

It's an out-of-context code snippet.  If $digit is a value from 10 to
15, $hexdigit will be the appropriate hexadecimal digit.  If $digit is
11, then $hexdigit is the 2nd item in the a-f array, or 'b'.

-Chris
-- 
<!NOTATION SGML.Geek PUBLIC "-//Anonymous//NOTATION SGML Geek//EN">
<!ENTITY crism PUBLIC "-//O'Reilly//NONSGML Christopher R. Maden//EN"
"<URL>http://www.oreilly.com/people/staff/crism/ <TEL>+1.617.499.7487
<USMAIL>90 Sherman Street, Cambridge, MA 02140 USA" NDATA SGML.Geek>


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

Date: Fri, 28 Aug 1998 17:32:52 -0500
From: Yevgeniy Belorusskiy <ybelor1@uic.edu>
Subject: Installed modules info?
Message-Id: <Pine.SOL.3.96.980828172903.21487A-100000@icarus.cc.uic.edu>

What is the proper way to get listing of all installed modules on a
given system?
I think I have seen it somewhere, but I can't find it again.

Any suggestions?





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

Date: 28 Aug 1998 22:00:37 GMT
From: Byron Brummer <zenin@bawdycaste.org>
Subject: Re: Misinterpreted => why no true/false keywords?
Message-Id: <904341452.265237@thrush.omix.com>

Russ Allbery <rra@stanford.edu> wrote:
: strict.pm and vars.pm I can buy.  I consider it a bug in the standard
: library that everything pulls in Carp.pm when one can just as easily do:
:         if ($something_failed) {
:             require Carp;
:             Carp::croak ("Wow, something failed!");
:         }
        >snip<

        Yes, but constantly typing out all that gets old quick.
        
        You could autoload it, but AUTOLOAD() may already be doing other
        work or may well be in your SUPER:: so you probably don't want to
        mess with it.

        If you're into real type glob and goto magic however, you can have
        some fun and solve the problem this way:

        unless (defined *croak{CODE}) {
            eval q(
                sub croak {
                    local $^W=0;  ## Avoid redefining warning at first call
                    require Carp; import Carp 'croak';
                    goto &Carp::croak;
                }
            ); die $@ if $@;
        }

        croak ("I'm dynamically loaded when called!");

        Who says we need an AUTOLOAD(). :-)

: >         Yes, it would be nice if constant.pm auto-included Carp (and
: >         therefore Exporter),
:
: It would be even better if they didn't use autouse or any other *module*
: solution and instead just delayed loading until the module was actually
: needed.  That's what I do with most of what I write and it works great for
: keeping load times down, particularly with modules where a lot of the
: functionality is never used in the common case.

        Well, that gets cumbersome to code quickly.
        
-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Fri, 28 Aug 1998 21:48:12 GMT
From: itxjcs@unix.ccc.nottingham.ac.uk (James Stout)
Subject: Re: pattern matching
Message-Id: <35e72581.39528093@news.nottingham.ac.uk>

Hi all

Thanks you for all you help.

James


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

Date: Fri, 28 Aug 1998 22:34:09 GMT
From: miker3@ix.netcom.com (Michael Rubenstein)
Subject: Re: Perl Cookbook, does anyone have it?
Message-Id: <35eb3033.244213079@nntp.ix.netcom.com>

On Fri, 28 Aug 1998 09:03:58 -0400, Scott Boss
<Scott.Boss@bridge.bellsouth.com> wrote:

>brian d foy wrote:
>
>> In article <6s29q2$mag$1@nnrp1.dejanews.com>, dturley@pobox.com posted:
>>
>> >checking my amazon order status twice a day!
>
>    Barnes & Noble, Amazon.Com, Walden Books, Borders, etc... has not
>received their shipment from Orielly yet.  I have called all of them multiple
>times.  I *think* that it will be just days before they get them.  Then it
>will take a few days for them to send it out to all their stores (or Mail it
>for Amazon..com).
>
>>
>>
>> maybe i should put my second copy on one of those auction script sites ;)
>
>    If it (the cookbook) is like the other Orielly Perl Books, I would not
>trade it for it's weight in gold (or silver).

Amazon, however, did not let the fact that they haven't received the
book stop them from shipping a copy to me; I got mine today.
--
Michael M Rubenstein


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

Date: Fri, 28 Aug 1998 21:58:25 GMT
From: Eric Wong <egwong@netcom.com>
Subject: Re: Problem with sending an array to a subrutine
Message-Id: <egwongEyF6DD.17J@netcom.com>

Hi,

The "problem" (if you can call it that), is that perl
passes arguments in a flat list of scalars.  Arrays and
hashes lose their "group-iness" when passed as arguments.
(See the persub manpage.)

I think you ought to use references when passing an array
to a subroutine (see perlref manpage.)
  @usuarios = &depurar(\@usuarios,"numeq",4,$fields{edad});  
  
  sub depurar {
     @ArrayAProc = @{$_[0]};
     $TipoComparacion = $_[1];
     ...

Alternatively, you could pop() the last three elements out
of the array.  What's left is @usuarios:
  @usuarios = &depurar(@usuarios,"numeq",4,$fields{edad});
  
  sub depurar {
     $TipoComparacion = pop;
     $NumDelCampo = pop;
     $ValorDelCampo = pop;
     @ArrayAProc = @_;
     ...

HTH,
,Eric

[cc'd]



Alejandro Lay <gt2214a@prism.gatech.edu> wrote:
: Hi and thanks in advance for any help.
: I would appreciate that any responses be mailed to me.
: Yes I have read the documentation, but still haven't found the solution.
: I am fairly new to perl, and I am not a native english speaker, maybe
: that's why I couldn't find the answer to this.

: The problem is that I have a "|" delimited database which I read in and
: then perform many selection operations on it, the problem I am having is
: that when trying to pass an array to a subrutine, the array becomes
: empty. If I do it without the subroutine, it works fine, but it would
: make the code too big and would be easier just to hard code the
: database to the script. Any ideas on how to solve this, and an
: explication of what is happening wrong would be greatly appreciated.

: The database is:
: # numero | perfil | foto | sexo | edad | tipoamigos
: 1|a|no|h|33|ninguno
: 6|m|si|m|18|locos
: <SNIP>...

: The code:
: <SNIP>...
: # at this point I know the users are in @usuarios since since I can
: # print tehm out
: # print @usuarios;
: @usuarios = &depurar(@usuarios,"numeq",4,$fields{edad});
: <SNIP>...

: ### depurar, removes entries from an array that do not match parameters
: ### param 0 - original array
: ### param 1 - type of comparison
: ### param 2 - field number
: ### param 3 - value to compare
: sub depurar {
:    @ArrayAProc = $_[0];
:    $TipoComparacion = $_[1];
:    $NumDelCampo = $_[2];
:    $ValorDelCampo = $_[3];
: # at this point there are no elements in the array, neither in
: # @ArrayAProc or in $_[0];
: # print @ArrayAProc;
: # print $_[0];
:    @retArray = ();
:    $len = 0;
:    for ($u=0;$u<=$#ArrayAProc;$u++){
:       @tempLineaSUB = split(/\|/, $ArrayAProc[$u]);
:       if ( $TipoComparacion eq "numeq" ) {
:          if ($tempLineaSUB[$NumDelCampo] == $ValorDelCampo) {
:             $retArray[$len] = $ArrayAProc[$u];
:             $len ++; }
:       }
:       elsif ( $TipoComparacion eq "numgteq" ) {
:          if ($tempLineaSUB[$NumDelCampo] >= $ValorDelCampo) {
:             $retArray[$len] = $ArrayAProc[$u];
:             $len ++; }
:       }
:       elsif ( $TipoComparacion eq "numlteq" ) {
:          if ($tempLineaSUB[$NumDelCampo] <= $ValorDelCampo) {
:             $retArray[$len] = $ArrayAProc[$u];
:             $len ++; }
:       }
:       elsif ( $TipoComparacion eq "texteq" ) {
:          if ($tempLineaSUB[$NumDelCampo] eq $ValorDelCampo) {
:             $retArray[$len] = $ArrayAProc[$u];
:             $len ++; }
:       }
:    }
:    return @retArray;
: }


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

Date: Fri, 28 Aug 1998 22:24:13 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Repeating grouped substitutions
Message-Id: <6s7asl$rp6$1@ligarius.ultra.net>

[ posted to usenet and courtesy e-mail sent to braynor@jupiter.kcc.com ]
braynor@jupiter.kcc.com (Bill Raynor (B12349)) wrote:
-> I occasionally recieve supposedly comma delimited data with missing 
-> comma's:
-> 1.2,3.4 5.6,7.8    9.0
-> and would like to "fix it" so that it becomes comma delimited:
-> 1.2,3.4,5.6,7.8,9.0

tr /. /,/;

That should translate all spaces and dots in the variable to commas.

Bob Trieger
sowmaster@juicepigs.com


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

Date: Fri, 28 Aug 1998 15:37:42 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Repeating grouped substitutions
Message-Id: <MPG.1050d1153d94e997989775@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <6s78br$bfv$1@gatekeep.kcc.com> on 28 Aug 1998 21:44:27 GMT, 
Bill Raynor (B12349) <braynor@jupiter.kcc.com> says...
> I occasionally recieve supposedly comma delimited data with missing 
> comma's:
> 1.2,3.4 5.6,7.8    9.0
> and would like to "fix it" so that it becomes comma delimited:
> 1.2,3.4,5.6,7.8,9.0
> However:
> s/(\d+\.\d*)\s+(\d+\.\d*)/\1\,\2/g;
> only fixes the first one (3.4 5.6 becomes 3.4,5.6).

That regex works for me, though the \1 and \2 should be $1 and $2, as the 
'-w' flag would inform you.  What version of perl are you using (`perl -
v`)?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Aug 1998 22:51:44 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Repeating grouped substitutions
Message-Id: <35E735F5.D5A45BC6@shaw.wave.ca>

[posted and mailed]

Bill Raynor (B12349) wrote:
> 
> I occasionally recieve supposedly comma delimited data with missing
> comma's:
> 1.2,3.4 5.6,7.8    9.0
> and would like to "fix it" so that it becomes comma delimited:
> 1.2,3.4,5.6,7.8,9.0
> However:
> s/(\d+\.\d*)\s+(\d+\.\d*)/\1\,\2/g;
> only fixes the first one (3.4 5.6 becomes 3.4,5.6).

It fixes both for me.  I get
\1 better written as $1 at temp line 5.
\2 better written as $2 at temp line 5.
1.2,3.4,5.6,7.8,9.0

You get the useful warnings by running with -w.  Btw, you don't need to
escape that last comma in your regex.

Presumably you want to fix the file so you can process it.  If so,
remember that the first arg to split is a regex, not a character.

@F = split /\s+|,/;

If you only want to fix it for loading into something else, you can
always put it back together.

print join(',', @F), "\n";

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Fri, 28 Aug 1998 15:52:42 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Repeating grouped substitutions
Message-Id: <MPG.1050d493344d32ba989778@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <6s7asl$rp6$1@ligarius.ultra.net> on Fri, 28 Aug 1998 22:24:13 
GMT, Bob Trieger <sowmaster@juicepigs.com> says...
 ...
> -> 1.2,3.4 5.6,7.8    9.0
> -> and would like to "fix it" so that it becomes comma delimited:
> -> 1.2,3.4,5.6,7.8,9.0
> 
> tr /. /,/;
> 
> That should translate all spaces and dots in the variable to commas.

Yes, it does.  So the result is

1,2,3,4,5,6,7,8,,,9,0

Am I missing something?

But I like the approach of

tr/ /,/s;

better than the regex.  Thanks.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 28 Aug 1998 23:06:14 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Repeating grouped substitutions
Message-Id: <6s7d56$qt3$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Bill Raynor (B12349)
<braynor@jupiter.kcc.com>],
who wrote in article <6s78br$bfv$1@gatekeep.kcc.com>:
> s/(\d+\.\d*)\s+(\d+\.\d*)/\1\,\2/g;
> only fixes the first one (3.4 5.6 becomes 3.4,5.6). It there any way 
> to force perl to change all the instances, other than:

Lookahead is your friend.

  s/(\d+\.\d*)\s+(?=\d+\.\d*)/\1\,/g;

Ilya


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

Date: Fri, 28 Aug 1998 23:15:54 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Repeating grouped substitutions
Message-Id: <6s7dth$vs4$3@ligarius.ultra.net>

ilya@math.ohio-state.edu (Ilya Zakharevich) wrote:
-> [A complimentary Cc of this posting was sent to Bill Raynor (B12349)
-> <braynor@jupiter.kcc.com>],
-> who wrote in article <6s78br$bfv$1@gatekeep.kcc.com>:
-> > s/(\d+\.\d*)\s+(\d+\.\d*)/\1\,\2/g;
-> > only fixes the first one (3.4 5.6 becomes 3.4,5.6). It there any way 
-> > to force perl to change all the instances, other than:
-> 
-> Lookahead is your friend.
-> 
->   s/(\d+\.\d*)\s+(?=\d+\.\d*)/\1\,/g;

I must be missing something here? Why hasn't anyone suggested:

s/(\d+)(\.| +)/\1\,/g;


Bob Trieger
sowmaster@juicepigs.com


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

Date: Fri, 28 Aug 1998 16:41:50 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Repeating grouped substitutions
Message-Id: <MPG.1050e015cba81382989779@nntp.hpl.hp.com>

In article <6s7dth$vs4$3@ligarius.ultra.net> on Fri, 28 Aug 1998 23:15:54 
GMT, Bob Trieger <sowmaster@juicepigs.com> says...
> ilya@math.ohio-state.edu (Ilya Zakharevich) wrote:
> -> [A complimentary Cc of this posting was sent to Bill Raynor (B12349)
> -> <braynor@jupiter.kcc.com>],
> -> who wrote in article <6s78br$bfv$1@gatekeep.kcc.com>:
> -> > s/(\d+\.\d*)\s+(\d+\.\d*)/\1\,\2/g;
> -> > only fixes the first one (3.4 5.6 becomes 3.4,5.6). It there any way 
> -> > to force perl to change all the instances, other than:
> -> 
> -> Lookahead is your friend.
> -> 
> ->   s/(\d+\.\d*)\s+(?=\d+\.\d*)/\1\,/g;
> 
> I must be missing something here? Why hasn't anyone suggested:
> 
> s/(\d+)(\.| +)/\1\,/g;

The main reason no one has suggested it is that there is no desire to 
change dots to commas in the problem.  However,

  s/(\d+) +/$1,/g;

should be fine, or, for that matter,

   s/ +/,/g;

Which leads to the conclusion that the best (shortest and most efficient) 
solution still seems to be

   tr/ /,/s;

As for Ilya's regex with lookahead, it is clearly better than the ones 
previously presented:

   s/(\d+.\d*)\s+(\d+\.\d*)/$1,$2/g;

 which would work on the dataset given:

   1.2,3.4 5.6,7.8    9.0

but not on, for example,

   1.2 3.4 5.6,7.8    9.0

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Aug 1998 22:08:41 GMT
From: Eric Wong <egwong@netcom.com>
Subject: Re: Simple variable manipulation question
Message-Id: <egwongEyF6uH.20p@netcom.com>

Paul Worthington <prw@evolving.com> wrote:
[ cut, before and after ]

: How do I put together a dollar sign (depicted as $), the
: lower case letter D (depicted as d), and a variable
: containing the two digit code I've extracted from the
: original variable (depicted as $sub) in such a way as to
: get the value of the variable I've just depicted?

If I understand what you're looking for, if $a has the
first part and $b has the second, then:
  $foo = eval("\$$a$b");

ought to do what you're looking for.

,Eric

[cc'd]


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

Date: Fri, 28 Aug 1998 22:14:16 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Simple variable manipulation question
Message-Id: <6s7aa0$rhf$1@ligarius.ultra.net>

[ posted to usenet and courtesy e-mail sent to Paul Worthington ]

Paul Worthington <prw@evolving.com> wrote:
-> Hi - This one ought to be easy for you regular Perl
-> authors.
-> 
-> I've got variables:
-> $m20 = 2
-> $c20 = 100
-> $d20 = Acrobat
-> $m21 = 1
-> $c21 = 20
-> $d21 = Netscape
-> 
-> Now, when given $m20 in my script, I use substr to
-> get "20" from the end of it.  Now that I know the
-> number code at the end, I want to print out
-> the value of $dwhatever_the_substr_returned (in this
-> case I want the value of $d20).
-> 
-> How do I put together a dollar sign (depicted as $), the
-> lower case letter D (depicted as d), and a variable
-> containing the two digit code I've extracted from the
-> original variable (depicted as $sub) in such a way as to
-> get the value of the variable I've just depicted?

I get spanked whenever I tell somebody to use `eval' but if it brings 
out the correct answer sobeit:

 print eval '$d'.$your_variable

untested:

#!/usr/local/bin/perl -w
$foo = "fubar";
$bar = "oo";
print eval '$f'.$bar;

this should print fubar


HTH

Bob Trieger
sowmaster@juicepigs.com


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

Date: Fri, 28 Aug 1998 22:35:17 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Simple variable manipulation question
Message-Id: <35E7321C.3E54C372@shaw.wave.ca>

[posted and mailed]

Paul Worthington wrote:
> 
> Now, when given $m20 in my script, I use substr to
> get "20" from the end of it.  Now that I know the
> number code at the end, I want to print out
> the value of $dwhatever_the_substr_returned (in this
> case I want the value of $d20).
> 

You would probably be better off using hashes.
See http://www.plover.com/~mjd/perl/varvarname.html for why.

%m = (20 => 2, 21 => 1);
%c = (20 => 100, 21 => 20);
%d = (20 => 'Acrobat', 21 => 'Netscape');

for (keys %m) { print "m = $m{$_}, c = $c{$_}, d = $d{$_}\n" }

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Fri, 28 Aug 1998 15:41:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Simple variable manipulation question
Message-Id: <MPG.1050d1f36fc3a23e989776@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <35E72224.766D5207@evolving.com> on Fri, 28 Aug 1998 15:33:25 
-0600, Paul Worthington <prw@evolving.com> says...
 ...
> How do I put together a dollar sign (depicted as $), the
> lower case letter D (depicted as d), and a variable
> containing the two digit code I've extracted from the
> original variable (depicted as $sub) in such a way as to
> get the value of the variable I've just depicted?

${"d$sub"}

But are you sure you really want to use symbolic references instead of a 
hash?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Aug 1998 16:23:42 -0600
From: Paul Worthington <prw@evolving.com>
Subject: re: simple variable manipulation
Message-Id: <35E72DEE.2D8BDCCC@evolving.com>

> If I understand what you're looking for, if $a has the
> first part and $b has the second, then:
>   $foo = eval("\$$a$b");
>
> ought to do what you're looking for.

Thanks, but that didn't work.  I think 'eval' is the
right direction, but I don't know it well enough.  I'm also
not sure I'm describing my problem clearly enough.

I've got a variable $d20.  I don't know what its value is.
I've got another variable $sub.  I know its value is 20.
How can I combine "$" and "d" and "$sub" such that I can
'print' whatever that combination is and get the value of
$d20?

I'm putting together three "pieces", and to us humans, they
look like "$d20".  How do I get Perl to recognize those
three "pieces" I've lined up next to each other as the
variable $d20 and have Perl give me the value of $d20?

I think we're on the right track, with 'eval' and escaping
the dollar sign... the answer seems to be right in front
of us... I just can't grasp it yet.

Thanks!
Paul
prw@evolving.com




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

Date: Fri, 28 Aug 1998 16:38:55 -0600
From: Paul Worthington <prw@evolving.com>
Subject: Re: simple variable manipulation
Message-Id: <35E7317F.71272E90@evolving.com>

> I get spanked whenever I tell somebody to use `eval' but if it brings
> out the correct answer sobeit:
>
>  print eval '$d'.$your_variable
>
> untested:
>
> #!/usr/local/bin/perl -w
> $foo = "fubar";
> $bar = "oo";
> print eval '$f'.$bar;
>
> this should print fubar

Yes, that does print fubar.  But it's just slightly short of what I'm
trying to do.  I've used your idea in my code and tried a few
variations on it in order to get what I want, but no dice.

I've got a variable $d20.  I don't know what its value is.
I've got another variable $sub.  I know its value is 20.
How can I combine "$" and "d" and "$sub" such that I can
'print' whatever that combination is and get the value of
$d20?

I'm putting together three "pieces", and to us humans, they
look like "$d20".  How do I get Perl to recognize those
three "pieces" I've lined up next to each other as the
variable $d20 and have Perl give me the value of $d20?

Thanks!
Paul Worthington
prw@evolving.com




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

Date: Fri, 28 Aug 1998 22:41:00 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: simple variable manipulation
Message-Id: <6s7bs3$vs4$1@ligarius.ultra.net>

[ posted to usenet and courtesy e-mail sent to Paul Worthington ]

Paul Worthington <prw@evolving.com> wrote:

-> I've got a variable $d20.  I don't know what its value is.
-> I've got another variable $sub.  I know its value is 20.
-> How can I combine "$" and "d" and "$sub" such that I can
-> 'print' whatever that combination is and get the value of
-> $d20?

print eval '$d'.$sub;

Bob Trieger
sowmaster@juicepigs.com


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

Date: Fri, 28 Aug 1998 18:11:00 -0500
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: simple variable manipulation
Message-Id: <35E73904.44F21C32@email.sps.mot.com>

Paul Worthington wrote:

> How do I get Perl to recognize those
> three "pieces" I've lined up next to each other as the
> variable $d20 and have Perl give me the value of $d20?

Try this:

$d20 = 'Acrobat';
$Acrobat = 1;		# put something into $Acrobat
$sub = 20;

eval '$Acrobat = $d'.$sub;

print $Acrobat;		# output: Acrobat

-TK-


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

Date: Fri, 28 Aug 1998 15:05:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: SWF (Shockwave Flash) file format
Message-Id: <MPG.1050c9876e6d090a989774@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <35E6BD4C.709B929C@sober.com> on Fri, 28 Aug 1998 10:23:08 -
0400, jason moore <jmoore@sober.com> says...
> > >     Larry> I am having difficulty parsing packed binary data from the
> > >     Larry> Shockwave Flash file format (.swf), despite having the
> > >     Larry> detailed specification in hand.  I have found no module
> > >     Larry> that helps either.
> > >
> > I will overlook the patronizing nature of your response.  Instead, I will
> > follow the advice of Jason Moore [jmoore@sober.com], sent to me by email:
> > 
> > "Send the newsgroup a code sample, and the part of the relevant part of
> > the spec.  I'm sure perl can do what you want, and it would probably be
> > a cool little addition to Image::Size if gets figured it out."
> > 
> > Here is the spec excerpt (from <URL:
> > http://www.macromedia.com/software/flash/open/spec/SWFfilereference.html
> > >.
> >
> 
> Hi Larry -- i don't think the previous poster was trying to insult you. 
> Sometimes there are some pretty silly questions in the perl ng's - he
> just mistook your question for one of them! <g>

Adrian sent me a hurt letter, and I apologized to him.  Having spent far 
too much time struggling with unpack, I boiled over at being pointed at 
it.  I shouldn't have.

>   Anyways, I dug up some
> old code where i was trying to read the header of a flash file.  It
> doesn't answer your question, but it does read the 5 bit number in the
> first part of the RECT field, so maybe this will get you one step
> further.
> 
> Apologies for the ugliness of the code.. and please note, the
> x/y/min/max coordinates are not being unpacked properly.  Also, the spec
> says "other types of values that follow one of more bit values are
> always aligned to the nearest byte boundary with zero bits as padding." 
> I took this to mean that after I extract the 5 bit number which gives me
> the number of bits in the remaining 4 fields of the RECT structure, i
> can just skip to the next byte.  Anyways, i'm not a master bit diddler,
> so have fun.  Let me know how it turns out.
> 
> :jason

<SNIP> of Jason's code, which was encouraging and helpful.  In fact, the 
specific problem I was facing was that the x/y/min/max coordinates were 
not being unpacked properly.  It turns out that Jason's conjecture about 
the bit packing was incorrect.  Following the 5-bit field that tells how 
many bits are in the succeeding fields, the fields themselves are packed 
contiguously.  The next field after *that* is byte-aligned.

So I have solved the problem, and will present working code.  I don't 
think it is ugly, but I do think it is baroque.  I hope someone here will 
have a nicer approach.

You can read the code to figure it out, but here is a gloss:

Extract and convert the 5-bit size field.  Then convert the appropriate 
number of bits into a binary string ('1's and '0's), split out the four 
chunks, pad them with leading '0's to 32 characters, and unpack those to 
long integers.  It works on PA-RISC and Intel, which I think are 
opposite-endians.  But yuck.  Is string-slinging the way to do this in 
Perl???

#!/usr/local/bin/perl -w
use strict;

my $data = "\x70\x00\x0c\x80\x00\x00\x96\x00";

my $n_bits = ord(substr($data, 0, 1)) >> 3;
my ($xmin, $xmax, $ymin, $ymax) = 
    map unpack('N' => pack 'B*' => '0' x (32 - $n_bits) . $_) =>
        substr(unpack("B${\(5 + 4 * $n_bits)}" => $data), 5) =~
            /(.{$n_bits})/g;
print "xmin = $xmin xmax = $xmax ymin = $ymin ymax = $ymax\n";
__END__
xmin = 0 xmax = 6400 ymin = 0 ymax = 4800  

BTW, when this is done, I will ask that it be included in Image::Size, so 
no one else has to suffer through this.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Aug 1998 16:22:40 -0700
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
To: Jeff Handley <Jeff.Handley@SDRC.com>
Subject: Re: Uploading Binary files
Message-Id: <35E73BC0.1FA51336@cks.ssd.k12.wa.us>

Jeff Handley wrote:
> 
> I am trying to write a CGI script in Perl which handles a file upload
> from a form.  I can read in and save text files without a problem, but
> when I read in binary files, they become corrupt.  Has anyone done this
> successfully?

Yep.  I have an image library that my users use to upload graphics.  The
magic trick is not to use the CGI.pm upload features, but use
CGI_Lite.pm.  Much cleaner.

Jerome


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

Date: Fri, 28 Aug 1998 16:43:17 -0600
From: Lynn Wilson <lynn@swcp.com>
Subject: Using OLE to get Excel VBA using the clipboard
Message-Id: <35E73285.49693315@swcp.com>

I am trying to extract the embedded VBA code that is found in
Excel modules.  I have included the perl code that I'm using to
do this.

If I include the commented out code "$module->PrintOut()", the
VBA that I'm seeking is printed out correctly on my printer.  OLE
does not offer a way to name the file if I were to elect to print
to a file, and I need this to run unattended -- thus no popup
dialog boxes asking for filenames.  ie; I can see no way to print
to a file.

My thought was to copy the contents of the VBA module to the
clipboard using the "$module->Copy("")" line but this does not
seem to work.  Can anyone see what I'm doing wrong?  Do you know
a way to do this?

Thanks,
Lynn

---------------------- cut here -----------------------------

use Win32::OLE;
use Win32::Clipboard;   # supports Empty(), Get(), and
Set("blah") methods

$clipboard = Win32::Clipboard->new()
        || die "Couldn't create clipboard object: $!\a\n";

$filename = "D:\\eds\\eds\\apps\\Depository_app\\OPEGMAS1.xls";

# Create OLE object - Excel Application Pointer
Win32::OLE::CreateObject( "Excel.Application", $xl_app)
    || die "Couldn't create OLE object: $!\a\n";

# Set Application Visibility  0=Not Visible  1=Visible
$xl_app->{Visible} = 0;

# Open Excel File
my $workbook = $xl_app->Workbooks->Open($filename)
        || die "Remember full path names are
required.\n$filename: $!\a\n";

# Get number of objects in each of the container types
my $total_modules = $workbook->Modules->Count();

# spin through all modules looking for VBA code
foreach my $index ( 1 .. $total_modules )
{
        my $module = $workbook->Modules($index);
        my $ModuleName = $module->{Name};
        $module->Activate();
        ### $module->PrintOut();    # prints the VBA on the
printer

        $clipboard->Empty();
        #$module->Cells->Select();
        $module->Copy("");      # copy the VBA code to the
clipboard
        $contents = $clipboard->Get();  # read the clipboard into
perl variable

        print "$ModuleName\n    $contents\n";
}


# Close It Up
$xl_app->ActiveWorkbook->Close(0);
$xl_app->Quit();
#$xl_app->Destroy;

__END__



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

Date: Fri, 28 Aug 1998 16:50:50 -0500
From: Tk Soh <r28629@email.sps.mot.com>
Subject: watching 'my' in debug mode
Message-Id: <35E7263A.A4EE1A5A@email.sps.mot.com>

I am trying to use the 'my' operator for all the good reason I read
about. But when I get into the debug mode (perl -d), I couldn't seem to
read the variables' content using 'X' or 'V'..., so I have to switch
them to 'local'. Appreciate if anyone could tell me what I have to do to
make it work for 'my'.

FYI, I scan the perldebug and faqs (with pod2man | nroff | grep) but
couldn't find help. I am using Perl 5.005_01 on Sun-Solaris.

thx,
-TK-


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

Date: 28 Aug 1998 23:15:53 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: watching 'my' in debug mode
Message-Id: <6s7dn9$rm5$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tk Soh 
<r28629@email.sps.mot.com>],
who wrote in article <35E7263A.A4EE1A5A@email.sps.mot.com>:
> I am trying to use the 'my' operator for all the good reason I read
> about. But when I get into the debug mode (perl -d), I couldn't seem to
> read the variables' content using 'X' or 'V'..., so I have to switch
> them to 'local'. Appreciate if anyone could tell me what I have to do to
> make it work for 'my'.

Follow the documentation.  Note that it does not advice you to use 'X'
or 'V', but it advices you to use 'h' and 'h h'.  Anybody knows why
people always do it?  Putting bad books under your pillow?

Btw, I'm answering this only because I thought you wanted to watch
'my' variables.  Supposing you stay in the same scope (otherwise
watching has no sense), I got the following recipe

   > perl -Ilib -de "my $a;" -e "$a=2;" -e "$a = 3"
Loading DB routines from perl5db.pl version 1.0301
Emacs support available.

Enter h or `h h' for help.

main::(-e:1):   my $a;
  DB<1> n
main::(-e:2):   $a=2;
  DB<1> $db::a_p = \$a

  DB<2> W $$db::a_p
  DB<3>
Watchpoint 0:   $$db::a_p changed:
    old value:  undef
    new value:  '2'
main::(-e:3):   $a = 3
  DB<3>
Watchpoint 0:   $$db::a_p changed:
    old value:  '2'
    new value:  '3'
Debugged program terminated.  Use q to quit or R to restart,
  use O inhibit_exit to avoid stopping after program termination,
  h q, h R or h O to get additional info.
  DB<4>

Ilya


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

Date: Fri, 28 Aug 1998 15:41:13 -0700
From: Joel Rosenberg <jhr@best.com>
Subject: Win32 LWP Perl Module
Message-Id: <35E73209.DC0CA14C@best.com>

Can anyone help me locate a Win32 LWP perl module?
I have found the UNIX, but not Win32.

--
Joel Rosenberg
jhr@best.com
650-941-3306




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

Date: Fri, 28 Aug 1998 22:23:11 GMT
From: aleyva@erols.com (Angel Leyva)
Subject: Re: Windows95, Perl, PWS (IIS)
Message-Id: <35e82d8d.1665815@news.erols.com>

I have tried all the above. I installed ActiveState Perl with the
ISAPI enabled. When I try to run the script from the browser, it
attempts to save the file with a .exe extension.

Any ideas?

A


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

Date: Fri, 28 Aug 1998 16:45:38 +0100
From: Jeff Kiser <jeffk@synplicity.com>
Subject: XS with win32 Perl
Message-Id: <35E6D0A2.5479F411@synplicity.com>

I am having problems writing my own extensions with XS and the latest
ActivePerl (5.005).  Even trying the simple "Hello world" example in
perlxstut.html gives me the same problem.  The message I am getting is:

C:\Perl\5.005\lib\MSWin32-x86-object\CORE\perl.h(1232) : error C2644:
basis class 'CPerlObj' for pointer to member has not been defined

Does anyone know a solution to this?  In the perl.h header file, it
mentioned that you must link the perlX.lib library to define this class
but I don't have this library anywhere on my machine.  Do you have to
build the Perl yourself to get this file and, if so, is the source code
to the new ActivePerl available anywhere on ActiveState's website?
Thanks for any help.

Jeff Kiser
jeffk@synplicity.com
jkiser@best.com





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

Date: 28 Aug 1998 17:08:44 -0400
From: Ala Qumsieh <aqumsieh@tigre.matrox.com>
Subject: Re: {n} quantifier question
Message-Id: <x3y3eagak6b.fsf@tigre.matrox.com>


rowlands@my-dejanews.com writes:

> 
> Apologies if I'm being dense, but can anyone explain why
> 
>   "ab" =~ /(a*[^b]*b){2}/
> 
> is true? I expect it to match only strings with at least two b's.
> 
Hmmmm...

#!/usr/local/bin/perl

if ("ab" =~ /(a*[^b]*b){2}/) { die "YES\n" }
print "Nope!\n";
__END__

This prints "Nope!" on my machine! What version of Perl are you using?
(I doubt if that would make a difference anyway!)

-- 
Ala Qumsieh             |  No .. not Just Another
ASIC Design Engineer    |  Perl Hacker!!!!!
Matrox Graphics Inc.    |
Montreal, Quebec        |  (Not yet!)


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3580
**************************************

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