[19718] in Perl-Users-Digest
Perl-Users Digest, Issue: 1913 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 11 14:06:10 2001
Date: Thu, 11 Oct 2001 11:05:08 -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: <1002823508-v10-i1913@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 11 Oct 2001 Volume: 10 Number: 1913
Today's topics:
Re: Bitwise And (Rafael Garcia-Suarez)
Re: Bitwise And (Anno Siegel)
Re: Bitwise And <caughran@chem.uga.edu>
Re: Bitwise And <JPFauvelle@Colt-Telecom.fr>
Re: Bitwise And <bart.lateur@skynet.be>
Re: Comparing files. <stevea@wrq.com>
File test operators can't tell a file from a directory (Eamonn)
Re: File test operators can't tell a file from a direct <uri@sysarch.com>
Re: Filename case... <stevea@wrq.com>
Re: Filename case... (Anno Siegel)
Re: Filename case... <rsherman@ce.gatech.edu>
Getting a list of running programs under Windows2000 (Greg Webster)
Re: Keeping an escape code in a line (Greg Thorne)
Length of last matched substring? <bryan@ayesha.phys.Virginia.EDU>
Re: Length of last matched substring? <ilya@martynov.org>
Re: Length of last matched substring? <bart.lateur@skynet.be>
Re: Length of last matched substring? (Rafael Garcia-Suarez)
Re: Length of last matched substring? (Anno Siegel)
Re: Length of last matched substring? (Anno Siegel)
Re: Pattern Matching <jurgenex@hotmail.com>
Question about generating HTML from cgi <gbeanery@hotmail.com>
Re: Question about generating HTML from cgi <echang@netstorm.net>
Re: Question about tab delimeted text file from Excel <gbeanery@hotmail.com>
Re: sort - only want unique records <jurgenex@hotmail.com>
Re: sort - only want unique records (Mario Rizzuti)
Re: Special Pattern Match (M.A. Oxby)
Uploading (M.A. Oxby)
Re: Uploading <pilsl_@goldfisch.at>
Re: YOU ARE ALL GAY! <spamfreenation@nigenet.org.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Oct 2001 15:08:09 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Bitwise And
Message-Id: <slrn9sbdel.dqv.rgarciasuarez@rafael.kazibao.net>
Joel Caughran wrote in comp.lang.perl.misc:
} I must not understand the results of the & operand. As I understand it,
} 6 & 2 would be 2 and 12 & 6 would be 4. However, if I try
}
} perl -e "if (12 & 6 > 0) { print 'hello' }"
}
} it doesn't print anything. What am I missing?
Precedence. What you wrote is equivalent to "12 & (6 > 0)".
See the perlop manpage.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
But what about a bit of artistic license?
-- Monty Python, The Penultimate Supper
------------------------------
Date: 11 Oct 2001 15:10:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bitwise And
Message-Id: <9q4cp7$pf1$4@mamenchi.zrz.TU-Berlin.DE>
According to Joel Caughran <caughran@chem.uga.edu>:
> I must not understand the results of the & operand. As I understand it,
> 6 & 2 would be 2 and 12 & 6 would be 4. However, if I try
>
> perl -e "if (12 & 6 > 0) { print 'hello' }"
>
> it doesn't print anything. What am I missing?
Precedence. The &-operator ties tighter than >, so what you are
saying is "if ( 12 & (6 > 0) ) ...". The result of "6 > 0" is true,
represented by 1, so you are doing "12 & 1" which is indeed 0.
Try
perl -e 'print "hello\n" if (12 & 6) > 0'
Anno
------------------------------
Date: Thu, 11 Oct 2001 11:12:46 -0400
From: Joel Caughran <caughran@chem.uga.edu>
Subject: Re: Bitwise And
Message-Id: <3BC5B6EE.CE58D19D@chem.uga.edu>
Rafael and Anno,
Thanks for the correction. I knew it was something simple.
Joel
--
Joel A Caughran caughran@chem.uga.edu
Chemistry Learning Center caughran@uga.edu
Department of Chemistry
University of Georgia (706) 542-1906 voice
Athens, Georgia 30602-2556 (706) 542-9454 fax
Rafael Garcia-Suarez wrote:
>
> Joel Caughran wrote in comp.lang.perl.misc:
> } I must not understand the results of the & operand. As I understand it,
> } 6 & 2 would be 2 and 12 & 6 would be 4. However, if I try
> }
> } perl -e "if (12 & 6 > 0) { print 'hello' }"
> }
> } it doesn't print anything. What am I missing?
>
> Precedence. What you wrote is equivalent to "12 & (6 > 0)".
> See the perlop manpage.
>
> --
> Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
> But what about a bit of artistic license?
> -- Monty Python, The Penultimate Supper
------------------------------
Date: Thu, 11 Oct 2001 17:21:37 +0200
From: Jean-Philippe Fauvelle <JPFauvelle@Colt-Telecom.fr>
Subject: Re: Bitwise And
Message-Id: <i5ebstct2vajgqa86sc11k82e2v477judb@4ax.com>
Le Thu, 11 Oct 2001 11:02:59 -0400, Joel Caughran <caughran@chem.uga.edu> écrit:
>I must not understand the results of the & operand. As I understand it,
>6 & 2 would be 2 and 12 & 6 would be 4. However, if I try
>
> perl -e "if (12 & 6 > 0) { print 'hello' }"
>
>it doesn't print anything. What am I missing?
It's just a question of priority.
try this:
perl -e "if ( (12 & 6) > 0) { print 'hello' }"
Jean-Philippe Fauvelle
------------------------------
Date: Thu, 11 Oct 2001 15:18:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Bitwise And
Message-Id: <k0ebst0auhll6kaddmdgdtd2o0nie2vged@4ax.com>
Joel Caughran wrote:
> perl -e "if (12 & 6 > 0) { print 'hello' }"
>
>it doesn't print anything. What am I missing?
Try
if ((12 & 6 )> 0)
Then it works for me. You had a precedence problem.
--
Bart.
------------------------------
Date: Thu, 11 Oct 2001 17:10:34 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Comparing files.
Message-Id: <m31yka9k73.fsf@vhilx.wrq.com>
merigrace@rediffmail.com (Merina) writes:
>Hi,
> How to compare files using perl? .Is any command has been there?
File::compare might be what you want.
Try
perldoc File::compare
from your shell to see it's usage.
--
-- Steve __
------------------------------
Date: 11 Oct 2001 09:44:17 -0700
From: eamonn.gormley@eecad.com (Eamonn)
Subject: File test operators can't tell a file from a directory
Message-Id: <a72c9fe6.0110110844.d55c5b0@posting.google.com>
Hi,
I open a directory and read all the files and sub-directories into an
array like so :
_____________________________________________________
opendir (THISDIR, ".") || die "could not open";
@topdir = grep { $_ ne '.' and $_ ne '..' and $_ ne 'CVS' } readdir
THISDIR;
closedir THISDIR;
_____________________________________________________
Then I cycle through the entries in the array to sort the files from
the directories. The files are put into another array and the
directories are examined in the same way. Every time a directory is
found it is opened and examined in the same way, the files are put
into the big file array and the directories are opened and examined.
_____________________________________________________
my $entrycount = 0;
my $subdircount = 0;
foreach $entry (@topdir)
{
if (-f $entry)
{
$entries[$entrycount] .= "$entry";
$entrycount++;
print " File entry added: $entry\n";
} else #if (-d $entry)
{
$subdirs[$subdircount] .= "$entry";
$subdircount++;
print " level 1 DIRECTORY entry added: $entry\n";
# read all directory entries except for the . and .. files
# and put them in an array
opendir (L1DIR, "$entry") || die "could not open $entry";
@thissubdir = grep { $_ ne '.' and $_ ne '..' and $_ ne 'CVS' }
readdir L1DIR;
closedir L1DIR;
foreach $subdirentry (@thissubdir)
{
print " listing $subdirentry\n";
if (-d $subdirentry)
{
$subdirs[$subdircount] .= "$subdirentry";
$subdircount++;
print " Level 2 DIRECTORY FOUND: $subdirentry\n";
# read all directory entries except for the . and .. files
# and put them in an array
print "Opening $entry/$subdirentry for reading\n";
opendir (L2DIR, "$entry/$subdirentry") || die "could not
open";
@thissubsubdir = grep { $_ ne '.' and $_ ne '..' and $_ ne
'CVS' } readdir L2DIR;
closedir L2DIR;
........................etc
_____________________________________________________
Once I get down into the second level of sub-directories, the file
test operators don't seem to be able to tell the difference between a
file and a directory. The scrip begins to treat sub-sub-directories
as files. I have tried using -d else treat as a file, tried -f else
treat as a directory, neither seem to work. Has anyone else found
this problem?
------------------------------
Date: Thu, 11 Oct 2001 16:47:36 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: File test operators can't tell a file from a directory
Message-Id: <x7vghm6s36.fsf@home.sysarch.com>
<snip of home brewed code>
use File::Find
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 11 Oct 2001 16:30:11 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Filename case...
Message-Id: <m3adyy9m2e.fsf@vhilx.wrq.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
< major snippage to isolate a minor point >
>
>Finally, you should learn how to indent you program text to help
>readability. Putting it all together, your program should have
>looked somewhat like this (untested):
>
> my $directory = "f:/work";
> opendir DIR, $directory or die "Can't open directory $directory: $!";
> while ( defined ( $_ = readdir DIR) ) {
> warn "$_ is already lower-case, skipping\n", next unless /[A-Z]/;
> my $new_name = lc;
> warn "Not renaming $_ to $new_name, $new_name exists\n", next if
> -e "$directory/$new_name";
> rename "$directory/$_", $directory/$new_name" or
> warn "Can't rename $_ to $new_name: $!";
> }
>
A co-worker and I were coincidentally working on this same problem
this week. I had initially used
if ( /[A-Z]/ ) {
rename $_, lc $_ or warn "Failed to rename $_: $!";
}
but thought it would be more efficient to use a string equality test
instead of a regex:
my $lcfile = lc $_;
unless ( $_ eq $lcfile ) {
rename $_, $lcfile or warn "Failed to rename $_: $!";
}
Do you think there's any significant difference between the two?
--
-- Steve __
------------------------------
Date: 11 Oct 2001 17:01:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Filename case...
Message-Id: <9q4j9l$9lm$2@mamenchi.zrz.TU-Berlin.DE>
According to Steve Allan <stevea@wrq.com>:
[renaming files to lower case]
> A co-worker and I were coincidentally working on this same problem
> this week. I had initially used
>
> if ( /[A-Z]/ ) {
> rename $_, lc $_ or warn "Failed to rename $_: $!";
> }
>
> but thought it would be more efficient to use a string equality test
> instead of a regex:
>
> my $lcfile = lc $_;
> unless ( $_ eq $lcfile ) {
> rename $_, $lcfile or warn "Failed to rename $_: $!";
> }
>
> Do you think there's any significant difference between the two?
Unlikely. Since IO is in the game, minor savings in CPU usage won't
win much.
Anno
------------------------------
Date: Thu, 11 Oct 2001 13:03:16 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Filename case...
Message-Id: <3BC55244.14B5CDDC@ce.gatech.edu>
just for the sake of options, here is a shell version (one-liner, but
may be wrapped):
for i in `find . -type f`; do L=$i; P=`dirname $i`; B=`basename $i`;
U=`echo $B | tr [:upper:] [:lower:]`; mv $L $P/$U; done
not *thoroughly* tested...and this version will drill down through the
directory tree...the prune option on find will let you fine tune that...
--
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa
------------------------------
Date: 11 Oct 2001 09:29:07 -0700
From: gwebster@ahbl.ca (Greg Webster)
Subject: Getting a list of running programs under Windows2000
Message-Id: <ffcf8756.0110110829.3ca7975b@posting.google.com>
Heya all,
I'm a unix guy so doing perl under Win2k is a bit weird for me.
In Unix, I'd just grep 'ps ax' for what I needed and if a program
wasn't running I'd start it, but I wonder if there is a way for me to
do this under Win2k.
I've got a program that does some funky terminal emulation for an
external program to print to a local printer, and that program keeps
crashing. So what I'd like to do is have a perl script running on this
Win2k box that runs (via some freeware scheduler) once a minute,
checks to see if the terminal emulation program is running and if not,
starts it.
Any ideas on how I'd find out if that terminal emulation program is
running or not?
Thanks,
Greg Webster
------------------------------
Date: 11 Oct 2001 08:06:11 -0700
From: gthorne@bitweever.com (Greg Thorne)
Subject: Re: Keeping an escape code in a line
Message-Id: <9e243fc1.0110110706.37f875b5@posting.google.com>
Ilmari Karonen <iltzu@sci.invalid> wrote in message news:<1002751760.8699@itz.pp.sci.fi>...
> In article <u93d4rl8kh.fsf@wcl-l.bham.ac.uk>, nobull@mail.com wrote:
> >
> >chop ( $_ = eval "<<__EndOfData__\n$_\n__EndOfData__\n" );
> >
> >This assumes that the string does not contain "\n__EndOfData__\n".
> >This is usually a safe assuption.
>
> If it's not, one can always do this:
>
> s/(\\*[\$\@\"])/length($1)%2 ? "\\$1" : $1/eg;
> $_ = eval qq("$_");
I had to stare at this a while, but I finally got it. The left-hand
side is equivalent to:
(\+[$@"])
right?
After messing around with this statement some, I came up with:
s/\\([nrt])/eval qq("\\$1")/eg;
Which doesn't do as much as your code snippet, but suits my needs just
fine.
Thanks for all your help, guys!
------------------------------
Date: 11 Oct 2001 15:01:57 GMT
From: "Bryan K. Wright" <bryan@ayesha.phys.Virginia.EDU>
Subject: Length of last matched substring?
Message-Id: <9q4c95$cv9$1@murdoch.acc.Virginia.EDU>
Hi folks,
I'm trying to come up with a regular expression
involving the length of a previously-matched substring. What
I have in mind is something like this:
$string = "this
---";
undef $/;
$string =~ s/(\w+)\n-{length(\1)}/<u>$1<\/u>/g;
(obviously, this example won't work, since I can't
just insert the length() call in the regular expression, but
you get the idea.)
It seems like there should be some way to get the LENGTH
of the last-matched substring, in addition to its value, but
I haven't found it yet. Any suggestions?
Bryan
--
===============================================================================
Bryan Wright |"If you take cranberries and stew them like
Physics Department | applesauce, they taste much more like prunes
University of Virginia | than rhubarb does." -- Groucho
Charlottesville, VA 22901 |
(434) 924-7218 | bryan@virginia.edu
===============================================================================
------------------------------
Date: 11 Oct 2001 19:27:57 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Length of last matched substring?
Message-Id: <877ku2mc1u.fsf@abra.ru>
>>>>> On 11 Oct 2001 15:01:57 GMT, "Bryan K. Wright" <bryan@ayesha.phys.Virginia.EDU> said:
BKW> Hi folks,
BKW> I'm trying to come up with a regular expression
BKW> involving the length of a previously-matched substring. What
BKW> I have in mind is something like this:
BKW> $string = "this
BKW> ---";
BKW> undef $/;
BKW> $string =~ s/(\w+)\n-{length(\1)}/<u>$1<\/u>/g;
BKW> (obviously, this example won't work, since I can't
BKW> just insert the length() call in the regular expression, but
BKW> you get the idea.)
Actually you can. At least in new Perls.
(untested):
$string =~ s/(\w+)\n -(??{ length($1) }) /<u>$1<\/u>/ge;
Check 'perldoc perlre' for more information about (??{ code })
regexp match pattern.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Thu, 11 Oct 2001 15:35:58 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Length of last matched substring?
Message-Id: <3febstk466cb4jc733itqaq099e0v1df3k@4ax.com>
Bryan K. Wright wrote:
>$string = "this
>---";
>undef $/;
>$string =~ s/(\w+)\n-{length(\1)}/<u>$1<\/u>/g;
>
> (obviously, this example won't work, since I can't
>just insert the length() call in the regular expression, but
>you get the idea.)
>
> It seems like there should be some way to get the LENGTH
>of the last-matched substring, in addition to its value, but
>I haven't found it yet. Any suggestions?
The experimental (?{...}) and (??{...}) things are what you should look
into, plus (?(...)...). Too bad these don't just implement pure code
assertions, although you use them to can emulate those.
/(\w+)\n(-+)(?(?{length $2 < length $1})(?!))/
Be careful: this might give unintuitive results:
$_ = "this\n---";
print /(\w+)\n(-+)(?(?{length $2 < length $1})(?!))/
? "yes: '$1'/'$2'":'no'
-->
yes: 'his'/'---'
Because the first time it fails, this will backtrack and continue
attempting matches in other places. Adding a '\b' before the '\w' would
help, in this case.
--
Bart.
------------------------------
Date: 11 Oct 2001 15:40:37 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Length of last matched substring?
Message-Id: <slrn9sbfbg.g0q.rgarciasuarez@rafael.kazibao.net>
Ilya Martynov wrote in comp.lang.perl.misc:
} >>>>> On 11 Oct 2001 15:01:57 GMT, "Bryan K. Wright" <bryan@ayesha.phys.Virginia.EDU> said:
}
} BKW> Hi folks,
} BKW> I'm trying to come up with a regular expression
} BKW> involving the length of a previously-matched substring. What
} BKW> I have in mind is something like this:
}
} BKW> $string = "this
} BKW> ---";
} BKW> undef $/;
} BKW> $string =~ s/(\w+)\n-{length(\1)}/<u>$1<\/u>/g;
}
} BKW> (obviously, this example won't work, since I can't
} BKW> just insert the length() call in the regular expression, but
} BKW> you get the idea.)
}
} Actually you can. At least in new Perls.
}
} (untested):
}
} $string =~ s/(\w+)\n -(??{ length($1) }) /<u>$1<\/u>/ge;
In fact this doesn't work, as you interpolate the length of $1 into the
regexp, and the OP wants a dash repeated as many times as the length of
the 1st word.
Here's an example that works for me (perl 5.6.1) :
for (qw/foo--- foo---- quux--- quux----/) {
if (/\b(\w+)((??{'-{'.(length $1).'}'}))$/) {
print "$_ matches ($1)($2)\n";
} else {
print "$_ doesn't match\n";
}
}
Outputs :
foo--- matches (foo)(---)
foo---- doesn't match
quux--- doesn't match
quux---- matches (quux)(----)
Note the \b and the $ in the regexp, to avoid counting an incorrect
number of letters or dashes.
The adaptation to the original case is left as an exercise to the
original poster.
Of course it's also possible to do a double test
/\b(\w+)\n(-+)$/ && $2 == length $1
and perform the substitution by hand, probably using substr (as an
lvalue) and values from @+ and @-. (See perlvar for those two special
arrays).
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
Owner: There, he moved!
Customer: No, he didn't, that was you hitting the cage!
-- Monty Python, The Pet Shop
------------------------------
Date: 11 Oct 2001 16:36:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Length of last matched substring?
Message-Id: <9q4hql$6q1$1@mamenchi.zrz.TU-Berlin.DE>
According to Bryan K. Wright <bryan@ayesha.phys.Virginia.EDU>:
> Hi folks,
>
> I'm trying to come up with a regular expression
> involving the length of a previously-matched substring. What
> I have in mind is something like this:
>
> $string = "this
> ---";
> undef $/;
> $string =~ s/(\w+)\n-{length(\1)}/<u>$1<\/u>/g;
>
> (obviously, this example won't work, since I can't
> just insert the length() call in the regular expression, but
> you get the idea.)
>
> It seems like there should be some way to get the LENGTH
> of the last-matched substring, in addition to its value, but
> I haven't found it yet. Any suggestions?
Apparently you want to detect if words in a line are fake-underlined
via "---..." and do some real underlining instead.
Even if you could get at the length of the last match the way you
describe, your regex wouldn't work right. (It would match a word
anywhere, and then look for so many "-" at the beginning of the
next line. I don't think that a single regex can reasonably do what
you want, especially when there can be more than one underlined word
in a line.
I would definitely work on a pair of lines, one containing the
text and the other possible underlines. If you only expect a single
underlined word at the beginning of a line, your approach becomes
feasible. Using two lines lets you access the length from the first
one when you match the other one.
Anno
------------------------------
Date: 11 Oct 2001 16:56:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Length of last matched substring?
Message-Id: <9q4j02$9lm$1@mamenchi.zrz.TU-Berlin.DE>
According to Rafael Garcia-Suarez <rgarciasuarez@free.fr>:
[snip good stuff]
> Of course it's also possible to do a double test
> /\b(\w+)\n(-+)$/ && $2 == length $1
> and perform the substitution by hand, probably using substr (as an
> lvalue) and values from @+ and @-. (See perlvar for those two special
> arrays).
Well, here is an example of how to use them:
use constant UL_ON => '<u>';
use constant UL_OFF => '</u>';
sub underline {
my ( $text, $ul) = @_;
return $text unless $ul =~ /^[- ]*$/;
my ( @ul_start, @ul_end);
while ( $ul =~ /(-+)/g ) {
unshift @ul_start, $-[ 1]; # collect them backwards
unshift @ul_end, $+[ 1];
}
for my $end ( @ul_end ) {
my $start = shift @ul_start;
substr( $text, $end, 0) = UL_OFF;
substr( $text, $start, 0) = UL_ON;
}
$text;
}
underline( $text, $ul) expects a line of text and another line of
blanks and '-', where '-' say the corresponding text should be
underlined.
The first loop collects the places where underlines begin and end.
As usual, when we want to do text substitutions at given positions,
this is best done right to left so as no to upset the given positions.
That's why unshift is used to collect the positions. We use $-[ 1]
and $+[ 1]. @- and @+ hold the position positions of the entire match
on index 0. The positions of $1, $2,... are stored at 1, 2... .
The second loop makes the insertions in a straightforward manner.
Anno
------------------------------
Date: Thu, 11 Oct 2001 08:05:53 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Pattern Matching
Message-Id: <3bc5b555@news.microsoft.com>
"shaz" <ssa1701@yahoo.co.uk> wrote in message
news:23e71812.0110110345.3e70bb6c@posting.google.com...
> > > I want to test for the occurance of a particular string within a hash.
> I want to find the number of times that a substring appears within a
longer string.
> Using the example above:
> If $small = "the"
> it should match "the end" or "the end of" or "end the book" etc BUT NOT
> "then they" or "there is".
Maybe you can try to make up your mind? Now you got three contradictory
specs:
- want to test for the occurence of a string
- want to find the number of times a substring appears in a string
- "the" is not a substring of "then they" (well, it sure is!)
Do you want to match/count whole words only? Then for heavens sake, why
don't you say so (this sounds more and more like school homework).
The easiest way would probably be to split the sentence into an array of
words (see perldoc -f split), grep (see perldoc -f grep) for elements which
are equal to "the", and assign the result to a scalar (to get the number of
words equal to "the").
And still: this has nothing to do with pattern matching.
jue
------------------------------
Date: Thu, 11 Oct 2001 16:49:18 GMT
From: "Mike" <gbeanery@hotmail.com>
Subject: Question about generating HTML from cgi
Message-Id: <i4kx7.200232$w7.32985367@news02.optonline.net>
For starters, I would like to generate a web page from a cgi script using
the 'use CGI.'
How can I do this in CGI without having to reformat everything. There are
html links which mean there are lots of " and slashes, etc etc. I know you
can do the
print "html code here \n";
but is there a way to do something like this?
print
html code
html code
*
*
*
*
html code
;
Thanks so much
------------------------------
Date: Thu, 11 Oct 2001 17:33:16 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: Question about generating HTML from cgi
Message-Id: <Xns91378ACB1BD7Eechangnetstormnet@207.106.92.86>
"Mike" <gbeanery@hotmail.com> wrote in
news:i4kx7.200232$w7.32985367@news02.optonline.net:
> For starters, I would like to generate a web page from a cgi script
> using the 'use CGI.'
>
> How can I do this in CGI without having to reformat everything.
> There are html links which mean there are lots of " and slashes,
> etc etc. I know you can do the
> print "html code here \n";
>
> but is there a way to do something like this?
>
> print
>
> html code
> html code
> *
> *
> *
> *
> html code
>
> ;
You want what is called a "here document." . Following a << you specify
a string to terminate the quoted material, and all lines following the
current line down to the terminating string are the value of the item.
The terminating string must appear by itself (unquoted and with no
surrounding whitespace) on the terminating line.
For example
print <<"ENDHTML";
html code
html code
*
*
*
*
html code
ENDHTML
Do "perldoc perldata" or see
http://perldoc.com/perl5.6.1/pod/perldata.html.
--
EBC
------------------------------
Date: Thu, 11 Oct 2001 16:45:53 GMT
From: "Mike" <gbeanery@hotmail.com>
Subject: Re: Question about tab delimeted text file from Excel
Message-Id: <51kx7.200231$w7.32980544@news02.optonline.net>
Thanks, I will try this.
"S Warhurst" <s.warhurst@rl.ac.uk> wrote in message
news:9q46i3$pf8@newton.cc.rl.ac.uk...
> "Mike" <gbeanery@hotmail.com> wrote in message
> news:K5gx7.198267$w7.32624814@news02.optonline.net...
> > I am tyring to save a tab delimted text file from an Excel database.
The
> > problem is that Excel reformats a lot of the stuff and doesnt leave it
> > alone. Especially when there are quotes, slashes etc etc. So when I
read
> > it from a perl script using the \t for tab delimited, it does not parse
it
> > correctly. The main problem I am having is the links field (html code
> that
> > points to another web site etc), it never displays for some reason.
What
> > can I try? In some cases the link is > 256 chars, so that is why I use
> > excel. Acces cant handle. Thanks
>
> Access can handle >256 characters.. you have to use a "memo" field type.
>
> Spencer
>
>
------------------------------
Date: Thu, 11 Oct 2001 08:09:23 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: sort - only want unique records
Message-Id: <3bc5b626@news.microsoft.com>
"Tim O'Sullivan" <tim.osullivan@cognotec.com> wrote in message
news:40b537f4.0110110255.6a98d403@posting.google.com...
> I'm new to Perl. I'm trying to sort a numerical list and retrieve
> only unique records. Sorting isn't a problem, I use:
>
> sub numerically { $a <=> $b }
> @sortedsessions = sort numerically @sessions;
>
> I cannot find how to retrieve only unique records. Can you help?
See
perldoc -q duplicate
The keyword used to be "unique", unfortunately it has been changed to
"duplicate" some time ago. Maybe that's why you couldn't find the FAQ entry.
jue
------------------------------
Date: 11 Oct 2001 08:29:31 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: Re: sort - only want unique records
Message-Id: <42f3ee2.0110110729.15536c32@posting.google.com>
tim.osullivan@cognotec.com (Tim O'Sullivan) wrote in message news:<40b537f4.0110110255.6a98d403@posting.google.com>...
> Hi,
> I'm new to Perl. I'm trying to sort a numerical list and retrieve
> only unique records. Sorting isn't a problem, I use:
>
> sub numerically { $a <=> $b }
> @sortedsessions = sort numerically @sessions;
>
> I cannot find how to retrieve only unique records. Can you help?
for (@sorted) { $Hash{$_} = "seen" } # duplicates don't add a new key
@unique = keys %Hash;
---
Mario Rizzuti
------------------------------
Date: Thu, 11 Oct 2001 15:08:24 GMT
From: JHM1MAO@leeds.ac.uk (M.A. Oxby)
Subject: Re: Special Pattern Match
Message-Id: <GL1rAH.HsL@leeds.ac.uk>
Thanks to everyone, but I finally got a sensible answer which works, and
thanks to thos who tried to understand me. The answer was
$string=~s#(?<!")((?http:|mailto:)\S+)(?<!")#<A HREF="$1">$1</a>#gi;
I believe I typed that right anyway! I have one further test..I need to do a
similar thing with a pure email. I currently have
$string=~s#(\S+\@\.\S+)(?<!")#<A HREF="mailto:$1">$1</a>#gi;
It works when someone just types an email..ie martin@resource-centre.net (it
turns it into a mailto anchor) but if someone manually types the mailto anchor
(i.e.<A HREF="mailto:martin@resource-centre.net">my email</a>) it mucks
everything up. I tried adding (?<!:) before the first set of () in the
statement, to look for the : of the mailto: bit but that didn't work..any
suggestions anyone?
Thanks,
Martin
P.S. If anyone really wants to know what this is for just ask :P *L*
In article <f02c4576.0110091805.432d6c74@posting.google.com>, ianb@ot.com.au
(Ian Boreham) wrote:
>Laocoon <Laocoon@eudoramail.com> wrote in message
> news:<Xns9135B7D6ED7CCLaocooneudoramailcom@62.153.159.134>...
>
>>JHM1MAO@leeds.ac.uk (M.A. Oxby) wrote in news:GKy3Gr.HpH@leeds.ac.uk:
>>> I might be asking a bit much here, but I need a special pattern
>>> match/substitution and I can't figure it out. I need to match a
>string
>>> that:
>>>
>>> 1. Is NOT surrounded by " " s
>>> 2. Begins with http:// or mailto:
>
>The question as stated is too vague. It doesn't say whether it is
>trying to match it within a larger string, or as a whole string.
>
>>$string =~ m#^[^"]*(?:http://|mailto:)[^"]+$#;
>
>This allows any number of non-quote characters at the start. That is
>not consistent with [2] if we are doing an exact match. If you are
>assuming it is in the context of a larger string, then you are going
>to lose matches in which there are quotes anywhere beforehand in the
>string. In this case, you should use a negative look-behind.
>
>This regex also forces the existence of a non-quote character after
>the prefix, which was not in the specification (although I imagine it
>probably should have been).
>
>It also disallows quotes anywhere in the trailing portion. Since
>e-mail addresses can contain quotes, that may not be valid either.
>
>The question should include a specification of what characters are
>allowed in the trailing portion. A description of the need for the
>match would probably help too. My quess is that the OP wants to match
>URLs in some text and substitute HTML links.
>
>Regards,
>
>
>Ian
- Martin Oxby
Founder and Administrator
[http://www.resource-centre.net]
Web Resources, Free Email, Messaging and Programming Tutorials all under one roof!
------------------------------
Date: Thu, 11 Oct 2001 15:10:46 GMT
From: JHM1MAO@leeds.ac.uk (M.A. Oxby)
Subject: Uploading
Message-Id: <GL1rEJ.I0L@leeds.ac.uk>
I want to add an extention to a web mailling script, but wish to allow for
once attachment. Can anyone point me in the right direction maybe of another
module to do this? I'm using <input type=file name="att"> (obviously!).
Any Offers?
Thanks,
Martin
- Martin Oxby
Founder and Administrator
[http://www.resource-centre.net]
Web Resources, Free Email, Messaging and Programming Tutorials all under one roof!
------------------------------
Date: Thu, 11 Oct 2001 18:08:23 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: Uploading
Message-Id: <3bc5c3f8$1@e-post.inode.at>
M.A. Oxby wrote:
> I want to add an extention to a web mailling script, but wish to allow for
> once attachment. Can anyone point me in the right direction maybe of
> another module to do this? I'm using <input type=file name="att">
> (obviously!). Any Offers?
> Thanks,
>
you may want to use the special file-upload-field which is documented in
any html-reference.
I recommend using the CGI-module (downloadable at www.cpan.org) and looking
for 'upload' in the documentation.
hope this helps,
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Thu, 11 Oct 2001 16:29:02 +0100
From: "nice.guy.nige" <spamfreenation@nigenet.org.uk>
Subject: Re: YOU ARE ALL GAY!
Message-Id: <9q4dro$m0eg7$1@ID-112325.news.dfncis.de>
"Geoffrey Pointer" <geoffrey@bigpond.net.au> wrote in message
news:B7EBA769.82EC%geoffrey@bigpond.net.au...
Hi Geoff,
[...]
> This was a comment about the psychobabble in the original message and not
> its subject.
If that is the case, then it would have been a good idea to include some of
the original message that you were replying to, so the context of the
conversation wouldn't be lost. I have not seen the original message - just
your reply - and as such your post made absolutely no sense whatsoever.
Cheers,
Nige
--
Nigel Moss
Visit me on the webby thing! http://www.nigenet.org.uk
Boycott E$$O!! http://www.stopesso.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 1913
***************************************