[8394] in Perl-Users-Digest
Perl-Users Digest, Issue: 2011 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 3 14:16:09 1998
Date: Tue, 3 Mar 98 11:00:26 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 3 Mar 1998 Volume: 8 Number: 2011
Today's topics:
Re: [Q] How to redirect STDERR to a subroutine? <jdf@pobox.com>
Re: a newbie regexp question xewj@odin.sunquest.com
Re: awk -> Perl on Win32 (Gurusamy Sarathy)
Re: can't get rmdir to succeed (Billy Chambless)
Re: can't get rmdir to succeed <barnett@houston.Geco-Prakla.slb.com>
Context Sensitive RexExp <whittaa1@hau112.ha.uk.sbphrd.com>
Re: Context Sensitive RexExp (Kevin B Cohen)
Re: Controlling TWO input files (merging) (John Klassa)
Re: DB_File problems (Mike Heins)
Re: DB_File problems (Boris Pelakh)
help with regexp (Collin Rogowski)
Re: help with regexp (Aaron B. Dossett)
Re: help with regexp (Douglas Wilson)
Re: help with regexp <rbratton@fore.com>
Re: Learn Perl on the WEB? - YES!!... well, sorta... xewj@odin.sunquest.com
Net::Telnet question, how to set prompt? <a-namsuk@microsoft.com>
NOT matching a string miko@idocs.com
Re: OOP query in PERL <jdporter@min.net>
perl executable finally mentions FAQ (was Re: Conflict <Russell_Schulz@locutus.ofB.ORG>
Re: Perl performs a second miracle. Prepare for canoni <keithmur@mindspring.com>
Re: Q: Appropriateness of (my $x = shift;) vs (my $x = (Will Morse)
Re: regex problem - problem with * (David Waring)
Re: simple perl question (Craig Berry)
Re: simple perl question <jdporter@min.net>
solved problem with rmdir function (Kevin B Cohen)
Re: The -w switch (was Re: better way to do this?) <ajohnson@gpu.srv.ualberta.ca>
Re: The -w switch (was Re: better way to do this?) (Andrew M. Langmead)
Re: The -w switch (was Re: better way to do this?) <jdf@pobox.com>
Re: Why PERL? [Re: Beginner in trouble] <jdporter@min.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 03 Mar 1998 13:39:21 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: [Q] How to redirect STDERR to a subroutine?
Message-Id: <d8g3bova.fsf@news.concentric.net>
John Porter <jdporter@min.net> writes:
> I hope you have at least perl 5.4, because if you do, you have
^^^
That should read 5.004, I think. Thanks for the excellent tutorial, John.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 3 Mar 1998 16:39:06 GMT
From: xewj@odin.sunquest.com
Subject: Re: a newbie regexp question
Message-Id: <6dhbna$2uf$1@iggy.sunquest.com>
In article <6dfpmq$auq$1@grouper.exis.net>,
Jeff Barnes <psrjeff@exisnospam.net> wrote:
>$temp = ($file =~ /\d*/);
>if ($temp < 2) { $next = ($temp++);}
>else { $next = ($temp++); $prev = ($temp--);}
>this doesn't work. if the number in $file is a 2 digit number, $next becomes
>a 3 digit number with the first digit being an increment of one of the \d's
>in $file. Why, and how can I fix it?
There are two possibilities for what you're trying to do... (please define
what you're aiming at next time)
I'm assuming something along the lines of a next number "guessing" routine.
your error has to do with return context and ():
$temp = ($file =~ /(\d*)/)[0]; #forces array return context with right regex
$temp = ($file =~ /\d*/); #assumes scalar context and has wrong regex
from the perlop manpage (under m//):
If used in a context that requires a list value, a pattern match
returns a list consisting of the subexpressions matched by the
parentheses in the pattern, i.e. ($1, $2, $3...). (Note that here
$1 etc. are also set, and that this differs from Perl 4's
behavior.) If the match fails, a null array is returned. If the
match succeeds, but there were no parentheses, a list value of (1)
is returned.
------------------------------
Date: 3 Mar 1998 18:46:23 GMT
From: gsar@engin.umich.edu (Gurusamy Sarathy)
Subject: Re: awk -> Perl on Win32
Message-Id: <6dhj5v$8m6@srvr1.engin.umich.edu>
[ mailed and posted ]
In article <6dfa0r$ebc@dfw-ixnews10.ix.netcom.com>,
Blue <mchase@ix.netcom.com> wrote:
>Your best bet is to install the Gurusamy Sarathy binary distribution (in
Thanks for the plug, but the bindist doesn't come with a2p either :-(
The devel versions include a2p in the build (as will 5.004_05 when it
comes).
- Sarathy.
gsar@umich.edu
------------------------------
Date: 3 Mar 1998 17:09:01 GMT
From: billy@cast.msstate.edu (Billy Chambless)
Subject: Re: can't get rmdir to succeed
Message-Id: <6dhdfd$i6l$1@nntp.msstate.edu>
In article <6dh6vi$853@julius.ling.ohio-state.edu>, kcohen@julius.ling.ohio-state.edu (Kevin B Cohen) writes:
|> my problem is that rmdir won't succeed. i'm running the following
|> snippet on NT:
|> if ($#NewContents <= 1) {
|> rmdir ($date) || print "couldn't delete the directory named $date.\n";
|> }
|> i allow for @NewContents to have 2 elements since it will contain .
|> and .. (current and parent directory).
|>
|> what happens is that i get the message "couldn't delete the directory
|> named $date." (looking over this message, it occurred to me that i
|> ought to try putting the variable $date in double quotes, but that
|> didn't help.)
You should include $! in your error message.
rmdir will usually tell you what went wrong.
--
* "And there _is_ a real world. In fact, some of you
* are in it right now." -- Gene Spafford
------------------------------
Date: Tue, 03 Mar 1998 11:00:29 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: can't get rmdir to succeed
Message-Id: <34FC372D.FCAF810F@houston.Geco-Prakla.slb.com>
Kevin B Cohen wrote:
>
> greetings---
>
> my problem is that rmdir won't succeed. i'm running the following
> snippet on NT:
>
> # recheck directory contents--make sure it's empty
>
> @NewContents = readdir (DATE);
>
> if ($#NewContents <= 1) {
>
> rmdir ($date) || print "couldn't delete the directory named $date.\n";
A useful modification would be to include $! variable. It should print
out any error returned by the OS.
rmdir ($date) or print "couldn't delete the directory named $date:
$!.\n";
This should generate some message similar to:
couldn't delete the directory named dave: No such directory.
That should help in troubleshooting this.
>
> }
> else {
> print "didn't remove the directory named $date, as it didn't seem
> to be empty.\n";
> }
>
<snip>
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
------------------------------------------------------------------------
* Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------
------------------------------
Date: 03 Mar 1998 15:28:44 +0000
From: Alex Whittaker <whittaa1@hau112.ha.uk.sbphrd.com>
Subject: Context Sensitive RexExp
Message-Id: <vorogzn23pv.fsf@hau112.ha.uk.sbphrd.com>
I have a requirement to look for a pattern in what amounts to a long
stream of letters something like this:
/[SEQRDN].*M[DE].*F/
Where the length of the whole match is between 10 and 20 characters. Now
the pattern is such that I could get any number of hits to what I'm
looking for. So if I do something like this:
if (/[SEQRDN].*M[DE].*F/ && length($&) >= 10 && length($&) <= 20) {
be_happy() ;
}
..I will miss hits, because .* is greedy and there are no .{n,m} length
restrictions in the regexp. If I change to .*? and then check the length,
I'm still on shakey ground because if I could fall under the 10 limit.
I suppose what I really want is something which would go like this:
/(?:[SEQRDN].*M[DE].*F){10,20}/
..and not mean the whole pattern repeated ten to twenty times.
The core problem is that the second .* is given context by the first one,
so that the pattern fails to be context free.
Any thoughts?
-- Alex Whittaker --
SmithKline Beecham Pharmaceuticals
New Frontiers Science Park Alex_Whittaker-1@sbphrd.com
Harlow, CM19 5AW All I know is that I know nothing
------------------------------
Date: 3 Mar 1998 13:15:55 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: Re: Context Sensitive RexExp
Message-Id: <6dhhcr$bci@julius.ling.ohio-state.edu>
In article <vorogzn23pv.fsf@hau112.ha.uk.sbphrd.com>,
Alex Whittaker <whittaa1@hau112.ha.uk.sbphrd.com> wrote:
>
> The core problem is that the second .* is given context by the first one,
> so that the pattern fails to be context free.
why are you concerned about whether or not the match pattern is
context-free?
kevin
------------------------------
Date: 3 Mar 1998 18:04:09 GMT
From: klassa@aursgh.aur.alcatel.com (John Klassa)
Subject: Re: Controlling TWO input files (merging)
Message-Id: <6dhgmp$1tm$1@aurwww.aur.alcatel.com>
On Tue, 03 Mar 1998 08:15:09 -0800, Rich Pinder <rpinder@usc.edu> wrote:
->I'm trying to read two files at the same time, keeping file pointer in
->sync on records of each file, and end up 'merging' info from line 1 of
->file A with line 1 of file B.
Do the obvious: open both files manually and read from them manually...
You seem to have some misconceptions about the way to structure such a
thing -- *Learning Perl* by Randal Schwartz is a good place to learn the
language (see other, recent posts on this topic).
--
John Klassa / Alcatel Telecom / Raleigh, NC, USA <><
------------------------------
Date: 3 Mar 98 16:56:28 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: DB_File problems
Message-Id: <34fc363c.0@news.one.net>
In comp.lang.perl.modules Boris Pelakh <pelakh@rsn.hp.com> wrote:
> I have written a CGI application to track problem reports for a computer
> store. It uses a DB_HASH Berkeley DB database to store the information.
> In the last couple of weeks, I have run into some problems, the most
> serious of which is the presence of duplicates in the file, i.e. when I
> each() through the hash tied to the DB_File, I get multiple records with
> identical keys (sometimes as many as 3).
This should not happen if you are really using the HASH type; it would
be consistent with BTREE or RECNO. Are you sure you are not deleting
records during your each() iteration?
Regards,
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
There ain't nothin' in this world 131 Willow Lane, Floor 2 | || _ \
that's worth being a snot over. Oxford, OH 45056 | || |_) |
--Larry Wall <mikeh@minivend.com> |___| _ <
513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: 3 Mar 1998 18:33:14 GMT
From: pelakh@rsn.hp.com (Boris Pelakh)
Subject: Re: DB_File problems
Message-Id: <6dhida$7t3$1@news.rsn.hp.com>
In article <34fc363c.0@news.one.net>, Mike Heins <mikeh@minivend.com> wrote:
>This should not happen if you are really using the HASH type; it would
>be consistent with BTREE or RECNO. Are you sure you are not deleting
>records during your each() iteration?
Here is how I tie the hash
$db_obj = tie(%db,"DB_File",'/usr/home/jeanhall/public_html/prs.db',
O_RDWR|O_CREAT, 0666, $DB_HASH);
And here is my traversal loop:
while (($key,$val) = each %db) {
$debug && print "<!-- Checking ticket $key -->\n";
$pr = {split(/\e/,$val)};
if (&$match($pr)) {
$debug && print "<!-- Adding $pr->{ticket} -->\n";
push(@res, $pr);
}
}
I get duplicates on about 0.5% of the records. I use synchronize access
to the database by getting the file descriptor from the 'fd' method,
opening a handle to that file descriptor, and then using flock on the handle.
P.S. Is this true that DB_File 2.0 will take care of the synchronization on
a lower level, so that I won't have to do this ?
--
Boris Pelakh SPP DevSW / HP CXDL pelakh@rsn.hp.com
Natural selection saw to it that professional heroes who at a crucial moment
tended to ask themselves questions like "What is my purpose in life?" very
quickly lacked both. -- (Terry Pratchett, Interesting Times)
------------------------------
Date: Tue, 03 Mar 1998 16:30:57 GMT
From: collin@rogowski.de (Collin Rogowski)
Subject: help with regexp
Message-Id: <34fc2f2a.635087006@news.osnabrueck.netsurf.de>
I have a line like this:
param1=value1, param2=value2, param3=value3, param4=value4, ...
I want to extract value3, so I thought I could something like this:
if (/param3=(.*),/) {
$value = $1
}
print $value; #this shows value3, param4=value4, ...
this menas the regexp matches on the ",", which is most right. But I
want it to match on the most left.
How can I do this?
Thanks in advance
------------------------------
Date: 3 Mar 1998 17:52:37 GMT
From: aarond@alpha.ewl.uky.edu (Aaron B. Dossett)
Subject: Re: help with regexp
Message-Id: <6dhg15$ngq$1@service3.uky.edu>
Collin Rogowski (collin@rogowski.de) wrote:
> I want to extract value3, so I thought I could something like this:
>
> if (/param3=(.*),/) {
> $value = $1
> }
> print $value; #this shows value3, param4=value4, ...
>
The simplest way would be to use (/param3=([^,]*)/)
This matches all of the non-comma character to the right of the equal sign.
> this menas the regexp matches on the ",", which is most right. But I
> want it to match on the most left.
> How can I do this?
Aaron
--
Aaron B. Dossett | Finger aarond@london.cslab.uky.edu for PGP key
dossett@bigfoot.com|
Comp. Sci. Senior | http://www.ewl.uky.edu/~aarond
University of Kentucky 1996 NCAA Basketball Champions
------------------------------
Date: Tue, 03 Mar 1998 18:06:29 GMT
From: dgwilson@gte.net (Douglas Wilson)
Subject: Re: help with regexp
Message-Id: <6dhgnb$7hu$1@gte1.gte.net>
On Tue, 03 Mar 1998 16:30:57 GMT, collin@rogowski.de (Collin Rogowski)
wrote:
>I have a line like this:
>
>param1=value1, param2=value2, param3=value3, param4=value4, ...
>
>I want to extract value3
Either:
#See perldoc perlfunc for split & map
my $line="p1=v1,p2=v2,p3=v3";
my %hash=map {split "=",$_} split ",",$line;
print "$hash{p3}\n";
or
#See perldoc perlre for '?' (Non-greedy matches)
if ($line=/p3=(.*?),/) {
$v3=$1;
}
Hope that helps,
Douglas Wilson
------------------------------
Date: Tue, 03 Mar 1998 18:08:08 +0000
From: "Robert E. Bratton" <rbratton@fore.com>
To: Collin Rogowski <collin@rogowski.de>
Subject: Re: help with regexp
Message-Id: <34FC4708.EF882BA@fore.com>
This is a multi-part message in MIME format.
--------------DB0E60234777483094E65553
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Collin Rogowski wrote:
>
> I have a line like this:
>
> param1=value1, param2=value2, param3=value3, param4=value4, ...
>
> I want to extract value3, so I thought I could something like this:
>
> if (/param3=(.*),/) {
> $value = $1
> }
> print $value; #this shows value3, param4=value4, ...
>
> this menas the regexp matches on the ",", which is most right. But I
> want it to match on the most left.
> How can I do this?
>
> Thanks in advance
Try the following:
======================
$strn = "param1=value1, param2=value2, param3=value3, param4=value4,
...";
# I want to extract value3, so I thought I could something like this:
$strn =~ /param3=([^, ]+),/;
print "\$1 = $1\n";
======================
Your problem was really only that your regular expression defaults to
matching the largest string possible. I fixed this by not allowing , or
space in the matched string. Your attempt was very close.
--
-=-=-=-=-=-=-=-=-=-
Robert E. Bratton, Electronic Systems Developer
FORE Systems, Inc. http://www.fore.com
Email:rbratton@fore.com Voice Phone: 724-742-7995
--------------DB0E60234777483094E65553
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Robert Bratton
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Robert Bratton
n: Bratton;Robert
org: FORE Systems, Inc.
adr: 1000 Fore Drive;;;Warrendale;PA;15086;USA
email;internet: rbratton@fore.com
title: Electronic Systems Developer
tel;work: 724-742-7995
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version: 2.1
end: vcard
--------------DB0E60234777483094E65553--
------------------------------
Date: 3 Mar 1998 16:45:50 GMT
From: xewj@odin.sunquest.com
Subject: Re: Learn Perl on the WEB? - YES!!... well, sorta...
Message-Id: <6dhc3u$35k$1@iggy.sunquest.com>
In article <6dfqhb$iiv$1@unix2.glink.net.hk>,
7sD_.q<V6i <taiwan@glink.net.hk> wrote:
>Dear Perler,
> Just a newbie's question. Any WEB provide online tutorial for PERL ?
Sorta. full documentation is available online at "www.perl.com".
And lots of people have put together tutorials on their homepages.
On the other hand, the full documentation at www.perl.com isn't terribly
helpful if you're not somewhat fluent in perl already and the tutorials
which are available from peoples homepages can be really... really.. "bad".
(Most of the code makes me wince.)
I guess it's just one of those situations where you have to already know
perl in order to learn it. [grin]
Perl is based on a whole number of languages, but I would suggest learning
these to make the perl-transition easier:
C
C++ (or any OOP)
sh/ksh
grep
sed
There are usually full manpages for all of these online, but (again) they're
not terribly helpful for a newbie.
Ever considered buying a tutorial book?
------------------------------
Date: Tue, 03 Mar 1998 09:43:57 -0800
From: Namsuk Kim <a-namsuk@microsoft.com>
Subject: Net::Telnet question, how to set prompt?
Message-Id: <34FC415C.844B2151@microsoft.com>
Thanks to Nathan P., I could log in silently. However, it complains
that timing-out for command prompt.
How do I set the command prompt in a script? Say my prompt is
"linux4:~> ". Evironment value for prompt in shell is "%m:%~%#".
Thanks,
Namsuk Kim
------------------------------
Date: Tue, 03 Mar 1998 12:22:01 -0600
From: miko@idocs.com
Subject: NOT matching a string
Message-Id: <6dhhn7$jhl$1@nnrp1.dejanews.com>
I am trying to create a regex in which part of the expression matches any
amount of text that is NOT some expression.
For example, I would like an expression that essentially says "X" followed by
anything that isn't "test", so that it matches everything up to but not
including "test".
For the string "X hi there temp test" it would find "X hi there temp ".
For the string "Xtest" it would find "X".
For the string "Xtetetest" it would find "Xtete".
I have tried
/X(?!test)/
but that only matches the X, not all the stuff following it. I also tried
"/X(?!test)*/" but that is no better.
I hope I'm not asking a FAQ, but I have searched diligently and (perhaps
because I lack the key vocabulary) haven't found an answer to this anywhere.
Thanks so much for your help.
-miko
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 03 Mar 1998 12:14:51 -0500
From: John Porter <jdporter@min.net>
Subject: Re: OOP query in PERL
Message-Id: <34FC3A8B.601D@min.net>
Srinivas Abburi wrote:
>
>
> package Emp;
>
> sub new {
>
> my $proto = shift;
> my $class = ref($proto) || $proto;
> my $self = {};
> $self->{$first_name} = undef;
> $self->{$last_name} = undef;
> $self->{$id} = undef;
> $self->{$employer} = undef;
> $self->{$status} = undef;
> bless($self, $class);
> return $self;
> }
> [etc.]
Are you aware that hashes are indexed by strings?
In this code, you are indexing %{$self} with variables
$first_name, $last_name, etc. Do these variables
contain distinct strings? Looks to me like they're
probably all undef. You probably meant to use string
literals. Change all occurences of $first_name to
'first_name', and so on.
Have you not worked with hashes before? If not,
jumping to objects might be somewhat premature.
hth,
John Porter
------------------------------
Date: Tue, 3 Mar 1998 14:36:50 +0000
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: perl executable finally mentions FAQ (was Re: Conflict in this Newsgroup)
Message-Id: <19980303.143650.9w8.rnr.w164w_-_@locutus.ofB.ORG>
tchrist@mox.perl.com (Tom Christiansen) writes:
> Complete documentation for Perl, including FAQ lists, should be
> found on this system using `man perl' or `perldoc perl'. If you have
> access to the Internet, point your browser at http://www.perl.com/,
> the Perl Home Page.
this is good news.
but I recommend spelling out `FAQ'. maybe even taking up 3 more lines:
Complete documentation for Perl, including:
answers to Frequently Asked Questions (FAQs)
solutions to common problems
pointers to libraries of freely-reusable code
should be found on this system using `man perl' or `perldoc perl'.
If you have access to the Internet, point your browser at
http://www.perl.com/, the Perl Home Page.
and let's not forget that PGP refuses to run unless it can find the
manual in the same directory, or it is given a command-line switch
that is only documented in the manual.
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Tue, 03 Mar 1998 13:32:59 -0600
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: Perl performs a second miracle. Prepare for canonizaton!
Message-Id: <34FC5AEB.74D4F21F@mindspring.com>
Be sure to have your pets checked for carpal tunnel syndrome..
William Denton wrote:
>
> It first happened to me last year. I'd been working on a fairly
> lengthy Perl script for most of the day, adding in piece by piece
> until it was almost right where I wanted it. Then I did something
> wrong and it wouldn't work. I couldn't figure out why, so I left it
> overnight. The next morning ... it worked! I hadn't touched it, and
> nothing about the set-up had changed.
>
> I thought it was just an odd occurrence, a one-time thing. But then
> it happened again! This weekend I was fiddling away with something at
> home and got it to the point where it did everything I needed, except
> actually work. I left it overnight, and, as before, the next morning
> it worked.
>
> I looked through the documentation and couldn't find anything on this
> wonderful behaviour. I grepped /usr/local/lib/perl5 on "miracle" and
> stringsed /usr/local/bin/perl on the same word, but nothing came up.
> I'm not one to complain about Perl docs, but really, this feature
> should be more widely known.
>
> Bill
>
> --
> --
> William Denton : Toronto, Ontario, Canada : buff@interlog.com
> http://www.vex.net/~buff/
------------------------------
Date: 3 Mar 1998 11:38:36 -0600
From: will@Starbase.NeoSoft.COM (Will Morse)
Subject: Re: Q: Appropriateness of (my $x = shift;) vs (my $x = @_;)
Message-Id: <6dhf6s$on2$1@Starbase.NeoSoft.COM>
As I recall,
my $somevar = shift;
will take the first item on the default list, which is the first
element of @_ in a subroutine.
my $somevar = @_;
will tell you the number of items in the list @_.
Hope this helps.
Will
>
In article <34fc7586.716672350@nntp.atlanta.com>,
John "Chris" Wren <jcwren@atlanta.com> wrote:
[ ... ]
>
> However: I can find virtually nothing that explains the @_
>operator. I seem to know that when a subroutine is called, whatever
>arguments are passed into the @_ variable.
>
> I've seen some code that uses
>
> my $somevar = shift;
>
> and some code that uses
>
> my $somevar = @_;
>
> and even
>
> my ($var1, $var2, $var3) = @_;
>
> I understand the third usage, but I don't understand what
>makes the first two different. I've tried changing my code from the =
>shift to the = @_ version, and it breaks.
>
[ ... ]
--
# Copyright 1998 Will Morse. Internet repost/archive freely permitted.
# Hardcopy newspaper, magazine, etc. quoting requires permission.
#
# Gravity, # Will Morse
# not just a good idea, # Houston, Texas
# it's the law. # will@starbase.neosoft.com
#
# These are my views and do not necessarly reflect anyone else.
------------------------------
Date: 3 Mar 1998 17:00:45 GMT
From: dwaring@nwsr.com (David Waring)
Subject: Re: regex problem - problem with *
Message-Id: <dwaring-0303980902120001@blv-lx104-ip6.nwnexus.net>
Sorry for the question a good night's sleep allowed me to figure out why
my idea of greedy and Perl's were not the same. Thanks for the replys.
David
In article <34FC076E.167E@theo.phy.uni-bayreuth.de>, Eike Grote
<eike.grote@theo.phy.uni-bayreuth.de> wrote:
> Hi,
>
> David Waring wrote:
> >
> > I cannot for the life of me figure out this problem. I am not new to
> > regex's but this confuses me. I am simply trying to grab a number frome a
> > line but if I use \d* it does not work while \d+ does. Here is a printout
> > of my code and the result:
******************************
*
* David Waring
* Freelance Web Developer
* HTML, Perl/CGI, Graphics etc.
* dwaring@nwsr.com
* http://www.nwsr.com
*
******************************
------------------------------
Date: 3 Mar 1998 06:37:34 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: simple perl question
Message-Id: <6dg8fe$p91$1@marina.cinenet.net>
Siemel Naran (sbnaran@bardeen.ceg.uiuc.edu) wrote:
: (a)
: If I have a string and want to get the string minus the last character if
: it is a '/', how can I do it? For example,
: /home/sbnaran/stuff ==> /home/sbnaran/stuff
: /home/sbnaran/stuff/ ==> /home/sbnaran/stuff
$string =~ s!/$!!; # Destructive operation
: (b) If I have a string and I want to return a substring in it starting at
: a given search-substring, how? For example, if the search-substring is
: "sbnaran", then
: /home/sbnaran/stuff ==> sbnaran/stuff
$search = 'sbnaran';
$string = '/home/sbnaran/stuff';
($substring) = $string =~ /(\Q$search\E.*)/; # Non-destructive.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Tue, 03 Mar 1998 13:02:00 -0500
From: John Porter <jdporter@min.net>
Subject: Re: simple perl question
Message-Id: <34FC4598.7CC6@min.net>
Siemel Naran wrote:
>
> (a)
> If I have a string and want to get the string minus the last character if
> it is a '/', how can I do it? For example,
> /home/sbnaran/stuff ==> /home/sbnaran/stuff
> /home/sbnaran/stuff/ ==> /home/sbnaran/stuff
Here's a way which uses the magic of chomp(). Look up chomp in the
docs.
$s = '/home/sbnaran/stuff/';
$t = 'no-trump';
{
local $/ = '/';
chomp( $s );
chomp( $t );
}
# now $s has been modified, but $t has not.
> (b) If I have a string and I want to return a substring in it starting at
> a given search-substring, how? For example, if the search-substring is
> "sbnaran", then
> /home/sbnaran/stuff ==> sbnaran/stuff
For cases as simple as this, you might try index() and substr().
hth,
John Porter
------------------------------
Date: 3 Mar 1998 13:38:06 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: solved problem with rmdir function
Message-Id: <6dhime$bot@julius.ling.ohio-state.edu>
grateful thanks to the many people who wrote here and to my email
address to tell me about $!. serendipidity being what it is, not only
did $! point me towards a resolution of the problem that i had posted
about, but it's helped me solve yet another problem already today.
kevin "$!" cohen
------------------------------
Date: Tue, 03 Mar 1998 11:54:32 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <34FC43D8.20922CB7@gpu.srv.ualberta.ca>
Art Cohen wrote:
!
[snip]
! Now, I'm not arguing that the -w switch or "use strict" are bad
! things. But I just find it bizarre and slightly unsettling the
! number of people -- supposedly knowledgeable about perl if not
! "gurus" -- who are eager to jump all over anyone who dares to
! suggest that certain "orthodoxies" aren't always necessary. Some
! people have implied that I'm a complete moron simply because I
! prefer to work without them. There's supposed to be more than one
! way to do it, remember? Perl is supposed to make the easy jobs
! easy, remember?
I think, for the most part, people get jumped on for not using
-w when using it would have given them a clue as to what the
problem was with the code they posted (I'm not saying that's the
case with your experiences) --- and perhaps this has happened so
many times that some of regulars here see a lack of -w as a sign
that the poster has not done any research to solve their problem
(they haven't even tried to see if -w helps them...probably haven't
read any docs either...)
People may well elect to not use -w for whatever reasons...but they
shouldn't necessarily expect debugging help from cplm until they've
at least demonstrated that they've tried to locate the problem on
their own, and -w compliance should be a necessary step in that
direction.
$0.02
regards
andrew
------------------------------
Date: Tue, 3 Mar 1998 18:38:27 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <Ep9AG3.M3q@world.std.com>
Art Cohen <upsetter@shore.net> writes:
>Yeah, but sometimes, for example, I just want to copy a piece of code from
>another program -- to populate a time array, for example, I just grab the
>text that says ($sec, $min, $hour .. whatever) = localtime(time) and
>continue working, even though I'm not using every element in that array.
One way around this is to make a slice of the list returned from
localtime that only contains the elements that you need.
($mon,$mday,$year) = (localtime())[4,3,5];
>Now, I'm not arguing that the -w switch or "use strict" are bad things.
>But I just find it bizarre and slightly unsettling the number of people --
>supposedly knowledgeable about perl if not "gurus" -- who are eager to
>jump all over anyone who dares to suggest that certain "orthodoxies"
>aren't always necessary. Some people have implied that I'm a complete
>moron simply because I prefer to work without them. There's supposed to be
>more than one way to do it, remember?
But for each decision that you make on how you "do it" there are
repercussions that you have to live with. You can get a list of files
by using opendir()/readdir() or by `/bin/ls`. The latter isn't
portable, and will fork off another process, but on the other hand it
sorts its output for you, hides dotfiles, prepends the path to the
file, and handles shell globs.
If someone intentionally chooses to program without "-w" and "use
strict", they are trading off easier programming for harder
debugging. If they realize the consequences of that, great. If they
then need help debugging, their decision is unfortunate for the
readers of the newsgroup when they then come asking for help. And
cleaning up nearly complete but non-working script to be "-w" and "use
strict" compliant is tougher than getting a working one to be. And
getting the working one to be work with these diagnostic tools is
tougher than ensuring that it is complient from the start.
More often, though, the reason that they didn't use these features is
that they don't know about them. There are too many bad script
examples and bad books that novices are learning from.
If you had a problem with a script that you wrote, what would you do?
Would you first enable the "-w" flag wade through the warnings and
examine which ones are legit and which ones aren't? Or assume that
your probelms are well beyond the scope of perl's built in diagnostic
tools and ask for help on Usenet? (actually, if you really do spend
more time writing than debugging, that doesn't seem to be a bad trade
off.)
Whenever I see a piece of code here that I want to try to help out
with, I immediately run it with "-w" to see pops up. Very frequently,
the interpreter tells me the answer.
--
Andrew Langmead
------------------------------
Date: 03 Mar 1998 13:44:58 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <btvnbolx.fsf@news.concentric.net>
Art Cohen <upsetter@shore.net> writes:
> But I just find it bizarre and slightly unsettling the number of people --
> supposedly knowledgeable about perl if not "gurus" -- who are eager to
> jump all over anyone who dares to suggest that certain "orthodoxies"
> aren't always necessary. Some people have implied that I'm a complete
> moron simply because I prefer to work without them.
Truly, anyone who'd imply such a thing isn't worthy of a response.
Ignore them.
I think it's good practice to recommend the use of -w to folks who
post code that would have been usefully questioned by the perl warning
elf. I can't imagine coding without it, myself, but then, I'm a lousy
tpyist.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Tue, 03 Mar 1998 13:09:57 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Why PERL? [Re: Beginner in trouble]
Message-Id: <34FC4775.35B5@min.net>
Mike Ellwood wrote:
>
> Larry Wall, Foreword to first edition of Learning Pearl
> by Randal L Schwartz and Tom Christiansen (2nd edition)
"first edition ... 2nd edition" ????
John Porter
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2011
**************************************