[9989] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3582 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 29 05:04:08 1998

Date: Sat, 29 Aug 98 02:00:21 -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           Sat, 29 Aug 1998     Volume: 8 Number: 3582

Today's topics:
        a novice loading perl <stallins@best.com>
    Re: a novice loading perl <zenin@bawdycaste.org>
    Re: a novice loading perl <nguyend7@msu.edu>
    Re: A perl filter script (Bill)
    Re: Another backslash question (Ronald J Kimball)
        Can you reload frames (Mark FINOCCHIARO)
        Imagine... a non-greedy world! <mee@mine.com>
    Re: Imagine... a non-greedy world! <rra@stanford.edu>
    Re: Imagine... a non-greedy world! (Larry Rosler)
    Re: Is this how it's supposed to be? (David A. Black)
        Java Web Server File Uploads simple@nanospace.com
        mod (%) operator oddities with large integers <danmcc@metro.net>
    Re: mod (%) operator oddities with large integers <nguyend7@msu.edu>
    Re: mod (%) operator oddities with large integers <zenin@bawdycaste.org>
    Re: mod (%) operator oddities with large integers (Dean Inada)
    Re: mod (%) operator oddities with large integers (Ilya Zakharevich)
    Re: output in shell, but not in browser? <nguyend7@msu.edu>
    Re: perl 5.005 RPM for redhat 4.2 anyone? <jdf@pobox.com>
    Re: PERL and Updating files (Sam Holden)
    Re: Perl Contract Engineer (Ronald J Kimball)
    Re: Perl Cookbook, does anyone have it? <admin@kewl.com.au>
    Re: Remove lines from output simple@nanospace.com
    Re: Repeating grouped substitutions (Ronald J Kimball)
    Re: Simple regex problem. simple@nanospace.com
    Re: SWF (Shockwave Flash) file format <uri@sysarch.com>
    Re: SWF (Shockwave Flash) file format (Larry Rosler)
    Re: variable interpolation in regular expressions (Ronald J Kimball)
    Re: watching 'my' in debug mode (Ronald J Kimball)
    Re: what's wrong with this statement? (Ronald J Kimball)
    Re: Windows95, Perl, PWS (IIS) <johnjac@berkshire.net>
    Re: Y2K Date Support <mee@mine.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 29 Aug 1998 05:23:16 GMT
From: "Curtis Stallins" <stallins@best.com>
Subject: a novice loading perl
Message-Id: <01bdd30d$27ee34c0$3e5c56ce@stallins.vip.best.com>

Can you please tell me where on the web I can find the software *and*
correct instructions for installing Perl onto my PC? I want desperately to
learn the language, but am having difficulty getting started. 
-- 

Curtis Stallins
AvidWeb Design
Setting Your Sites on the World


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

Date: 29 Aug 1998 06:09:43 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: a novice loading perl
Message-Id: <904370756.637266@thrush.omix.com>

Curtis Stallins <stallins@best.com> wrote:
: Can you please tell me where on the web I can find the software *and*
: correct instructions for installing Perl onto my PC? I want desperately to
: learn the language, but am having difficulty getting started. 

        What operating system?

        http://www.perl.org/

-- 
-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: 29 Aug 1998 07:14:10 GMT
From: Dan Nguyen <nguyend7@msu.edu>
Subject: Re: a novice loading perl
Message-Id: <6s89o2$n8a$1@msunews.cl.msu.edu>

Curtis Stallins <stallins@best.com> wrote:
: Can you please tell me where on the web I can find the software *and*
: correct instructions for installing Perl onto my PC? I want desperately to
                                                   ^^
: learn the language, but am having difficulty getting started. 


I'll make an assumption that your using windows.  The easiest port to
windows is probably the Activestate port.  http://www.Activestate.com

REMEMBER READ the faq and man pages provided before posting questions.
-dan
-- 
           Dan Nguyen            | There is only one happiness in
        nguyend7@msu.edu         |   life, to love and be loved.
http://www.cse.msu.edu/~nguyend7 |                   -George Sand



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

Date: Sat, 29 Aug 1998 06:08:38 GMT
From: wmcclatc@primenet.com (Bill)
Subject: Re: A perl filter script
Message-Id: <362c28f4.977529453@nntpd.databasix.com>

For some reason on 26 Aug 1998 03:53:51 GMT, 
Dan Nguyen <nguyend7@msu.edu> babbled:

>In comp.lang.perl.misc Phil Barone <pbarone@cape.net> wrote:
>Don't reinvent the wheel.  Try the unix util procmail

Utility?!!  Calling Procmail a utility is like calling VB a good
alternative to Perl.

BTW, procmail lets you use Perl for filtering purposes.
-- 
wmcclatc@primenet.com 
wmcclatc@nyx.net


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

Date: Sat, 29 Aug 1998 00:49:08 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Another backslash question
Message-Id: <1dehvl3.33009d1umyngqN@bay1-148.quincy.ziplink.net>

Doug <dmr@doug.fc.hp.com> wrote:

>   $fqdn =~ tr/\\//;

This translates backslash characters to backslash characters.  Not
particularly useful. [1]

>   $fqdn =~ tr[\][];  #(pukes)

This is syntax error, because you have two left square brackets, and
only one right square bracket.

>   $fqdn =~ tr/\\\\//;

This translates backslash characters to backslash characters.  Still not
particularly useful. [2]


If you want to delete characters, you must use the /d modifier to
tr///;.

$fqdn =~ tr/\\//d;

If you want to replace single characters with multiple characters, you
should not be using tr///, because tr/// only does one-to-one character
translations.

$fqdn =~ s/\\/\\\\/g;


[1] Unless you want to count the number of backslashes.

[2] See [1]

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 29 Aug 1998 05:32:01 GMT
From: mfin@ecr.mu.oz.au (Mark FINOCCHIARO)
Subject: Can you reload frames
Message-Id: <6s83oi$ciu$1@mulga.cs.mu.OZ.AU>

Using forms is is possible to send data to more than one perl script?


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

Date: Sat, 29 Aug 1998 00:49:33 -0700
From: Mee <mee@mine.com>
Subject: Imagine... a non-greedy world!
Message-Id: <35E7B28D.2207FF28@mine.com>

To: All priests of Perl black maguc

My favorite beef with Perl (besides it being the ugliest 
language man has ever devised) is its implementation of 
Regular Expresssions (regexp).

Day after day, I find myself fighting the regexp greediness
tooth and nail to arrive at the desired result.

Why in the world should /si*k/ match "something that bozos
put on their ugly, bloated faces when they get drunk" 
rather than just simply "sink" is beyond me.

Now, can anyone imagine a world with Perl in harmony 
with nature? Would it take away the magic, would it make 
it too plain?

Or am I simply overlooking some hidden, but obvious too
the enlightened, logical reason for greediness?

Mee


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

Date: 29 Aug 1998 01:21:21 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Imagine... a non-greedy world!
Message-Id: <m3yas8kxku.fsf@windlord.Stanford.EDU>

Mee <mee@mine.com> writes:

> Why in the world should /si*k/ match "something that bozos put on their
> ugly, bloated faces when they get drunk" rather than just simply "sink"
> is beyond me.

It doesn't.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 29 Aug 1998 01:41:21 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Imagine... a non-greedy world!
Message-Id: <MPG.10515e8b855927c5989811@nntp.hpl.hp.com>

In article <35E7B28D.2207FF28@mine.com> on Sat, 29 Aug 1998 00:49:33 -
0700, Mee <mee@mine.com> says...
 ...
> Day after day, I find myself fighting the regexp greediness
> tooth and nail to arrive at the desired result.
> 
> Why in the world should /si*k/ match "something that bozos
> put on their ugly, bloated faces when they get drunk" 
> rather than just simply "sink" is beyond me.

It doesn't match that.

 ... 
> Or am I simply overlooking some hidden, but obvious too
> the enlightened, logical reason for greediness?

Maybe you are overlooking the '?' quantifier, which constrains the 
greediness that upsets you so much.

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


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

Date: Fri, 28 Aug 1998 20:08:09 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: Is this how it's supposed to be?
Message-Id: <6s7gp9$c5h$1@earth.superlink.net>

Hello -

webmuse@my-dejanews.com writes:

>Using version 5.004_69 built for MSWin32-x86. Is
>this a bug in perl, a bug in THIS build of perl, or
>not a bug at all?

The latter :-)

my() variables don't appear in the symbol table - but
symbolic references only work with variables which do
appear in the symbol table.  Therefore, if the value of
$1 is the name of a my() variable, the expression ${$1}
does not refer to that variable, but rather to a package
variable of the same name.



David Black
dblack@saturn.superlink.net





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

Date: Sat, 29 Aug 1998 01:00:42 +0100
From: simple@nanospace.com
Subject: Java Web Server File Uploads
Message-Id: <simple-2908980100420001@tc1-dialin8.nanospace.com>

Does anywone out there have experience in uploading a file to a Java Web
Server?  I'm using the standard cgi-lib.pl (version 2.17).  I can specify
an enctype of "multipart/form-data". I can even upload files on IIS under
Windows NT and on Apache under Solaris and Linux.  Fortunately, version
2.17 of the cgi-lib.pl spits out an error message. "Reached end of file
before finding end of headers".  The cgi-lib.pl works with the default
enctype. I can even do away with the cgi-lib.pl and redirect STDIN to
write a file.  So file uploading is working. Its just that the sub section
of the ReadParse routine that handles the content type of
"multipart/form-data" doesn't work on JWS.

Has anyone had any experience with this?


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

Date: Fri, 28 Aug 1998 21:40:12 -0700
From: Dan McCormick <danmcc@metro.net>
Subject: mod (%) operator oddities with large integers
Message-Id: <35E7862B.3089F974@metro.net>

Can anyone provide any insight into this odd occurrence:

$ perl -e 'print 34259873425 % 1000000'
102353

$ bc
34259873425 % 1000000
873425

The ever-helpful Windows calculator confirmed bc's suspicions.
Furthermore, perl returned different results on two different platforms
(linux/solaris).

My first assumption that I was pushing perl's integer limits seems to be
refuted by

$ perl -e 'print 34259873425 + 34259873425'
68519746850

$ bc
34259873425 + 34259873425
68519746850

 ... and other successful tests with large-number arithmetic.

Anyone have any clues as to what's going on?

Dan



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

Date: 29 Aug 1998 06:06:28 GMT
From: Dan Nguyen <nguyend7@msu.edu>
Subject: Re: mod (%) operator oddities with large integers
Message-Id: <6s85p4$cnf$1@msunews.cl.msu.edu>

Dan McCormick <danmcc@metro.net> wrote:
: Can anyone provide any insight into this odd occurrence:

: $ perl -e 'print 34259873425 % 1000000'
: 102353
967295 on a Solaris 2.6 machine with 5.00501
102353 on a Linux 2.0.33 machine with 5.00404
483647 on a IRIX 6.2 machine running 5.003

This is wierd!!!

-dan
-- 
           Dan Nguyen            | There is only one happiness in
        nguyend7@msu.edu         |   life, to love and be loved.
http://www.cse.msu.edu/~nguyend7 |                   -George Sand



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

Date: 29 Aug 1998 06:06:56 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: mod (%) operator oddities with large integers
Message-Id: <904370589.476750@thrush.omix.com>

[posted & mailed]

Dan McCormick <danmcc@metro.net> wrote:
: Can anyone provide any insight into this odd occurrence:
        >sniped and moved around a bit<
: My first assumption that I was pushing perl's integer limits seems to be
: refuted by
: $ perl -e 'print 34259873425 + 34259873425'
: 68519746850

        Nope, that isn't doing what you think it is.

        Perl stores it's numbers as (long?) doubles, even if you always use
        them as ints.  This is why 34259873425 + 34259873425 works.  Try it
        with -Minteger and it won't work on most machines.

: $ perl -e 'print 34259873425 % 1000000'
: 102353

        The modulus operator can't be used on floats, so perl casts
        them to unsigned longs to do this operation, and then you
        still hit integer limits on most machines:

        $ cat foo.c
        #include <stdio.h>
        void main () {
            unsigned long foo = 34259873425;
            unsigned long bar = 1000000;
            printf ("%d %% %d == %d\n", foo, bar, foo % bar);
        }
        $ gcc -o foo foo.c
        foo.c: In function ain':
        foo.c:3: warning: integer constant out of range
        foo.c:3: warning: decimal constant is so large that it is unsigned
        $ ./foo
        -99864943 % 1000000 == 102353

        Duh!

: $ bc
: 34259873425 % 1000000
: 873425

        Use Math::BigInt if you want to handle ints this big.

        $ perl -MMath::BigInt -e '
        > $foo = Math::BigInt->new("34259873425");
        > $bar = Math::BigInt->new ("1000000");
        > print $foo % $bar'
        +873425

: Furthermore, perl returned different results on two different platforms
: (linux/solaris).

        FreeBSD x86 and Solaris 2.5.1 on an UltraSparc 1 report the same
        numbers.  What kind of boxes are they?  Is either the Linux or
        Solaris box 64 bit?
 
        >snip<
: ... and other successful tests with large-number arithmetic.

        Yes, but you're not working with ints here, even if it looks
        on the outside like you are.  They only turn into ints when
        you try to divide them.

-- 
-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: 29 Aug 1998 07:25:53 GMT
From: dmi@delta1.deltanet.com (Dean Inada)
Subject: Re: mod (%) operator oddities with large integers
Message-Id: <6s8ae1$i1f$1@news01.deltanet.com>

In article <904370589.476750@thrush.omix.com>,
Zenin  <zenin@bawdycaste.org> wrote:
>
>        The modulus operator can't be used on floats, so perl casts
Why not?  It's a perfectly sensible operator to use on floats.

>        them to unsigned longs to do this operation, and then you
>        still hit integer limits on most machines:


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

Date: 29 Aug 1998 08:18:51 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: mod (%) operator oddities with large integers
Message-Id: <6s8dhb$6eo$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Dean Inada
<dmi@delta1.deltanet.com>],
who wrote in article <6s8ae1$i1f$1@news01.deltanet.com>:
> In article <904370589.476750@thrush.omix.com>,
> Zenin  <zenin@bawdycaste.org> wrote:
> >
> >        The modulus operator can't be used on floats, so perl casts

> Why not?  It's a perfectly sensible operator to use on floats.

The only reason is that Larry objects.  I have no idea why, except
that it is very hard to make an implementation which is as quick as
the current one with small arguments, and works with strings as well.

Ilya


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

Date: 29 Aug 1998 04:23:52 GMT
From: Dan Nguyen <nguyend7@msu.edu>
Subject: Re: output in shell, but not in browser?
Message-Id: <6s7voo$qh8$1@msunews.cl.msu.edu>

Dan Bassett <dan@bns.com> wrote:
: When running the attached script via Telnet, it outputs the information
: from the program on the screen.  However, when I run the same script
: from a browser, the output is just blank.

Browsers need to be sent a content-type.  Try
print "Content-type: text/plain\n\n";

That might help.

-- 
           Dan Nguyen            | There is only one happiness in
        nguyend7@msu.edu         |   life, to love and be loved.
http://www.cse.msu.edu/~nguyend7 |                   -George Sand



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

Date: 29 Aug 1998 00:00:08 -0400
From: Jonathan Feinberg <jdf@pobox.com>
To: el@linux.lisse.na (Dr Eberhard W Lisse)
Subject: Re: perl 5.005 RPM for redhat 4.2 anyone?
Message-Id: <m3u32wxws7.fsf@joshua.panix.com>

el@linux.lisse.na (Dr Eberhard W Lisse) writes:

> above subject says it all, does anyone have a pointer to where I can
> grab this?

There's no reason not to grab the vanilla perl source distribution
from the CPAN, and then build it yourself.  It's trivial.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: 29 Aug 1998 07:52:48 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: PERL and Updating files
Message-Id: <slrn6ufcqg.3lu.sholden@pgrad.cs.usyd.edu.au>

On Sat, 29 Aug 1998 00:34:24 +0100, simple@nanospace.com <simple@nanospace.com>
    wrote:
>Lets see.
>
># open a file for reading like this:
>
>open (FILEHANDLE, "filename");
>@lines = <FILEHANDLE>;
>close FILEHANDLE;
>
># now you've got all the lines in an array called @lines
>
>
># While you've got them you could change info with substitution
># this will replace all occurrences of string1 with string 2.
>
>foreach $line (@lines) {
>   $line =~ s/string1/string2/g;
>}
># open a file for writing like this
>
>open (FILEHANDLE, ">filename");
>print FILEHANDLE (@lines);
>close FILEHANDLE;

Well you could but you wouldn't want to be using large files, seeing you slurp
them all into memory... and let's just say your not being lazy enough how 
about :

perl -pi -e 's/string1/string2/g'

perldoc is your friend...

Sam



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

Date: Sat, 29 Aug 1998 00:49:09 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl Contract Engineer
Message-Id: <1dehx04.bpb4al15b2v9uN@bay1-148.quincy.ziplink.net>

<@san.rr.com> wrote:

> We are looking for a contract engineer with experience in Perl 5.1
> programming for a project we have.

I think you may be looking for quite some time...

5.1??

> Please contact via email or phone.

The former may be difficult, since your email address does not include a
username.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 29 Aug 1998 15:12:12 +1000
From: "Craig Nuttall" <admin@kewl.com.au>
Subject: Re: Perl Cookbook, does anyone have it?
Message-Id: <l4MF1.3309$LF.1264192@nsw.nnrp.telstra.net>


Owen Cook <rcook@pcug.org.au> wrote in message
35e83428.805397@newshost.pcug.org.au...
>On Wed, 26 Aug 1998 19:14:05 GMT, ptimmins@netserv.unmc.edu
(Patrick
>Timmins) wrote:
>
>Guess it will never get to Australia
>
>
>Owen

Fear not, I have a copy on order from a Brisbane distributor and
they assure me that the new version will be available early
September........... but the Aust. price will be a killer for
some......... $89 if memory serves correctly :-(

Anyways....... My library of O'Reilly books has been well worth
the investment and I doubt that the cookbook will be any less
than well worth the money :-)

Craig




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

Date: Sat, 29 Aug 1998 01:28:06 +0100
From: simple@nanospace.com
Subject: Re: Remove lines from output
Message-Id: <simple-2908980128060001@tc1-dialin8.nanospace.com>

Try matching instead of equality:

if ($port !~ /ttyE60|ttyE61/)  {
   print "$port $timeon $pid\n"
}

That is if port is not matched by ttyE60 or ttyE61

In article <6qunjr$5in$1@nswpull.telstra.net>, "Craig Nuttall"
<admin@kewl.com.au> wrote:

> This does what I want.
> 
> for (keys %ppp) {
>     my ($port, $timeon, $pid) = split /\s+/, $ppp{$_};
> if ($port ne "ttyE60,") {
>     print "$port $timeon $pid\n";
>     }
> }
> 
> how do I remove more than just ttyE60, from the report
> eg ttyE60 and ttyE61 and etc etc
> 
> Any help appreciated
> Craig
> admin@kewl.com.au
> The effort of learning provides the gift of teaching :-)


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

Date: Sat, 29 Aug 1998 00:49:10 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Repeating grouped substitutions
Message-Id: <1dehxcw.1apbl8q1sj9d6aN@bay1-148.quincy.ziplink.net>

Bill Raynor (B12349) <braynor@jupiter.kcc.com> 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 there any way 
> to force perl to change all the instances, other than:

Well, you've already gotten several suggested solutions, but no one has
explained why this regex fails to work as you intended.

First off, it does work for the example data you presented above.  It
would, however, fail with a string like '1.2 3.4 5.6 7.8', which results
in '1.2,3.4 5.6,7.8'.  As you can see, one of the spaces was skipped.

Why?  Consider what your regex matches.  On the first try, (\d+\.\d*)
matches '1.2', \s+ matches ' ', and (\d+\.\d*) matches '3.4'.
On the second try, the regex engine begins at the position where the
last match ended.  In this case, the last match ended between '3' and '
'.  The regex engine tries to match ' ' with \d, fails, and bumps along
to the '5'.
Now (\d+\.\d*) matches '5.6', \s+ matches ' ', and (\d+\.\d*) matches
'7.8', skipping the space between '4' and '5' in the process.

Thus, with consecutive missing commas, your regex will skip every other
space.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 29 Aug 1998 01:41:51 +0100
From: simple@nanospace.com
Subject: Re: Simple regex problem.
Message-Id: <simple-2908980141510001@tc1-dialin8.nanospace.com>

You can do a pattern match.  Remember those brackets are special
characters and need to be escaped.  You can then save the pattern you
found

if ($line =~ /\[(.+)\]/) {
   $adapter = $1;
}

You could have multiple parentheses groups.  Those matched patterns would
be saved in $2, $3 etc.

In article <35d1e65c.0@news1.ibm.net>, "RickR" <richardr@airmail.net> wrote:

> I have a file which consists of the follwing two lines:
> 
> Listing of [system\currentcontrolset\services\netbt\adapters]
> 
> [Elnk31]
> 
> How do I search for whatever is in the second set of brackets, and pass that
> value to a variable? For instance, $adapter = Elnk31.
> 
> I will now RTFM, but if anyone can supply an answer in the meantime, I would
> appreciate it.  (I know it will be less rewarding if someone gives me the
> answer, but it will be much faster and easier, which is why I use computers
> and newsgroups in the first place).
> 
> Thanks


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

Date: 29 Aug 1998 01:42:14 -0400
From: Uri Guttman <uri@sysarch.com>
To: lr@hpl.hp.com (Larry Rosler)
Subject: Re: SWF (Shockwave Flash) file format
Message-Id: <x74suw4a4p.fsf@sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

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


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

larry,

your code was too ugly for me to bear, so i did you (and the perl
community) a little favor.

here is a bit field extract routine. it runs a little slower than your
code (which surprises me a little) and so maybe it could be optimized
some. but it is much cleaner and more general purpose than your code.

better yet it could be written in C and made into an XS module.

perl needs a true bit field extraction module. PL/I supports substr on
bit strings which would be cool in perl but we would need a different
function name (PL/I knows the difference between bit and char
strings). bit and byte ordering can/would cause portability problems too.

but lo, what did i find but Bit::Vector. unfortunately it needs bits in
low to high in each byte. so i have to reverse each byte's bits on input
and then reverse the bits of the extracted fields on output.

so here are the benchmarked versions in all their glory. i spent too
much time on this so you owe me! :-)

uri


Benchmark: timing 1024 iterations of larry, uri, vec...
     larry:  2 secs ( 1.94 usr  0.00 sys =  1.94 cpu)
       uri:  3 secs ( 2.78 usr  0.00 sys =  2.78 cpu)
       vec:  4 secs ( 3.76 usr  0.12 sys =  3.88 cpu)


#!/usr/local/bin/perl

use integer ;
use Benchmark;
use Bit::Vector ;

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

timethese (1 << 10, {
	larry  => '&larry',
	uri  => '&uri',
	vec => '&vect',
} );

sub larry {

	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;
}

sub uri {

	my $width = &get_fields( $data, 0, 5 ) ;

	my($xmin, $xmax, $ymin, $ymax) = &get_fields( $data, 5, $width, 4 ) ;
}

sub get_fields {

	my( $in_bits, $offset, $width, $count ) = @_ ;

	my( $byte_off, $int, $mask, $shift, $field, @fields ) ;

	$mask = ( 1 << $width ) - 1 ;

	$count ||= 1 ;

	while( $count-- ) {

		$byte_off = int( $offset / 8 ) ;

		$int = vec( substr( $in_bits, $byte_off, 4 ), 0, 32 ) ;

		$shift =  $byte_off * 8 + 32 - ( $offset + $width ) ;

		$field = ( $int >> $shift ) & $mask ; 

		push( @fields, $field ) ;

		$offset += $width ;
	}

	if ( wantarray ) {

		return( @fields ) ;
	}
	else {

		return( $fields[0] ) ;
	}
}

sub vect {

	my $vec = Bit::Vector->new( 64 ) ;

	$vec->Block_Store( $data ) ;

	for ( $b = 0; $b < 64 ; $b += 8 ) {

		$vec->Interval_Reverse( $b, $b + 7 ) ;
	}

	$width = $vec->Chunk_Read( 5, 0 ) ;

	$off = 5 ;

	$vec->Interval_Reverse( $off, $off + $width - 1 ) ;
	$xmin = $vec->Chunk_Read( $width, $off ) ;

	$off += $width ;
	$vec->Interval_Reverse( $off, $off + $width - 1) ;
	$xmax = $vec->Chunk_Read( $width, $off ) ;

	$off += $width ;
	$vec->Interval_Reverse( $off, $off + $width - 1 ) ;
	$ymin = $vec->Chunk_Read( $width, $off ) ;

	$off += $width ;
	$vec->Interval_Reverse( $off, $off + $width - 1) ;
	$ymax = $vec->Chunk_Read( $width, $off ) ;

}




-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Sat, 29 Aug 1998 01:22:55 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: SWF (Shockwave Flash) file format
Message-Id: <MPG.10515a3ca61a6c33989810@nntp.hpl.hp.com>

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

In article <x74suw4a4p.fsf@sysarch.com> on 29 Aug 1998 01:42:14 -0400, 
Uri Guttman <uri@sysarch.com> says...
> >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
 ...
>   LR> But yuck.  Is string-slinging the way to do this in Perl???
 ... 
> larry,
> 
> your code was too ugly for me to bear, so i did you (and the perl
> community) a little favor.
> 
> here is a bit field extract routine. it runs a little slower than your
> code (which surprises me a little) and so maybe it could be optimized
> some. but it is much cleaner and more general purpose than your code.
> 
> better yet it could be written in C and made into an XS module.
 ... 
> so here are the benchmarked versions in all their glory. i spent too
> much time on this so you owe me! :-)
 ...
> Benchmark: timing 1024 iterations of larry, uri, vec...
>      larry:  2 secs ( 1.94 usr  0.00 sys =  1.94 cpu)
>        uri:  3 secs ( 2.78 usr  0.00 sys =  2.78 cpu)
>        vec:  4 secs ( 3.76 usr  0.12 sys =  3.88 cpu)
 ...
> sub larry {
> 	my $n_bits = ord(substr($data, 0, 1)) >> 3;

I could do better here.  I forgot that 'ord' works on the first character 
of its argument string, automatically, so the substr is a no-op.

> 	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;
> }

So let's see:  I presented 5 lines of ungainly Perl code that runs faster 
than your ~40 well-formed lines (plus the module Bit::Vector).  My code 
manipulates 'binary character strings'; yours manipulates bits in words.  
But yours could be made faster using C and XS.  Not surprising, because 
it reads like C code.

One might well conclude that Perl-ish Perl (being tuned for string-
slinging) does better on this kind of problem than C-ish Perl (which 
isn't tuned for bit-slinging).

You may indeed have done me (and the perl community) a little favor.  I 
appreciate the time you spent on this, and I do owe you, Uri!  But I 
won't switch to using your code.  :-)

Larry

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


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

Date: Sat, 29 Aug 1998 00:49:12 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: variable interpolation in regular expressions
Message-Id: <1dehy0r.132npy41q2odwuN@bay1-148.quincy.ziplink.net>

Wim Bartsoen <r20030@glo.be> wrote:

> Does anyone know how to properly do the following:
> 
> s/<!-- INPUT ([\w\-]+) -->/$query->param($1)/;

Double-quotish interpolation does not allow for use of the -> operator.
Your string probably ends up looking something like
'CGI=HASH(0x2032814)->param(xyz)'

Try the following instead

s/<!-- INPUT ([\w\-]+) -->/${\$query->param($1)}/;

in which $query->param($1) is an expression rather than a double-quotish
string.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 29 Aug 1998 00:49:13 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: watching 'my' in debug mode
Message-Id: <1dehyal.n5yfvhzy4e2nN@bay1-148.quincy.ziplink.net>

Tk Soh <r28629@email.sps.mot.com> wrote:

> 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'.

According to the documentation for the debugger, 'X' and 'V' are used
for printing the values of package variables, which appear in symbol
tables.

According to the documentation on my(), variables declared with my() are
not package variables, and do not appear in symbol tables.

Use the 'x' command instead.


-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 29 Aug 1998 00:49:14 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: what's wrong with this statement?
Message-Id: <1dehyfu.147stti1ouoepaN@bay1-148.quincy.ziplink.net>

<@thefree.net> wrote:

> Subject: what's wrong with this statement?

perl -c
> print "<HTML>\n<HEAD>\n<META NAME=\"description\" CONTENT=\"Own your own
> [...]
> CELLSPACING=\"0\"><TR VALIGN=\"top\"><TD><p><br><br><BR>";
- syntax OK

Nothing, as far as Perl is concerned.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 29 Aug 1998 00:03:47 -0700
From: "John Jacques" <johnjac@berkshire.net>
Subject: Re: Windows95, Perl, PWS (IIS)
Message-Id: <6s7vsb$kg7$1@news2.ispnews.com>

Try:
http://www.dynamicnet.net/support/fp/perlwithPWS.htm

I was just sent this to solve a simliar problem, everything is on this page.

Angel Leyva wrote in message <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: Sat, 29 Aug 1998 00:55:03 -0700
From: Mee <mee@mine.com>
Subject: Re: Y2K Date Support
Message-Id: <35E7B3D7.F2C2CCCD@mine.com>

James,

The number of linear algebra classes your friend Mee has 
taken (and given) is probably greater than the the number 
of years you've been on this Earth.

Get a life, grow up and learn to listen.

Mee


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

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

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