[20029] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2224 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 28 03:05:52 2001

Date: Wed, 28 Nov 2001 00:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006934710-v10-i2224@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 28 Nov 2001     Volume: 10 Number: 2224

Today's topics:
    Re: [OT] deja-vu all over again (was Re: A Perl Bug?) <joe+usenet@sunstarsys.com>
    Re: Bizarre languages ( was Re: Best language for low I <pulse@nyc.rr.com>
    Re: Bizarre languages ( was Re: Best language for low I <pulse@nyc.rr.com>
    Re: File position of of every word in a file <goldbb2@earthlink.net>
        Filehandle Comparing? (Kit)
        How do you pronounce "Perl"? <devnull@cauce.org>
    Re: How do you pronounce "Perl"? <tim@vegeta.ath.cx>
        How to get the content of a URL in perl? <mmlai@sfu.ca>
    Re: How to get the content of a URL in perl? (Smiley)
    Re: How to implement "peres unbiasing" in perl. (John J. Trammell)
    Re: How to implement "peres unbiasing" in perl. <goldbb2@earthlink.net>
    Re: Must be a better way.. <davidhilseenews@yahoo.com>
    Re: Must be a better way.. (HoboSong)
    Re: New problem.. <mds@wam.umd.edu>
    Re: New problem.. <wyzelli@yahoo.com>
    Re: no autovivication for subs (Rafael Garcia-Suarez)
    Re: perl memory efficiency (Logan Shaw)
        Replacement for Matt's Script Archive <dave@dave.org.uk>
    Re: Serious Regexp help... <ahamm@programmer.net>
        Time::JulianDay in ActivePerl <ksyqhk@yahoo.com.hk>
        Trying to decipher something (Smiley)
    Re: Using CGI.pm to obtain a list of params <goldbb2@earthlink.net>
    Re: Using frames with PERL? <admin@asarian-host.net>
    Re: Using frames with PERL? <admin@asarian-host.net>
    Re: Would this be global variables? (Kit)
    Re: Would this be global variables? (Kit)
    Re: Would this be global variables? <bernard.el-hagin@lido-tech.net>
    Re: { in s///; ? <nilram@boisdarc.tamu-commerce.edu>
    Re: { in s///; ? <jeffp@crusoe.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Nov 2001 01:47:06 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: [OT] deja-vu all over again (was Re: A Perl Bug?)
Message-Id: <m3adx74ck5.fsf@mumonkan.sunstarsys.com>

"Jake Fan" <jake@chaogic.com> writes:

> As far as the goal of my original post is concerned, I think I have
> already got the answer I was looking for, plus a decent understanding
> of the subject matter at hand.  

In most cases, perl is supposed to do "what you expect"; and in 
this case it didn't.  Even though your code was "bad", I still think 
your expectation that perl's "||=" should behave more consistently 
with "= ||" in this case was valid.  It might have been nice to see 
what Abigail had to say about it, but it looks like she's not posting 
here anymore, either.  I'll hazard a guess as to why below.

[...]

> And yes, it's ridiculous that the off-topic netiquette posts in this
> group have such a high rate.  But it's even more ridiculous to think
> it's ok to maintain the status quo, and blame on the damn
> "inconsiderate" newbies every single time.  You (regulars in this
> group) are fully aware that the audience of this group is about as
> diverse as you can get -- as far as programming language groups are
> concerned, especially with this group bearing the name ".misc".  

*sigh*  It's remarkable to me how anyone could take such umbrage over
Uri's out-of-band comments about how to get along here.  I thought 
he was unchar^H^H^H^Hexceedingly polite in his remarks, but you blatantly 
ignored his (and my) request to abide by the local customs.  You did get 
the automailed introduction to clp.misc, no?  If not, there's also a 
"posting guide" that appears here every week or so- perhaps you missed 
that, too.

> One would hope that the group would adopt relaxed rules to cater as
> many people as possible.  But no, you choose to be anal and
> tyrannical, and not even aware of it.  Of course, nobody is obliged to
> be nice, as much as everybody has the full right of being an asshole.
> Granted, post authors are generally expected to be considerate and
> conform to the "de facto" standard of a given group.  But this is a
> highly subjective matter.  

[...]

> But again, I fully anticipate that people's responses to this post
> will still be, "but it's netiquette, moron".  And I fully expect that
> this OT post phenomena will continue to manifest itself down the road.
> To hope otherwise is like hoping tomorrow the Sun would rise from the
> west (a Chinese catchphrase), i.e., it's hopeless.  But It really
> doesn't matter.

I assume you intend all this as an insult; no one who fancies themselves
a rational person could accuse any of that garbage as totaling to much 
more than another crass endorsement of the "logic of the commons":

Garrett Hardin ("The Tragedy of the Commons", _Science_ 1968):

  The tragedy of the commons develops in this way. Picture a pasture
  open to all. It is to be expected that each herdsman will try to keep
  as many cattle as possible on the commons. Such an arrangement may
  work reasonably satisfactorily for centuries because tribal wars,
  poaching, and disease keep the numbers of both man and beast well
  below the carrying capacity of the land.  Finally, however, comes the
  day of reckoning, that is, the day when the long-desired goal of
  social stability becomes a reality. At this point, the inherent 
  *logic of the commons* remorselessly generates tragedy.

  [...]

  Ruin is the destination toward which all men rush, each pursuing his
  own best interest in a society that believes in the freedom of the
  commons.  Freedom in a commons brings ruin to all.

You may not buy into what Hardin has to say here, but I *do*.  And I'm
quite certain that this very crowded newsgroup has well-passed the stage of 
social stability.  So while I appreciate your thanks, I hope you'll 
understand why I plan to onk-play everyone that's given Uri any crap 
about the group's norms in this thread.  The hit-and-run drivers
that pass through these parts have cost this community (both the regulars
and the lurkers) a lot of valuable human resources, and I'm sure not
going to be accomodating to bozos that have the nerve to bitch about 
the please-drive-on-the-right-side signs that are virtually plastered
onto almost every thread.


-- 
Joe Schaefer     "The eternal mystery of the world is its comprehensibility."
                                               --Albert Einstein



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

Date: Wed, 28 Nov 2001 05:33:09 GMT
From: no <pulse@nyc.rr.com>
Subject: Re: Bizarre languages ( was Re: Best language for low IQ programmers? )
Message-Id: <3C0476B0.76F792FC@nyc.rr.com>



TRIM NYC.FOOD PLEASE!!!!!!


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

Date: Wed, 28 Nov 2001 05:32:45 GMT
From: no <pulse@nyc.rr.com>
Subject: Re: Bizarre languages ( was Re: Best language for low IQ programmers? )
Message-Id: <3C047697.28D5059C@nyc.rr.com>


TRIM NYC. FOOD PLEASE


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

Date: Wed, 28 Nov 2001 01:41:01 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: File position of of every word in a file
Message-Id: <3C0486FD.9EBB684D@earthlink.net>

Rob van Strien wrote:
> 
> Thanks to all of you who helped me with this problem.
> This is my solution (apart from the discussion of what
> a 'word' might be, which isn't solved yet in my case).
> 
> while ($startOfLine = tell, $line = <INV>)  {
>       chomp($line);
>       while ($line =~ m/\b([a-zA-Z]+)\b/g) {
>          $match = $&;
>          $position = $startOfLine+pos($line);
>          print TEMP "$match:$position\n";
>       }
> }

tell, with no arguments, works on the last file read.  The very fist 
time that the condition in the while() is executed, there is no last
file read, or else it'll be STDIN, or DATA, or something.  But certainly
not what you seem to expect.

Also, the only time that perl will translate "while( $foo = <BAR> )"
into "while( defined($foo = <BAR>) )" is when it's the only thing inside
the while() condition, so if you're having another statement in there,
you need to add a defined() test.

   while( $startOfLine = tell INV, defined($line = <INV>) ) {

Next...

pos returns the place where the next /g type match will begin searching,
which is also the place *after* the most recent match.  To make your
code slightly more correct, you would need to change the line to
    $position = $startOfLine + pos($line) - length($match);

Of course, it might be better to change your whole block to:

until(eof INV) {
    my $start_of_line = tell INV;
    my $line = <INV>; # *will* succeed, since eof returned false.
    while( $line =~ m/\b([a-zA-Z]+)\b/g ) {
        print TEMP $1, ":", $start_of_line + $-[0], "\n";
    }
}

Or if speed were your concern:
binmod INV;
my $pos = 0;
while( sysread( INV, $_, 4096, length $_ ) ) {
    while( m/\b([a-zA-Z]+)(?=\W)/gc ) {
        print TEMP $1, ":", $pos + $-[0], "\n";
    }
    $pos += pos; substr($_,0,pos,""); pos = 0;
}
print TEMP $1, ":", $pos + $-[0], "\n" if m/\b([a-zA-Z]+)\Z/g;

[untested]

-- 
Klein bottle for rent - inquire within.


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

Date: 27 Nov 2001 23:49:57 -0800
From: adrook@yahoo.com (Kit)
Subject: Filehandle Comparing?
Message-Id: <e756f30f.0111272349.44c468c@posting.google.com>

Hello, all,

I am opening a folder in which holds just .dat files.  I set the
filehandle DATFILE for all of the .dat files (or, more precisely, each
of them).
open REGFILE, "$ENV{'BASEFOLDER'}/$ENV{'DATFILES'}/";
my ($email,$password,$name) = <REGFILE>;

Right now I need to compare one variable, $address, to the name of
each dat file.  How do I do this?  I tried:
if REGFILE eq $address {
#Commands
}
But perl did not seem to want the filehandle.  What can I do?


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

Date: Wed, 28 Nov 2001 06:23:47 +0100
From: Jan Pieter Kunst <devnull@cauce.org>
Subject: How do you pronounce "Perl"?
Message-Id: <281120010623472577%devnull@cauce.org>

Hello all,

This is probably a stupid question, but my native language is not
English, so please bear with me.

How do you pronounce "Perl"? Does it sound like "pearl" , or is the "e"
the same as the "e" in "help"?

Thanks,
Jan Pieter Kunst.-

-- 
Sorry, <devnull@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.


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

Date: Wed, 28 Nov 2001 06:05:08 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: How do you pronounce "Perl"?
Message-Id: <slrna08vls.7lm.tim@vegeta.ath.cx>

Jan Pieter Kunst <devnull@cauce.org> graced us by uttering:
> This is probably a stupid question, but my native language is not
> English, so please bear with me.
> 
> How do you pronounce "Perl"? Does it sound like "pearl" , or is the "e"
> the same as the "e" in "help"?

"perl" like "pearl" for me.

(some manuals alude to the legend that perl used to be spelled "pearl",
also, but that Larry didn't want to type all 4 characters...)

Tim Hammerquist
-- 
Let us be charitable, and call it a misleading feature  :-)
    -- Larry Wall in <2609@jato.Jpl.Nasa.Gov>


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

Date: 28 Nov 2001 07:10:17 GMT
From: Murvin Ming-Wai Lai <mmlai@sfu.ca>
Subject: How to get the content of a URL in perl?
Message-Id: <9u22kp$qqf$1@morgoth.sfu.ca>


Hi all,


  I want to get the content of a webpage in perl.  For example in perl, I
do this:

  $content = function ("www.yahoo.com");

  What function can  help me out to do that?  or what package?
  I know there is a package named Libwww... Can this package do that?
  And how to set the timeout ?  

  Thanks.


  

-- 
 .........................................................................
*>>>>Murvin Lai<<<<     >>>>--Muffin--<<<<     email: murvin_lai@sfu.ca *
*homepage:           http://www.sfu.ca/~mmlai              mmlai@sfu.ca *
`````````````````````````````````````````````````````````````````````````



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

Date: Wed, 28 Nov 2001 07:38:23 GMT
From: gurm@intrasof.com (Smiley)
Subject: Re: How to get the content of a URL in perl?
Message-Id: <3c0493c0.350714410@news1.on.sympatico.ca>


>  I want to get the content of a webpage in perl.  For example in perl, I
>do this:
>
>  $content = function ("www.yahoo.com");
>
>  What function can  help me out to do that?  or what package?
>  I know there is a package named Libwww... Can this package do that?
>  And how to set the timeout ?  
>
>  Thanks.

It's been a while since I've done this, but going back to my old
scripts these are the commands I used:


use LWP::Simple;

my $location = "http://www.websitehere.com";

my $ydata = (get $location);


Does that help?


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

Date: Tue, 27 Nov 2001 23:02:07 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: How to implement "peres unbiasing" in perl.
Message-Id: <slrna08s42.odn.trammell@haqq.el-swifto.com>

On Tue, 27 Nov 2001 19:06:28 -0500, Benjamin Goldberg wrote:
> I'm trying to implement a really funky algorithm known as "Peres
> unbiasing."
[snip]

sub advanced_multi_level
{
    my @bits = ( [ @_ ] );
    my @out;
    my $max = 0;

    LEVEL:
    for (my $j = 0; $j <= 2 * $max + 2; $j++)
    {
        unless ($bits[$j] && @{$bits[$j]} > 1)
        {
            next LEVEL;
        }
        $max = $j;
        my @set = splice @{$bits[$j]},0,2;
        if ($set[0] == $set[1])
        {
            push @{$bits[ 2 * $j + 1 ]}, $set[0] ? 1 : 0 ;
            push @{$bits[ 2 * $j + 2 ]}, 1;
        }
        else
        {
            push @out, $set[0] ? 1 : 0 ;
            push @{$bits[ 2 * $j + 2 ]}, 0;
        }
        redo LEVEL;
    }
    return @out;
}

-- 
A mosquito cried out in pain,
"A chemist has poisoned my brain."
The cause of his sorrow, was para-dichloro- 
diphenyl-trichloro-ethane.


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

Date: Wed, 28 Nov 2001 02:30:35 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to implement "peres unbiasing" in perl.
Message-Id: <3C04929B.B9139BE9@earthlink.net>

John J. Trammell wrote:
> 
> On Tue, 27 Nov 2001 19:06:28 -0500, Benjamin Goldberg wrote:
> > I'm trying to implement a really funky algorithm known as "Peres
> > unbiasing."
> [snip]
> 
> sub advanced_multi_level
> {
>     my @bits = ( [ @_ ] );
>     my @out;
>     my $max = 0;
[snip]

Hmm.  Verry interesting.  However, I'm sorta looking for something which
will process bits in an incremental fashion, and not require that I grab
my entire input and process it all at once... especially since my input
is potentially gargantuan.

If the size of the input is in the vicinity of 2**32 items, the code *I*
gave would work with a relatively tiny amount of memory, and yours might
not even fit within the computer's addressable space!  Now, if only my
code worked right :)

Not that I don't appreciate it... it's just not suitable for my
purposes.

-- 
Klein bottle for rent - inquire within.


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

Date: Wed, 28 Nov 2001 05:24:18 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: Must be a better way..
Message-Id: <6y_M7.60172$Ze5.33911291@news1.rdc1.md.home.com>


"HoboSong" <chrisvano@yahoo.com> wrote in message
news:4fbb9396.0111271715.68a37058@posting.google.com...
> Clearly Im a newbie to both Perl and programming, but I havent learned
> a better way to do this... Ive used similar many times without any
problems
> but Im trying to be more efficient, can someone just give me a nudge in
the
> right direction?
>
> Thank you
>
> while (<TEXTFILE>) {
>
> if ( /SETTLEMENT SECTION/ ) {
> $section = "settlement";
>    } elsif ( /DIVIDENDS REPORT/ ) {
> $section = "divs";
>    } elsif ( /RISK MANAGEMENT REPORT/ ) {
> $section = "risk";
>    }
>
>
> if ( $section eq "settlement" ) {
> parse_settlement($_);
>   } elsif ($section eq "divs" ) {
> parse_divs($_);
>   } elsif ( $section eq "risk" ) {
> parse_risk($_);
>   }
> }

It seems like you might could use the .. or ... operators here, but the code
doesn't indicate that this is currently possible with the data you're
expecting.  Just for informative purposes, here's some example code:

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

while (<DATA>)
{
    if ( /BEGIN FOO_SECTION/ .. /END FOO_SECTION/ )
    {
        print "Foo section: $_";
    }
    elsif ( /BEGIN BAR_SECTION/ .. /END BAR_SECTION/ )
    {
        if ( /BEGIN BAR_INT_SECTION/ .. /END BAR_INT_SECTION/ )
        {
            print "Bar internal section: $_";
        }
        else
        {
            print "Bar section: $_";
        }
    }
    elsif ( /BEGIN BAZ_SECTION/ .. /END BAZ_SECTION/ )
    {
        print "Baz section: $_";
    }
}

__DATA__
BEGIN FOO_SECTION
Foo line 1
Foo line 2
END FOO_SECTION
BEGIN BAR_SECTION
Bar line 1
BEGIN BAR_INT_SECTION
Bar internal line 1
END BAR_INT_SECTION
Bar line 2
END BAR_SECTION
BEGIN BAZ_SECTION
Baz line 1
Baz line 2
END BAZ_SECTION


Maybe you can work with this.

--
David Hilsee




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

Date: 27 Nov 2001 23:52:57 -0800
From: chrisvano@yahoo.com (HoboSong)
Subject: Re: Must be a better way..
Message-Id: <4fbb9396.0111272352.1d2a5286@posting.google.com>

"Andrew Hamm" <ahamm@programmer.net> wrote in message news:<3c04485c_1@news.iprimus.com.au>...

> 
> while(<TEXTFILE>) {
>     chomp;    # on a hunch, I've added this for you
>     parse_settlement($_) if /SETTLEMENT SECTION/;
>     parse_divs($_) if /DIVIDENDS REPORT/;
>     parse_risk($_) if /RISK MANAGEMENT REPORT/;
> }
> 
> I can't even be bothered trying to skip the next tests because of the cost
> of reading the file in the first place. I don't think you need your $section
> variable, because that's implicitly known since you are entering a specific
> code path.
> 
> However, if your parse_ functions is modifying $_ or reading more lines,
> there may be a chance of false matches on the following lines, then you can
> use a structure like this:
> 
> while(<TEXTFILE>) {
>     chomp;    # on a hunch, I've added this for you
>     parse_settlement($_), next if /SETTLEMENT SECTION/;
>     parse_divs($_), next if /DIVIDENDS REPORT/;
>     parse_risk($_), next if /RISK MANAGEMENT REPORT/;
> }
> 
> As usual, there's more than one way to do it in Perl. Which is why that's a
> famous Perl slogan.
> 
> As you can gather from my reply, the proper answer for you depends on your
> data and what you will be doing to it.

 Im sorry, I should have been more clear. Im using those regexes as
'switches' while reading a text file. Each section of the file has a
completely different set of instructions, so I need to process all the
lines until I run into a new
section. How do you say:

 &DoThis until ( /YOU SEE THIS/ ) and then &DoDifferent until ( /YOU
GET HERE/);

etc..,etc..

Oh, and I didnt use chomp because I cant seem to find the right
combination of "\l\n" or whatever to designate the end of a page, so I
leave them as is.

Thanks, Chris


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

Date: Wed, 28 Nov 2001 01:03:57 -0500
From: "Mike Schmitt" <mds@wam.umd.edu>
Subject: Re: New problem..
Message-Id: <9u1upk$7s2$1@hecate.umd.edu>

Wyzelli wrote in message ...
>You mean Perl not PERL.  Check the FAQ for why.


Well, I'm a newbie so I don't know exactly where the c.l.p.m FAQ is.. sorry
;-)




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

Date: Wed, 28 Nov 2001 16:57:50 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: New problem..
Message-Id: <6k0N7.2$104.131@vicpull1.telstra.net>

"Mike Schmitt" <mds@wam.umd.edu> wrote in message
news:9u1upk$7s2$1@hecate.umd.edu...
> Wyzelli wrote in message ...
> >You mean Perl not PERL.  Check the FAQ for why.
>
>
> Well, I'm a newbie so I don't know exactly where the c.l.p.m FAQ is..
sorry
> ;-)
>

www.perl.com
If you installed Activeperl, it will be in html documentation in your start
menu
It will be on your hard disk in some format, at least (if you have installed
Perl) - type perldoc perldoc at your command prompt.

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: 28 Nov 2001 07:54:21 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: no autovivication for subs
Message-Id: <slrna09636.9n4.rgarciasuarez@rafael.kazibao.net>

Charles DeRykus wrote in comp.lang.perl.misc:
} Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
} >...
} >} 
} >}   % perl -wle ' sub f:lvalue {$_} print f() -> [0] '
} >}   Can't use an undefined value as an ARRAY reference at -e line 1.
} >
} >Hm, this looks like a bug. As $_ is undefined, it should spring into
} >existence, as documented in perlref. Can you report it via perlbug?
} 
} I thought autovivifying worked only for a hash or array element...
} as in perlref's example:  
} 
}    $array[$x]->{"foo"}->[0] = "January";
} 
} That is, I don't see any doc instances in this context of an 
} unsubscripted lvalue which could autovivify - unless there's
} an actual array or hash ref. The base lvalue ref to the left
} of the -> as in  $array->{foo}->{"foo"} will generate an error 
} unless $array is a valid ref.  

The following works :

    $ perl -wle '$x=undef;$x->[0]=1;print "<@$x>"'
    <1>

Obviously $x becomes an array ref here. So why should this not
work for lvalue subs ?

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 28 Nov 2001 00:38:06 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: perl memory efficiency
Message-Id: <9u20oe$dtq$1@starbuck.cs.utexas.edu>

In article <3c046946@news.victoria.tc.ca>,
Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
>That's not 70 bytes per integer - it's 70 bytes per dynamic polymorphic
>data structure, all help within a larger dynamic data structure that can
>be efficiently manipulated in a variety of useful ways. 
>
>70 bytes doesn't sound too bad really.
>
>If you want ints to take 4 bytes then program in C, or get more memory, or
>possibly tie the data to something else.

Or store it in a big string and use vec() to access it.  It's not
clean, but it is efficient with memory.

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Wed, 28 Nov 2001 06:57:13 +0000
From: Dave Cross <dave@dave.org.uk>
Subject: Replacement for Matt's Script Archive
Message-Id: <3C048AC9.7080702@dave.org.uk>

Don't know why I haven't got round to mentioning it here before, but a 
group of us are quietly working away on a set of scripts which are 
drop-in replacements for the scripts in Matt's Script Archive.

You can see the currently available scripts at

<http://nms-cgi.sourceforge.net/>

We can always use more people wh ocan get involved with programming, 
testing and documenting. If you're interested, please visit the 
developers page at:

<http://sourceforge.net/projects/nms-cgi/>

And please mention these scripts whenever you see people talking about MSA.

Cheers,

Dave...



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

Date: Wed, 28 Nov 2001 16:31:16 +1100
From: "Andrew Hamm" <ahamm@programmer.net>
Subject: Re: Serious Regexp help...
Message-Id: <3c047701$1_1@news.iprimus.com.au>

Ashley M. Kirchner wrote in message <3C045480.E59B2F99@pcraft.com>...
>Andrew Hamm wrote:
>
>> Mona's result is the same as our corrected result (if you discount the
>> missing field) but just formatted differently. As such, it didn't need
any
>> corrections ;)
>
>    Mona's regexp splits everything as it should, in six fields, right of
the bat.  The original regexp posted by you only did 5 fields.  What has me
confused is the greediness you guys were talking about earlier.  Did I say
regexp isn't exactly my forte?  <grin>
>
OK - well, shame on us for not noticing the missing field. Actual testing
would surely have shown that very quickly. As Dr. Hibbert would say
"accolades to Mona for paying attention to details" and "brickbats to Andrew
and Gary for not".

As to greediness:

First another bit of jargon, to set the stage. A quantifier in regex is
something like * + ? {n,m} which is applied after an actual matchable item -
for example

 .*    zero or more anything
a?    an optional 'a'
\s+    one or more spaces (\s being the Perl symbol for whitespace - space
and tab and a few others)
(\d+)(\.\d+){1,3}

this last one is a very rough match of an IP address, and it illustrates
{1,3} - it says i want a bunch of digits \d+ followed by 1 to 3 copies of a
dot and a bunch of digits. BTW when I say rough I do mean rough. A few
logical issues might force something tougher on that particular pattern for
IP matching depending on the situation. But I digress...

If it's clear what a quantifier is, the other thing to know about them is
that traditionally they are considered greedy - they attempt to match as
much as possible in the first instance, and then they begrudgingly "give
back" characters if the regex engine forces a backtrack in an attempt to
find a solution to the complete pattern. To illustrate this clearly,
consider:

    $str = "aaaaa";
    $str =~ /(a*)(a?)/;
    $f1 = $1;
    $f2 = $2;

$f1 will contain "aaaaa" and $f2 will contain nothing. That's because the a*
gets greedy and gobbles up all the 'a' characters, and the final a? will
attempt match an 'a' (being greedy) but it fails, then it tries maching an
empty string which can succeed.

To make a quantifier non-greedy, put a ? after the quantifier (only in Perl
as far as I know but that doesn't mean other utilities don't support it
already)

    $str = "aaaaa";
    $str =~ /(a*?)(a??)/;
    $f1 = $1;
    $f2 = $2;

Now, $f1 will be empty and $f2 will be .... empty! I threw in a trick there.
Since they are now both non-greedy, they both first try to match nothing and
they succeed, having consumed no characters. If I modify the pattern like
this:

    $str = "aaaaa";
    $str =~ /^(a*?)(a??)$/;
    $f1 = $1;
    $f2 = $2;

I've added ^ and $ anchors. Now we'll see that $f1 contains ... "aaaa" and
$f2 contains "a". So what's going on now? Well, the first part tries to
match nothing, then the 2nd part and then the $ attempts to anchor to the
end but it won't. The engine backtracks thru the 2nd part and the 1st part
repeatedly until it's made a match. The benefit here is, since the first
part is being non-greedy, it gives any following parts more of a chance to
match something, since there will likely be more characters still available.

The regex engine would only need to backtrack the first part to "aaaa"
before the 2nd part and the $ will allow a match. In that case, the 2nd part
would first attempt to match nothing (being non-greedy this time...) but the
$ will fail so then the 2nd part will backtrack and absorb a 'a' and then
the $ works and then everyone can get some sleep.

If I change the pattern once again to /^(a*?)(a?)$/ then we'll see the same
result, but that's only because of the situation we're working in. As you
can see already, going non-greedy has interesting effects, but you still
need to consider failure cases and what results you might get so that you
can pick the correct pattern for your job.

If I had a pattern of /^(a*?)(a*?)$/ then $f1 would now be empty and $f2
would be "aaaaa". That's because the 2nd part would start with nothing and
gradually grow thru backtracking until the $ can work. The engine would
never backtrack as far as the first (a*?) so it would never get a chance to
start consuming characters.

Regex's: almost as much fun as falling out of a tree
--
Space Corps Directive #723
Terraformers are expressly forbidden from recreating Swindon.
    -- Red Dwarf





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

Date: Wed, 28 Nov 2001 15:29:21 +0800
From: "Jim" <ksyqhk@yahoo.com.hk>
Subject: Time::JulianDay in ActivePerl
Message-Id: <9u23kq$qg0$1@gemini.ntu.edu.tw>

Hi,
     I found that ActivePerl do not provide the modules
Time::JulianDay
     Did it means that I cannot use this function in ActivePerl?
I mean is there a download site to download such modules?

Thanks
Jim




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

Date: Wed, 28 Nov 2001 07:06:46 GMT
From: gurm@intrasof.com (Smiley)
Subject: Trying to decipher something
Message-Id: <3c048b41.348538912@news1.on.sympatico.ca>

I'd appreciate any help.  I'm trying to fix a small problem with a
Perl application that the company I'm working for purchased to handle
web-based email.

Apparently attachments received in word .doc format aren't being
processed properly.  When I try to open one it wants to ask for the
server's username and password in order to be able to access it, I'm
trying to find out why.

I've looked at the link to open the URL, and it seems a little
strange, it asks for the following directory:

webmail.cgi/indiarent.doc?sid=;t=default;msgdata_did=491;do=messages-print_attach

There is a file called webmail.cgi, but it doesn't act as a directory
in any way whatsoever.  Even though it doesn't work when clicked on,
it does work when I right-click and choose to save target.

I can't get my mind around how it could work at all, can anybody tell
me what might be going on here?


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

Date: Wed, 28 Nov 2001 01:02:31 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <3C047DF7.CE872B77@earthlink.net>

William Alexander Segraves wrote:
> Jon Bell wrote:
[snip]
> > Now, if I actually had several hundred parameters to deal with, I'd
> > probably be using a design that didn't involve several hundred
> > individual variables for them in the first place.  For example, I
> > can imagine a form for inputting a rectangular table of numbers,
> > with parameters named 'row0col0', 'row0col1', etc.  Then I could
> > generate parameter names dynamically as needed, and extract the
> > individual entries using $cgi->param().  If I needed to use each
> > entry repeatedly, I'd probably use a loop to extract them into an
> > array of arrays or something similar.
> 
> Jon, thanks for your ideas.
> 
> You may note that your naming scheme would play havoc with renaming
> data items to move them to a different place, e.g., moving all of the
> lineage data on a lineage society application form down by one
> generation to allow reuse of a parent's data to do an application for
> a child. Example follows:
> 
> Suppose each generation has variable names, e.g.,
[snip]
> Name_G1
> Address_G1
> ...
> Name_G12
> Address_G12

If these are the variable names, then the scheme matching Jon's
suggestion would be:

my @generations;
for( my $i = 1; ; ++$i ) {
    defined(my $name = param("Name_G$i")) or last;
    defined(my $addr = param("Address_G$i")) or last;
    push @generations => { name => $name, addr => $addr };
}

You can access this using, for example:
   $generations[$n]{name};

Now, supposing you want to move all the data down by one generation.
This is simple.

shift @generations;

There's no need to do that ugly series of s/// things you suggest.
And if one *were* doing something like that, it would be done as:
   s/G(\d+)$/$1 + 1/e;
which would do all those changes with just a single substitution.

-- 
Klein bottle for rent - inquire within.


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

Date: Wed, 28 Nov 2001 06:22:20 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: Using frames with PERL?
Message-Id: <wo%M7.144327$2w.9042491@bin4.nnrp.aus1.giganews.com>

"Kumaran Srimantha" <kumaran76@yahoo.com> wrote in message
news:861ae413.0111271135.1dc1b19a@posting.google.com...

> hello,
>
>           I have a question regarding using PERL with HTML frames.
>           Please find the perl program below.
>
>           --------
>
>           #!/usr/local/bin/perl
>
>           print "Content-type:text/html", "\n\n";
>           print "<html>";
>           print "<head><title> Report </title></head>";
>
>           print "<frameset rows=\"15%,85%\">";
>           print "<frame src=\"menu_bar.html\" name=\"topmenu\">";
>           print "<frame src=\"O49361.pdf\" name=\"mainwindow\">";
>           print "</frameset>";
>
>           print "</html>";
>
>           -------------
>
>      When this perl program is run (i.e, when I point the web browser
>      to this perl program), it tries to execute the menu_bar.html
>      and the O49361.pdf instead of just displaying the 2 files. I
>      just want the 2 files to be displayed as is instead of it
>      getting executed. How do I do that?


Well, for starters, you should prepend a backslash ("/") to the document
name of your source documents; because, this way, you try to run them from
the current (cgi-bin) location. Like this:

frame src = "/menu_bar.html"

- Mark




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

Date: Wed, 28 Nov 2001 06:25:55 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: Using frames with PERL?
Message-Id: <Tr%M7.144350$2w.9045020@bin4.nnrp.aus1.giganews.com>

"Mark" <admin@asarian-host.net> wrote in message
news:wo%M7.144327$2w.9042491@bin4.nnrp.aus1.giganews.com...

> Well, for starters, you should prepend a backslash ("/") ....

A slash, that is; not backslash. Duh on me. :)

- Mark




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

Date: 27 Nov 2001 21:53:08 -0800
From: adrook@yahoo.com (Kit)
Subject: Re: Would this be global variables?
Message-Id: <e756f30f.0111272153.68dc63e4@posting.google.com>

Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote in message news:<slrna06r6e.qsr.bernard.el-hagin@gdndev25.lido-tech>...
> On 27 Nov 2001 01:34:22 -0800, Kit <adrook@yahoo.com> wrote:
> > Just a quick question.  I am writing a single script.  I need to use
> > variables defined in one subroutine in another subroutine.  How would
> > I do this?  Would this be declaring global variables?  Thanks!
> 
> 
> If you have variables defined in a sub then they're not global
> (well, not normally). If you want to get at them then it
> depends on how you're invoking the function which uses
> those variables.
> 
> 
> You didn't provide example code so I'm only guessing at what
> exactly it is you're doing, but if you're calling that other
> function from the first function you can do this:
> 
> 
> sub aaa{
>   my $var_a1;
>   my $var_a2;
> 
>   # do some stuff
>   # then call bbb with vars
>   # $var_a1 and $var_a2
>   
>   bbb ($var_a1, $var_a2);
> }
> 
> sub bbb{
>   my ($var_b1, $var_b2) = @_;
> 
>   # $var_b1 == $var_a1 and
>   # $var_b2 == $var_a2
> }
> 
> 
> If you're calling bbb somewhere else then it's better to get
> aaa() to return the values you're going to use in bbb() rather
> than use global variables. For example:
> 
> 
> sub aaa{
>   my $var_a1;
>   my $var_a2;
> 
>   # do the wild thang
> 
>   return ($var_a1, $var_a2);
> }
> 
> 
> sub bbb{
>   my ($var_b1, $var_b2) = aaa();
> }
> 
> 
> Cheers,
> Bernard

Thanks for the replies.  I do not quite understand the use of
$line_ref, so I will play around with Bernard's idea for now.  Tell
me, what is the return command for and what happens if it is not used?


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

Date: 27 Nov 2001 22:35:32 -0800
From: adrook@yahoo.com (Kit)
Subject: Re: Would this be global variables?
Message-Id: <e756f30f.0111272235.7ecee8db@posting.google.com>

As for the example code, here is an example of the code I have
written.  I have only included some parts of it that is relevant to my
question; this is not the whole two subroutines.  I am using CGI.pm,
which includes CGI::Cookie.  Please tell me if it should work as far
as sharing $email and $password in the subroutines manage and update:

sub manage {
my $email = $form{'LOGIN'};
my $password = $form{'PASSWORD'};
if ((!$email || $password) && !$cookie) {
print redirect("login.html"); exit;
if (!$cookie) {
$cookie = new CGI::Cookie(-name => 'Login',
			  -value => "$email $password",
   			  -expires => '+1h',
		 	  -path => '/'
    			  );
print header(-cookie=>$cookie);
}else{
    print header;
    ($email, $password) = split(" ",$cookie);
}
$email = untaint(qr(/^.+\@.+\..+$), $email);
$password = untaint(qr(a-z0-9$), $password);
# Irrelevent code in this subroutine here.
update ($email, $password);
}
}

sub update {
my ($email, $password) = @_;
%cookies = fetch CGI::Cookie;
$cookie = $cookies{'Login'};
unless ($email, $password) = $cookie->value {
print redirect("login.html"); exit;
#More irrelevant code here.
}}


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

Date: 28 Nov 2001 07:58:47 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Would this be global variables?
Message-Id: <slrna0996o.qsr.bernard.el-hagin@gdndev25.lido-tech>


On 27 Nov 2001 21:53:08 -0800, Kit <adrook@yahoo.com> wrote:
> Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote in message
>news:<slrna06r6e.qsr.bernard.el-hagin@gdndev25.lido-tech>...


[snipped old reply]

 
> Thanks for the replies.  I do not quite understand the use of
> $line_ref, so I will play around with Bernard's idea for now.


You'll probably want to learn about references sooner or later
so why not start now:


   perldoc perlreftut
   perldoc perlref
   perldoc perldsc
   perldoc perllol


>Tell me, what is the return command for and what happens
>if it is not used?


When a sub ends it returns a value. You can compare this to the value of a
variable. If you write:


   $x = 5;


you know that that each time you use $x you're really using the number
5. The same thing happens with the return value of a subroutine.
Here's a basic example:


   sub is_digit{
     my $arg = shift; # $arg is now the value of the first argument to
                      # is_digit
     
     if ( $arg =~ /^\d$/ ){
       return 1;
     }
     else{
       return 0;
     }
   }


This function returns a value of 1 if its argument is a single digit
and 0 if not. Here's how you might want to use this function:


   if ( is_digit(5) == 1 ){ # or simply if (is_digit(5)){
   	print "Yeah!\n";
   }
   else{
   	print "Nay!\n";
   }


This will print "Yeah!".


You can also assign the return value of a sub to a variable:


   my $x = is_digit(6);
	
	
If you don't use the return function explicitly a sub will return the
value of its last evaluated expression. So we can rewrite the is_digit
function in a more perlish way:


   sub is_digit{
     my $arg = shift;
   
     $arg =~ /^\d$/ ? 1 : 0;
   }


If $arg matches the regex the whole statement will have a value of 1,
otherwise it will have a value of 0. Since this is the last statement
in the sub whatever value it has will be returned by the sub. We can
shorten that sub even more by not using the $arg variable:


   sub is_digit{ shift =~ /^\d$/ ? 1 : 0 }


Of course a sub doesn't have to return only one value. I showed
you an example of a sub returning a two-element list in my previous
post. You could use that sub like this:


   sub blah{
     # sub returns a list
   }

   my @list = blah();


Sometimes it's better to return a reference to a list or
a hash, but you'll have to read the docs I listed at the
beginning to learn about those.
   
   
To learn more about the return function read:


   perldoc -f return


[
 To those who noticed - yes, I am aware of the fact that
 is_digit(5.0) will return 1 :)
]
 

Cheers,
Bernard


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

Date: 27 Nov 2001 23:21:57 -0600
From: Dale Henderson <nilram@boisdarc.tamu-commerce.edu>
Subject: Re: { in s///; ?
Message-Id: <87n117wjuy.fsf@camel.tamu-commerce.edu>

>>>>> "JP" == Jeff 'japhy' Pinyan <jeffp@crusoe.net> writes:

    JP> On Nov 26, Martien Verbruggen said:
    >> On 26 Nov 2001 03:35:59 -0600,
    >> Dale Henderson <nilram@boisdarc.tamu-commerce.edu> wrote:
    >>>  Now I'm wondering why the next line:
    >>> 
    >>> s/@/@@/g;
    >>> 
    >>> works perfectly. I've experimented and found that @@ is a
    >>> valid name for a perl list.
    >>  Array.

    JP> What might be "odd" though is that s/@/@@/g turns all '@'s
    JP> into '@@'s.

     Actually that's what I meant when I said "works perfectly". I
     realize on re-reading the post that it was a rather ambiguous
     statement.


-- 
Dale Henderson 

"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..."  -- G. H. Hardy


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

Date: Wed, 28 Nov 2001 01:32:56 -0500
From: Jeff 'japhy' Pinyan <jeffp@crusoe.net>
Subject: Re: { in s///; ?
Message-Id: <Pine.GSO.4.21.0111280132180.15763-100000@crusoe.crusoe.net>

[posted & mailed]

On Nov 27, Dale Henderson said:

>>>>>> "JP" == Jeff 'japhy' Pinyan <jeffp@crusoe.net> writes:
>
>    JP> On Nov 26, Martien Verbruggen said:
>    >> On 26 Nov 2001 03:35:59 -0600,
>    >> Dale Henderson <nilram@boisdarc.tamu-commerce.edu> wrote:
>    >>>  Now I'm wondering why the next line:
>    >>> 
>    >>> s/@/@@/g;
>    >>> 
>    >>> works perfectly. I've experimented and found that @@ is a
>    >>> valid name for a perl list.
>    >>  Array.
>
>    JP> What might be "odd" though is that s/@/@@/g turns all '@'s
>    JP> into '@@'s.
>
>     Actually that's what I meant when I said "works perfectly". I
>     realize on re-reading the post that it was a rather ambiguous
>     statement.

I had a feeling that was what you meant, so I posted it just in case.  I
do not know if the odd array-interpolation rules are documented anywhere.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 2224
***************************************


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