[19218] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1413 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 31 06:06:04 2001

Date: Tue, 31 Jul 2001 03:05:12 -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: <996573912-v10-i1413@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 31 Jul 2001     Volume: 10 Number: 1413

Today's topics:
    Re: Caching information about IP subnets nobull@mail.com
    Re: CGI-BIN doesnt execute scripts nobull@mail.com
    Re: Chainging specific part of a file <pne-news-20010731@newton.digitalspace.net>
    Re: Cleaning replacing the value of a constant <godzilla@stomp.stomp.tokyo>
    Re: FAQ: How do I capitalize all the words on one line? nobull@mail.com
    Re: FAQ: How do I expand function calls in a string? nobull@mail.com
        FAQ: What's wrong with always quoting "$vars"? <faq@denver.pm.org>
        Finding "this" but not "this and that" with a regex? (Jay McGavren)
    Re: Finding keywords in text files (Yves Orton)
    Re: Flock on DATA? (Anno Siegel)
    Re: Flock on DATA? <bart.lateur@skynet.be>
        formatting an SGML file (Shang-Lin Chen)
        Help Please <bob@nowhere.com>
    Re: Help Please (Steven Smolinski)
    Re: Help with an array and foreach <pne-news-20010731@newton.digitalspace.net>
    Re: Help with an array and foreach (Helgi Briem)
    Re: Iterating through an array nobull@mail.com
    Re: Lanaguage files <pne-news-20010731@newton.digitalspace.net>
    Re: Module help needed! <Tassilo.Parseval@post.rwth-aachen.de>
    Re: negative lookahead <pne-news-20010731@newton.digitalspace.net>
    Re: negative lookahead <bart.lateur@skynet.be>
    Re: negative lookahead <nospam-abuse@ilyaz.org>
    Re: newbe question splitting a string into two differen (Helgi Briem)
        Parse::RecDescent (David Roe)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 30 Jul 2001 18:01:30 +0100
From: nobull@mail.com
Subject: Re: Caching information about IP subnets
Message-Id: <u9snfeuz9x.fsf@wcl-l.bham.ac.uk>

Guillaume Filion <gfk@spamcop.net> writes:

> Hi all,
> 
> I'm working with a module that queries IP Whois servers 
> (ARIN,APNIC,RIPE,etc) and returns the content of the record. This module 
> offers the option of caching the result of the query but caches it only 
> considering the IP address.
> ex: the cache key for 209.85.157.220 on whois.arin.net is:
> 209.85.157.220@whois.arin.net
> 
> It would be much more efficient to have it cache its data considering 
> the IP's subnet.
> ex: the cache key for 209.85.157.220 on whois.arin.net would be:
> 209.85.157.0/24@whois.arin.net
> or something like that.
> 
> That way if I make a query about 209.85.157.100, I could use my cache 
> instead of reconnecting to the server.
> 
> The problem is that I really have no idea on how to do this. 
> 
> Any pointer or idea would be really appreciated.

I suggest you take a look at NetAddr::IP.

It will not solve your problem but it will maybe simplify it.

I also suggest you structure your cache like: 

$cache{'whois.arin.net'}{24}{'209.85.157.0'} = 'whatever';

To look up 209.85.157.220@whois.arin.net you'd interate over
keys(%{$cache{'whois.arin.net'}}) and clip 209.85.157.220 to the
appropriate length.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 30 Jul 2001 17:33:21 +0100
From: nobull@mail.com
Subject: Re: CGI-BIN doesnt execute scripts
Message-Id: <u9vgkav0ku.fsf@wcl-l.bham.ac.uk>

"Mr. Ed" <springb2k@yahoo.com> writes:

> I have an issue with a project manager that centers around if his Unix
> server is configured right. I have scripts in the cgi-bin that have all the
> correct chmod permissions. That scripts do not execute. I cannot even get an
> html webpage to show up (the error sez Page Not Found) is it sits in that
> cgi-bin. I made another directory underneath a directory outside the
> cgi-bin, and in that new directory that I named cgi-bin ( after giving the
> directory and files the right permissions) i tried to get scripts to
> execute, but in MSExplorer, the browser prompted me to download the file,
> whle in netscape, it displayed the actual script (yikes!) but no execution.
> Is this an issue that the server admin doesnot have perl installed the
> correct way, or set up the scripts directory correctly?

Server setup issue.  Not Perl related.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 31 Jul 2001 06:59:15 +0200
From: Philip Newton <pne-news-20010731@newton.digitalspace.net>
Subject: Re: Chainging specific part of a file
Message-Id: <ueecmtck0qn3vl78k1ch3jq6ue92jii831@4ax.com>

On Mon, 30 Jul 2001 18:17:45 +0100, "Nathan Randle"
<nathan.randle@ntlworld.com> wrote:

> How do you make your program open a file and change a specific area of the
> text.

: Those are operations of a text editor. Perl is not a
: text editor. Perl is a programming language. You have to
: decompose the problem into low-level calls to read,
: write, open, close, and seek.

Quoted from `perldoc -q "change one line"`, which you should probably
read in this context.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Mon, 30 Jul 2001 20:44:30 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Cleaning replacing the value of a constant
Message-Id: <3B66299E.5B3F80BC@stomp.stomp.tokyo>

Bernie Cosell wrote:

(snipped a lot)
 
> In my other thread [on problems with fcntl file locking] I discovered that
> in my Perl installation, the constant F_SETLKW has the wrong value
 
> so I'd like to 'correct' that.  I tried:
 
>    use Fcntl;
>    use constant F_SETLKW => 7 ;
 

I have more information on this. Possibly you have read my
parallel article on this topic, if not, your loss.

According to documentation for fcntl, this syntax,

use Fcntl ":Fcompat";

 ...should import only the old fashion Fwhatever symbols,
like fasync, fnonblock, but not the F_ whatever symbols
with which you are currently working; f_setlkw.

Being a rogue programmer, as is my habit, I ignored what
documentation indicates and experimented. I am able to
successfully import F_SETLKW into main:: using this
syntax, which should not work, but does:

use Fcntl ":Fcompat";
use constant F_SETLKW;

As indicated in my other article, I cannot venture too far
on this with my Win32 box not supporting file lock. However,
you might consider using this "wrong" syntax above and
discover if your F_SETLKW works right. With this rogue
syntax, it is being defined as a macro and, is being
successfully imported, with NO modification to fcntl.pm
as exemplified in my parallel article.

Here is my test code which will print main:: contents.
You will find your constant in there but, this time,
F_SETLKW64 will NOT be present, which is a good sign.

#!perl

print "Content-type: text/plain\n\n";

use Fcntl ":Fcompat";
use constant F_SETLKW;

foreach $key_name (keys %main::)
 {  print "$key_name \n"; }

print "done";

exit;

You will discover it is much easier to view this long
list with a browser; scrolling and searching are afforded.


Godzilla!


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

Date: 30 Jul 2001 18:28:42 +0100
From: nobull@mail.com
Subject: Re: FAQ: How do I capitalize all the words on one line?
Message-Id: <u9k80quy0l.fsf@wcl-l.bham.ac.uk>

Andras Malatinszky <andras@mortgagestats.com> writes:

> PerlFAQ Server wrote:
> >         $string =~ /([\w']+)/\u\L$1/g;
> 
> Don't we need an 's' after the binding operator here? Like this:
> 
> $string =~ s/([\w']+)/\u\L$1/g;

Yep, you've found a typo in the FAQ.

Did you honour the "Mail-Copies-To: faq@denver.pm.org" header on the
orginal post in this thread?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 30 Jul 2001 12:41:54 +0100
From: nobull@mail.com
Subject: Re: FAQ: How do I expand function calls in a string?
Message-Id: <u91ymywsn1.fsf@wcl-l.bham.ac.uk>

Benjamin Goldberg <goldbb2@earthlink.net> writes:

> nobull@mail.com wrote:
> > 
> > PerlFAQ Server <faq@denver.pm.org> writes:
> > >
> > >     Version 5.004 of Perl had a bug that gave list context to the expression
> > >     in "${...}", but this is fixed in version 5.005.
> > 
> > This may be true, however it is irrelevant as the \(...) construct
> > does not propagate the scalar context.  Rather, scalar(\(EXPR))
> > evaluates EXPR in a list context[1] and then returns a reference to
> > the last element.
> 
> Why doesn't "${\do {EXPR}}" work for this?  I tried:

Because scalar(\EXPR) evaluates EXPR in a list context.  This,
arguably, is a bug.

do{EXPR} simply propagates the context in which it is evaluated - this
is as designed.

> > [ snip "NoBull" BUAG logo ]

Please do not quote sigs.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 31 Jul 2001 06:19:24 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: What's wrong with always quoting "$vars"?
Message-Id: <M5s97.7$Ivk.170731520@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  What's wrong with always quoting "$vars"?

    The problem is that those double-quotes force stringification-- coercing
    numbers and references into strings--even when you don't want them to be
    strings. Think of it this way: double-quote expansion is used to produce
    new strings. If you already have a string, why do you need more?

    If you get used to writing odd things like these:

        print "$var";       # BAD
        $new = "$old";      # BAD
        somefunc("$var");   # BAD

    You'll be in trouble. Those should (in 99.8% of the cases) be the
    simpler and more direct:

        print $var;
        $new = $old;
        somefunc($var);

    Otherwise, besides slowing you down, you're going to break code when the
    thing in the scalar is actually neither a string nor a number, but a
    reference:

        func(\@array);
        sub func {
            my $aref = shift;
            my $oref = "$aref";  # WRONG
        }

    You can also get into subtle problems on those few operations in Perl
    that actually do care about the difference between a string and a
    number, such as the magical "++" autoincrement operator or the syscall()
    function.

    Stringification also destroys arrays.

        @lines = `command`;
        print "@lines";             # WRONG - extra blanks
        print @lines;               # right

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.35
-- 
    This space intentionally left blank


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

Date: 30 Jul 2001 22:14:52 -0700
From: sgarfunkle@hotmail.com (Jay McGavren)
Subject: Finding "this" but not "this and that" with a regex?
Message-Id: <6bb557e1.0107302114.696bc739@posting.google.com>

I suppose I'm missing something obvious here...  I need to compare a
string with a list of regular expressions, and if any of them match I
need to skip processing it.  Problem is, one of the strings I *don't*
want to ignore contains one of the phrases I *do* want to ignore; the
only difference is another substring farther along in the string.

This is a grossly simplified version of my code:

------
sub CanYouIgnore {
	$Record = shift;
	@IgnorePhrases = ("other thing", "this");
	
	$Ignore = 0;
	foreach (@IgnorePhrases) {
		$Ignore = 1 if ($Record =~ /$_/m);
	}
	print "$Record\n" unless $Ignore;
}

CanYouIgnore("just anything"); #Prints
CanYouIgnore("this \n gobbledygook"); #Is ignored
CanYouIgnore("this gobbledygook \n and that"); #Is ignored but
shouldn't be
------

Setting my comparison regex to ^this$ won't work because
"gobbledygook" may or may not be present, and "that" could appear
anywhere in the Record.  This would do it:

if ($Record =~ /this/ && $Record !~ /that/)

 ...but I'm hoping there's something I can just add to the
IgnorePhrases.  Any suggestions?


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

Date: 31 Jul 2001 01:40:59 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Finding keywords in text files
Message-Id: <74f348f7.0107310040.25a4f791@posting.google.com>

Michael Budash <mbudash@sonic.net> wrote in message news:<mbudash-27A37C.08093130072001@news.sonic.net>...
> > > delete @counts{qw(a is or of it the and)}; # delete "stopwords"
> > 
> > Cool.  Never thought of using delete with array slices.
> > Nice trick.
> 
> er... isn't that a hash slice?

Yup.  I knew someone would jump on that one as soon as I hit send...
:-)

> perldoc -f delete shows other pretty cool stuff...

True, and ive even read it.  Just dont have a lot of call to use
delete so subtleties like deleting hash slice arent really part of my
m.o.

Yves


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

Date: 31 Jul 2001 09:18:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Flock on DATA?
Message-Id: <9k5t4m$plo$1@mamenchi.zrz.TU-Berlin.DE>

According to Benjamin Goldberg  <goldbb2@earthlink.net>:
> I'm not sure how well this would work, but... if a particular file (say,
> a DB file) is only being accessed from one module, could we simply lock
> the DATA filehandle within that module, rather than creating something
> *just* to be a lockfile?  After all, if DATA is the filehandle of the
> module, and only one instance of perl, with that module, is supposed to
> be accessing the DB, then we should be all set.
> 
> Plus, this would mean that we eliminate the need to remove our lockfiles
> later.

My guts feeling is, don't.  It may look economical to use a file for
locking that's already there, but you'll create all sorts of cross-
dependencies that will bite you later.

Suppose, someone wants to move the module to an NFS-mounted file
system.  Now locking may be insecure.

Worse, a user who wants an exclusive lock to the database would need
write access to the *module*, which is more than uncomfortable.  If
the program is running setuid, it may even refuse to load the module.

I'm sure there is more.  If you want a chisel, get a chisel even if
you happen to have a screwdriver in your hand.

Anno


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

Date: Tue, 31 Jul 2001 09:31:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Flock on DATA?
Message-Id: <6pucmtgr6nk5i9j205pa7ccg58pta8fqt9@4ax.com>

Benjamin Goldberg wrote:

>I'm not sure how well this would work, but... if a particular file (say,
>a DB file) is only being accessed from one module, could we simply lock
>the DATA filehandle within that module, rather than creating something
>*just* to be a lockfile?

No. You need write access for an exclusive lock.

-- 
	Bart.


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

Date: 31 Jul 2001 02:17:52 -0700
From: schen@caltech.edu (Shang-Lin Chen)
Subject: formatting an SGML file
Message-Id: <ced2ab2d.0107310117.d6d155e@posting.google.com>

In my SGML file, I use tags that specify when an argument is repeated,
as in:

<arg choice="req" rep="repeat">repeated_arg=<replaceable>val</replaceable></arg>.

I want to add an ellipsis (...) after "val" before removing the SGML
tags so that the final output will be:

repeated_arg=val... .

I read all the data from the SGML file into a string called $data and
then used regular expressions to format $data. I tried the regular
expression:

$data =~ s/(<\s*arg[\w\s\"=]*[\"]?\s*repeat\s*[\"]?[\w\s\"=]*>)([\w\W]*)(<s*replaceable\s*>)([\w\W]*)(\W+replaceable\s*>)/$1$2$3$4\.\.\.$5/gi;

to add the ellipsis, but the ellipsis was added in front of the last
</replaceable> tag in the file, not the correct </replaceable> tag. To
clarify what I mean, there was another arg statement later in the SGML
file:

<arg choice="opt">other_arg=<replaceable>value</replaceable></arg>.

After being formatted, $data contained:

repeated_arg = val

and

other_arg=value...

instead of what I originally wanted. The regular expression seemed to
have skipped to the later </replaceable> tag. How can I fix this
problem?


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

Date: Tue, 31 Jul 2001 02:27:14 GMT
From: "News Only" <bob@nowhere.com>
Subject: Help Please
Message-Id: <6Io97.40151$cK1.10071963@typhoon.jacksonville.mediaone.net>

Can someone help me with a perl script.

What I would like it to do is.

1. Find all files in a folder with todays date. -----       f:\folder
2. read the modify date and time.       -----   07/28/2001  12:53:42 AM
3. Delete all lines in the files containing a "string"  -----     delete
"any test here"
4. Change the modify date back to the original one. -----   07/28/2001
12:53:42 AM
5. Must be able to read long file names like "urls_072840000.log"

If its too much trouble to add the change modify date and time just leave it
out.

Thanks in advance.
perl challenged






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

Date: Tue, 31 Jul 2001 04:11:55 GMT
From: steven.smolinski@sympatico.ca (Steven Smolinski)
Subject: Re: Help Please
Message-Id: <feq97.3891$D55.413372@news20.bellglobal.com>

News Only <bob@nowhere.com> wrote:
> 1. Find all files in a folder with todays date. -----       f:\folder
> 2. read the modify date and time.       -----   07/28/2001  12:53:42
> AM

perldoc -f stat

I don't know if the behaviour differs on win32.

> 3. Delete all lines in the files containing a "string"  -----
> delete "any test here"

perldoc -q  "delete a line"

> 4. Change the modify date back to the original one. -----   07/28/2001
> 12:53:42 AM

On Windows, I don't know how to do this.

> 5. Must be able to read long file names like "urls_072840000.log"

Perl handles these just fine--no special handling required.

Let us know how you progress. :-)

Steve
-- 
Steven Smolinski => http://arbiter.ca/


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

Date: Tue, 31 Jul 2001 06:59:17 +0200
From: Philip Newton <pne-news-20010731@newton.digitalspace.net>
Subject: Re: Help with an array and foreach
Message-Id: <0jecmtsalo67ok6tp94edognic424gbubl@4ax.com>

[comp.lang.perl (RIP) snipped]

On 31 Jul 2001 00:42:25 +0200, Steve Holland <holland@origo.ifa.au.dk>
wrote:

>      The quick and dirty anwser is to use a while loop instead of
> foreach.

Or use for(;;), which is probably more appropriate here if you're going
to use that sort of construct.

> my $i = 3;
> while ($i <= $#x ) {
>     print "\@x[$i] = @x[$i]\n";
>     $i++;
> }

This is equivalent to

    for(my $i = 3; $i <= $#x; $i++) {
        print "\$x[$i] = $x[$i]\n";
    }

except for the scoping of $i (though you can declare it with "my $i;"
before the loop if you want to read it afterwards) and for the
replacement of your array slice with a proper (scalar) array element.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Tue, 31 Jul 2001 09:41:31 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Help with an array and foreach
Message-Id: <3b667c49.695211220@news.isholf.is>

On Mon, 30 Jul 2001 16:18:29 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:

>Ryan Gralinski wrote:
> 
>> i have a foreach loop like this
>
>> foreach $cover (@covers)
>> {
>>   }
> 
>> What i need to know, is how can i start this loop
>> at $start element of the array
>> f.e instead of starting at $covers[0] start at $covers[1000]
>
>Due due to perl core automation, you cannot do this
>with a foreach loop; it starts at element zero. There
>is no trick I know of to do this. Perhaps others know.

Not so.  For and foreach are exactly the same 
in function. Foreach is just a more grammatical 
way of writing some things.

Here is a simple example with a short array:

#!/usr/bin/perl -w
use strict;
my @names = qw/anna barney cathy david ellie fred/;
my $start = 3; my $stop = $#names;
foreach my $name (@names[$start..$stop]) { 
	print "$name\n";
 }

Regards,
Helgi Briem


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

Date: 30 Jul 2001 18:20:33 +0100
From: nobull@mail.com
Subject: Re: Iterating through an array
Message-Id: <u9puaiuye6.fsf@wcl-l.bham.ac.uk>

Ron Smith <ronnet@mediaone.net> writes:

> I need a little help with this one. I'm not finding exactly what I
> want in "The Cookbook" or the "Reference".

Never expect to find exactly what you want - expect to find something
that can trivally be converted into what you want.
 
> I'm using the following 16 lines in a text file:
> 
> -------------------snip------------------------------------
> /directory/directory/directory/directory/
> a frame.0001.rgb
> a frame.0002.rgb
> a frame.0003.rgb
> a frame.0004.rgb
> a frame.0005.rgb
> a frame_v12.0001.rgb
> a frame_v12.0002.rgb
> a frame_v12.0003.rgb
> a frame_v12.0004.rgb
> a frame_v12.0005.rgb
> a frame_v12.0006.rgb
> a frame_v3.0001.rgb
> a frame_v3.0002.rgb
> a frame_v3.0003.rgb
> a frame_v3.0004.rgb
> -------------------snip------------------------------------
> 
> What I've done is split each line so that the basename of the entries
> (frame, frame_v12, frame_v3) are in their own array; the numbers
> (0001, 0002, 0006, etc.) are in their own array, and all the "rgb"s
> are also in their own array.

Are you sure?
 
> From here, I'd like to iterate over the arrays until a new element is
> encountered (one that doesn't match the previous element), then print
> to a new file, or the same file the same info as above, but only in
> the following format:
> 
> 1 frame.%04d.rgb 1-5
> 2 frame_v12.%04d.rgb 1-6
> 3 frame_v3.%04d.rgb 1-4
> 
> Here's what I have, so far. I'd like a little direction from here, or
> even a new approach, on the iteration part.
>
> -------------------snip------------------------------------
> #!/usr/bin/perl -w
> use strict;
> 
> my($file, $leading_symbol, $filename, $basename, $pad, $ext);
> my(@basename, @pad, @ext);

Good, you use strict and warnings then declare your variables with
my().  This is good - but you are declating all your variables in the
outermost file scope, negating 50% of the beniefit of using lexiacally
scoped variables.  Always declare lexically scoped variables in the
smallest possible scope (this applies to all languages which have the
concept of lexically scoped variables not just Perl).

> print "\nWhich file would you like to make a log from?: ";
> chomp($file = <STDIN>);
> open(FILE, "+<$file") || die "Could not open $file: $!\n";

Why "+<" and not just "<"?

> while (<FILE>) {
>     ($leading_symbol, $filename) = split;



>         foreach ($filename) {

Using foreach with a single element list is somewhat affected.  Doing
so and not then making any use of the iterator variable is just pure
obfuscation.

>         ($basename, $pad, $ext) = split (/\./, $filename);
>         @basename = $basename;
>         @pad = $pad;
>         @ext = $ext;

These are assignment statements.  They replace the entire contents of
the arrays on the LHS with single element lists on the RHS.  I stronly
suspect you actually meant to build up lists in these variables.

>         
>     }
> }
> close FILE;

So fixing all that we get:

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

print "\nWhich file would you like to make a log from?: ";
chomp(my $file = <STDIN>);
open(FILE, "<$file") || die "Could not open $file: $!\n";

my(@basename, @pad, @ext);
while (<FILE>) {
      my ($leading_symbol, $filename) = split;
      my ($basename, $pad, $ext) = split (/\./, $filename);
      push @basename => $basename;
      push @pad => $pad;
      push @ext => $ext;
}
close FILE;
__END__

Having fixed the obvious mistakes in the code you have written so far
I now have a problem as the code you have written so far seems to bare
little relation to the stated problem.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 31 Jul 2001 06:59:11 +0200
From: Philip Newton <pne-news-20010731@newton.digitalspace.net>
Subject: Re: Lanaguage files
Message-Id: <fldcmtg299db58q2dq6hob68ojparqitms@4ax.com>

On 30 Jul 2001 09:07:00 GMT, zhuangli <zhuangli@liv.ac.uk> wrote:

> Recent experience with Perl on a web site has seen the following on the web 
> error log files.

They don't seem to be Perl errors to me (unless you have a very
'strange' [e.g. non-Unix non-Win32] system that needs such files to
run). If Perl is involved at all, they are probably error messages
generated by a Perl script, but not by the Perl interpreter itself.

> Could someone tell me what are those files and where can I download them?

It it is as I expected, then you'll have to ask the author of the script
what the files are and what he needs them for.

>  --NO SUCH LANGUAGE FILE: ../lib/language//_lp_dbm_lang_util.txt--
>  --NO SUCH LANGUAGE FILE: ../lib/language//_settings.txt--
>  --NO SUCH LANGUAGE FILE: ../lib/language//_lp_admin_config.txt--
[etc. etc.]

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Tue, 31 Jul 2001 11:11:06 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Module help needed!
Message-Id: <3B66762A.4080107@post.rwth-aachen.de>

BCC wrote:

>Hi, I am clearly screwing something up here, but I cannot figure it
>out.  I built a module with some small test subroutines, that I wish to
>access via the object oriented method ($mod->sub()).
>
>I have a test cgi called index.cgi that calls the module, builds an
>object (thanks for the help on getting this part done! :), and so on.  
>
>I believe the problem may be with the call to readCookie from loggedIn
>because loggedIn is not doing the call through an object reference...? 
>But Im not sure.  readCookie will need to be called from within the
>module, and through and object.  When I execute index.cgi via my
>

Since readCookie is supposed to be a method you call it upon an object. 
See below.

[snip]

>Eh?  What am I doing wrong?
>
>Thanks!
>Bryan
>
[snip]

>
>CgiMOD.pm
>---------
>package CgiMOD;
>
[snip]

>
>## Custom subs
>sub readCookie {
>  my $shift = shift;
>  my %cookies = fetch CGI::Cookie;
>  my $login = $cookies{'Oreo'}{value}[0];
>  my $level = $cookies{'Oreo'}{value}[1];
>
>  if ($login && $level) {
>    return ($login, $level);
>  } else {
>    return ("", "");
>  }
>}
>
>sub loggedIn {
>  my ($shift, $login, $level) = readCookie();
>

Shouldn't this better be:
    my $shift = shift;
    my ($login, $level) = $shift->readCookie;

You better rename $shift to $self here and elsewhere since it is a 
convention in Perl.

>
>
>  if (($login ne "null" && $level ne "null") && ($login ne "" && $level
>ne "")) {
>    return 1;
>  } else {
>    return 0;
>  }
>}
>

Tassilo

-- 
Of course it's possible to love a human being if you don't know them too well.
		-- Charles Bukowski




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

Date: Tue, 31 Jul 2001 06:59:13 +0200
From: Philip Newton <pne-news-20010731@newton.digitalspace.net>
Subject: Re: negative lookahead
Message-Id: <r7ecmtkiaa8g170cjhalksik5u7obok84l@4ax.com>

On 30 Jul 2001 06:11:19 -0700, rafalam@cadmus.com (mike) wrote:

> I want to match a string that starts with "aaa" and ends with "bbb" as
> long as the is no "zzz" between aaa and bbb.

If the string starts with 'aaa' and ends with 'bbb', then it's easy to
do in two steps:

    $mystring =~ m/^aaa.*bbb$/si && $mystring !~ /zzz/i

since regardless of where the zzz is in the string, it has to be between
aaa and bbb if it's there at all.

If aaa and bbb are allowed to be somewhere in the middle of the string,
this should still work:

    $mystring =~ m/aaa.*bbb/si && $mystring !~ /aaa.*zzz.*bbb/si

Cheesr,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Tue, 31 Jul 2001 06:57:42 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: negative lookahead
Message-Id: <rnkcmtk7h2f99jinuuob3a05hahtsln3a2@4ax.com>

Randal L. Schwartz wrote:

>        /aaa((?!zzz).)*?bbb/s
>
>Sure, it's inching a character at a time, but it does the job.

Perhaps this may speed things up a little.

	/aaa(?:[^z]|(?!zzz)z)*?bbb/

It only does the lookbehind test for where it might actually succeed,
bypassing it for non-"z" characters (the bulk, I would expect). I'm too
lazy to actually do a benchmark.

And, people, please don't fall for the trap to add a "+" after the
"[^z]". You might actually slow it down quite a bit on some occasions,
because of excessive backtracking. See Jeffrey Friedle's book, "Master
Regular Expressions", ch.5, pp. 143-145 in my version (search the index
for "neverending match").

-- 
	Bart.


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

Date: Tue, 31 Jul 2001 07:22:02 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: negative lookahead
Message-Id: <9k5maq$2gua$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Bart Lateur 
<bart.lateur@skynet.be>], who wrote in article <rnkcmtk7h2f99jinuuob3a05hahtsln3a2@4ax.com>:
> Randal L. Schwartz wrote:
> 
> >        /aaa((?!zzz).)*?bbb/s
> >
> >Sure, it's inching a character at a time, but it does the job.

Works only because zzz and bbb can't overlap.

> Perhaps this may speed things up a little.
> 
> 	/aaa(?:[^z]|(?!zzz)z)*?bbb/

Then make it

  /aaa(?:(?>[^z]+)|(?!zzz)z)*?bbb/

But again, this is useful only as far as you consider the subject
topic - which of course does not interest the actual poster.

> And, people, please don't fall for the trap to add a "+" after the
> "[^z]". You might actually slow it down quite a bit on some occasions,
> because of excessive backtracking. See Jeffrey Friedle's book, "Master
> Regular Expressions", ch.5, pp. 143-145 in my version (search the index
> for "neverending match").

It is many years already as this book became useless as far as Perl is
concerned.

Ilya


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

Date: Tue, 31 Jul 2001 09:23:04 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: newbe question splitting a string into two different variables
Message-Id: <3b6678a7.694281123@news.isholf.is>

On Mon, 30 Jul 2001 10:45:30 -0700, "Oliver"
<ow22@nospam-cornell.edu> wrote:

>i have a slightly harder question, how could i split a string like
>
>      hello      good    bye  1  444
>
>into an array of strings (hello,good,bye,1,444). basically i have these
>strings that are seperated by an arbitary number of spaces, and i need to
>get them into an array. okay thanks in advance
>
>oliver
>
>
>"fred58" <none@nowere.com> wrote in message
>news:3roamt4jqf75g3ierd9qic6d8m8ar42dvj@4ax.com...
>> Right here is my problem i would like to split this string at the |
>> "hello | good buy" into two different variables but im unsure of the
>> best way to do this any help would be gratefully received
>>
You are posting the same question with minor
variations over and over again.  Why don't you
think just a little bit before reposting?

Regards,
Helgi Briem


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

Date: 30 Jul 2001 18:55:28 -0700
From: davidgroe@hotmail.com (David Roe)
Subject: Parse::RecDescent
Message-Id: <f08b44cc.0107301755.28390810@posting.google.com>

in this simple example of using Parse::RecDescent, i would like to
split the process up into 2 stages:

$::RD_AUTOACTION = q{[@item]};
my $grammar = <<'EOGRAMMAR'

startrule:	/set/i atom ASSIGN expression
expression:	<leftop: factor OPERATOR factor>
factor:		'(' expression ')' | atom
atom:		/\w+/

ASSIGN:		'=' | '+=' | '-=' | '/=' | '*='
OPERATOR:	'+' | '-' | '/' | '*' | '%' |
		'==' | '>' | '>=' | '<' | '<=' |
		/eq/i | /gt/i | /ge/i | /lt/i | /le/i |
		'&&' | '||' |
		/and/i | /or/i

EOGRAMMAR

i might pass "SET fruits = oranges" or "SET fruits += apples + bananas
+ pears" to it.

the first thing i am using Parse::RecDescent for is building a
parse-tree (and checking the validity of syntax). the second part is
to identify "atoms" beyond being just a word - i might look at
"apples" and figure out whether it really is a fruit.

if i were to redefine the grammar for "atom" to "atom: valid_fruit"
(with the appropriate subrule), it would certainly do both jobs at
once, but the downside appears to be that parsing the above second
expression results in multiple calls to identify what an apple, banana
or pear is, meaning if the expression has enough parts to warrant more
intense investigation, it re-evaluates each atom upon each attempt.

so if i create a parse-tree from the above grammar, effectively doing
the first job, can i use the resulting data structure with
Parse::RecDescent to continue with the second job? otherwise, can
anyone point out alternative approaches?

regards,
/dave
davidroe@email.com


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

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


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