[18209] in Perl-Users-Digest
Perl-Users Digest, Issue: 377 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 28 14:10:59 2001
Date: Wed, 28 Feb 2001 11:10:29 -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: <983387428-v10-i377@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 28 Feb 2001 Volume: 10 Number: 377
Today's topics:
Newbie question re: Perl on RedHat 7 mwhyte_@_pmds.com
Re: Newbie question re: Perl on RedHat 7 <madden@cms-stl.com>
Re: Newbie question re: Perl on RedHat 7 <john_simpson@us.ibm.com>
Opening STDERR for input <bernie@fantasyfarm.com>
Perl comments ?? <debbie.knight@ntlworld.com>
Perl comments ?? <debbie.knight@ntlworld.com>
Re: Perl comments ?? nobull@mail.com
Re: Perl comments ?? <shanem@ll.mit.edu>
Re: Perl string (Tad McClellan)
print "</tr><tr>" vs. print $tr <stan_no_spam_for_me@alamo.nmsu.edu>
Re: print "</tr><tr>" vs. print $tr <comdog@panix.com>
Re: print "</tr><tr>" vs. print $tr <flavell@mail.cern.ch>
Re: print "</tr><tr>" vs. print $tr <iltzu@sci.invalid>
Re: Problem Solved!! <stiroff@elsitech.com>
problem with {q}? <bernie@fantasyfarm.com>
Re: problem with {q}? nobull@mail.com
Re: Reg. Exp. Challenge <crowj@aol.com>
Re: Reg. Exp. Challenge (Anno Siegel)
Re: Reg. Exp. Challenge <mjcarman@home.com>
Re: Reg. Exp. Challenge nobull@mail.com
Re: regex help please <ren@tivoli.com>
Re: Sorting by date <sorryno@email.at.all>
Re: Sorting by date (Anno Siegel)
Re: Sorting by date <godzilla@stomp.stomp.tokyo>
XML modules <tom.kralidis@ccrs.nrcan.gcDOTca>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Feb 2001 16:20:02 GMT
From: mwhyte_@_pmds.com
Subject: Newbie question re: Perl on RedHat 7
Message-Id: <97j8fi$esp$1@news.netmar.com>
I was hoping someone can help me with is probably a simple issue. I'm
running
RedHat 7 and my version of perl is 5.6 - the version that ships with RedHat
7. I've written my very first perl scrip, called test.pl naturally. When I
run "perl test.pl", everything works just fine (the script simply
prints 3
lines of test to the screen). However, after making test.pl executable
(chmod +x test.pl), I cannot run it just by typing "test" at the
command
line. The first line of the script is "#!/usr/bin/perl", just like all
the
examples I've seen. When I type "test", nothing happens - no error
messages
or anything, I simply return to a command prompt.
I apologize if this is covered in some kind of FAQ, but I wasn't able to
track
one down. I appreciate any help anyone can give me, and I'd really
appreciate it if you could email your response as well - I don't want to miss
anything!
TIA,
Mark
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Wed, 28 Feb 2001 11:12:58 -0600
From: "Michael J. Madden" <madden@cms-stl.com>
Subject: Re: Newbie question re: Perl on RedHat 7
Message-Id: <3A9D319A.FEC4FF4@cms-stl.com>
If you want to run it as test, you'll need to name the file
test. Otherwise, you can run it as test.pl or ./test.pl if
. isn't in your path.
Thanks,
Mike
mwhyte_@_pmds.com wrote:
>
> I was hoping someone can help me with is probably a simple issue. I'm
> running
> RedHat 7 and my version of perl is 5.6 - the version that ships with RedHat
> 7. I've written my very first perl scrip, called test.pl naturally. When I
> run "perl test.pl", everything works just fine (the script simply
> prints 3
> lines of test to the screen). However, after making test.pl executable
> (chmod +x test.pl), I cannot run it just by typing "test" at the
> command
> line. The first line of the script is "#!/usr/bin/perl", just like all
> the
> examples I've seen. When I type "test", nothing happens - no error
> messages
> or anything, I simply return to a command prompt.
>
> I apologize if this is covered in some kind of FAQ, but I wasn't able to
> track
> one down. I appreciate any help anyone can give me, and I'd really
> appreciate it if you could email your response as well - I don't want to miss
> anything!
>
> TIA,
>
> Mark
>
> ----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
> http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
> NewsOne.Net prohibits users from posting spam. If this or other posts
> made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Wed, 28 Feb 2001 12:34:56 -0500
From: John Simpson <john_simpson@us.ibm.com>
Subject: Re: Newbie question re: Perl on RedHat 7
Message-Id: <3A9D36C0.FCBDD69F@us.ibm.com>
mwhyte_@_pmds.com wrote:
> I was hoping someone can help me with is probably a simple issue. I'm
> running
> RedHat 7 and my version of perl is 5.6 - the version that ships with RedHat
> 7. I've written my very first perl scrip, called test.pl naturally. When I
> run "perl test.pl", everything works just fine (the script simply
> prints 3
> lines of test to the screen). However, after making test.pl executable
> (chmod +x test.pl), I cannot run it just by typing "test" at the
> command
> line. The first line of the script is "#!/usr/bin/perl", just like all
> the
> examples I've seen. When I type "test", nothing happens - no error
> messages
> or anything, I simply return to a command prompt.
>
> I apologize if this is covered in some kind of FAQ, but I wasn't able to
> track
> one down. I appreciate any help anyone can give me, and I'd really
> appreciate it if you could email your response as well - I don't want to miss
> anything!
>
> TIA,
>
> Mark
>
> ----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
> http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
> NewsOne.Net prohibits users from posting spam. If this or other posts
> made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
Looks like you are not running the "test" you want. Try "which test" to see what it
is executing. If you have the same RH 7.0 its probably picking up this:
# which test
/usr/bin/test
#
You can either export your PATH to include the path where your program is located:
export PATH=<new dir>:$PATH <-- this assumes ksh or bash
you can also run it by specifying the whole path or the current path if you are in
the directory that has it.
<dir>/test
or ./test
Hope this helps...
John
--
John Simpson
Unix System Services Development
Poughkeepsie UNIX Development Lab
IBM Server Group
2455 South Road
Poughkeepsie, NY 12601-5400
email: john_simpson@us.ibm.com
Phone Ext: 845-433-7917 Tie: 8-293-7917 Fax: 845-433-8363
------------------------------
Date: Wed, 28 Feb 2001 12:39:30 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Opening STDERR for input
Message-Id: <3mdq9t4rrr9gkkiss1pl8v0hu00m4hvi8t@news.supernews.net>
On Unix, STDERR is standardly open for both reading and writing [try it
from a shell script, for example]. I was somewhat surprised to discover
that in Perl, STDERR is open for output-only. Is there some machination
that'll get you a 'both ways' handle on STDERR? I tried the simple but
incredibly ugly:
} open (SAVERR, "+<&STDERR") or die "Can't save STDERR:$!\n" ;
} open (STDERR, "+<&SAVERR") or die "Can't reopen STDERR:$!\n" ;
} close SAVERR ;
And although there are no errors [neither 'die' gets executed], the STDERR
I'm left with still gets me just undef's when I try to read from it. I
even tried:
} open (STDERR, "+<&2") or die "Can't reopen STDERR:$!\n" ;
to no apparent avail [later in the program I try to do:
} print STDERR "Account to connect to: \n" ;
} chomp ($acct = <STDERR>) ;
and the print works fine but the <> always blows up. Is there some way to
program around this [preferably not hugely ugly]. THANKS!
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Wed, 28 Feb 2001 17:00:24 -0000
From: "deborah.knight1" <debbie.knight@ntlworld.com>
Subject: Perl comments ??
Message-Id: <c8an6.216$_4.159123@news6-win.server.ntlworld.com>
Hello,
I've edited a cgi scrpit using notepad, wordpad and ultraedit, using both
the # and /*..*/ for comments but none work, with the comments showing up in
both netscape and IE from home and my server.
This is the code:
#!/usr/local/bin/perl
/*comment see if it works*/
#this perhaps
print "content-type:text/html\n\n";
<HTML><HEAD><TITLE>Hiya there</TITLE></HEAD>
<BODY><H1>Web page</H1></BODY></HTML>
Any hints gratefully recieved.
Debbie Knight
------------------------------
Date: Wed, 28 Feb 2001 17:00:55 -0000
From: "deborah.knight1" <debbie.knight@ntlworld.com>
Subject: Perl comments ??
Message-Id: <d8an6.217$_4.159258@news6-win.server.ntlworld.com>
Hello,
I've edited a cgi scrpit using notepad, wordpad and ultraedit, using both
the # and /*..*/ for comments but none work, with the comments showing up in
both netscape and IE from home and my server.
This is the code:
#!/usr/local/bin/perl
/*comment see if it works*/
#this perhaps
print "content-type:text/html\n\n";
<HTML><HEAD><TITLE>Hiya there</TITLE></HEAD>
<BODY><H1>Web page</H1></BODY></HTML>
Any hints gratefully recieved.
Debbie Knight
------------------------------
Date: 28 Feb 2001 17:41:34 +0000
From: nobull@mail.com
Subject: Re: Perl comments ??
Message-Id: <u9snkyogc1.fsf@wcl-l.bham.ac.uk>
"deborah.knight1" <debbie.knight@ntlworld.com> writes:
> I've edited a cgi scrpit using notepad, wordpad and ultraedit, using both
> the # and /*..*/ for comments but none work,
Perl comments are introduced with #
> with the comments showing up in
> both netscape and IE from home and my server.
If your script's source is showing up in the browser then the server
is misconfigured not to realise they are scripts and is simply
serving them up as static content.
> This is the code:
No it isn't. That would not compile and hense what would show up in
the the browser is simply a "internal server error".
Show us the actual code.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 28 Feb 2001 13:42:47 -0500
From: Shane McDaniel <shanem@ll.mit.edu>
Subject: Re: Perl comments ??
Message-Id: <3A9D46A7.E30B2292@ll.mit.edu>
Does the code show up too? If so you probably have the wrong path to
the perl binary.
"deborah.knight1" wrote:
>
> Hello,
>
> I've edited a cgi scrpit using notepad, wordpad and ultraedit, using both
> the # and /*..*/ for comments but none work, with the comments showing up in
> both netscape and IE from home and my server.
>
> This is the code:
>
> #!/usr/local/bin/perl
>
> /*comment see if it works*/
> #this perhaps
>
> print "content-type:text/html\n\n";
>
> <HTML><HEAD><TITLE>Hiya there</TITLE></HEAD>
> <BODY><H1>Web page</H1></BODY></HTML>
>
> Any hints gratefully recieved.
>
> Debbie Knight
------------------------------
Date: Wed, 28 Feb 2001 12:46:59 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl string
Message-Id: <slrn99qecj.jon.tadmc@tadmc26.august.net>
Peter Søgaard <peter.s@tjgroup.dk> wrote:
>> What are "inverted commas"?
>
>I think he means back ticks ``
>...not sure tho'
But there were not any backtick characters in his post...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 28 Feb 2001 08:51:29 -0700
From: Stan McCann <stan_no_spam_for_me@alamo.nmsu.edu>
Subject: print "</tr><tr>" vs. print $tr
Message-Id: <3A9D1E81.C2182300@alamo.nmsu.edu>
I've been writing some scripts that displays data in tables and it
becomes cumbersome to keep using print "</tr><tr>" every time I need to
start a new row in the table. I thought of doing it as a small function
and calling the funtion but I'm pretty sure that is going to involve
some slowdown of program execution. I finally thought of defining a
variable my ($tr) = "</tr><tr>" and then just printing the variable when
needed. This works pretty well but I'm wondering if there is a better
way. I thought about a define or an inline function as in C but don't
know how to do this in perl. I've tried looking at perldocs but can't
find anything suitable.
Which is more efficent? Is there a better way?
Thanks.
Stan McCann
------------------------------
Date: Wed, 28 Feb 2001 12:06:39 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <comdog-4F08C8.12063928022001@news.panix.com>
In article <3A9D1E81.C2182300@alamo.nmsu.edu>,
stan_no_spam_for_me@alamo.nmsu.edu wrote:
> Which is more efficent? Is there a better way?
how about:
use CGI qw(:standard);
print Tr( ... );
--
brian d foy <comdog@panix.com>
------------------------------
Date: Wed, 28 Feb 2001 18:59:28 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <Pine.LNX.4.30.0102281841420.18159-100000@lxplus003.cern.ch>
On Wed, 28 Feb 2001, Stan McCann wrote:
> I've been writing some scripts that displays data in tables and it
> becomes cumbersome to keep using print "</tr><tr>" every time I need to
> start a new row in the table.
I'd recommend a more structured thought. Each table row is a complete
HTML "element", starting with <tr> and ending with </tr> and
containing, well, whatever it contains (td and th elements, if you
want to be specific). If you wish, you can print a tr element using
CGI.pm's Tr() function. If you don't wish, then that's fine too, but
I'd still recommend getting the structure right.
> I thought of doing it as a small function
> and calling the funtion but I'm pretty sure that is going to involve
> some slowdown of program execution.
Rule 1 of program optimisation is "don't optimise yet". (that's also
rule 2, and possibly rule 3 also).
The first priority is to engineer it right. That in itself is a form
of optimisation: but don't think of it in those terms. Just don't
optimise yet,
> Which is more efficent?
Frankly, you'd have to be generating an unreasonably vast amount of
HTML per invocation before this mattered. In reality the dominant
time and resource consumption of what you're discussing is likely to
be the process startup. Stop worrying about the detailed efficiency
of what you're coding, and start worrying about its robustness,
correctness, but most of all about the overall organisation of what
you're doing.
Good luck.
------------------------------
Date: 28 Feb 2001 18:32:05 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <983383233.335@itz.pp.sci.fi>
In article <3A9D1E81.C2182300@alamo.nmsu.edu>, Stan McCann wrote:
>
>I thought of doing it as a small function and calling the funtion but
>I'm pretty sure that is going to involve some slowdown of program
>execution.
Yes. About 5 microseconds per call, according to my measurements.
That's not a very reliable measurement, however, since the overhead of
timing the call is about 10 times larger. In other words, the slowdown
is about as significant as a fly's piss in the pacific ocean.
There are plenty of modules for timing your code on CPAN if you want to
test it yourself. I'll take the opportunity to plug Time::Stopwatch,
which I just recently uploaded and which is about as trivially simple to
use as anything can get.
I probably ought to post a proper announcement.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"So if you were shot with a .38, the homeopathic treatment is probably to
deal with the remaining problem with a .22." -- Zed Pobre in the SDM
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Wed, 28 Feb 2001 12:50:45 -0600
From: "Sharon Weis" <stiroff@elsitech.com>
Subject: Re: Problem Solved!!
Message-Id: <3048D2340674970E.97DD8F3A64B5DF12.3C4244018EB94FCF@lp.airnews.net>
Hi everyone!
Finally, I am able to send HTML mail without error!!!!!!!!
This is what solved the problem:
# Specify the domain-name for SMTP.
$ENV{DOMAIN} = "your.domain";
where "your.domain" is a valid domain name.
I added this one line of code to my CGI script and everything worked great!
Hope this helps anyone who may be experiencing the same problem!
Sharon Weis <stiroff@elsitech.com> wrote in message
news:EBF56D79C6BE9938.1D1A41A8D360FFC4.14CEDE79AC80EC63@lp.airnews.net...
> Hi, I am new to Perl CGI and I am trying to send mail in HTML format. I
am
> using ActivePerl on a Windows NT box. I am using the MIME::Lite and
> Net::Config packages. I am able to send
> mail successfully. However, it is printing the following errors on my CGI
> form. I have never modified, let alone opened the
> Domain.pm. Am I suppose to modify this file and if so what am I suppose
to
> modify?
>
> Errors:
> Use of uninitialized value in scalar assignment at
> E:/Perl/site/lib/Net/Domain.pm line 204.
> Use of uninitialized value in scalar assignment at
> E:/Perl/site/lib/Net/Domain.pm line 204.
> Use of uninitialized value in pattern match (m//) at
> E:/Perl/site/lib/Net/Domain.pm line 228. Use of uninitialized value in
split
> at E:/Perl/site/lib/Net/Domain.pm line 235.
>
> I've included the code in which the errors point:
>
> Domain.pm
> --------------------------------------------------------------------------
--
> -------
> # Look for environment variable
>
> $domain ||= $ENV{LOCALDOMAIN} ||= $ENV{DOMAIN} || undef; #line 204
>
> if(defined $domain) {
> $domain =~ s/[\r\n\0]+//g;
> $domain =~ s/(\A\.+|\.+\Z)//g;
> $domain =~ s/\.\.+/\./g;
> }
>
>
> sub domainname {
>
> return $fqdn
> if(defined $fqdn);
>
> _hostname();
> _hostdomain();
>
> # Assumption: If the host name does not contain a period
> # and the domain name does, then assume that they are correct
> # this helps to eliminate calls to gethostbyname, and therefore
> # eleminate DNS lookups
>
> return $fqdn = $host . "." . $domain #line 228
> if($host !~ /\./ && $domain =~ /\./);
>
> # For hosts that have no name, just an IP address
> return $fqdn = $host if $host =~ /^\d+(\.\d+){3}$/;
>
> my @host = split(/\./, $host);
> my @domain = split(/\./, $domain); #line 235
> my @fqdn = ();
>
> # Determine from @host & @domain the FQDN
>
> my @d = @domain;
>
>
> Thanks,
>
> Sheri
>
>
>
>
>
>
>
>
------------------------------
Date: Wed, 28 Feb 2001 11:38:33 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: problem with {q}?
Message-Id: <v99q9t0o8dkvda4itci94cq1rsbfsincus@news.supernews.net>
In a program I'm playing with [Perl 5.004_004], I do
} my %opts ;
} getopts("a:p:q", \%opts) ;
and then I play with the hash in the program. In one place I do:
if ($opts{a})
{ $acct = $opts{a} ; }
else
{ print...dostuff..etc..
and down later in the program I do
} sub say
} { print @_ unless $opts{q} ; }
I don't exactly understand why the reference to $opts{a} [and {p}] seem to
be OK, but for that last one, I get
>>> Ambiguous use of {q} resolved to {"q"}
What was 'q' ambiguous with? I just looked through my program and I
for-sure don't have a symbol named 'q'.. why would just that one hash-key
be ambiguous but the others not? In case it is some package messing with
me, the program includes only:
use Mail::POP3Client ;
use Mail::Header ;
use Mail::Address ;
use Getopt::Std ;
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: 28 Feb 2001 17:39:33 +0000
From: nobull@mail.com
Subject: Re: problem with {q}?
Message-Id: <u9u25eogfe.fsf@wcl-l.bham.ac.uk>
Bernie Cosell <bernie@fantasyfarm.com> writes:
> In a program I'm playing with [Perl 5.004_004], I do
I strongly recomend moving 5.5 or 5.6 (there are rather a lot of bugs
in 5.6.0 - it may be worth waiting for 5.6.1.
> I don't exactly understand why the reference to $opts{a} [and {p}] seem to
> be OK, but for that last one, I get
>
> >>> Ambiguous use of {q} resolved to {"q"}
>
> What was 'q' ambiguous with?
The q operator. This "feature" has been removed in 5.5.
> I just looked through my program and I
> for-sure don't have a symbol named 'q'.. why would just that one hash-key
> be ambiguous but the others not?
Because 'a' and 'p' are not then names of builtin Perl operators/functions.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 28 Feb 2001 10:58:03 -0500
From: John Crowley <crowj@aol.com>
Subject: Re: Reg. Exp. Challenge
Message-Id: <3A9D200B.9A99C38D@aol.com>
Kurt Tappe wrote:
>
> This BASIC-looking code snippet examines $string of unknown length for
> a set of parentheses of unknown location within it. It then extracts a
> substring of unknown length or contents from between those parentheses.
>
> Can you convert it to a regular expression?
>
> for ($counter=0; $counter <= $length($string); $counter++) {
> if (substr($string, $counter, 1) eq "(") {
> $start = $counter;
> }
> if (substr($string, $counter, 1) eq ")") {
> $end = $counter;
> }
> }
> my $substring = substr($string,$start,$end-$start);
>
> # If $string="This is the (sample) input string", $substring="sample"
>
> -Kurt
>
this should be in the ballpark:
$ cat x.pl
#!/usr/local/bin/perl5.00503 -w
my $string = $ARGV[0];
my @matches = $string =~ m#\((.*?)\)#g;
foreach (@matches) {
print "in parens: $_\n";
}
$ x.pl "The quick (brown) fox jumps (over) the lazy dog
in parens: brown
in parens: over
------------------------------
Date: 28 Feb 2001 16:55:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reg. Exp. Challenge
Message-Id: <97jaii$15r$1@mamenchi.zrz.TU-Berlin.DE>
According to Tad McClellan <tadmc@augustmail.com>:
> Kurt Tappe <ktappe@assocgraphics.com> wrote:
[...]
> Maybe it is "good enough" anyway...
>
>
> >for ($counter=0; $counter <= $length($string); $counter++) {
> ^
> ^ what's that dollar sign there for?
>
>
> > if (substr($string, $counter, 1) eq "(") {
> > $start = $counter;
>
> $start = $counter + 1;
>
> > }
> > if (substr($string, $counter, 1) eq ")") {
> > $end = $counter;
> > }
> > }
> >my $substring = substr($string,$start,$end-$start);
> >
> ># If $string="This is the (sample) input string", $substring="sample"
Okay, that about repairs the OPs program. Of course, perl has index()
and rindex() to do the job, so
$start = 1 + index $string, '(';
$end = rindex $string, ')';
$substring = substr($string, $start, $end-$start);
does the same thing. As often, this can be folded into a single
statement:
$substring = substr( substr( $string, 0, rindex $string, ')'),
1 + index $string, '(');
Anno, who still refuses to take up the regex challenge
------------------------------
Date: Wed, 28 Feb 2001 09:36:58 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Reg. Exp. Challenge
Message-Id: <3A9D1B1A.65AB092@home.com>
Kurt Tappe wrote:
>
> This BASIC-looking code snippet examines $string of unknown length for
> a set of parentheses of unknown location within it. It then extracts a
> substring of unknown length or contents from between those parentheses.
>
> Can you convert it to a regular expression?
>
> for ($counter=0; $counter <= $length($string); $counter++) {
> if (substr($string, $counter, 1) eq "(") {
> $start = $counter;
> }
> if (substr($string, $counter, 1) eq ")") {
> $end = $counter;
> }
> }
> my $substring = substr($string,$start,$end-$start);
If you really wanted extract the data via substr() the Perlish way would
be to use index() instead of a loop:
#!/user/local/bin/perl -w
use strict;
my $string = 'This is the (sample) input string';
my $start = index($string, '(') + 1;
my $end = index($string, ')') - 1;
my $length = $end - $start + 1;
my $substring = substr($string, $start, $length);
print $substring, "\n";
But regex's are more in keeping with the Perl idiom:
#!/user/local/bin/perl -w
use strict;
my $string = 'This is the (sample) input string';
(my $substring) = ($string =~ /\(([^)]+)\)/);
print $substring, "\n";
-mjc
------------------------------
Date: 28 Feb 2001 17:39:20 +0000
From: nobull@mail.com
Subject: Re: Reg. Exp. Challenge
Message-Id: <u9vgpuogfr.fsf@wcl-l.bham.ac.uk>
Kurt Tappe <ktappe@assocgraphics.com> writes:
> Subject: Reg. Exp. Challenge
s/Challenge/Trivial exercise/;
> This BASIC-looking code snippet examines $string of unknown length for
> a set of parentheses of unknown location within it. It then extracts a
> substring of unknown length or contents from between those parentheses.
>
> Can you convert it to a regular expression?
>
> for ($counter=0; $counter <= $length($string); $counter++) {
> if (substr($string, $counter, 1) eq "(") {
> $start = $counter;
> }
> if (substr($string, $counter, 1) eq ")") {
> $end = $counter;
> }
> }
> my $substring = substr($string,$start,$end-$start);
> # If $string="This is the (sample) input string", $substring="sample"
Actually that's not what the above code does.
It would extract $substring="(sample".
my ($substring) = /.*\((.*)\)/;
Note: the initial .* is so that you get the last substring.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Feb 2001 12:31:37 -0600
From: Ren Maddox <ren@tivoli.com>
Subject: Re: regex help please
Message-Id: <m3y9uqirqu.fsf@dhcp9-175.support.tivoli.com>
If you don't mind using experimental features of Perl, you can take
the example from perlre(1) under the description of `(??{ code })' and
use it very simply. The example is:
The following pattern matches a parenthesized
group:
$re = qr{
\(
(?:
(?> [^()]+ ) # Non-parens without backtracking
|
(??{ $re }) # Group with matching parens
)*
\)
}x;
To apply it to this problem, simply use:
1 while s/\(\s*($re)\s*\)/$1/g;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 28 Feb 2001 17:55:43 -0000
From: "Brian J" <sorryno@email.at.all>
Subject: Re: Sorting by date
Message-Id: <3a9d3bb2_2@news2.uncensored-news.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:97j3gm$k0t$2@mamenchi.zrz.TU-Berlin.DE...
> According to Godzilla! <godzilla@stomp.stomp.tokyo>:
<snip>
> You are sorting numerical data in a string sort. Your program
> will break in about 200 days.
>
> Anno
Why?
--
Brian
______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
With Servers In California, Texas And Virginia - The Worlds Uncensored News Source
------------------------------
Date: 28 Feb 2001 18:40:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting by date
Message-Id: <97jgmv$6s7$1@mamenchi.zrz.TU-Berlin.DE>
According to Brian J <sorryno@email.at.all>:
>
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:97j3gm$k0t$2@mamenchi.zrz.TU-Berlin.DE...
> > According to Godzilla! <godzilla@stomp.stomp.tokyo>:
> <snip>
> > You are sorting numerical data in a string sort. Your program
> > will break in about 200 days.
> >
> > Anno
>
>
> Why?
perl -le 'print time'
perl -le 'print 200*24*60*60 + time'
Anno
------------------------------
Date: Wed, 28 Feb 2001 11:04:22 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sorting by date
Message-Id: <3A9D4BB6.1645138E@stomp.stomp.tokyo>
Anno Siegel wrote:
> Brian J wrote:
> > Anno Siegel wrote:
> > > Godzilla! wrote:
> > <snip>
> > > You are sorting numerical data in a string sort. Your program
> > > will break in about 200 days.
> > Why?
> perl -le 'print time'
> perl -le 'print 200*24*60*60 + time'
You are a constant source of comedy.
Godzilla!
------------------------------
Date: Wed, 28 Feb 2001 12:31:25 -0500
From: "Tom Kralidis" <tom.kralidis@ccrs.nrcan.gcDOTca>
Subject: XML modules
Message-Id: <97jcld$hk53@nrn2.NRCan.gc.ca>
Hi,
Is anyone aware of any XML::Parser documentation, other than perldoc
I'm writing a CGI script, which checks an XML file to return values.
eg. I'd like to access and use the elements, attributes and values of a file
like this:
<TestRoot>
<GIF />
<elemOne valtype="testing">Test value</elemOne>
</TestRoot>
Any advice would be valued.
..Tom
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 377
**************************************