[16819] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4231 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 6 00:05:33 2000

Date: Tue, 5 Sep 2000 21:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968213113-v9-i4231@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 5 Sep 2000     Volume: 9 Number: 4231

Today's topics:
    Re: $LIST_SEPARATOR bug?? <elephant@squirrelgroup.com>
    Re: Accessing a C array in Perl <tim@ipac.caltech.edu>
    Re: ASCII code <yanick@babyl.sympatico.ca>
        help with a hash? ptomsic@my-deja.com
    Re: help with a hash? <bwalton@rochester.rr.com>
    Re: help with a hash? <brondsem@my-deja.com>
    Re: Match any character w/ regular expressions <sallan@nwlink.com>
    Re: Pattern matching (Keith Calvert Ivey)
    Re: Perl and mod <bwalton@rochester.rr.com>
    Re: RegEx:  I'm stumped <jar@mminternet.com>
    Re: RegEx:  I'm stumped (Keith Calvert Ivey)
    Re: Remove carriage returns from input <brondsem@my-deja.com>
        Spooling open file via http til close... dnedrow@usa.net
    Re: Stable sorting <uri@sysarch.com>
    Re: string parsing/pattern matching <bwalton@rochester.rr.com>
    Re: string parsing/pattern matching <wyzelli@yahoo.com>
    Re: translation! <brondsem@my-deja.com>
    Re: uninitialized value - but I have initilised it! Hav <Cheng3@email.msn.com>
    Re: uninitialized value - but I have initilised it! Hav <tim@ipac.caltech.edu>
    Re: using perl in a redundant way. <uri@sysarch.com>
    Re: using perl in a redundant way. (Andrew Johnson)
    Re: using the value of a variable for another varible's (Gwyn Judd)
    Re: using the value of a variable for another varible's (Mark-Jason Dominus)
    Re: using the value of a variable for another varible's (Gwyn Judd)
    Re: using the value of a variable for another varible's (Gwyn Judd)
    Re: using the value of a variable for another varible's <rick.delaney@home.com>
        weird behavior of _ file handle <qchen@snet.net>
    Re: World Wide PERL PROGRAMMERS TELECOMMUTE <uri@sysarch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 6 Sep 2000 14:49:06 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: $LIST_SEPARATOR bug??
Message-Id: <MPG.14205bb1bedc230d989766@localhost>

Keith Calvert Ivey <kcivey@cpcug.org> wrote ..
>jason <elephant@squirrelgroup.com> wrote:
>>Keith Calvert Ivey <kcivey@cpcug.org> wrote ..
>
>>look closer .. specifically the following like is removed
>>
>>     $$quote = 1 if $text =~ s/"/``/s;
>>
>>and that was the one responsible for trashing the $"
>
>Okay, I guess, but won't your substitution still trash
>paragraphs (I assume this a happening a paragraph at a time)
>that contain $" twice, or contain $" and some quoted text?

yes it would .. to be honest I spent like 2 minutes hacking a quick 
debug .. tested - and it worked .. and I moved on to paying work ;)

>Also, I know it was in the original code, but the while() --
>like the /s -- doesn't seem to serve a purpose there.  Once the
>substitution has been performed, there won't be more than one "
>in $text anymore, so it will never be true the second time it's
>tested.

feel free to debug it yourself .. but my attention span has been 
exhausted on this issue I'm afraid .. and like I said to LR - if you 
started improving the code in these modules - then you'd be there all 
day

>Not necessary.  Plain " is fine except inside attribute values
>(unless you quote them with single quotes, which I don't
>generally do).

while I know that all modern browsers support bare "s .. I'm not sure 
(and can't be bothered checking) what W3C says about them .. I thought 
that because there was such a thing as &quot; that a bare " was not 
strict HTML .. but I've never checked

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 05 Sep 2000 19:40:32 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Accessing a C array in Perl
Message-Id: <39B5AEA0.E9F2F9AE@ipac.caltech.edu>

Howerd Oakford wrote:
> I am new to Perl and I m having problems interfacing Perl to C. Perl can
> call a C function, and can get back a return value which is the address 
> of a C array. ( i.e. a pointer ). I understand that Perl does not have 
> pointers, so how can I take this pointer and access each byte 
> sequentially in Perl? The array is up to 600 bytes long.
> 
> $result  = call_C_function;
> $first = ???( $result );

perldoc -f pack
perldoc -f unpack  

Read about the 'P' (cap p) template. Never played this tune myself, but I think
it goes a little something like this ...

$packed_structure = unpack("P128",$result); # For a 128 byte struct
@values_from_structure = unpack($template,$packed_structure);

 ... where $template describes the layout of the structure.

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Wed, 06 Sep 2000 01:25:04 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: ASCII code
Message-Id: <Q1ht5.217359$Gh.4643610@news20.bellglobal.com>

Daniel <dchan@wcwpt.com.hk> wrote:
: Is there any function in Perl for getting the ascii code of a
: character?

#!/usr/bin/perl 
use strict;

sub ord
{
        my( $chr, $region, $ord, $y ) = ( shift, 2**3*5**2 );

        $ord += $y * rand $region + 1 and $region >>= 1 
                while $y = $chr cmp chr $ord;

        return int $ord;
}

print &ord( chr( $_ ) ),"\n" for 100..200;
__END__

	;)

(or perhaps you will prefer the built-in 'ord' function, 
more efficient, but not half as funny)

Joy,
Yanick



-- 
$_="+21P-A6-d-.+i-51-12+V-#+22-;-L+6-2-H+6-21+R+3-5-13+T-12";
s/[#.A-Wild;]/ord$&/eg;while( /[-+]\d+/g ){   @a or @a=($&) and next; 
unshift @a, map {($_+$&)/2 => ($_-$&)/2} pop @a; } print map chr, @a;


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

Date: Wed, 06 Sep 2000 02:31:07 GMT
From: ptomsic@my-deja.com
Subject: help with a hash?
Message-Id: <8p4a9c$3qj$1@nnrp1.deja.com>

I want to rip a string apart, finding the HREF and the Text that's
associated w/ the HREF, and place this into a HASH, i.e.
$link{this.html} = "Click Here";

for all the links on a page.  How could I do this using a function call
to return the HASH?

So, I want to make a call to a function (getHREFS) and have it return
a HASH, w/ Key's as HREFS and VALUES as the text.

Could someone assist (with the function returning part) as I've got the
HREF and the text part down using TokeParser.

Thanks


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 06 Sep 2000 02:54:02 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: help with a hash?
Message-Id: <39B5B1B9.47BB6EC@rochester.rr.com>

ptomsic@my-deja.com wrote:
> 
> I want to rip a string apart, finding the HREF and the Text that's
> associated w/ the HREF, and place this into a HASH, i.e.
> $link{this.html} = "Click Here";
> 
> for all the links on a page.  How could I do this using a function call
> to return the HASH?
> 
> So, I want to make a call to a function (getHREFS) and have it return
> a HASH, w/ Key's as HREFS and VALUES as the text.
> 
> Could someone assist (with the function returning part) as I've got the
> HREF and the text part down using TokeParser.
 ...
One way:

sub getHREFS{
    #stuff to compute %hash
    return %hash;
}
#to use it:
%h=&getHREFS;
#stuff using %h
-- 
Bob Walton


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

Date: Wed, 06 Sep 2000 03:07:04 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: help with a hash?
Message-Id: <8p4ccd$5sg$1@nnrp1.deja.com>

In article <8p4a9c$3qj$1@nnrp1.deja.com>,
  ptomsic@my-deja.com wrote:
> I want to rip a string apart, finding the HREF and the Text that's
> associated w/ the HREF, and place this into a HASH, i.e.
> $link{this.html} = "Click Here";
>
> for all the links on a page.  How could I do this using a function
call
> to return the HASH?
>
> So, I want to make a call to a function (getHREFS) and have it return
> a HASH, w/ Key's as HREFS and VALUES as the text.
>
> Could someone assist (with the function returning part) as I've got
the
> HREF and the text part down using TokeParser.

Use HTML::Parser or HTML::SimpleParse

They may make your work a little easier.

>
> Thanks
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

--
Dave Brondsema


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 05 Sep 2000 19:56:41 -0700
From: Steve Allan <sallan@nwlink.com>
Subject: Re: Match any character w/ regular expressions
Message-Id: <uog22w7me.fsf@nwlink.com>

Brendon Caligari <bcaligari@my-deja.com> writes:

>In article <8p1p2s$ckg$1@nnrp1.deja.com>,
>  Todd Wilson <toddcw@my-deja.com> wrote:
>> Sorry for the newbie question, but I'm still getting my feet wet with
>> regular expressions.
>>
>> I'm trying to match ANY character between two strings.  Something like
>> using the . character, but must also include the \n character.
>> Specifically, I'm working with an HTML file and I would like to delete
>> all text between <html> and, say, a specific <table> tag.  There will
>> obviously be many characters in between the two tags, both white space
>> and non-white space.  The regular expression I would like to use would
>> be something as simple as this:
>>
>> s/<html>.*<table>//g
>>
>> The problem is that .* won't match the newline characters.
>>
>> Any help would be much appreciated.
>>
>> Regards,
>>
>> Todd Wilson
>
>You can copy all the html file to a scalar
>   my $html;
>   $html = `cat test.html`;
>(or `type test.html` under win systems)
>

<snip>

A slight but hopefully useful digression -

There are portable ways to read a file into a scalar in Perl without
making direct calls to the system.  One which appeared here just last
week:

open(FILE, $fname) or die "Can't open $fname for reading: $!";
my $file = do {local $/; <FILE>};
close FILE;

-- Steve __


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

Date: Wed, 06 Sep 2000 03:16:25 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Pattern matching
Message-Id: <39b6b62f.4839267@news.newsguy.com>

Stephen Kloder <stephenk@cc.gatech.edu> wrote:
>Sven Rixen wrote:

>> if(${$searchfield1} =~ /$search_for1/){
>>
>> The problem is now, that if you type just one letter - let's say an 's'
>> the script will return the first datarow it encounters where the
>> searched word begins with an 's'.
>>
>> How can I force the script to compare the complete words and not just
>> stop after it finds a partial match?
>
>Use ^ to match the beginning of the string, and $ to match the end.
>It sounds like you need the regex to be /^$search_for1$/
>perldoc perlre

Of course he'll have to consider the possibility that
$search_for1 contains regex metacharacters like '?' and '(' 
-- which could be handled with \Q.

Why not avoid the regex entirely and just use the eq operator?

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Wed, 06 Sep 2000 02:44:32 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl and mod
Message-Id: <39B5AFB7.F23D18B1@rochester.rr.com>

zideon@my-deja.com wrote:
 ...
> Can somebody tell my how I can calculate with 'mod'?
> 
> P.E. $xy = 207 mod 3;
 ...
> Zid
 ...
$xy=207%3;
-- 
Bob Walton


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

Date: Tue, 05 Sep 2000 19:20:24 -0700
From: jim roush <jar@mminternet.com>
Subject: Re: RegEx:  I'm stumped
Message-Id: <deabrs8nl5l8t2falh2f0ovded38m5lpvp@4ax.com>

On Tue, 05 Sep 2000 21:50:17 GMT, Bart Lateur <bart.lateur@skynet.be>
wrote:

>jim roush wrote:
>
>>     s/&Amp;/&/
>>
>>this did nothing. 
>
>Probably just the wrong case. It's "&amp;", not "&Amp;". Oh, and you
>need to add the //g modifier (put a "g" between the 3rd slash and the
>semicolon), unless you only want to replace the first occurrence.


Good idea.


jar@mminternet.com
James A Roush


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

Date: Wed, 06 Sep 2000 02:44:05 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: RegEx:  I'm stumped
Message-Id: <39b5aee4.2972148@news.newsguy.com>

Bart Lateur <bart.lateur@skynet.be> wrote:
>jim roush wrote:
>
>>     s/&Amp;/&/
>>
>>this did nothing. 
>
>Probably just the wrong case. It's "&amp;", not "&Amp;". Oh, and you
>need to add the //g modifier (put a "g" between the 3rd slash and the
>semicolon), unless you only want to replace the first occurrence.

You also need to have your text in $_ if you want that line to
affect it.  Otherwise, you'll need to specify the variable like
this:

    $text =~ s/&amp;/&/g;

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Wed, 06 Sep 2000 03:14:14 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: Remove carriage returns from input
Message-Id: <8p4cpp$6ei$1@nnrp1.deja.com>

In article <PM6t5.15421$gg.4088888@typhoon.southeast.rr.com>,
  "Philip Garrett" <philipg@atl.mediaone.net> wrote:
> RGA <rga@io.com> wrote in message
> news:Ru6t5.61106$g53.970650@news5.giganews.com...
> > Hope I don't stimulate too many of the Unsenet police with this
silly Q,
> >
> > I need to strip out any carriage returns from my input.
> >
> > What's the character to match on.
> > I have 2 books, but can't find ..
> >
> > Can't I do a simple
> >
> >  $results =~ s/chr(10)//g;
> >
> >   Whatever that nasty carriage return is ?
>
> Carriage return is "\r".  Try s/\r//g.

AND s/\n//g

\r is return (ascii 13)
\n is newline (ascii 10)

It depends where your input is coming from, but I'd do 2 s///
statements, one to remove your returns and then again to remove your
newlines.

This simple answer was the result of a ~2 hr frustrating search.

>
> hth,
> Philip
>
>

--
Dave Brondsema


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 06 Sep 2000 01:06:20 GMT
From: dnedrow@usa.net
Subject: Spooling open file via http til close...
Message-Id: <8p45a1$u3q$1@nnrp1.deja.com>

I have an application that generates a log file of about 50k over 45
minutes. The application generates a specific set of characters to
indicate completion. I would like to continuously display the content of
this file as it's built until the file is closed/complete. The logic I
need is as follows:

INPUT: FILE == fully qualified path to log

1) If !exists(FILE) close page;

2) do (display new lines in FILE)
   until (line contains "~^~^COMPLETE")

3) Close page

The part that has me stumped is how to basically tail the file as it's
built until the "~^~^COMPLETE" line appears.

Additionally, I need to have the page start from the beginning of the
log each time someone accesses it.

Any pointers would be appreciated.

If it makes a difference, this is all Solaris based with an Apache web
server.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 06 Sep 2000 01:18:24 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Stable sorting
Message-Id: <x7wvgql3mn.fsf@home.sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes:

  Randal> For example, the GRT cannot sort "strings of arbitrary length,
  Randal> case insensitive", a fairly common requirement.  You have to
  Randal> define an upper bound for the length of a string.  Whereas
  Randal> this is trivial with an ST.

  Randal> Unless I misunderstand the entire subtleties of the GRT.

  RLS> And after rereading the paper, I'm more convinced of this.  If you
  RLS> restrict your input data to "strings that don't contain NULs", or
  RLS> "strings that do not exceed X chars", you can do it with GRT.  But a
  RLS> general solution cannot use the GRT, hence back to the ST or (gasp!)
  RLS> the original sorting.

if you want you could encode an arbitrary length strings in hex and
separate those by null bytes. not the best idea but should work fine.
the data encoding/conversion tricks of the GRT are not always easy and
are usually only worth it for large sorts where speed matters. and how
often do you sort arbitrary length strings with embedded null bytes? 

(i am waiting for larry to chime in here).

and we have never claimed that the GRT should replace the ST. in fact i
use ST more often as it is easier to code up for basic cases. i don't
actually do massive sorts so i don't care about any speed issues. and
for short datasets it is irrelevent what sort method you use.

bart asked for a faster sort and i gave him one. so it would be obvious
that i meant faster in this case. but in general we found that for
equivilent sorts (or large enough data sets) the GRT is faster as the
perl callback is removed from the compare code. all the
encoding/decoding is meant to allow the default string compare to be
used. we found many ways to create those encodings for almost any
combination of sort fields (as i have shown above for your worst case
scenario).

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Wed, 06 Sep 2000 03:30:15 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: string parsing/pattern matching
Message-Id: <39B5BA36.D646227C@rochester.rr.com>

smehta60@my-deja.com wrote:
 ...
> I have the following pseudo code:
> 
> if ($OS eq "windows")
>    $fileSeperator = "\\";
> else
>    $fileSeperator = "/";
> 
> I have a file name that is:
> $fname=$startDir.$fileSeperator."temp".$fileSeperator."temp2".$fileSeper
> ator;
> 
> So for e.g. on a windows m/c I have a file name that is :
> $fname=c:\mystartdir\temp\temp2\;
> 
> I need to parse the above string so that I have a new string that has
> only the word temp2 (i.e the subtsring between the last and the 2nd
> last fileseperator).
> 
> Is there anyway that I can do this.
 ...
> smehta60
 ...
How about

   ($newstring)=$fname=~m#[/\\]([^/\\]+)[/\\]$#;

-- 
Bob Walton


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

Date: Wed, 6 Sep 2000 13:12:18 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: string parsing/pattern matching
Message-Id: <8fjt5.30$%K.2163@vic.nntp.telstra.net>

<smehta60@my-deja.com> wrote in message
news:8p3qkd$i81$1@nnrp1.deja.com...
> Hello all:
>
> I have the following pseudo code:
>
> if ($OS eq "windows")
>    $fileSeperator = "\\";
> else
>    $fileSeperator = "/";

Why bother with all that?  Just use / on both systems.  (Try it!)


> I have a file name that is:
>
$fname=$startDir.$fileSeperator."temp".$fileSeperator."temp2".$fileSeper
> ator;
>
> So for e.g. on a windows m/c I have a file name that is :
> $fname=c:\mystartdir\temp\temp2\;
>
> I need to parse the above string so that I have a new string that has
> only the word temp2 (i.e the subtsring between the last and the 2nd
> last fileseperator).
>
> Is there anyway that I can do this.
>

If you control the separator, then you only need to do:

($name) = ($fname =~ m|.*/(.*)/|);

However, if the path can still sometimes come in from the system on
win32 with backslashes, you may still need to do:

($name) = ($fname =~ m|.*[/\\](.*)[/\\]|);

Wyzelli




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

Date: Wed, 06 Sep 2000 03:04:30 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: translation!
Message-Id: <8p4c7k$5q5$1@nnrp1.deja.com>

In article <39B4E4BB.48736B3B@staffs.ac.uk>,
  Tim Cockle <T.Cockle@staffs.ac.uk> wrote:
> Can someone give me a hint to what this means?
>
> Attempt to free non-existent shared string at (eval
> 2)[C:/Perl/lib/DynaLoader.pm:219] line 1.

What script do you have on line 1 of C:/Perl/lib/DynaLoader.pm?   Or
maybe line 219?

> Thanks,
>
> Tim
>
>

--
Dave Brondsema


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 5 Sep 2000 20:55:33 -0400
From: "Liang Cheng" <Cheng3@email.msn.com>
Subject: Re: uninitialized value - but I have initilised it! Haven't I?
Message-Id: <uzidFz5FAHA.436@cpmsnbbsa07>

check if initialization with defined() function, also read the perldoc -f
defined
The thing is that is a variables contains a null value, such as <undef> most
operation will tell you it's undefined.
It is a bit different than C.
Mark Worsdall <linux@wizdom.org.uk> wrote in message
news:16yhpIAd4Xt5EwA6@worsdall.demon.co.uk...
> Why do I get this error:-
>
> Use of uninitialized value at /usr/www/cgi-bin/DisplayAgents.pl line 57.
>
> Line 57: @pairs = split(/&/, $ENV{'QUERY_STRING'});
>
>
> from this code:-
>
> my $name   = '';
> my $value  = '';
> my $pair   = '';
> my @pairs  = ();
> my $buffer = '';
>
>     if ($ENV{'REQUEST_METHOD'} eq 'GET') {
>         # Split the name-value pairs
>         @pairs = split(/&/, $ENV{'QUERY_STRING'});
>     }
>     elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
>         # Get the input
>         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
>         # Split the name-value pairs
>         @pairs = split(/&/, $buffer);
>     }
>     else {
>         exit;
>     }
>
>
> --
> He came from Econet - Oh no, I've run out of underpants :(
> Home:- jaydee@wizdom.org.uk       http://www.wizdom.org.uk
> Shadow:- webmaster@shadow.org.uk  http://www.shadow.org.uk
> Work:- netman@hinwick.demon.co.uk http://www.hinwick.demon.co.uk
> Web site Monitoring:-             http://www.shadow.org.uk/SiteSight/




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

Date: Tue, 05 Sep 2000 19:24:50 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: uninitialized value - but I have initilised it! Haven't I?
Message-Id: <39B5AAF2.E36E7235@ipac.caltech.edu>

Mark Worsdall wrote:
> 
> Why do I get this error:-
> 
> Use of uninitialized value at /usr/www/cgi-bin/DisplayAgents.pl line 57.
> 
> Line 57: @pairs = split(/&/, $ENV{'QUERY_STRING'});
> 

Well, since @pairs is initialized, what other variable in that statement might
not be? Besides, since @pairs is in the receiving side of the '=', it doesn't
matter if it's initialized, only that it's declared.

Also: you're working way too hard doing intializations on all those other
variables. You're better off simply testing where neceesary for definedness. 

perldoc -f defined

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Wed, 06 Sep 2000 01:23:01 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: using perl in a redundant way.
Message-Id: <x7pumil3ex.fsf@home.sysarch.com>

>>>>> "AJ" == Andrew Johnson <andrew-johnson@home.com> writes:

  AJ> In article <x77l8qms04.fsf@home.sysarch.com>,
  AJ>  Uri Guttman <uri@sysarch.com> wrote:

  >> while( $line = <SRC> ) {

  AJ> wouldn't it be more perlish to do while(<SRC>) and
  AJ> then operate on $_ ?

i happen to like named vars over $_ in most cases. and the OP used it so
i didn't feel i had to change it.


  AJ> another reduced version might be:

  AJ>     while(<SRC> ){
  AJ>         s{(?:(//.*$|;;.*$)|(/\*)|(\*/))}
  AJ>          {$1?"<i>$1</i>":$2?"<i>$2":$3?"$3</i>":''}eg;
  AJ>         print;
  AJ>     }

what a fun mess! :)

  AJ> but it looks like rain here, so I think I'll just head straight over
  AJ> to the 19th hole ...

i would join you but i only play perl golf.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Wed, 06 Sep 2000 01:33:47 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: using perl in a redundant way.
Message-Id: <%9ht5.12257$a5.178802@news1.rdc1.mb.home.com>

In article <x7pumil3ex.fsf@home.sysarch.com>,
 Uri Guttman <uri@sysarch.com> wrote:

[snip] 

> what a fun mess! :)

Well, some kind of mess anyway...

andrew

-- 
Andrew L. Johnson   http://members.home.net/perl-epwp/
      But puzzles in programming are what make it challenging and fun
      sometimes... you always end up learning one more way not to do
      something each time.  -- Brad Fenwick


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

Date: Wed, 06 Sep 2000 02:59:43 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: using the value of a variable for another varible's name?
Message-Id: <slrn8rbcor.arq.tjla@thislove.dyndns.org>

I was shocked! How could Mark-Jason Dominus <mjd@plover.com>
say such a terrible thing:
>In article <slrn8r91r0.3uj.tjla@thislove.dyndns.org>,
>Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>>Where did you get that idea? I (and benchmark) beg to differ. Did you
>>test that assertion you made?
>
>Yes, and I tested the original assertion before I made it also.
>
>The benchmark is at 
>
>        http://www.plover.com/~mjd/perl/symref.pl
>
>
>Your program is broken.

My bad. I should know better than to argue with you :)

I'm kind of nervous to say it now but your program doesn't appear to do
exactly what you say it does...or at least what the program seems to
think it does, or say, or something. I'll leave it there, I've been
burned once today. In my defence I wrote that very late last night on
too little sleep.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Linux - Why use Windows, since there is a door?


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

Date: Wed, 06 Sep 2000 03:07:56 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: using the value of a variable for another varible's name?
Message-Id: <39b5b50c.5feb$90@news.op.net>

In article <slrn8rbcor.arq.tjla@thislove.dyndns.org>,
Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>>The benchmark is at 
>>
>>        http://www.plover.com/~mjd/perl/symref.pl
>
>My bad. I should know better than to argue with you :)

Actually, I make a lot of mistakes.  Arguing with me is often a good bet.

>I'm kind of nervous to say it now but your program doesn't appear to do
>exactly what you say it does...

No?  Maybe I screwed up.  Could you be more specific?


>In my defence I wrote that very late last night on too little sleep.

Me too.


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

Date: Wed, 06 Sep 2000 03:23:33 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: using the value of a variable for another varible's name?
Message-Id: <slrn8rbe5h.arq.tjla@thislove.dyndns.org>

I was shocked! How could Rick Delaney <rick.delaney@home.com>
say such a terrible thing:
>
>Gwyn Judd wrote:
>> 
>> [gwyn@thislove:~]$ cat sym.pl
>> #!/usr/bin/perl -w
>> use strict;
>> use Benchmark;
>> 
>> my $day = 'monday';
>> my $monday;
>> my $temp;
>> my $ref = \$monday;
>> my %days;
>
>None of these variables are visible inside Benchmark::timethese or
>whatever the actual sub that evals the code is called.  You might want
>to run this again, getting rid of all those 'my's.

Whoops, mark that one up as a learning experience. I rewrote it so they
are now visible (having it run cleanly under 'use strict' should have
been a large whack over the head with a clue-stick *doh*).

Interestingly the hash comes out on top (slightly) for speed. Guess that
goes to show, the hash wins out in every way. I hope I haven't made any
more subtle errors, this benchmarking is not as simple as I first though
:)

here:

#!/usr/bin/perl -w
use Benchmark;

my $day = 'monday';
my $monday = '11 am';
my $ref = \$monday;
my $temp;
my %days = ($day => $monday);

timethese (1 << 20, {
    'symref-read' => sub {
                $temp = $$day 
                },
    'symref-write' => sub {
                $$day = $monday
                },
    'hash-read' => sub {
                $temp = $days{monday}
                },
    'hash-write' => sub {
                $days{monday} = $monday
                },
    'trueref-read' => sub {
                $temp = $$ref
                },
    'trueref-write' => sub {
                $$ref = $monday
                },
    'var-read' => sub {
                $temp = $monday
                },
    'var-write' => sub {
                $monday = '11 am'
                },
});

[gwyn@thislove:~]$ perl  sym.pl 
Benchmark: timing 1048576 iterations of hash-read, hash-write,
symref-read, symref-write, trueref-read, trueref-write, var-read,
var-write...
 hash-read:  2 wallclock secs ( 1.86 usr +  0.00 sys =  1.86 CPU) @
563750.54/s (n=1048576)
hash-write:  2 wallclock secs ( 1.86 usr +  0.00 sys =  1.86 CPU) @
563750.54/s (n=1048576)
symref-read:  2 wallclock secs ( 1.97 usr +  0.01 sys =  1.98 CPU) @
529583.84/s (n=1048576)
symref-write:  2 wallclock secs ( 2.35 usr +  0.00 sys =  2.35 CPU) @
446202.55/s (n=1048576)
trueref-read:  1 wallclock secs ( 1.03 usr +  0.00 sys =  1.03 CPU) @
1018034.95/s (n=1048576)
trueref-write:  1 wallclock secs ( 0.72 usr +  0.00 sys =  0.72 CPU) @
1456355.56/s (n=1048576)
  var-read:  1 wallclock secs ( 0.83 usr +  0.00 sys =  0.83 CPU) @
1263344.58/s (n=1048576)
 var-write:  1 wallclock secs ( 0.82 usr +  0.00 sys =  0.82 CPU) @
1278751.22/s (n=1048576)

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The need to write comes from the need to make sense of one's life and
discover one's usefulness.
-John Cheever


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

Date: Wed, 06 Sep 2000 03:27:56 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: using the value of a variable for another varible's name?
Message-Id: <slrn8rbedq.arq.tjla@thislove.dyndns.org>

I was shocked! How could Mark-Jason Dominus <mjd@plover.com>
say such a terrible thing:
>In article <slrn8rbcor.arq.tjla@thislove.dyndns.org>,
>Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>
>>I'm kind of nervous to say it now but your program doesn't appear to do
>>exactly what you say it does...
>
>No?  Maybe I screwed up.  Could you be more specific?

Well in the bit where it says SYMREF FETCH: it actually appears to fetch
from a normal variable. That is not a problem since the part above where
it says SYMREF appears to fetch from a symref. The HASH and HASH FETCH
also appear to do almost exactly the same thing (fetch). Have a look at
the other side of this thread for a rewritten version of the program I
wrote which (I hope I hope) does the right thing. There is an
interesting conclusion that I don't think either of us suspected...

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Ronald Reagan -- America's favorite placebo


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

Date: Wed, 06 Sep 2000 03:40:44 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: using the value of a variable for another varible's name?
Message-Id: <39B5BF34.752B6B34@home.com>


Gwyn Judd wrote:
> 
> Whoops, mark that one up as a learning experience. I rewrote it so they
> are now visible (having it run cleanly under 'use strict' should have
> been a large whack over the head with a clue-stick *doh*).

It's running cleanly under 'use strict' wasn't the problem, since strict
isn't active in Benchmark.pm.  But you still have a problem.

 
> my $day = 'monday';
> my $monday = '11 am';
[snip]
>                 $temp = $$day

What do you expect is the value of $temp?  Lexical variables have
nothing to do with symrefs.

You should always use some prints in your benchmarks on a couple of
iterations to make sure that you're measuring what you think you are.

If it makes you feel any better, mjd has the same problem in his code. 
;-)

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 05 Sep 2000 23:57:04 -0400
From: Richard Chen <qchen@snet.net>
Subject: weird behavior of _ file handle
Message-Id: <39B5C090.206B26F9@snet.net>

According to perldoc -f -s, once a stat is applied to a file, one can
find
other stat attributes by querying _ file handle, saving system calls.

But the following shows that this is not the case if the file has the
permission mode 111:

$ cat tmp.pl
#!/usr/local/bin/perl
$file="/tmp/hosts";
stat($file);
print "Text\n" if -T _;
my $size=-s _;
print "\$size=$size\n";
my $size2=-s $file;
print "\$size2=$size2\n";

$ cp /etc/hosts /tmp/hosts
$ chmod 111 /tmp/hosts
$ perl tmp.pl
$size=
$size2=942

So, after the -T _ test, -s _ does not work any more, contrary to
documentation!.
One has to use another stat system call to get the correct result.

Is this intended behavior? If there is no way around it, then to ensure
accurate result,
duplicated stat calls are necessary in this and similar situations.

I am using perl 5.005_03.

Thanks for any info.

Richard



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

Date: Wed, 06 Sep 2000 01:21:14 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: World Wide PERL PROGRAMMERS TELECOMMUTE
Message-Id: <x7snrel3hw.fsf@home.sysarch.com>

>>>>> "C" == Chris  <exit72@excite.com> writes:

  C> No offense Guttman but if I had to pick on who I didn't want in the
     ^^ ^^^^^^^
  C> group it would be you. Take a look at some of your responses to posts
  C> and you'll see why, you are the only person that replies with such
  C> hate towards everything.

  C> Soo back in your face for all the newbies you shit on.
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

i don't know what your definition of no offense is, but that hurts! :)

ooooh, i will crawl in to my hole and die. please go suckle at
moronzilla's teats. she needs new suckers.

and i hope you work for these clowns for $15/hour too. it is a step up
from the fryer job.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4231
**************************************


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